示例#1
0
def status():
    """
    Display the client list and the MAC blacklist, along with an optional
    message.
    """
    if not is_valid_user(request):
        return redirect(url_for('index'))
    mgr = WirelessAccessManager(EvilMommy.Config)
    msg = request.args['msg']
    return render_template('status.html', 
                           message = msg,
                           clients = mgr.get_dhcp_clients_table(),
                           mac_filters = mgr.get_blacklist())
示例#2
0
def run_command():
    """
    Executes a command from the user: disable or enable access for
    some device.
    """
    if not is_valid_user(request):
        return redirect(url_for('index'))
    command = request.form['command']
    device = request.form['device']

    # Log to STDOUT during dev
    print ("\nCommand = %s\nDevice = %s\n" % (command, device))

    mgr = WirelessAccessManager(EvilMommy.Config)    
    clients_table = mgr.get_dhcp_clients_table()
    target_device = find_device_by_hostname(device, clients_table)
    if target_device is None:
        target_device = find_device_by_hostname(device, 
                                                EvilMommy.Config.machines)

    if target_device is None:
        err_message = "Request failed. Could not find device entry " + \
                      "in config or in list of router clients."
        return redirect(url_for('status') + '?msg=' + err_message)
    
    removed = False
    blacklited = False
    result_msg = "Request failed."
    if (command == 'disconnect'):
        if ('ip_address' in target_device):
            removed = mgr.remove_from_dhcp_clients_table(target_device['ip_address'])
        else:
            removed = True # Device is not currently connected
        blacklisted = mgr.add_to_blacklist(target_device['mac_address'])
        if (removed and blacklisted):
            result_msg = "Request succeeded."
    elif (command == 'reconnect' and
             mgr.remove_from_blacklist(target_device['mac_address'])):
            result_msg = "Request succeeded."

    return redirect(url_for('status') + '?msg=' + result_msg)
示例#3
0
def integration_test():
    """
    These only run manually, if you uncomment the last line of this file.
    """

    mgr = WirelessAccessManager(EvilMommy.Config)

    # Get the blacklist, add a MAC address to it, then get the list
    # again to see if it was really added.
    print mgr.get_blacklist()
    print "Adding '00:55:55:55:55:55' to the blacklist"
    mgr.add_to_blacklist('00:55:55:55:55:55')
    print mgr.get_blacklist()

    # Now remove the MAC address and see if it really worked.
    print "Removing '00:55:55:55:55:55' from the blacklist"
    mgr.remove_from_blacklist('00:55:55:55:55:55')
    print mgr.get_blacklist()