def process_input(input): input = input.lower().strip() if input == 'h' or input == 'help': help() elif input == 'stat': stat() elif input == 'if': show_ip() elif input == 'ifcfg': ifcfg() elif input == 'reboot': reboot() elif input == 'poweroff': poweroff() elif input == 'xterm': xterm() else: colorinfo.show_fail("Unrecognized command. Press 'h' to view help.")
def ifcfg(): interfaces = get_nic_interfaces() interfaces = [inter for inter in interfaces if inter['interface'] != 'lo'] nic = len(interfaces) - 1 address = None gateway = None mask = '255.255.255.0' for i, name in enumerate(interfaces): colorinfo.show_info("%s: %s" % (i, name)) r = input(colorinfo.format_input_text('Choice a interface[0..%s]? ' % nic)) if not r.isnumeric(): colorinfo.show_fail('Input must be a number.') return n = int(r) if n < 0 or n > nic: colorinfo.show_fail('Input must in range [0..%s].' % nic) return interface = interfaces[n]['interface'] r = input(colorinfo.format_input_text('%s IP ? ' % interface)) address = validate_ip(r) if address is None: colorinfo.show_fail('Invalid ip') return r = input(colorinfo.format_input_text('%s Mask ? ' % interface)) if len(r) > 0: r = validate_ip(r) if r: mask = r r = input(colorinfo.format_input_text('%s Gateway ? ' % interface)) if len(r) == 0: colorinfo.show_warning('Skip config gateway') else: r = validate_ip(r) if r: gateway = r colorinfo.show_info('-'*30) colorinfo.show_info('Interface=%s' % interface) colorinfo.show_info('IP=%s' % address) colorinfo.show_info('MASK=%s' % mask) if gateway: colorinfo.show_info('GATEWAY=%s' % gateway) colorinfo.show_info('-'*30) r = confirm('Save network configuration') if r: config_ip(interface, address, mask, gateway)
def ifcfg(): interfaces = get_nic_interfaces() interfaces = [inter for inter in interfaces if inter['interface'] != 'lo'] nic = len(interfaces) - 1 address = None gateway = None mask = '255.255.255.0' for i, name in enumerate(interfaces): colorinfo.show_info("%s: %s" % (i, name)) r = input(colorinfo.format_input_text('Choice a interface[0..%s]? ' % nic)) if not r.isnumeric(): colorinfo.show_fail('Input must be a number.') return n = int(r) if n < 0 or n > nic: colorinfo.show_fail('Input must in range [0..%s].' % nic) return interface = interfaces[n]['interface'] r = input(colorinfo.format_input_text('%s IP ? ' % interface)) address = validate_ip(r) if address is None: colorinfo.show_fail('Invalid ip') return r = input(colorinfo.format_input_text('%s Mask ? ' % interface)) if len(r) > 0: r = validate_ip(r) if r: mask = r r = input(colorinfo.format_input_text('%s Gateway ? ' % interface)) if len(r) == 0: colorinfo.show_warning('Skip config gateway') else: r = validate_ip(r) if r: gateway = r colorinfo.show_info('-' * 30) colorinfo.show_info('Interface=%s' % interface) colorinfo.show_info('IP=%s' % address) colorinfo.show_info('MASK=%s' % mask) if gateway: colorinfo.show_info('GATEWAY=%s' % gateway) colorinfo.show_info('-' * 30) r = confirm('Save network configuration') if r: config_ip(interface, address, mask, gateway)