Exemple #1
0
def action_set_dhcpd(arg):
    if arg not in ['yes', 'no']:
        print 'error: only "yes" and "no" are allowed'
        return 10
    print 'DHCP server enabled: %s' % arg
    en = {"general": {"enabled": arg}}
    write_role('dhcpd', en)
Exemple #2
0
def action_set_apate(arg):
    if arg not in ['yes', 'no']:
        print 'error: only "yes" and "no" are allowed'
        return 10
    print 'apate enabled: %s' % arg
    en = {"general": {"enabled": arg}}
    write_role('apate', en)
Exemple #3
0
def action_set_silent(arg):
    if arg not in ['yes', 'no']:
        print 'error: only "yes" and "no" are allowed'
        return 10
    print 'silent enabled: %s' % arg
    silent = {"general": {"enabled": arg}}
    write_role('wlan', silent)
Exemple #4
0
def action_set_static_ip(arg):
    if arg not in ['yes', 'no']:
        print 'error: only "yes" and "no" are allowed'
        return 10
    arg = "static" if arg == "yes" else "dhcp"
    print 'interface mode: %s' % arg
    en = {"general": {"mode": arg}}
    write_role('interfaces', en)
Exemple #5
0
def action_set_vpn(arg):
    if arg not in ['yes', 'no']:
        print 'error: only "yes" and "no" are allowed'
        return 10
    print 'vpn enabled: %s' % arg
    vpn = {"general": {"enabled": arg}}
    write_role('vpn', vpn)
    return 0
Exemple #6
0
def action_set_wlan_channel(arg):
    if not int(arg) in range(1, 10):
        print 'error: channel must be between 1 and 10'
        return 10
    print 'wifi channel: %s' % arg
    channel = {"general": {"channel": arg}}
    write_role('wlan', channel)
    return 0
Exemple #7
0
def action_set_gateway(arg):
    print 'setting ip to "%s"' % arg
    ip = None
    try:
        ip = IPAddress(arg, flags=ZEROFILL)
    except:
        return 12

    obj = {"static": {"gateway": str(ip)}}
    write_role('interfaces', obj)
Exemple #8
0
def _config_mac(group, mac, remove=False):
    if check_mac(mac):
        devices = get_fact('devices', group) or []
        if not remove and mac.lower() not in devices:
            devices.append(mac.lower())
        elif remove and mac.lower() in devices:
            devices.remove(mac.lower())
        en = {group: devices}
        write_role('devices', en)
    else:
        return 30
Exemple #9
0
def action_set_netmask(arg):
    print 'setting ip to "%s"' % arg
    ip = None
    try:
        ip = IPAddress(arg, flags=ZEROFILL)
        if not ip.is_netmask():
            return 13
    except:
        return 12

    obj = {"static": {"netmask": str(ip)}}
    write_role('interfaces', obj)
Exemple #10
0
def action_set_vpn_connection(arg):
    '1194/udp'
    port, protocol = arg.split('/')
    protocol = protocol.upper()
    if not int(port) in range(1025, 65535) or protocol not in ['UDP', 'TCP']:
        print 'error: only valid "port/protocol" combinations are allowed e.g. "1194/UDP"'
        print 'port must be unprivileged: 1025 - 65535'
        print 'protocol can be either UDP or TCP'
        return 10
    print 'vpn connection: %s' % arg
    vpn_connection = {"connection": {"port": port, "protocol": protocol}}
    write_role('vpn', vpn_connection)
    return 0
Exemple #11
0
def action_set_password(arg):
    print 'setting password'
    if not check_passwd(arg):
        return 11
    passwd = {"upri": {"passwd": arg}}
    write_role('wlan', passwd)
Exemple #12
0
def action_set_ssid(arg):
    print 'setting ssid to "%s"' % arg
    if not check_ssid(arg):
        return 12
    ssid = {"upri": {"ssid": arg}}
    write_role('wlan', ssid)