mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-18 20:47:51 +00:00
Support bundled ubridge, Ref: #314
This commit is contained in:
parent
c40767879f
commit
b7b2bd4592
@ -11,19 +11,13 @@ const isWin = /^win/.test(process.platform);
|
||||
let runningServers = {};
|
||||
|
||||
exports.getLocalServerPath = async () => {
|
||||
const lookupDirectories = [
|
||||
__dirname,
|
||||
path.dirname(app.getPath('exe'))
|
||||
];
|
||||
let binary = isWin ? 'gns3server.exe': 'gns3server';
|
||||
return findBinary('exe.', binary);
|
||||
}
|
||||
|
||||
for(var directory of lookupDirectories) {
|
||||
const serverPath = await findLocalServerPath(directory);
|
||||
if(serverPath !== undefined) {
|
||||
return serverPath;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
exports.getUbridgePath = async () => {
|
||||
let binary = isWin ? 'ubridge.exe': 'ubridge';
|
||||
return findBinary('ubridge', binary);
|
||||
}
|
||||
|
||||
exports.startLocalServer = async (server) => {
|
||||
@ -44,7 +38,21 @@ exports.stopAllLocalServers = async () => {
|
||||
return await stopAll();
|
||||
}
|
||||
|
||||
async function findLocalServerPath(baseDirectory) {
|
||||
async function findBinary(binaryDirectory, filename) {
|
||||
const lookupDirectories = [
|
||||
__dirname,
|
||||
path.dirname(app.getPath('exe'))
|
||||
];
|
||||
|
||||
for(var directory of lookupDirectories) {
|
||||
const serverPath = await findBinaryInDirectory(directory, binaryDirectory, filename);
|
||||
if(serverPath !== undefined) {
|
||||
return serverPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function findBinaryInDirectory(baseDirectory, binaryDirectory, filename) {
|
||||
const distDirectory = path.join(baseDirectory, 'dist');
|
||||
|
||||
if (!fs.existsSync(distDirectory)) {
|
||||
@ -53,26 +61,22 @@ async function findLocalServerPath(baseDirectory) {
|
||||
|
||||
const files = fs.readdirSync(distDirectory);
|
||||
|
||||
let serverPath = null;
|
||||
let binaryPath = null;
|
||||
|
||||
files.forEach((directory) => {
|
||||
if(directory.startsWith('exe.')) {
|
||||
if (isWin) {
|
||||
serverPath = path.join(baseDirectory, 'dist', directory, 'gns3server.exe');
|
||||
}
|
||||
else {
|
||||
serverPath = path.join(baseDirectory, 'dist', directory, 'gns3server');
|
||||
}
|
||||
if(directory.startsWith(binaryDirectory)) {
|
||||
binaryPath = path.join(baseDirectory, 'dist', directory, filename);
|
||||
}
|
||||
});
|
||||
|
||||
if(serverPath !== null && fs.existsSync(serverPath)) {
|
||||
return serverPath;
|
||||
if(binaryPath !== null && fs.existsSync(binaryPath)) {
|
||||
return binaryPath;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
function getServerArguments(server, overrides, configPath) {
|
||||
let serverArguments = [];
|
||||
if(server.host) {
|
||||
@ -183,6 +187,9 @@ async function configure(configPath, server) {
|
||||
if(server.port) {
|
||||
config.port = server.port;
|
||||
}
|
||||
if(server.ubridge_path) {
|
||||
config.ubridge_path = server.ubridge_path;
|
||||
}
|
||||
|
||||
fs.writeFileSync(configPath, ini.stringify(config, { section: 'Server' }));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ WORKING_DIR = os.path.join(FILE_DIR, 'tmp')
|
||||
SOURCE_ZIP = os.path.join(WORKING_DIR, 'gns3-server.source.zip')
|
||||
SOURCE_DESTINATION = os.path.join(WORKING_DIR, 'source')
|
||||
BINARIES_EXTENSION = platform.system() == "Windows" and ".exe" or ""
|
||||
|
||||
UBRIDGE_VERSION = 'LATEST' # or for eg. 0.9.14
|
||||
|
||||
def download(url, output):
|
||||
print("Downloading {} to {}".format(url, output))
|
||||
@ -88,20 +88,24 @@ def download_dependencies_command(arguments):
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
releases = response.json()
|
||||
last_release = releases[0]
|
||||
|
||||
|
||||
if UBRIDGE_VERSION == 'LATEST':
|
||||
release = releases[0]
|
||||
else:
|
||||
release = list(filter(lambda x: x['tag_name'] == "v{}".format(UBRIDGE_VERSION), releases))[0]
|
||||
|
||||
# on Windows download cygwin1.dll and ubridge.exe
|
||||
if platform.system() == "Windows":
|
||||
ubridge_dir = os.path.join(output_directory, 'ubridge')
|
||||
os.makedirs(ubridge_dir, exist_ok=True)
|
||||
|
||||
cygwin_file = os.path.join(ubridge_dir, 'cygwin1.dll')
|
||||
cygwin_url = list(filter(lambda x: x['name'] == 'cygwin1.dll', last_release['assets']))[0]['url']
|
||||
cygwin_url = list(filter(lambda x: x['name'] == 'cygwin1.dll', release['assets']))[0]['browser_download_url']
|
||||
download(cygwin_url, cygwin_file)
|
||||
print('Downloaded cygwin1.dll to {}'.format(cygwin_file))
|
||||
|
||||
ubridge_file = os.path.join(ubridge_dir, 'ubridge.exe')
|
||||
ubridge_url = list(filter(lambda x: x['name'] == 'ubridge.exe', last_release['assets']))[0]['url']
|
||||
ubridge_url = list(filter(lambda x: x['name'] == 'ubridge.exe', release['assets']))[0]['browser_download_url']
|
||||
download(ubridge_url, ubridge_file)
|
||||
print('Downloaded ubridge.exe to {}'.format(ubridge_file))
|
||||
|
||||
|
@ -16,6 +16,10 @@
|
||||
<input matInput tabindex="1" formControlName="path" placeholder="Local server path" />
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field *ngIf="serverForm.get('location').value === 'local'">
|
||||
<input matInput tabindex="1" formControlName="ubridge_path" placeholder="Ubridge path" />
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<input matInput tabindex="1" formControlName="host" placeholder="Host" />
|
||||
</mat-form-field>
|
||||
|
@ -18,6 +18,7 @@ export class AddServerDialogComponent implements OnInit {
|
||||
'name': new FormControl('', [ Validators.required ]),
|
||||
'location': new FormControl(''),
|
||||
'path': new FormControl(''),
|
||||
'ubridge_path': new FormControl(''),
|
||||
'host': new FormControl('', [ Validators.required ]),
|
||||
'port': new FormControl('', [ Validators.required, Validators.min(1) ]),
|
||||
'authorization': new FormControl('none'),
|
||||
@ -72,24 +73,39 @@ export class AddServerDialogComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
async getDefaultUbridgePath() {
|
||||
if(this.electronService.isElectronApp) {
|
||||
return await this.electronService.remote.require('./local-server.js').getUbridgePath();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
this.locations = await this.getLocations();
|
||||
|
||||
const defaultLocalServerPath = await this.getDefaultLocalServerPath();
|
||||
const defaultUbridgePath = await this.getDefaultUbridgePath();
|
||||
|
||||
this.serverForm.get('location').valueChanges.subscribe((location: string) => {
|
||||
const pathControl = this.serverForm.get('path');
|
||||
const ubridgePathControl = this.serverForm.get('ubridge_path');
|
||||
|
||||
if(location === 'local') {
|
||||
pathControl.setValue(defaultLocalServerPath);
|
||||
pathControl.setValidators([Validators.required]);
|
||||
|
||||
ubridgePathControl.setValue(defaultUbridgePath);
|
||||
ubridgePathControl.setValidators([Validators.required]);
|
||||
}
|
||||
else {
|
||||
pathControl.setValue('');
|
||||
pathControl.clearValidators();
|
||||
|
||||
ubridgePathControl.setValue('');
|
||||
ubridgePathControl.clearValidators();
|
||||
}
|
||||
|
||||
[pathControl].forEach((control) => {
|
||||
[pathControl, ubridgePathControl].forEach((control) => {
|
||||
control.updateValueAndValidity({
|
||||
onlySelf: true
|
||||
});
|
||||
|
@ -9,6 +9,7 @@ export class Server {
|
||||
host: string;
|
||||
port: number;
|
||||
path: string;
|
||||
ubridge_path: string;
|
||||
authorization: ServerAuthorization;
|
||||
login: string;
|
||||
password: string;
|
||||
|
Loading…
Reference in New Issue
Block a user