Beispiel #1
0
    def usage(self):
        # if no interfaces at all - display error and go to advanced
        if len(self._get_filtered_ifnames()) == 0:
            self.console.msgbox("Error", "No network adapters detected")
            return "advanced"

        # if interfaces but no default - display error and go to networking
        ifname = self._get_default_nic()
        if not ifname:
            self.console.msgbox("Error", "Networking is not yet configured")
            return "networking"

        # display usage
        ipaddr = ifutil.get_ipconf(ifname)[0]
        hostname = netinfo.get_hostname().upper()

        try:
            # backwards compatible - use usage.txt if it exists
            t = file(conf.path("usage.txt"), "r").read()
            text = Template(t).substitute(hostname=hostname, ipaddr=ipaddr)

            retcode = self.console.msgbox("Usage", text, button_label="Advanced Menu")
        except conf.Error:
            t = file(conf.path("services.txt"), "r").read().rstrip()
            text = Template(t).substitute(ipaddr=ipaddr)

            retcode = self.console.msgbox("%s appliance services" % hostname, text, button_label="Advanced Menu")

        if retcode is not self.OK:
            self.running = False

        return "advanced"
Beispiel #2
0
    def __init__(self):
        title = "TurnKey Linux Configuration Console"
        self.width = 60
        self.height = 20

        self.console = Console(title, self.width, self.height)
        self.appname = "TurnKey Linux %s" % netinfo.get_hostname().upper()

        self.installer = Installer(path='/usr/bin/di-live')
    def __init__(self):
        title = "TurnKey Linux Configuration Console"
        self.width = 60
        self.height = 20

        self.console = Console(title, self.width, self.height)
        self.appname = "TurnKey Linux %s" % netinfo.get_hostname().upper()

        self.installer = Installer(path='/usr/bin/di-live')
Beispiel #4
0
    def __init__(self):
        title = "Avamagic Network Configuration Console"
        self.width = 60
        self.height = 20

        self.console = Console(title, self.width, self.height)
        self.appname = "%s" % netinfo.get_hostname().upper()

        self.installer = Installer(path="/usr/bin/di-live")
Beispiel #5
0
    def __init__(self, advanced_enabled=True):
        title = "Chitanka Configuration Console"
        self.width = 60
        self.height = 20

        self.console = Console(title, self.width, self.height)
        self.appname = "%s" % netinfo.get_hostname().upper()

        self.installer = Installer(path='/usr/bin/di-live')

        self.advanced_enabled = advanced_enabled
Beispiel #6
0
    def __init__(self, advanced_enabled=True):
        title = "Chitanka Configuration Console"
        self.width = 60
        self.height = 20

        self.console = Console(title, self.width, self.height)
        self.appname = "%s" % netinfo.get_hostname().upper()

        self.installer = Installer(path='/usr/bin/di-live')

        self.advanced_enabled = advanced_enabled
    def __init__(self, advanced_enabled=True):
        title = "TurnKey GNU/Linux Configuration Console"
        self.width = 60
        self.height = 20

        self.console = Console(title, self.width, self.height)
        self.appname = "TurnKey GNU/Linux %s" % netinfo.get_hostname().upper()

        self.installer = Installer(path="/usr/bin/di-live")

        self.advanced_enabled = advanced_enabled
Beispiel #8
0
    def __init__(self, advanced_enabled=True):
        title = "TurnKey GNU/Linux Configuration Console"
        self.width = 60
        self.height = 20

        self.console = Console(title, self.width, self.height)
        self.appname = "TurnKey GNU/Linux %s" % netinfo.get_hostname().upper()

        self.installer = Installer(path='/usr/bin/di-live')

        self.advanced_enabled = advanced_enabled

        self.eventManager = plugin.EventManager()
        self.pluginManager = plugin.PluginManager(PLUGIN_PATH, {'eventManager': self.eventManager, 'console': self.console})
Beispiel #9
0
    def __init__(self, pluginManager, eventManager, advanced_enabled=True):
        title = "TurnKey GNU/Linux Configuration Console"
        self.width = 60
        self.height = 20

        self.console = Console(title, self.width, self.height)
        self.appname = "TurnKey GNU/Linux %s" % netinfo.get_hostname().upper()

        self.installer = Installer(path='/usr/bin/di-live')

        self.advanced_enabled = advanced_enabled

        #self.eventManager = plugin.EventManager()
        #self.pluginManager = plugin.PluginManager(PLUGIN_PATH, {'eventManager': self.eventManager, 'console': self.console})

        self.eventManager = eventManager
        self.pluginManager = pluginManager
        self.pluginManager.updateGlobals({'console': self.console})
        #tklbam integration
        try:
            tklbam_status = executil.getoutput("tklbam-status --short")
        except executil.ExecError, e:
            if e.exitcode in (10, 11): #not initialized, no backups
                tklbam_status = e.output
            else:
                tklbam_status = ''

        #display usage
        ip_addr = self._get_public_ipaddr()
        if not ip_addr:
            ip_addr = ifutil.get_ipconf(ifname)[0]

        hostname = netinfo.get_hostname().upper()

        try:
            #backwards compatible - use usage.txt if it exists
            t = file(conf.path("usage.txt"), 'r').read()
            text = Template(t).substitute(hostname=hostname, ipaddr=ip_addr)

            retcode = self.console.msgbox("Usage", text,
                                          button_label=default_button_label)
        except conf.Error:
            t = file(conf.path("services.txt"), 'r').read().rstrip()
            text = Template(t).substitute(ipaddr=ip_addr)

            text += "\n\n%s\n\n" % tklbam_status
            text += "\n" * (self.height - len(text.splitlines()) - 7)
            text += "         TurnKey Backups and Cloud Deployment\n"
Beispiel #11
0
class TurnkeyConsole:
    OK = 0
    CANCEL = 1

    def __init__(self, advanced_enabled=True):
        title = "Chitanka Configuration Console"
        self.width = 60
        self.height = 20

        self.console = Console(title, self.width, self.height)
        self.appname = "%s" % netinfo.get_hostname().upper()

        self.installer = Installer(path='/usr/bin/di-live')

        self.advanced_enabled = advanced_enabled

    @staticmethod
    def _get_filtered_ifnames():
        ifnames = []
        for ifname in netinfo.get_ifnames():
            if ifname.startswith(('lo', 'tap', 'br', 'tun', 'vmnet', 'wmaster')):
                continue
            ifnames.append(ifname)

        ifnames.sort()
        return ifnames

    @classmethod
    def _get_default_nic(cls):
        def _validip(ifname):
            ip = ifutil.get_ipconf(ifname)[0]
            if ip and not ip.startswith('169'):
                return True
            return False

        ifname = conf.Conf().default_nic
        if ifname and _validip(ifname):
            return ifname

        for ifname in cls._get_filtered_ifnames():
            if _validip(ifname):
                return ifname

        return None

    def _get_advmenu(self):
        items = []
        items.append(("Networking", "Configure appliance networking"))

        if self.installer.available:
            items.append(("Install", "Install to hard disk"))

        items.append(("Reboot", "Reboot the appliance"))
        items.append(("Shutdown", "Shutdown the appliance"))
        items.append(("Ping", "Test internet connection"))
        items.append(("Repair", "Repair and update Chitanka"))
        items.append(("UPDATENOW", "Get latest books"))
        #items.append(("Share", "Share content folder in LAN"))
        #items.append(("Noshare", "Remove shared content folder"))
        items.append(("Clear", "Clear free space"))

        return items



    def _get_netmenu(self):
        menu = []
        for ifname in self._get_filtered_ifnames():
            addr = ifutil.get_ipconf(ifname)[0]
            ifmethod = ifutil.get_ifmethod(ifname)

            if addr:
                desc = addr
                if ifmethod:
                    desc += " (%s)" % ifmethod

                if ifname == self._get_default_nic():
                    desc += " [*]"
            else:
                desc = "not configured"

            menu.append((ifname, desc))

        return menu

    def _get_ifconfmenu(self, ifname):
        menu = []
        menu.append(("DHCP", "Configure networking automatically"))
        menu.append(("StaticIP", "Configure networking manually"))

        if not ifname == self._get_default_nic() and \
           len(self._get_filtered_ifnames()) > 1 and \
           ifutil.get_ipconf(ifname)[0] is not None:
            menu.append(("Default", "Show this adapter's IP address in Usage"))

        return menu

    def _get_ifconftext(self, ifname):
        addr, netmask, gateway, nameservers = ifutil.get_ipconf(ifname)
        if addr is None:
            return "Network adapter is not configured\n"

        text =  "IP Address:      %s\n" % addr
        text += "Netmask:         %s\n" % netmask
        text += "Default Gateway: %s\n" % gateway
        text += "Name Server(s):  %s\n\n" % " ".join(nameservers)

        ifmethod = ifutil.get_ifmethod(ifname)
        if ifmethod:
            text += "Networking configuration method: %s\n" % ifmethod

        if len(self._get_filtered_ifnames()) > 1:
            text += "Is this adapter's IP address displayed in Usage: "
            if ifname == self._get_default_nic():
                text += "yes\n"
            else:
                text += "no\n"

        return text

    def usage(self):
        if self.advanced_enabled:
            default_button_label = "Advanced Menu"
            default_return_value = "advanced"

        else:
            default_button_label = "Quit"
            default_return_value = "quit"

        #if no interfaces at all - display error and go to advanced
        if len(self._get_filtered_ifnames()) == 0:
            error = "No network adapters detected"
            if not self.advanced_enabled:
                fatal(error)

            self.console.msgbox("Error", error)
            return "advanced"

        #if interfaces but no default - display error and go to networking
        ifname = self._get_default_nic()
        if not ifname:
            error = "Networking is not yet configured"
            if not self.advanced_enabled:
                fatal(error)

            self.console.msgbox("Error", error)
            return "networking"

        #tklbam integration
        try:
            tklbam_status = executil.getoutput("tklbam-status --short")
        except executil.ExecError, e:
            if e.exitcode in (10, 11): #not initialized, no backups
                tklbam_status = e.output
            else:
                tklbam_status = ''

        #display usage
        ipaddr = ifutil.get_ipconf(ifname)[0]
        hostname = netinfo.get_hostname().upper()

        try:
            #backwards compatible - use usage.txt if it exists
            t = file(conf.path("usage.txt"), 'r').read()
            text = Template(t).substitute(hostname=hostname, ipaddr=ipaddr)

            retcode = self.console.msgbox("Usage", text,
                                          button_label=default_button_label)
        except conf.Error:
            t = file(conf.path("services.txt"), 'r').read().rstrip()
            text = Template(t).substitute(ipaddr=ipaddr)


            retcode = self.console.msgbox("%s appliance services" % hostname,
                                          text, button_label=default_button_label)

        if retcode is not self.OK:
            self.running = False

        return default_return_value
Beispiel #12
0
    def usage(self):
        if self.advanced_enabled:
            default_button_label = "Advanced Menu"
            default_return_value = "advanced"
        else:
            default_button_label = "Quit"
            default_return_value = "quit"

        # if no interfaces at all - display error and go to advanced
        if len(self._get_filtered_ifnames()) == 0:
            error = "No network adapters detected"
            if not self.advanced_enabled:
                fatal(error)

            self.console.msgbox("Error", error)
            return "advanced"

        # if interfaces but no default - display error and go to networking
        ifname = self._get_default_nic()
        if not ifname:
            error = "Networking is not yet configured"
            if not self.advanced_enabled:
                fatal(error)

            self.console.msgbox("Error", error)
            return "networking"

        # tklbam integration
        tklbamstatus_cmd = subprocess.run(['which', 'tklbam-status'],
                                          stdout=PIPE,
                                          encoding='utf-8').stdout.strip()
        if tklbamstatus_cmd:
            tklbam_status = subprocess.run([tklbamstatus_cmd, "--short"],
                                           stdout=PIPE,
                                           encoding='utf-8').stdout
        else:
            tklbam_status = ("TKLBAM not found - please check that it's"
                             " installed.")

        # display usage
        ip_addr = self._get_public_ipaddr()
        if not ip_addr:
            ip_addr = ifutil.get_ipconf(ifname)[0]

        hostname = netinfo.get_hostname().upper()

        try:
            # backwards compatible - use usage.txt if it exists
            with open(conf.path("usage.txt"), 'r') as fob:
                t = fob.read()
            text = Template(t).substitute(hostname=hostname, ipaddr=ip_addr)

            retcode = self.console.msgbox("Usage",
                                          text,
                                          button_label=default_button_label)
        except conf.Error:
            try:
                with open(conf.path('services.txt'), 'r') as fob:
                    t = fob.read().rstrip()
            except:
                t = ""
            text = Template(t).substitute(ipaddr=ip_addr)

            text += "\n\n%s\n\n" % tklbam_status
            text += "\n" * (self.height - len(text.splitlines()) - 7)
            text += "         TurnKey Backups and Cloud Deployment\n"
            text += "             https://hub.turnkeylinux.org"

            retcode = self.console.msgbox("%s appliance services" % hostname,
                                          text,
                                          button_label=default_button_label)

        if retcode is not self.OK:
            self.running = False

        return default_return_value
Beispiel #13
0
        #tklbam integration
        try:
            tklbam_status = executil.getoutput("tklbam-status --short")
        except executil.ExecError, e:
            if e.exitcode in (10, 11): #not initialized, no backups
                tklbam_status = e.output
            else:
                tklbam_status = ''

        #display usage
        ip_addr = self._get_public_ipaddr()
        if not ip_addr:
            ip_addr = ifutil.get_ipconf(ifname)[0]

        hostname = netinfo.get_hostname().upper()

        try:
            #backwards compatible - use usage.txt if it exists
            t = file(conf.path("usage.txt"), 'r').read()
            text = Template(t).substitute(hostname=hostname, ipaddr=ip_addr)

            retcode = self.console.msgbox("Usage", text,
                                          button_label=default_button_label)
        except conf.Error:
            t = file(conf.path("services.txt"), 'r').read().rstrip()
            text = Template(t).substitute(ipaddr=ip_addr)

            text += "\n\n%s\n\n" % tklbam_status
            text += "\n" * (self.height - len(text.splitlines()) - 7)
            text += "         TurnKey Backups and Cloud Deployment\n"