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
Пример #2
0
    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
Пример #3
0
    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
def get_nics():
    nics = []

    for ifname in netinfo.get_ifnames():
        if ifname in NIC_BLACKLIST:
            continue

        nic = netinfo.InterfaceInfo(ifname)
        if nic.is_up and nic.address:
            nics.append((ifname, nic.address))

    nics.sort(lambda a, b: cmp(a[0], b[0]))
    return nics
Пример #5
0
def get_nics():
    nics = []

    for ifname in netinfo.get_ifnames():
        if ifname in NIC_BLACKLIST:
            continue

        nic = netinfo.InterfaceInfo(ifname)
        if nic.is_up and nic.address:
            nics.append((ifname, nic.address))

    nics.sort(lambda a,b: cmp(a[0], b[0]))
    return nics
Пример #6
0
    def _get_filtered_ifnames():
        ifnames = []
        for ifname in netinfo.get_ifnames():
            if ifname.startswith(('lo', 'tap', 'br', 'natbr', 'tun', 'vmnet', 'veth', 'wmaster')):
                continue
            ifnames.append(ifname)

        # handle bridged LXC where br0 is the default outward-facing interface
        defifname = conf.Conf().default_nic
        if defifname and defifname.startswith('br'):
                ifnames.append(defifname)
                bridgedif = executil.getoutput('brctl', 'show', defifname).split('\n')[1].split('\t')[-1]
                ifnames.remove(bridgedif)

        ifnames.sort()
        return ifnames
Пример #7
0
    def _get_filtered_ifnames():
        ifnames = []
        for ifname in netinfo.get_ifnames():
            if ifname.startswith(('lo', 'tap', 'br', 'natbr', 'tun', 'vmnet', 'veth', 'wmaster')):
                continue
            ifnames.append(ifname)

        # handle bridged LXC where br0 is the default outward-facing interface
        defifname = conf.Conf().default_nic
        if defifname and defifname.startswith('br'):
                ifnames.append(defifname)
                bridgedif = executil.getoutput('brctl', 'show', defifname).split('\n')[1].split('\t')[-1]
                ifnames.remove(bridgedif)

        ifnames.sort()
        return ifnames
Пример #8
0
def main():
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], "h",
                                       ['help', 'pass='******'bind=', 'protected_mode='])
    except getopt.GetoptError as e:
        usage(e)

    password = ""
    bind = ""
    protected_mode = ""
    for opt, val in opts:
        if opt in ('-h', '--help'):
            usage()
        elif opt == '--bind':
            bind = val
        elif opt == '--pass':
            password = val
        elif opt == '--protected_mode':
            protected_mode = val

    if not password:
        d = Dialog('TurnKey Linux - First boot configuration')
        password = d.get_password(
             "Redis-commander 'admin' password",
             "Enter password for 'admin' access to redis-commander UI")

    if not bind:
        d = Dialog('TurnKey Linux - First boot configuration')
        bind = d.menu(
            "Interface(s) for Redis to bind to",
            ("Inteface for Redis to bind to?\n\nIf you wish to securely"
             " allow remote connections using 'all', ensure the system"
             " firewall is enabled & block all traffic on port 6379,"
             " except for the desired remote IP(s).\n\nManually edit the"
             " config file to set a custom interface."),
            choices=(
                ("localhost", "Redis will not respond to remote computer"),
                ("all", "Redis will allow all connections"),
                ("local", "Enter custom range")))
    if bind == "all":
        bind_ip = "0.0.0.0"
    if bind == "local":
        localaddr = InterfaceInfo(get_ifnames()[0]).address
        d = Dialog('TurnKey Linux - First boot configuration')
        bind_ip = d.get_input("Bind IP Range", "Enter bind ip range", localaddr)    
    else:
        bind_ip = "127.0.0.1"

    if not protected_mode:
        d = Dialog('TurnKey Linux - First boot configuration')
        protected_mode = d.yesno(
                'Keep protected-mode enabled?',
                "In protected  mode Redis only replies to queries from"
                " localhost. Clients connecting from other addresses will"
                " receive an error, noting why & how to configure Redis.\n"
                "\nUnless you set really good password, this is recommended",
                'Yes', 'No')

    protected_mode_str = {True: "yes", False: "no"}
    protected_mode = protected_mode_str[protected_mode]
    conf = "/etc/redis/redis.conf"
    redis_commander_conf = "/opt/tklweb-cp/ecosystem.config.js"
    subprocess.run(["sed", "-i", f"s|^bind .*|bind {bind_ip}|", conf])
    subprocess.run([
        "sed", "-i",
        f"s|^protected-mode .*|protected-mode {protected_mode}|",
        conf])
    subprocess.run([
        "sed", "-i",
        f"s|HTTP_PASSWORD\": \".*\"|HTTP_PASSWORD\": \"{password}\"|",
        redis_commander_conf])

    # restart redis and redis commander if running so change takes effect
    try:
        subprocess.run(["systemctl", "is-active",
                        "--quiet", "redis-server.service"])
        subprocess.run(["service", "redis-server", "restart"])
    except ExecError:
        pass

    # reload and restart pm2 so changes take affect
    # and save them to /home/node/.pm2/dump.pm2
    try:
        subprocess.run(["systemctl", "is-active",
                        "--quiet", "pm2-node.service"])
        subprocess.run(["systemctl", "reload",
                        "pm2-node.service"])
#        subprocess.run(["rm", "/home/node/.pm2/dump.pm2"])
        subprocess.run(["pm2", "reload", "/opt/tklweb-cp/ecosystem.config.js"],env={"PM2_HOME": "/home/node/.pm2", "PATH": "/usr/local/bin"}, check=True, user="******")
        subprocess.run(["pm2", "save"],env={"PM2_HOME": "/home/node/.pm2", "PATH": "/usr/local/bin"}, check=True, user="******")
        subprocess.run(["service", "pm2-node", "restart"])
    except ExecError:
        pass
Пример #9
0
    def get_interface(self, s_iface = None):
        ''' Get's the primary interface to configure, skips to config if only 1 valid interface present '''
        interfaces = filter(lambda x: not InterfaceInfo(x)._get_ioctl_flag(IFF_LOOPBACK), get_ifnames())
        choices = [((interfaces[0], '', 1))]+[(iface, '', 0) for iface in interfaces[1:]]
        code, value = self.dialog.radiolist('Interface config', 'Select Primary Interface (usually eth0 or wlan0)', choices = choices)

        if not code:
            self.interface = value