From 70d3f991ed66d1bb77ac16e168a53fc95704a9df Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sat, 11 Feb 2023 17:57:12 -0500 Subject: [PATCH 01/21] Add welcome.py script from GNS3vm --- scripts/welcome.py | 439 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 439 insertions(+) create mode 100644 scripts/welcome.py diff --git a/scripts/welcome.py b/scripts/welcome.py new file mode 100644 index 00000000..23f101cc --- /dev/null +++ b/scripts/welcome.py @@ -0,0 +1,439 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015 GNS3 Technologies Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import locale +import re +import os +import sys +import time +import subprocess +import configparser +import urllib.request +from dialog import Dialog, PythonDialogBug + +try: + locale.setlocale(locale.LC_ALL, '') +except locale.Error: + # Not supported via SSH + pass + +def get_ip(): + """ + Return the IP of the eth0 + """ + my_ip = subprocess.Popen(['ifconfig eth0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'], stdout=subprocess.PIPE, shell=True) + (IP,errors) = my_ip.communicate() + my_ip.stdout.close() + if len(IP) == 0: + return None + return IP.decode().strip() + + +def get_config(): + """ + Read the config + """ + config = configparser.RawConfigParser() + path = os.path.expanduser("~/.config/GNS3/gns3_server.conf") + config.read([path], encoding="utf-8") + return config + + +def write_config(config): + """ + Write the config file + """ + + with open(os.path.expanduser("~/.config/GNS3/gns3_server.conf"), 'w') as f: + config.write(f) + + +def gns3_major_version(): + """ + Returns the GNS3 major server version + """ + + version = gns3_version() + if version: + match = re.search(r"\d+.\d+", version) + return match.group(0) + return "" + + +def gns3_version(): + """ + Return the GNS3 server version + """ + try: + return subprocess.check_output(["gns3server", "--version"]).strip().decode() + except (subprocess.CalledProcessError, FileNotFoundError): + return None + + +def gns3vm_version(): + """ + Return the GNS3 VM version + """ + with open('/home/gns3/.config/GNS3/gns3vm_version') as f: + return f.read().strip() + + +d = Dialog(dialog="dialog", autowidgetsize=True) +if gns3_version() is None: + d.set_background_title("GNS3") +else: + d.set_background_title("GNS3 {}".format(gns3_version())) + + +def mode(): + if d.yesno("This feature is for testers only. You may break your GNS3 installation. Are you REALLY sure you want to continue?", yes_label="Exit (Safe option)", no_label="Continue") == d.OK: + return + code, tag = d.menu("Select the GNS3 version", + choices=[("2.1", "Stable release for this GNS3 VM (RECOMMENDED)"), + ("2.1dev", "Development version for stable release"), + ("2.2", "Latest stable release")]) + d.clear() + if code == Dialog.OK: + os.makedirs(os.path.expanduser("~/.config/GNS3"), exist_ok=True) + with open(os.path.expanduser("~/.config/GNS3/gns3_release"), "w+") as f: + f.write(tag) + + update(force=True) + + +def get_release(): + try: + with open(os.path.expanduser("~/.config/GNS3/gns3_release")) as f: + content = f.read() + + # Support old VM versions + if content == "stable": + content = "1.5" + elif content == "testing": + content = "1.5" + elif content == "unstable": + content = "1.5dev" + + return content + except OSError: + return "1.5" + + +def update(force=False): + if not force: + if d.yesno("PLEASE SNAPSHOT THE VM BEFORE RUNNING THE UPGRADE IN CASE OF FAILURE. The server will reboot at the end of the upgrade process. Continue?") != d.OK: + return + release = get_release() + if release == "2.2": + if d.yesno("It is recommended to run GNS3 version 2.2 with lastest GNS3 VM based on Ubuntu 18.04 LTS, please download this VM from our website or continue at your own risk!") != d.OK: + return + if release.endswith("dev"): + ret = os.system("curl -Lk https://raw.githubusercontent.com/GNS3/gns3-vm/unstable/scripts/update_{}.sh > /tmp/update.sh && bash -x /tmp/update.sh".format(release)) + else: + ret = os.system("curl -Lk https://raw.githubusercontent.com/GNS3/gns3-vm/master/scripts/update_{}.sh > /tmp/update.sh && bash -x /tmp/update.sh".format(release)) + if ret != 0: + print("ERROR DURING UPGRADE PROCESS PLEASE TAKE A SCREENSHOT IF YOU NEED SUPPORT") + time.sleep(15) + + +def migrate(): + """ + Migrate GNS3 VM data. + """ + + code, option = d.menu("Select an option", + choices=[("Setup", "Configure this VM to send data to another GNS3 VM"), + ("Send", "Send images and projects to another GNS3 VM")]) + d.clear() + if code == Dialog.OK: + (answer, destination) = d.inputbox("What is IP address or hostname of the other GNS3 VM?", init="172.16.1.128") + if answer != d.OK: + return + if destination == get_ip(): + d.msgbox("The destination cannot be the same as this VM IP address ({})".format(destination)) + return + if option == "Send": + # first make sure they are no files belonging to root + os.system("sudo chown -R gns3:gns3 /opt/gns3") + # then rsync the data + command = r"rsync -az --progress -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /home/gns3/.ssh/gns3-vm-key' /opt/gns3 gns3@{}:/opt".format(destination) + ret = os.system('bash -c "{}"'.format(command)) + time.sleep(10) + if ret != 0: + d.msgbox("Could not send data to the other GNS3 VM located at {}".format(destination)) + else: + d.msgbox("Images and projects have been successfully sent to the other GNS3 VM located at {}".format(destination)) + elif option == "Setup": + script = """ +if [ ! -f ~/.ssh/gns3-vm-key ] +then + ssh-keygen -f ~/.ssh/gns3-vm-key -N '' -C gns3@{} +fi +ssh-copy-id -i ~/.ssh/gns3-vm-key gns3@{} +""".format(get_ip(), destination) + ret = os.system('bash -c "{}"'.format(script)) + time.sleep(10) + if ret != 0: + d.msgbox("Error while setting up the migrate feature") + else: + d.msgbox("Configuration successful, you can now send data to the GNS3 VM located at {} without password".format(destination)) + + +def shrink_disk(): + + ret = os.system("lspci | grep -i vmware") + if ret != 0: + d.msgbox("Shrinking the disk is only supported when running inside VMware") + return + + if d.yesno("Would you like to shrink the VM disk? The VM will reboot at the end of the process. Continue?") != d.OK: + return + + os.system("sudo service gns3 stop") + os.system("sudo service docker stop") + os.system("sudo vmware-toolbox-cmd disk shrink /opt") + os.system("sudo vmware-toolbox-cmd disk shrink /") + + d.msgbox("The GNS3 VM will reboot") + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + +def vm_information(): + """ + Show IP, SSH settings.... + """ + + content = "Welcome to GNS3 appliance\n\n" + + version = gns3_version() + if version is None: + content += "GNS3 is not installed please install it with sudo pip3 install gns3-server. Or download a preinstalled VM.\n\n" + else: + content = "GNS3 version: {gns3_version}\nVM version: {gns3vm_version}\nKVM support available: {kvm}\n\n".format( + gns3vm_version=gns3vm_version(), + gns3_version=version, + kvm=kvm_support()) + + ip = get_ip() + + if ip: + content += "IP: {ip}\n\nTo log in using SSH:\nssh gns3@{ip}\nPassword: gns3\n\nImages and projects are located in /opt/gns3""".format(ip=ip) + else: + content += "eth0 is not configured. Please manually configure it via the Networking menu." + + content += "\n\nRelease channel: " + get_release() + + try: + d.msgbox(content) + # If it's an scp command or any bugs + except: + os.execvp("bash", ['/bin/bash']) + + +def check_internet_connectivity(): + d.pause("Please wait...\n\n") + try: + response = urllib.request.urlopen('http://pypi.python.org/', timeout=5) + except urllib.request.URLError as err: + d.infobox("Can't connect to Internet (pypi.python.org): {}".format(str(err))) + time.sleep(15) + return + d.infobox("Connection to Internet: OK") + time.sleep(2) + + +def keyboard_configuration(): + """ + Allow user to change the keyboard layout + """ + os.system("/usr/bin/sudo dpkg-reconfigure keyboard-configuration") + + +def set_security(): + config = get_config() + if d.yesno("Enable server authentication?") == d.OK: + if not config.has_section("Server"): + config.add_section("Server") + config.set("Server", "auth", True) + (answer, text) = d.inputbox("Login?") + if answer != d.OK: + return + config.set("Server", "user", text) + (answer, text) = d.passwordbox("Password?") + if answer != d.OK: + return + config.set("Server", "password", text) + else: + config.set("Server", "auth", False) + + write_config(config) + + +def log(): + os.system("/usr/bin/sudo chmod 755 /var/log/upstart/gns3.log") + with open("/var/log/upstart/gns3.log") as f: + try: + while True: + line = f.readline() + sys.stdout.write(line) + except (KeyboardInterrupt, MemoryError): + return + + +def edit_config(): + """ + Edit GNS3 configuration file + """ + + major_version = gns3_major_version() + if major_version == "2.2": + os.system("nano ~/.config/GNS3/{}/gns3_server.conf".format(major_version)) + else: + os.system("nano ~/.config/GNS3/gns3_server.conf") + + +def edit_network(): + """ + Edit network configuration file + """ + if d.yesno("The server will reboot at the end of the process. Continue?") != d.OK: + return + os.system("sudo nano /etc/network/interfaces") + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + + +def edit_proxy(): + """ + Configure proxy settings + """ + res, http_proxy = d.inputbox(text="HTTP proxy string, for example http://:@:. Leave empty for no proxy.") + if res != d.OK: + return + res, https_proxy = d.inputbox(text="HTTPS proxy string, for example http://:@:. Leave empty for no proxy.") + if res != d.OK: + return + + with open('/tmp/00proxy', 'w+') as f: + f.write('Acquire::http::Proxy "' + http_proxy + '";') + os.system("sudo mv /tmp/00proxy /etc/apt/apt.conf.d/00proxy") + os.system("sudo chown root /etc/apt/apt.conf.d/00proxy") + os.system("sudo chmod 744 /etc/apt/apt.conf.d/00proxy") + + with open('/tmp/proxy.sh', 'w+') as f: + f.write('export http_proxy="' + http_proxy + '"\n') + f.write('export https_proxy="' + https_proxy + '"\n') + f.write('export HTTP_PROXY="' + http_proxy + '"\n') + f.write('export HTTPS_PROXY="' + https_proxy + '"\n') + os.system("sudo mv /tmp/proxy.sh /etc/profile.d/proxy.sh") + os.system("sudo chown root /etc/profile.d/proxy.sh") + os.system("sudo chmod 744 /etc/profile.d/proxy.sh") + os.system("sudo cp /etc/profile.d/proxy.sh /etc/default/docker") + + d.msgbox("The GNS3 VM will reboot") + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + + +def kvm_support(): + """ + Returns true if KVM is available + """ + return subprocess.call("kvm-ok") == 0 + + +def kvm_control(): + """ + Check if KVM is correctly configured + """ + + kvm_ok = kvm_support() + config = get_config() + try: + if config.getboolean("Qemu", "enable_kvm") is True: + if kvm_ok is False: + if d.yesno("KVM is not available!\n\nQemu VM will crash!!\n\nThe reason could be unsupported hardware or another virtualization solution is already running.\n\nDisable KVM and get lower performances?") == d.OK: + config.set("Qemu", "enable_kvm", False) + write_config(config) + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + else: + if kvm_ok is True: + if d.yesno("KVM is available on your computer.\n\nEnable KVM and get better performances?") == d.OK: + config.set("Qemu", "enable_kvm", True) + write_config(config) + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + except configparser.NoSectionError: + return + + +vm_information() +kvm_control() + + +try: + while True: + code, tag = d.menu("GNS3 {}".format(gns3_version()), + choices=[("Information", "Display VM information"), + ("Upgrade", "Upgrade GNS3"), + ("Migrate", "Migrate data to another GNS3 VM"), + ("Shell", "Open a console"), + ("Security", "Configure authentication"), + ("Keyboard", "Change keyboard layout"), + ("Configure", "Edit server configuration (advanced users ONLY)"), + ("Proxy", "Configure proxy settings"), + ("Networking", "Configure networking settings"), + ("Log", "Show server log"), + ("Test", "Check internet connection"), + ("Shrink", "Shrink the VM disk"), + ("Version", "Select the GNS3 version"), + ("Restore", "Restore the VM (if you have trouble for upgrade)"), + ("Reboot", "Reboot the VM"), + ("Shutdown", "Shutdown the VM")]) + d.clear() + if code == Dialog.OK: + if tag == "Shell": + os.execvp("bash", ['/bin/bash']) + elif tag == "Version": + mode() + elif tag == "Restore": + os.execvp("sudo", ['/usr/bin/sudo', "/usr/local/bin/gns3restore"]) + elif tag == "Reboot": + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + elif tag == "Shutdown": + os.execvp("sudo", ['/usr/bin/sudo', "poweroff"]) + elif tag == "Upgrade": + update() + elif tag == "Information": + vm_information() + elif tag == "Log": + log() + elif tag == "Migrate": + migrate() + elif tag == "Configure": + edit_config() + elif tag == "Networking": + edit_network() + elif tag == "Security": + set_security() + elif tag == "Keyboard": + keyboard_configuration() + elif tag == "Test": + check_internet_connectivity() + elif tag == "Proxy": + edit_proxy() + elif tag == "Shrink": + shrink_disk() +except KeyboardInterrupt: + sys.exit(0) \ No newline at end of file From 2eca92e34d02cf241f34a2a18006338a3bb4719b Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sat, 11 Feb 2023 18:05:03 -0500 Subject: [PATCH 02/21] The legacy get_ip function no longer worked on new versions of ubuntu LTS. --- scripts/welcome.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/scripts/welcome.py b/scripts/welcome.py index 23f101cc..ae9be436 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -23,6 +23,7 @@ import sys import time import subprocess import configparser +from json import loads as convert import urllib.request from dialog import Dialog, PythonDialogBug @@ -34,14 +35,27 @@ except locale.Error: def get_ip(): """ - Return the IP of the eth0 + Return the active IP """ - my_ip = subprocess.Popen(['ifconfig eth0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'], stdout=subprocess.PIPE, shell=True) - (IP,errors) = my_ip.communicate() - my_ip.stdout.close() - if len(IP) == 0: - return None - return IP.decode().strip() + #request 'ip addr' data in JSON format from shell + ip_addr_response = subprocess.run(['ip', '--json', 'addr'],capture_output=True) + + #process response, decode and use json.loads to convert the string to a dict + ip_addr_data = convert(ip_addr_response.stdout.decode("utf-8")) + + #search ip_addr_data for the first ip adress that is not under a virtual bridge or loopback interface + for i in ip_addr_data: + if ('virbr' in i['ifname']) or ('lo' in i['ifname']): + continue + try: + if 'UP' in i['flags']: + ip_addr = i['addr_info'][0]['local'] + break + except: + continue + ip_addr = None + + return ip_addr def get_config(): From bf5970b904b4feae6f773627924a593877e5ea5e Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sat, 11 Feb 2023 19:57:54 -0500 Subject: [PATCH 03/21] Update install and welcome to support running it --- scripts/remote-install.sh | 30 +++++++++++++++++++++++++++++- scripts/welcome.py | 6 ++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index 5c20c3a6..a60cb4b5 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -26,6 +26,7 @@ function help { echo "--with-openvpn: Install OpenVPN" >&2 echo "--with-iou: Install IOU" >&2 echo "--with-i386-repository: Add the i386 repositories required by IOU if they are not already available on the system. Warning: this will replace your source.list in order to use the official Ubuntu mirror" >&2 + echo "--with-welcome: Install GNS3-VM welcome.py script" >&2 echo "--without-kvm: Disable KVM, required if system do not support it (limitation in some hypervisors and cloud providers). Warning: only disable KVM if strictly necessary as this will degrade performance" >&2 echo "--unstable: Use the GNS3 unstable repository" echo "--help: This help" >&2 @@ -49,7 +50,7 @@ I386_REPO=0 DISABLE_KVM=0 UNSTABLE=0 -TEMP=`getopt -o h --long with-openvpn,with-iou,with-i386-repository,without-kvm,unstable,help -n 'gns3-remote-install.sh' -- "$@"` +TEMP=`getopt -o h --long with-openvpn,with-iou,with-i386-repository,with-welcome,without-kvm,unstable,help -n 'gns3-remote-install.sh' -- "$@"` if [ $? != 0 ] then help @@ -72,6 +73,10 @@ while true ; do I386_REPO=1 shift ;; + --with-welcome) + WELCOME_SETUP=1 + shift + ;; --without-kvm) DISABLE_KVM=1 shift @@ -296,6 +301,29 @@ fi log "GNS3 installed with success" +if [ $WELCOME_SETUP == 1 ] +then +apt-get install -y net-tools +NEEDRESTART_MODE=a apt-get install -y python3-pip +NEEDRESTART_MODE=a pip install --no-input --upgrade pip +NEEDRESTART_MODE=a pip install --no-input pythondialog + +curl https://raw.githubusercontent.com/Xatrekak/gns3-server/master/scripts/welcome.py > /usr/local/bin/welcome.sh + +mkdir /etc/systemd/system/getty@tty1.service.d +cat < /etc/systemd/system/getty@tty1.service.d/override.conf +[Service] +ExecStart= +ExecStart=-/sbin/agetty -a gns3 --noclear %I \$TERM +EOFI + +chmod 755 /etc/systemd/system/getty@tty1.service.d/override.conf +chown root:root /etc/systemd/system/getty@tty1.service.d/override.conf + +echo "python3 welcome.py" >> /opt/gns3/.bashrc + +fi + if [ $USE_VPN == 1 ] then log "Setup VPN" diff --git a/scripts/welcome.py b/scripts/welcome.py index ae9be436..f69c2f5e 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -57,6 +57,10 @@ def get_ip(): return ip_addr +def repair_remote_install(): + ip_addr = get_ip() + subprocess.run(["sed", "-i", f"'s/host = 0.0.0.0/host = {ip_addr}/'", "/etc/gns3/gns3_server.conf"],capture_output=False) + def get_config(): """ @@ -449,5 +453,7 @@ try: edit_proxy() elif tag == "Shrink": shrink_disk() + elif tag == "Repair": + repair_remote_install() except KeyboardInterrupt: sys.exit(0) \ No newline at end of file From 7689b7841f29c1017d7fa0009917f5afee3be2f6 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sat, 11 Feb 2023 21:00:37 -0500 Subject: [PATCH 04/21] switched to modifed welcome by and full path to it --- scripts/remote-install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index a60cb4b5..7bd9a490 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -308,7 +308,10 @@ NEEDRESTART_MODE=a apt-get install -y python3-pip NEEDRESTART_MODE=a pip install --no-input --upgrade pip NEEDRESTART_MODE=a pip install --no-input pythondialog -curl https://raw.githubusercontent.com/Xatrekak/gns3-server/master/scripts/welcome.py > /usr/local/bin/welcome.sh +curl https://raw.githubusercontent.com/Xatrekak/gns3-server/remote_install_changes/scripts/welcome.py > /usr/local/bin/welcome.sh + +chmod 755 /usr/local/bin/welcome.sh +chown gns3:gns3 /usr/local/bin/welcome.sh mkdir /etc/systemd/system/getty@tty1.service.d cat < /etc/systemd/system/getty@tty1.service.d/override.conf @@ -320,7 +323,7 @@ EOFI chmod 755 /etc/systemd/system/getty@tty1.service.d/override.conf chown root:root /etc/systemd/system/getty@tty1.service.d/override.conf -echo "python3 welcome.py" >> /opt/gns3/.bashrc +echo "python3 /usr/local/bin/welcome.sh" >> /opt/gns3/.bashrc fi From 3b0336bd7ea64a74a0688ffe5e9c6087576be496 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sat, 11 Feb 2023 22:23:45 -0500 Subject: [PATCH 05/21] fixed typo --- scripts/remote-install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index 7bd9a490..cab68c1c 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -308,10 +308,10 @@ NEEDRESTART_MODE=a apt-get install -y python3-pip NEEDRESTART_MODE=a pip install --no-input --upgrade pip NEEDRESTART_MODE=a pip install --no-input pythondialog -curl https://raw.githubusercontent.com/Xatrekak/gns3-server/remote_install_changes/scripts/welcome.py > /usr/local/bin/welcome.sh +curl https://raw.githubusercontent.com/Xatrekak/gns3-server/remote_install_changes/scripts/welcome.py > /usr/local/bin/welcome.py -chmod 755 /usr/local/bin/welcome.sh -chown gns3:gns3 /usr/local/bin/welcome.sh +chmod 755 /usr/local/bin/welcome.py +chown gns3:gns3 /usr/local/bin/welcome.py mkdir /etc/systemd/system/getty@tty1.service.d cat < /etc/systemd/system/getty@tty1.service.d/override.conf @@ -323,7 +323,7 @@ EOFI chmod 755 /etc/systemd/system/getty@tty1.service.d/override.conf chown root:root /etc/systemd/system/getty@tty1.service.d/override.conf -echo "python3 /usr/local/bin/welcome.sh" >> /opt/gns3/.bashrc +echo "python3 /usr/local/bin/welcome.py" >> /opt/gns3/.bashrc fi From 952b4e72499fd519dcbf0d71eb519e6084c5b2a0 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sat, 11 Feb 2023 23:24:23 -0500 Subject: [PATCH 06/21] fixed some shell bugs --- scripts/remote-install.sh | 10 ++++++---- scripts/welcome.py | 7 +++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index cab68c1c..85c16414 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -164,7 +164,7 @@ apt-get install -y gns3-server log "Create user GNS3 with /opt/gns3 as home directory" if [ ! -d "/opt/gns3/" ] then - useradd -d /opt/gns3/ -m gns3 + useradd -m -d /opt/gns3/ gns3 fi @@ -303,10 +303,11 @@ log "GNS3 installed with success" if [ $WELCOME_SETUP == 1 ] then -apt-get install -y net-tools +NEEDRESTART_MODE=a apt-get install -y net-tools NEEDRESTART_MODE=a apt-get install -y python3-pip -NEEDRESTART_MODE=a pip install --no-input --upgrade pip -NEEDRESTART_MODE=a pip install --no-input pythondialog +NEEDRESTART_MODE=a apt-get install -y dialog +pip install --no-input --upgrade pip +pip install --no-input pythondialog curl https://raw.githubusercontent.com/Xatrekak/gns3-server/remote_install_changes/scripts/welcome.py > /usr/local/bin/welcome.py @@ -324,6 +325,7 @@ chmod 755 /etc/systemd/system/getty@tty1.service.d/override.conf chown root:root /etc/systemd/system/getty@tty1.service.d/override.conf echo "python3 /usr/local/bin/welcome.py" >> /opt/gns3/.bashrc +usermod --shell /bin/bash gns3 fi diff --git a/scripts/welcome.py b/scripts/welcome.py index f69c2f5e..993bd2e5 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -107,8 +107,11 @@ def gns3vm_version(): """ Return the GNS3 VM version """ - with open('/home/gns3/.config/GNS3/gns3vm_version') as f: - return f.read().strip() + try: + with open('/home/gns3/.config/GNS3/gns3vm_version') as f: + return f.read().strip() + except FileNotFoundError: + return "Remote Install" d = Dialog(dialog="dialog", autowidgetsize=True) From e44999f588f3e354b1f48af448214fc8f9795d2f Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 02:07:18 -0500 Subject: [PATCH 07/21] Refactored welcome.py to use a class so its functions would be callable by remote-install.sh. This ensure the setup uses the same IP address that will be displayed by Dialog. --- scripts/remote-install.sh | 6 + scripts/welcome.py | 837 +++++++++++++++++++------------------- 2 files changed, 428 insertions(+), 415 deletions(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index 85c16414..8cf1506d 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -450,3 +450,9 @@ service gns3 start log "Download http://$MY_IP_ADDR:8003/$UUID/$HOSTNAME.ovpn to setup your OpenVPN client after rebooting the server" fi + +if [ $WELCOME_SETUP == 1 ] +then +python3 -c 'import sys; sys.path.append("/usr/local/bin/"); import welcome; ws = welcome.Welcome_dialog(); ws.repair_remote_install()' +su gns3 & cd ~ +fi \ No newline at end of file diff --git a/scripts/welcome.py b/scripts/welcome.py index 993bd2e5..e78e9be3 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -27,436 +27,443 @@ from json import loads as convert import urllib.request from dialog import Dialog, PythonDialogBug -try: - locale.setlocale(locale.LC_ALL, '') -except locale.Error: - # Not supported via SSH - pass -def get_ip(): - """ - Return the active IP - """ - #request 'ip addr' data in JSON format from shell - ip_addr_response = subprocess.run(['ip', '--json', 'addr'],capture_output=True) - - #process response, decode and use json.loads to convert the string to a dict - ip_addr_data = convert(ip_addr_response.stdout.decode("utf-8")) - - #search ip_addr_data for the first ip adress that is not under a virtual bridge or loopback interface - for i in ip_addr_data: - if ('virbr' in i['ifname']) or ('lo' in i['ifname']): - continue +class Welcome_dialog(): + def __init__(self): try: - if 'UP' in i['flags']: - ip_addr = i['addr_info'][0]['local'] - break + locale.setlocale(locale.LC_ALL, '') + except locale.Error: + # Not supported via SSH + pass + self.d = Dialog(dialog="dialog", autowidgetsize=True) + if self.gns3_version() is None: + self.d.set_background_title("GNS3") + else: + self.d.set_background_title("GNS3 {}".format(self.gns3_version())) + + def get_ip(self): + """ + Return the active IP + """ + #request 'ip addr' data in JSON format from shell + ip_addr_response = subprocess.run(['ip', '--json', 'addr'],capture_output=True) + + #process response, decode and use json.loads to convert the string to a dict + ip_addr_data = convert(ip_addr_response.stdout.decode("utf-8")) + + #search ip_addr_data for the first ip adress that is not under a virtual bridge or loopback interface + for i in ip_addr_data: + if ('virbr' in i['ifname']) or ('lo' in i['ifname']): + continue + try: + if 'UP' in i['flags']: + ip_addr = i['addr_info'][0]['local'] + break + except: + continue + ip_addr = None + + return ip_addr + + def repair_remote_install(self): + """ + This method is only called by remote-install.sh during setup to ensure it is setting the same IP as shown by Dialog + """ + ip_addr = self.get_ip() + subprocess.run(["sed", "-i", f"s/host = 0.0.0.0/host = {ip_addr}/", "/etc/gns3/gns3_server.conf"],capture_output=False) + subprocess.run(["service", "gns3", "stop"],capture_output=False) + subprocess.run(["service", "gns3", "start"],capture_output=False) + + + def get_config(self): + """ + Read the config + """ + config = configparser.RawConfigParser() + path = os.path.expanduser("~/.config/GNS3/gns3_server.conf") + config.read([path], encoding="utf-8") + return config + + + def write_config(self, config): + """ + Write the config file + """ + + with open(os.path.expanduser("~/.config/GNS3/gns3_server.conf"), 'w') as f: + config.write(f) + + + def gns3_major_version(self): + """ + Returns the GNS3 major server version + """ + + version = self.gns3_version() + if version: + match = re.search(r"\d+.\d+", version) + return match.group(0) + return "" + + + def gns3_version(self): + """ + Return the GNS3 server version + """ + try: + return subprocess.check_output(["gns3server", "--version"]).strip().decode() + except (subprocess.CalledProcessError, FileNotFoundError): + return None + + + def gns3vm_version(self): + """ + Return the GNS3 VM version + """ + try: + with open('/home/gns3/.config/GNS3/gns3vm_version') as f: + return f.read().strip() + except FileNotFoundError: + return "Remote Install" + + + def mode(self): + if self.d.yesno("This feature is for testers only. You may break your GNS3 installation. Are you REALLY sure you want to continue?", yes_label="Exit (Safe option)", no_label="Continue") == self.d.OK: + return + code, tag = self.d.menu("Select the GNS3 version", + choices=[("2.1", "Stable release for this GNS3 VM (RECOMMENDED)"), + ("2.1dev", "Development version for stable release"), + ("2.2", "Latest stable release")]) + self.d.clear() + if code == Dialog.OK: + os.makedirs(os.path.expanduser("~/.config/GNS3"), exist_ok=True) + with open(os.path.expanduser("~/.config/GNS3/gns3_release"), "w+") as f: + f.write(tag) + + self.update(force=True) + + + def get_release(): + try: + with open(os.path.expanduser("~/.config/GNS3/gns3_release")) as f: + content = f.read() + + # Support old VM versions + if content == "stable": + content = "1.5" + elif content == "testing": + content = "1.5" + elif content == "unstable": + content = "1.5dev" + + return content + except OSError: + return "1.5" + + + def update(self, force=False): + if not force: + if self.d.yesno("PLEASE SNAPSHOT THE VM BEFORE RUNNING THE UPGRADE IN CASE OF FAILURE. The server will reboot at the end of the upgrade process. Continue?") != self.d.OK: + return + release = self.get_release() + if release == "2.2": + if self.d.yesno("It is recommended to run GNS3 version 2.2 with lastest GNS3 VM based on Ubuntu 18.04 LTS, please download this VM from our website or continue at your own risk!") != self.d.OK: + return + if release.endswith("dev"): + ret = os.system("curl -Lk https://raw.githubusercontent.com/GNS3/gns3-vm/unstable/scripts/update_{}.sh > /tmp/update.sh && bash -x /tmp/update.sh".format(release)) + else: + ret = os.system("curl -Lk https://raw.githubusercontent.com/GNS3/gns3-vm/master/scripts/update_{}.sh > /tmp/update.sh && bash -x /tmp/update.sh".format(release)) + if ret != 0: + print("ERROR DURING UPGRADE PROCESS PLEASE TAKE A SCREENSHOT IF YOU NEED SUPPORT") + time.sleep(15) + + + def migrate(self): + """ + Migrate GNS3 VM data. + """ + + code, option = self.d.menu("Select an option", + choices=[("Setup", "Configure this VM to send data to another GNS3 VM"), + ("Send", "Send images and projects to another GNS3 VM")]) + self.d.clear() + if code == Dialog.OK: + (answer, destination) = self.d.inputbox("What is IP address or hostname of the other GNS3 VM?", init="172.16.1.128") + if answer != self.d.OK: + return + if destination == self.get_ip(): + self.d.msgbox("The destination cannot be the same as this VM IP address ({})".format(destination)) + return + if option == "Send": + # first make sure they are no files belonging to root + os.system("sudo chown -R gns3:gns3 /opt/gns3") + # then rsync the data + command = r"rsync -az --progress -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /home/gns3/.ssh/gns3-vm-key' /opt/gns3 gns3@{}:/opt".format(destination) + ret = os.system('bash -c "{}"'.format(command)) + time.sleep(10) + if ret != 0: + self.d.msgbox("Could not send data to the other GNS3 VM located at {}".format(destination)) + else: + self.d.msgbox("Images and projects have been successfully sent to the other GNS3 VM located at {}".format(destination)) + elif option == "Setup": + script = """ + if [ ! -f ~/.ssh/gns3-vm-key ] + then + ssh-keygen -f ~/.ssh/gns3-vm-key -N '' -C gns3@{} + fi + ssh-copy-id -i ~/.ssh/gns3-vm-key gns3@{} + """.format(self.get_ip(), destination) + ret = os.system('bash -c "{}"'.format(script)) + time.sleep(10) + if ret != 0: + self.d.msgbox("Error while setting up the migrate feature") + else: + self.d.msgbox("Configuration successful, you can now send data to the GNS3 VM located at {} without password".format(destination)) + + + def shrink_disk(self): + + ret = os.system("lspci | grep -i vmware") + if ret != 0: + self.d.msgbox("Shrinking the disk is only supported when running inside VMware") + return + + if self.d.yesno("Would you like to shrink the VM disk? The VM will reboot at the end of the process. Continue?") != self.d.OK: + return + + os.system("sudo service gns3 stop") + os.system("sudo service docker stop") + os.system("sudo vmware-toolbox-cmd disk shrink /opt") + os.system("sudo vmware-toolbox-cmd disk shrink /") + + self.d.msgbox("The GNS3 VM will reboot") + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + + def vm_information(self): + """ + Show IP, SSH settings.... + """ + + content = "Welcome to GNS3 appliance\n\n" + + version = self.gns3_version() + if version is None: + content += "GNS3 is not installed please install it with sudo pip3 install gns3-server. Or download a preinstalled VM.\n\n" + else: + content = "GNS3 version: {gns3_version}\nVM version: {gns3vm_version}\nKVM support available: {kvm}\n\n".format( + gns3vm_version=self.gns3vm_version(), + gns3_version=version, + kvm=self.kvm_support()) + + ip = self.get_ip() + + if ip: + content += "IP: {ip}\n\nTo log in using SSH:\nssh gns3@{ip}\nPassword: gns3\n\nImages and projects are located in /opt/gns3""".format(ip=ip) + else: + content += "eth0 is not configured. Please manually configure it via the Networking menu." + + content += "\n\nRelease channel: " + self.get_release() + + try: + self.d.msgbox(content) + # If it's an scp command or any bugs except: - continue - ip_addr = None - - return ip_addr - -def repair_remote_install(): - ip_addr = get_ip() - subprocess.run(["sed", "-i", f"'s/host = 0.0.0.0/host = {ip_addr}/'", "/etc/gns3/gns3_server.conf"],capture_output=False) + os.execvp("bash", ['/bin/bash']) -def get_config(): - """ - Read the config - """ - config = configparser.RawConfigParser() - path = os.path.expanduser("~/.config/GNS3/gns3_server.conf") - config.read([path], encoding="utf-8") - return config - - -def write_config(config): - """ - Write the config file - """ - - with open(os.path.expanduser("~/.config/GNS3/gns3_server.conf"), 'w') as f: - config.write(f) - - -def gns3_major_version(): - """ - Returns the GNS3 major server version - """ - - version = gns3_version() - if version: - match = re.search(r"\d+.\d+", version) - return match.group(0) - return "" - - -def gns3_version(): - """ - Return the GNS3 server version - """ - try: - return subprocess.check_output(["gns3server", "--version"]).strip().decode() - except (subprocess.CalledProcessError, FileNotFoundError): - return None - - -def gns3vm_version(): - """ - Return the GNS3 VM version - """ - try: - with open('/home/gns3/.config/GNS3/gns3vm_version') as f: - return f.read().strip() - except FileNotFoundError: - return "Remote Install" - - -d = Dialog(dialog="dialog", autowidgetsize=True) -if gns3_version() is None: - d.set_background_title("GNS3") -else: - d.set_background_title("GNS3 {}".format(gns3_version())) - - -def mode(): - if d.yesno("This feature is for testers only. You may break your GNS3 installation. Are you REALLY sure you want to continue?", yes_label="Exit (Safe option)", no_label="Continue") == d.OK: - return - code, tag = d.menu("Select the GNS3 version", - choices=[("2.1", "Stable release for this GNS3 VM (RECOMMENDED)"), - ("2.1dev", "Development version for stable release"), - ("2.2", "Latest stable release")]) - d.clear() - if code == Dialog.OK: - os.makedirs(os.path.expanduser("~/.config/GNS3"), exist_ok=True) - with open(os.path.expanduser("~/.config/GNS3/gns3_release"), "w+") as f: - f.write(tag) - - update(force=True) - - -def get_release(): - try: - with open(os.path.expanduser("~/.config/GNS3/gns3_release")) as f: - content = f.read() - - # Support old VM versions - if content == "stable": - content = "1.5" - elif content == "testing": - content = "1.5" - elif content == "unstable": - content = "1.5dev" - - return content - except OSError: - return "1.5" - - -def update(force=False): - if not force: - if d.yesno("PLEASE SNAPSHOT THE VM BEFORE RUNNING THE UPGRADE IN CASE OF FAILURE. The server will reboot at the end of the upgrade process. Continue?") != d.OK: + def check_internet_connectivity(self): + self.d.pause("Please wait...\n\n") + try: + response = urllib.request.urlopen('http://pypi.python.org/', timeout=5) + except urllib.request.URLError as err: + self.d.infobox("Can't connect to Internet (pypi.python.org): {}".format(str(err))) + time.sleep(15) return - release = get_release() - if release == "2.2": - if d.yesno("It is recommended to run GNS3 version 2.2 with lastest GNS3 VM based on Ubuntu 18.04 LTS, please download this VM from our website or continue at your own risk!") != d.OK: - return - if release.endswith("dev"): - ret = os.system("curl -Lk https://raw.githubusercontent.com/GNS3/gns3-vm/unstable/scripts/update_{}.sh > /tmp/update.sh && bash -x /tmp/update.sh".format(release)) - else: - ret = os.system("curl -Lk https://raw.githubusercontent.com/GNS3/gns3-vm/master/scripts/update_{}.sh > /tmp/update.sh && bash -x /tmp/update.sh".format(release)) - if ret != 0: - print("ERROR DURING UPGRADE PROCESS PLEASE TAKE A SCREENSHOT IF YOU NEED SUPPORT") - time.sleep(15) + self.d.infobox("Connection to Internet: OK") + time.sleep(2) -def migrate(): - """ - Migrate GNS3 VM data. - """ + def keyboard_configuration(): + """ + Allow user to change the keyboard layout + """ + os.system("/usr/bin/sudo dpkg-reconfigure keyboard-configuration") - code, option = d.menu("Select an option", - choices=[("Setup", "Configure this VM to send data to another GNS3 VM"), - ("Send", "Send images and projects to another GNS3 VM")]) - d.clear() - if code == Dialog.OK: - (answer, destination) = d.inputbox("What is IP address or hostname of the other GNS3 VM?", init="172.16.1.128") - if answer != d.OK: + + def set_security(self): + config = self.get_config() + if self.d.yesno("Enable server authentication?") == self.d.OK: + if not config.has_section("Server"): + config.add_section("Server") + config.set("Server", "auth", True) + (answer, text) = self.d.inputbox("Login?") + if answer != self.d.OK: + return + config.set("Server", "user", text) + (answer, text) = self.d.passwordbox("Password?") + if answer != self.d.OK: + return + config.set("Server", "password", text) + else: + config.set("Server", "auth", False) + + self.write_config(config) + + + def log(self): + os.system("/usr/bin/sudo chmod 755 /var/log/upstart/gns3.log") + with open("/var/log/upstart/gns3.log") as f: + try: + while True: + line = f.readline() + sys.stdout.write(line) + except (KeyboardInterrupt, MemoryError): + return + + + def edit_config(self): + """ + Edit GNS3 configuration file + """ + + major_version = self.gns3_major_version() + if major_version == "2.2": + os.system("nano ~/.config/GNS3/{}/gns3_server.conf".format(major_version)) + else: + os.system("nano ~/.config/GNS3/gns3_server.conf") + + + def edit_network(self): + """ + Edit network configuration file + """ + if self.d.yesno("The server will reboot at the end of the process. Continue?") != self.d.OK: return - if destination == get_ip(): - d.msgbox("The destination cannot be the same as this VM IP address ({})".format(destination)) + os.system("sudo nano /etc/network/interfaces") + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + + + def edit_proxy(self): + """ + Configure proxy settings + """ + res, http_proxy = self.d.inputbox(text="HTTP proxy string, for example http://:@:. Leave empty for no proxy.") + if res != self.d.OK: return - if option == "Send": - # first make sure they are no files belonging to root - os.system("sudo chown -R gns3:gns3 /opt/gns3") - # then rsync the data - command = r"rsync -az --progress -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /home/gns3/.ssh/gns3-vm-key' /opt/gns3 gns3@{}:/opt".format(destination) - ret = os.system('bash -c "{}"'.format(command)) - time.sleep(10) - if ret != 0: - d.msgbox("Could not send data to the other GNS3 VM located at {}".format(destination)) + res, https_proxy = self.d.inputbox(text="HTTPS proxy string, for example http://:@:. Leave empty for no proxy.") + if res != self.d.OK: + return + + with open('/tmp/00proxy', 'w+') as f: + f.write('Acquire::http::Proxy "' + http_proxy + '";') + os.system("sudo mv /tmp/00proxy /etc/apt/apt.conf.d/00proxy") + os.system("sudo chown root /etc/apt/apt.conf.d/00proxy") + os.system("sudo chmod 744 /etc/apt/apt.conf.d/00proxy") + + with open('/tmp/proxy.sh', 'w+') as f: + f.write('export http_proxy="' + http_proxy + '"\n') + f.write('export https_proxy="' + https_proxy + '"\n') + f.write('export HTTP_PROXY="' + http_proxy + '"\n') + f.write('export HTTPS_PROXY="' + https_proxy + '"\n') + os.system("sudo mv /tmp/proxy.sh /etc/profile.d/proxy.sh") + os.system("sudo chown root /etc/profile.d/proxy.sh") + os.system("sudo chmod 744 /etc/profile.d/proxy.sh") + os.system("sudo cp /etc/profile.d/proxy.sh /etc/default/docker") + + self.d.msgbox("The GNS3 VM will reboot") + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + + + def kvm_support(self): + """ + Returns true if KVM is available + """ + return subprocess.call("kvm-ok") == 0 + + + def kvm_control(self): + """ + Check if KVM is correctly configured + """ + + kvm_ok = self.kvm_support() + config = self.get_config() + try: + if config.getboolean("Qemu", "enable_kvm") is True: + if kvm_ok is False: + if self.d.yesno("KVM is not available!\n\nQemu VM will crash!!\n\nThe reason could be unsupported hardware or another virtualization solution is already running.\n\nDisable KVM and get lower performances?") == self.d.OK: + config.set("Qemu", "enable_kvm", False) + self.write_config(config) + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) else: - d.msgbox("Images and projects have been successfully sent to the other GNS3 VM located at {}".format(destination)) - elif option == "Setup": - script = """ -if [ ! -f ~/.ssh/gns3-vm-key ] -then - ssh-keygen -f ~/.ssh/gns3-vm-key -N '' -C gns3@{} -fi -ssh-copy-id -i ~/.ssh/gns3-vm-key gns3@{} -""".format(get_ip(), destination) - ret = os.system('bash -c "{}"'.format(script)) - time.sleep(10) - if ret != 0: - d.msgbox("Error while setting up the migrate feature") - else: - d.msgbox("Configuration successful, you can now send data to the GNS3 VM located at {} without password".format(destination)) - - -def shrink_disk(): - - ret = os.system("lspci | grep -i vmware") - if ret != 0: - d.msgbox("Shrinking the disk is only supported when running inside VMware") - return - - if d.yesno("Would you like to shrink the VM disk? The VM will reboot at the end of the process. Continue?") != d.OK: - return - - os.system("sudo service gns3 stop") - os.system("sudo service docker stop") - os.system("sudo vmware-toolbox-cmd disk shrink /opt") - os.system("sudo vmware-toolbox-cmd disk shrink /") - - d.msgbox("The GNS3 VM will reboot") - os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) - -def vm_information(): - """ - Show IP, SSH settings.... - """ - - content = "Welcome to GNS3 appliance\n\n" - - version = gns3_version() - if version is None: - content += "GNS3 is not installed please install it with sudo pip3 install gns3-server. Or download a preinstalled VM.\n\n" - else: - content = "GNS3 version: {gns3_version}\nVM version: {gns3vm_version}\nKVM support available: {kvm}\n\n".format( - gns3vm_version=gns3vm_version(), - gns3_version=version, - kvm=kvm_support()) - - ip = get_ip() - - if ip: - content += "IP: {ip}\n\nTo log in using SSH:\nssh gns3@{ip}\nPassword: gns3\n\nImages and projects are located in /opt/gns3""".format(ip=ip) - else: - content += "eth0 is not configured. Please manually configure it via the Networking menu." - - content += "\n\nRelease channel: " + get_release() - - try: - d.msgbox(content) - # If it's an scp command or any bugs - except: - os.execvp("bash", ['/bin/bash']) - - -def check_internet_connectivity(): - d.pause("Please wait...\n\n") - try: - response = urllib.request.urlopen('http://pypi.python.org/', timeout=5) - except urllib.request.URLError as err: - d.infobox("Can't connect to Internet (pypi.python.org): {}".format(str(err))) - time.sleep(15) - return - d.infobox("Connection to Internet: OK") - time.sleep(2) - - -def keyboard_configuration(): - """ - Allow user to change the keyboard layout - """ - os.system("/usr/bin/sudo dpkg-reconfigure keyboard-configuration") - - -def set_security(): - config = get_config() - if d.yesno("Enable server authentication?") == d.OK: - if not config.has_section("Server"): - config.add_section("Server") - config.set("Server", "auth", True) - (answer, text) = d.inputbox("Login?") - if answer != d.OK: + if kvm_ok is True: + if self.d.yesno("KVM is available on your computer.\n\nEnable KVM and get better performances?") == self.d.OK: + config.set("Qemu", "enable_kvm", True) + self.write_config(config) + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + except configparser.NoSectionError: return - config.set("Server", "user", text) - (answer, text) = d.passwordbox("Password?") - if answer != d.OK: - return - config.set("Server", "password", text) - else: - config.set("Server", "auth", False) - - write_config(config) -def log(): - os.system("/usr/bin/sudo chmod 755 /var/log/upstart/gns3.log") - with open("/var/log/upstart/gns3.log") as f: + def display_loop(self): try: while True: - line = f.readline() - sys.stdout.write(line) - except (KeyboardInterrupt, MemoryError): - return + code, tag = self.d.menu("GNS3 {}".format(self.gns3_version()), + choices=[("Information", "Display VM information"), + ("Upgrade", "Upgrade GNS3"), + ("Migrate", "Migrate data to another GNS3 VM"), + ("Shell", "Open a console"), + ("Security", "Configure authentication"), + ("Keyboard", "Change keyboard layout"), + ("Configure", "Edit server configuration (advanced users ONLY)"), + ("Proxy", "Configure proxy settings"), + ("Networking", "Configure networking settings"), + ("Log", "Show server log"), + ("Test", "Check internet connection"), + ("Shrink", "Shrink the VM disk"), + ("Version", "Select the GNS3 version"), + ("Restore", "Restore the VM (if you have trouble for upgrade)"), + ("Reboot", "Reboot the VM"), + ("Shutdown", "Shutdown the VM")]) + self.d.clear() + if code == Dialog.OK: + if tag == "Shell": + os.execvp("bash", ['/bin/bash']) + elif tag == "Version": + self.mode() + elif tag == "Restore": + os.execvp("sudo", ['/usr/bin/sudo', "/usr/local/bin/gns3restore"]) + elif tag == "Reboot": + os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) + elif tag == "Shutdown": + os.execvp("sudo", ['/usr/bin/sudo', "poweroff"]) + elif tag == "Upgrade": + self.update() + elif tag == "Information": + self.vm_information() + elif tag == "Log": + self.log() + elif tag == "Migrate": + self.migrate() + elif tag == "Configure": + self.edit_config() + elif tag == "Networking": + self.edit_network() + elif tag == "Security": + self.set_security() + elif tag == "Keyboard": + self.keyboard_configuration() + elif tag == "Test": + self.check_internet_connectivity() + elif tag == "Proxy": + self.edit_proxy() + elif tag == "Shrink": + self.shrink_disk() + except KeyboardInterrupt: + sys.exit(0) - -def edit_config(): - """ - Edit GNS3 configuration file - """ - - major_version = gns3_major_version() - if major_version == "2.2": - os.system("nano ~/.config/GNS3/{}/gns3_server.conf".format(major_version)) - else: - os.system("nano ~/.config/GNS3/gns3_server.conf") - - -def edit_network(): - """ - Edit network configuration file - """ - if d.yesno("The server will reboot at the end of the process. Continue?") != d.OK: - return - os.system("sudo nano /etc/network/interfaces") - os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) - - -def edit_proxy(): - """ - Configure proxy settings - """ - res, http_proxy = d.inputbox(text="HTTP proxy string, for example http://:@:. Leave empty for no proxy.") - if res != d.OK: - return - res, https_proxy = d.inputbox(text="HTTPS proxy string, for example http://:@:. Leave empty for no proxy.") - if res != d.OK: - return - - with open('/tmp/00proxy', 'w+') as f: - f.write('Acquire::http::Proxy "' + http_proxy + '";') - os.system("sudo mv /tmp/00proxy /etc/apt/apt.conf.d/00proxy") - os.system("sudo chown root /etc/apt/apt.conf.d/00proxy") - os.system("sudo chmod 744 /etc/apt/apt.conf.d/00proxy") - - with open('/tmp/proxy.sh', 'w+') as f: - f.write('export http_proxy="' + http_proxy + '"\n') - f.write('export https_proxy="' + https_proxy + '"\n') - f.write('export HTTP_PROXY="' + http_proxy + '"\n') - f.write('export HTTPS_PROXY="' + https_proxy + '"\n') - os.system("sudo mv /tmp/proxy.sh /etc/profile.d/proxy.sh") - os.system("sudo chown root /etc/profile.d/proxy.sh") - os.system("sudo chmod 744 /etc/profile.d/proxy.sh") - os.system("sudo cp /etc/profile.d/proxy.sh /etc/default/docker") - - d.msgbox("The GNS3 VM will reboot") - os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) - - -def kvm_support(): - """ - Returns true if KVM is available - """ - return subprocess.call("kvm-ok") == 0 - - -def kvm_control(): - """ - Check if KVM is correctly configured - """ - - kvm_ok = kvm_support() - config = get_config() - try: - if config.getboolean("Qemu", "enable_kvm") is True: - if kvm_ok is False: - if d.yesno("KVM is not available!\n\nQemu VM will crash!!\n\nThe reason could be unsupported hardware or another virtualization solution is already running.\n\nDisable KVM and get lower performances?") == d.OK: - config.set("Qemu", "enable_kvm", False) - write_config(config) - os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) - else: - if kvm_ok is True: - if d.yesno("KVM is available on your computer.\n\nEnable KVM and get better performances?") == d.OK: - config.set("Qemu", "enable_kvm", True) - write_config(config) - os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) - except configparser.NoSectionError: - return - - -vm_information() -kvm_control() - - -try: - while True: - code, tag = d.menu("GNS3 {}".format(gns3_version()), - choices=[("Information", "Display VM information"), - ("Upgrade", "Upgrade GNS3"), - ("Migrate", "Migrate data to another GNS3 VM"), - ("Shell", "Open a console"), - ("Security", "Configure authentication"), - ("Keyboard", "Change keyboard layout"), - ("Configure", "Edit server configuration (advanced users ONLY)"), - ("Proxy", "Configure proxy settings"), - ("Networking", "Configure networking settings"), - ("Log", "Show server log"), - ("Test", "Check internet connection"), - ("Shrink", "Shrink the VM disk"), - ("Version", "Select the GNS3 version"), - ("Restore", "Restore the VM (if you have trouble for upgrade)"), - ("Reboot", "Reboot the VM"), - ("Shutdown", "Shutdown the VM")]) - d.clear() - if code == Dialog.OK: - if tag == "Shell": - os.execvp("bash", ['/bin/bash']) - elif tag == "Version": - mode() - elif tag == "Restore": - os.execvp("sudo", ['/usr/bin/sudo', "/usr/local/bin/gns3restore"]) - elif tag == "Reboot": - os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) - elif tag == "Shutdown": - os.execvp("sudo", ['/usr/bin/sudo', "poweroff"]) - elif tag == "Upgrade": - update() - elif tag == "Information": - vm_information() - elif tag == "Log": - log() - elif tag == "Migrate": - migrate() - elif tag == "Configure": - edit_config() - elif tag == "Networking": - edit_network() - elif tag == "Security": - set_security() - elif tag == "Keyboard": - keyboard_configuration() - elif tag == "Test": - check_internet_connectivity() - elif tag == "Proxy": - edit_proxy() - elif tag == "Shrink": - shrink_disk() - elif tag == "Repair": - repair_remote_install() -except KeyboardInterrupt: - sys.exit(0) \ No newline at end of file +if __name__ == "__main__": + ws = Welcome_dialog() + ws.vm_information() + ws.kvm_control() + ws.display_loop() \ No newline at end of file From ac042b02c4cc38dc9c58c15a2ae72df2061a10c3 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 02:30:28 -0500 Subject: [PATCH 08/21] changes self.d to self.display so it would be more intuitive. --- scripts/welcome.py | 78 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/scripts/welcome.py b/scripts/welcome.py index e78e9be3..ac64d0ca 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -35,11 +35,11 @@ class Welcome_dialog(): except locale.Error: # Not supported via SSH pass - self.d = Dialog(dialog="dialog", autowidgetsize=True) + self.display = Dialog(dialog="dialog", autowidgetsize=True) if self.gns3_version() is None: - self.d.set_background_title("GNS3") + self.display.set_background_title("GNS3") else: - self.d.set_background_title("GNS3 {}".format(self.gns3_version())) + self.display.set_background_title("GNS3 {}".format(self.gns3_version())) def get_ip(self): """ @@ -128,13 +128,13 @@ class Welcome_dialog(): def mode(self): - if self.d.yesno("This feature is for testers only. You may break your GNS3 installation. Are you REALLY sure you want to continue?", yes_label="Exit (Safe option)", no_label="Continue") == self.d.OK: + if self.display.yesno("This feature is for testers only. You may break your GNS3 installation. Are you REALLY sure you want to continue?", yes_label="Exit (Safe option)", no_label="Continue") == self.display.OK: return - code, tag = self.d.menu("Select the GNS3 version", + code, tag = self.display.menu("Select the GNS3 version", choices=[("2.1", "Stable release for this GNS3 VM (RECOMMENDED)"), ("2.1dev", "Development version for stable release"), ("2.2", "Latest stable release")]) - self.d.clear() + self.display.clear() if code == Dialog.OK: os.makedirs(os.path.expanduser("~/.config/GNS3"), exist_ok=True) with open(os.path.expanduser("~/.config/GNS3/gns3_release"), "w+") as f: @@ -163,11 +163,11 @@ class Welcome_dialog(): def update(self, force=False): if not force: - if self.d.yesno("PLEASE SNAPSHOT THE VM BEFORE RUNNING THE UPGRADE IN CASE OF FAILURE. The server will reboot at the end of the upgrade process. Continue?") != self.d.OK: + if self.display.yesno("PLEASE SNAPSHOT THE VM BEFORE RUNNING THE UPGRADE IN CASE OF FAILURE. The server will reboot at the end of the upgrade process. Continue?") != self.display.OK: return release = self.get_release() if release == "2.2": - if self.d.yesno("It is recommended to run GNS3 version 2.2 with lastest GNS3 VM based on Ubuntu 18.04 LTS, please download this VM from our website or continue at your own risk!") != self.d.OK: + if self.display.yesno("It is recommended to run GNS3 version 2.2 with lastest GNS3 VM based on Ubuntu 18.04 LTS, please download this VM from our website or continue at your own risk!") != self.display.OK: return if release.endswith("dev"): ret = os.system("curl -Lk https://raw.githubusercontent.com/GNS3/gns3-vm/unstable/scripts/update_{}.sh > /tmp/update.sh && bash -x /tmp/update.sh".format(release)) @@ -183,16 +183,16 @@ class Welcome_dialog(): Migrate GNS3 VM data. """ - code, option = self.d.menu("Select an option", + code, option = self.display.menu("Select an option", choices=[("Setup", "Configure this VM to send data to another GNS3 VM"), ("Send", "Send images and projects to another GNS3 VM")]) - self.d.clear() + self.display.clear() if code == Dialog.OK: - (answer, destination) = self.d.inputbox("What is IP address or hostname of the other GNS3 VM?", init="172.16.1.128") - if answer != self.d.OK: + (answer, destination) = self.display.inputbox("What is IP address or hostname of the other GNS3 VM?", init="172.16.1.128") + if answer != self.display.OK: return if destination == self.get_ip(): - self.d.msgbox("The destination cannot be the same as this VM IP address ({})".format(destination)) + self.display.msgbox("The destination cannot be the same as this VM IP address ({})".format(destination)) return if option == "Send": # first make sure they are no files belonging to root @@ -202,9 +202,9 @@ class Welcome_dialog(): ret = os.system('bash -c "{}"'.format(command)) time.sleep(10) if ret != 0: - self.d.msgbox("Could not send data to the other GNS3 VM located at {}".format(destination)) + self.display.msgbox("Could not send data to the other GNS3 VM located at {}".format(destination)) else: - self.d.msgbox("Images and projects have been successfully sent to the other GNS3 VM located at {}".format(destination)) + self.display.msgbox("Images and projects have been successfully sent to the other GNS3 VM located at {}".format(destination)) elif option == "Setup": script = """ if [ ! -f ~/.ssh/gns3-vm-key ] @@ -216,19 +216,19 @@ class Welcome_dialog(): ret = os.system('bash -c "{}"'.format(script)) time.sleep(10) if ret != 0: - self.d.msgbox("Error while setting up the migrate feature") + self.display.msgbox("Error while setting up the migrate feature") else: - self.d.msgbox("Configuration successful, you can now send data to the GNS3 VM located at {} without password".format(destination)) + self.display.msgbox("Configuration successful, you can now send data to the GNS3 VM located at {} without password".format(destination)) def shrink_disk(self): ret = os.system("lspci | grep -i vmware") if ret != 0: - self.d.msgbox("Shrinking the disk is only supported when running inside VMware") + self.display.msgbox("Shrinking the disk is only supported when running inside VMware") return - if self.d.yesno("Would you like to shrink the VM disk? The VM will reboot at the end of the process. Continue?") != self.d.OK: + if self.display.yesno("Would you like to shrink the VM disk? The VM will reboot at the end of the process. Continue?") != self.display.OK: return os.system("sudo service gns3 stop") @@ -236,7 +236,7 @@ class Welcome_dialog(): os.system("sudo vmware-toolbox-cmd disk shrink /opt") os.system("sudo vmware-toolbox-cmd disk shrink /") - self.d.msgbox("The GNS3 VM will reboot") + self.display.msgbox("The GNS3 VM will reboot") os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) def vm_information(self): @@ -265,21 +265,21 @@ class Welcome_dialog(): content += "\n\nRelease channel: " + self.get_release() try: - self.d.msgbox(content) + self.display.msgbox(content) # If it's an scp command or any bugs except: os.execvp("bash", ['/bin/bash']) def check_internet_connectivity(self): - self.d.pause("Please wait...\n\n") + self.display.pause("Please wait...\n\n") try: response = urllib.request.urlopen('http://pypi.python.org/', timeout=5) except urllib.request.URLError as err: - self.d.infobox("Can't connect to Internet (pypi.python.org): {}".format(str(err))) + self.display.infobox("Can't connect to Internet (pypi.python.org): {}".format(str(err))) time.sleep(15) return - self.d.infobox("Connection to Internet: OK") + self.display.infobox("Connection to Internet: OK") time.sleep(2) @@ -292,16 +292,16 @@ class Welcome_dialog(): def set_security(self): config = self.get_config() - if self.d.yesno("Enable server authentication?") == self.d.OK: + if self.display.yesno("Enable server authentication?") == self.display.OK: if not config.has_section("Server"): config.add_section("Server") config.set("Server", "auth", True) - (answer, text) = self.d.inputbox("Login?") - if answer != self.d.OK: + (answer, text) = self.display.inputbox("Login?") + if answer != self.display.OK: return config.set("Server", "user", text) - (answer, text) = self.d.passwordbox("Password?") - if answer != self.d.OK: + (answer, text) = self.display.passwordbox("Password?") + if answer != self.display.OK: return config.set("Server", "password", text) else: @@ -337,7 +337,7 @@ class Welcome_dialog(): """ Edit network configuration file """ - if self.d.yesno("The server will reboot at the end of the process. Continue?") != self.d.OK: + if self.display.yesno("The server will reboot at the end of the process. Continue?") != self.display.OK: return os.system("sudo nano /etc/network/interfaces") os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) @@ -347,11 +347,11 @@ class Welcome_dialog(): """ Configure proxy settings """ - res, http_proxy = self.d.inputbox(text="HTTP proxy string, for example http://:@:. Leave empty for no proxy.") - if res != self.d.OK: + res, http_proxy = self.display.inputbox(text="HTTP proxy string, for example http://:@:. Leave empty for no proxy.") + if res != self.display.OK: return - res, https_proxy = self.d.inputbox(text="HTTPS proxy string, for example http://:@:. Leave empty for no proxy.") - if res != self.d.OK: + res, https_proxy = self.display.inputbox(text="HTTPS proxy string, for example http://:@:. Leave empty for no proxy.") + if res != self.display.OK: return with open('/tmp/00proxy', 'w+') as f: @@ -370,7 +370,7 @@ class Welcome_dialog(): os.system("sudo chmod 744 /etc/profile.d/proxy.sh") os.system("sudo cp /etc/profile.d/proxy.sh /etc/default/docker") - self.d.msgbox("The GNS3 VM will reboot") + self.display.msgbox("The GNS3 VM will reboot") os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) @@ -391,13 +391,13 @@ class Welcome_dialog(): try: if config.getboolean("Qemu", "enable_kvm") is True: if kvm_ok is False: - if self.d.yesno("KVM is not available!\n\nQemu VM will crash!!\n\nThe reason could be unsupported hardware or another virtualization solution is already running.\n\nDisable KVM and get lower performances?") == self.d.OK: + if self.display.yesno("KVM is not available!\n\nQemu VM will crash!!\n\nThe reason could be unsupported hardware or another virtualization solution is already running.\n\nDisable KVM and get lower performances?") == self.display.OK: config.set("Qemu", "enable_kvm", False) self.write_config(config) os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) else: if kvm_ok is True: - if self.d.yesno("KVM is available on your computer.\n\nEnable KVM and get better performances?") == self.d.OK: + if self.display.yesno("KVM is available on your computer.\n\nEnable KVM and get better performances?") == self.display.OK: config.set("Qemu", "enable_kvm", True) self.write_config(config) os.execvp("sudo", ['/usr/bin/sudo', "reboot"]) @@ -408,7 +408,7 @@ class Welcome_dialog(): def display_loop(self): try: while True: - code, tag = self.d.menu("GNS3 {}".format(self.gns3_version()), + code, tag = self.display.menu("GNS3 {}".format(self.gns3_version()), choices=[("Information", "Display VM information"), ("Upgrade", "Upgrade GNS3"), ("Migrate", "Migrate data to another GNS3 VM"), @@ -425,7 +425,7 @@ class Welcome_dialog(): ("Restore", "Restore the VM (if you have trouble for upgrade)"), ("Reboot", "Reboot the VM"), ("Shutdown", "Shutdown the VM")]) - self.d.clear() + self.display.clear() if code == Dialog.OK: if tag == "Shell": os.execvp("bash", ['/bin/bash']) From fbe10360c23f4646b3de1cda6bf5cdb1278954d0 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 02:44:15 -0500 Subject: [PATCH 09/21] Finished gns3 user setup --- scripts/remote-install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index 8cf1506d..8a74de51 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -325,7 +325,9 @@ chmod 755 /etc/systemd/system/getty@tty1.service.d/override.conf chown root:root /etc/systemd/system/getty@tty1.service.d/override.conf echo "python3 /usr/local/bin/welcome.py" >> /opt/gns3/.bashrc +echo "gns3" | passwd gns3 --stdin usermod --shell /bin/bash gns3 +usermod -aG sudo username fi @@ -454,5 +456,6 @@ fi if [ $WELCOME_SETUP == 1 ] then python3 -c 'import sys; sys.path.append("/usr/local/bin/"); import welcome; ws = welcome.Welcome_dialog(); ws.repair_remote_install()' -su gns3 & cd ~ +cd /opt/gns3 +su gns3 fi \ No newline at end of file From 290df5290ac73bf791af612a101e701f5e68b5a6 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 02:48:17 -0500 Subject: [PATCH 10/21] fixed transcription --- scripts/remote-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index 8a74de51..f784757c 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -327,7 +327,7 @@ chown root:root /etc/systemd/system/getty@tty1.service.d/override.conf echo "python3 /usr/local/bin/welcome.py" >> /opt/gns3/.bashrc echo "gns3" | passwd gns3 --stdin usermod --shell /bin/bash gns3 -usermod -aG sudo username +usermod -aG sudo gns3 fi From 19a8d1caed31f7d666b9df8d743d112eaf7eef37 Mon Sep 17 00:00:00 2001 From: Dustin Date: Sun, 12 Feb 2023 12:59:06 -0500 Subject: [PATCH 11/21] Update welcome.py --- scripts/welcome.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/welcome.py b/scripts/welcome.py index ac64d0ca..612bab27 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -28,7 +28,7 @@ import urllib.request from dialog import Dialog, PythonDialogBug -class Welcome_dialog(): +class Welcome_dialog: def __init__(self): try: locale.setlocale(locale.LC_ALL, '') @@ -466,4 +466,4 @@ if __name__ == "__main__": ws = Welcome_dialog() ws.vm_information() ws.kvm_control() - ws.display_loop() \ No newline at end of file + ws.display_loop() From 13df828ca709f24c56815dc805aa298ddf7e38c3 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 13:12:20 -0500 Subject: [PATCH 12/21] switched to a direct link to the latest commit instead of the branch alias to bypass github raw caching issues. --- scripts/remote-install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index f784757c..8fdf6efe 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -309,7 +309,8 @@ NEEDRESTART_MODE=a apt-get install -y dialog pip install --no-input --upgrade pip pip install --no-input pythondialog -curl https://raw.githubusercontent.com/Xatrekak/gns3-server/remote_install_changes/scripts/welcome.py > /usr/local/bin/welcome.py +#using a direct link to the latest commit instead of the branch alias to bypass github raw caching issues. +curl https://raw.githubusercontent.com/Xatrekak/gns3-server/19a8d1caed31f7d666b9df8d743d112eaf7eef37/scripts/welcome.py > /usr/local/bin/welcome.py chmod 755 /usr/local/bin/welcome.py chown gns3:gns3 /usr/local/bin/welcome.py From 42a5f1956e3aa2be58276e6b5411688f9378b588 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 14:21:01 -0500 Subject: [PATCH 13/21] Changed mechanism used to set gns3 user password that works on all shells. --- scripts/remote-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index 8fdf6efe..61c2e179 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -326,7 +326,7 @@ chmod 755 /etc/systemd/system/getty@tty1.service.d/override.conf chown root:root /etc/systemd/system/getty@tty1.service.d/override.conf echo "python3 /usr/local/bin/welcome.py" >> /opt/gns3/.bashrc -echo "gns3" | passwd gns3 --stdin +echo "gns3:gns3" | chpasswd usermod --shell /bin/bash gns3 usermod -aG sudo gns3 From f98a60fc74cfbf40e7cf26064d9f6568b78ed3ae Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 14:42:53 -0500 Subject: [PATCH 14/21] added an OS update to end when using welcome option --- scripts/remote-install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index 61c2e179..ff222700 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -456,6 +456,8 @@ fi if [ $WELCOME_SETUP == 1 ] then +NEEDRESTART_MODE=a apt-get update +NEEDRESTART_MODE=a apt-get upgrade python3 -c 'import sys; sys.path.append("/usr/local/bin/"); import welcome; ws = welcome.Welcome_dialog(); ws.repair_remote_install()' cd /opt/gns3 su gns3 From 62c2ca9be1d73ccbdcc076508f6d1bb32353fad0 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 17:20:25 -0500 Subject: [PATCH 15/21] Added Web UI to Dialog --- scripts/welcome.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/welcome.py b/scripts/welcome.py index 612bab27..821e4f97 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -143,7 +143,7 @@ class Welcome_dialog: self.update(force=True) - def get_release(): + def get_release(self): try: with open(os.path.expanduser("~/.config/GNS3/gns3_release")) as f: content = f.read() @@ -258,7 +258,17 @@ class Welcome_dialog: ip = self.get_ip() if ip: - content += "IP: {ip}\n\nTo log in using SSH:\nssh gns3@{ip}\nPassword: gns3\n\nImages and projects are located in /opt/gns3""".format(ip=ip) + content += f""" +IP: {ip} +Web UI: http://{ip}:3080 + +To log in using SSH: +ssh gns3@{ip} +Password: gns3 + +Images and projects are located in /opt/gns3 +""".strip() + else: content += "eth0 is not configured. Please manually configure it via the Networking menu." From fac224ac485929cbf9649b1f6e321baaa732119b Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 17:26:53 -0500 Subject: [PATCH 16/21] Updated to latest welcome.py commit. Raw cache still bugged --- scripts/remote-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index ff222700..3e3b6d72 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -310,7 +310,7 @@ pip install --no-input --upgrade pip pip install --no-input pythondialog #using a direct link to the latest commit instead of the branch alias to bypass github raw caching issues. -curl https://raw.githubusercontent.com/Xatrekak/gns3-server/19a8d1caed31f7d666b9df8d743d112eaf7eef37/scripts/welcome.py > /usr/local/bin/welcome.py +curl https://raw.githubusercontent.com/Xatrekak/gns3-server/62c2ca9be1d73ccbdcc076508f6d1bb32353fad0/scripts/welcome.py > /usr/local/bin/welcome.py chmod 755 /usr/local/bin/welcome.py chown gns3:gns3 /usr/local/bin/welcome.py From e257fb425edabd61f800fd881ce91cb8eb83aad3 Mon Sep 17 00:00:00 2001 From: Xatrekak Date: Sun, 12 Feb 2023 18:30:01 -0500 Subject: [PATCH 17/21] This commit is stacked and assumes welcome.py has already been merged into the GNS3 master repo --- scripts/remote-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index 3e3b6d72..750b6c0d 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -309,8 +309,8 @@ NEEDRESTART_MODE=a apt-get install -y dialog pip install --no-input --upgrade pip pip install --no-input pythondialog -#using a direct link to the latest commit instead of the branch alias to bypass github raw caching issues. -curl https://raw.githubusercontent.com/Xatrekak/gns3-server/62c2ca9be1d73ccbdcc076508f6d1bb32353fad0/scripts/welcome.py > /usr/local/bin/welcome.py +#Pull down welcome script from repo +curl https://raw.githubusercontent.com/GNS3/gns3-server/master/scripts/welcome.py > /usr/local/bin/welcome.py chmod 755 /usr/local/bin/welcome.py chown gns3:gns3 /usr/local/bin/welcome.py From 791ce6a56e5f17ec09ea9c89fe908f9efb02267f Mon Sep 17 00:00:00 2001 From: eantowne Date: Thu, 23 Mar 2023 07:59:20 -0400 Subject: [PATCH 18/21] Added declaration for in remote-install.sh to resolve 'unary operator operator expected' error --- scripts/remote-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/remote-install.sh b/scripts/remote-install.sh index 750b6c0d..4664cd04 100644 --- a/scripts/remote-install.sh +++ b/scripts/remote-install.sh @@ -49,6 +49,7 @@ USE_IOU=0 I386_REPO=0 DISABLE_KVM=0 UNSTABLE=0 +WELCOME_SETUP=0 TEMP=`getopt -o h --long with-openvpn,with-iou,with-i386-repository,with-welcome,without-kvm,unstable,help -n 'gns3-remote-install.sh' -- "$@"` if [ $? != 0 ] From a0943b0b5a89ba785e27b472233a8a772001f20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=81astawiecki?= Date: Fri, 2 Jun 2023 09:39:08 +0200 Subject: [PATCH 19/21] Parse name for request to node creation from template --- gns3server/handlers/api/controller/template_handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gns3server/handlers/api/controller/template_handler.py b/gns3server/handlers/api/controller/template_handler.py index 0f88efb3..9462cc13 100644 --- a/gns3server/handlers/api/controller/template_handler.py +++ b/gns3server/handlers/api/controller/template_handler.py @@ -169,6 +169,7 @@ class TemplateHandler: node = await project.add_node_from_template(request.match_info["template_id"], x=request.json["x"], y=request.json["y"], + name=request.json.get("name")) compute_id=request.json.get("compute_id")) response.set_status(201) response.json(node) From 045c0c4c14886e0832f7e4d6427481166af40eb8 Mon Sep 17 00:00:00 2001 From: Mlastawi Date: Fri, 2 Jun 2023 10:38:42 +0200 Subject: [PATCH 20/21] Add missing comma --- gns3server/handlers/api/controller/template_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gns3server/handlers/api/controller/template_handler.py b/gns3server/handlers/api/controller/template_handler.py index 9462cc13..d297309a 100644 --- a/gns3server/handlers/api/controller/template_handler.py +++ b/gns3server/handlers/api/controller/template_handler.py @@ -169,7 +169,7 @@ class TemplateHandler: node = await project.add_node_from_template(request.match_info["template_id"], x=request.json["x"], y=request.json["y"], - name=request.json.get("name")) + name=request.json.get("name")), compute_id=request.json.get("compute_id")) response.set_status(201) response.json(node) From cc4ead40e22930c7eed51c7f386cc88388017d44 Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 2 Jun 2023 20:08:21 +0930 Subject: [PATCH 21/21] Fix unexpected indent --- gns3server/handlers/api/controller/template_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gns3server/handlers/api/controller/template_handler.py b/gns3server/handlers/api/controller/template_handler.py index d297309a..27734942 100644 --- a/gns3server/handlers/api/controller/template_handler.py +++ b/gns3server/handlers/api/controller/template_handler.py @@ -169,7 +169,7 @@ class TemplateHandler: node = await project.add_node_from_template(request.match_info["template_id"], x=request.json["x"], y=request.json["y"], - name=request.json.get("name")), + name=request.json.get("name"), compute_id=request.json.get("compute_id")) response.set_status(201) response.json(node)