Exemple #1
0
def cmd():
    """
    Executes commands called from the webui
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info['isadmin'] != 'yes':
        return 'You are unauthorized to perform this action.\n'

    ipb = ''
    oper = request.args.get('op')
    if oper == 'THING_OFF' or oper == 'THING_ON':
        macaddr = request.args.get('macaddr')
        ipb = RSTOR.hget('thing_%s' % macaddr, 'ip4')
        ip4 = request.args.get('ip4')
        if not macaddr:
            return 'Missing MAC address in request.\n'
        if not ip4:
            return 'Missing IP address in request.\n'
    elif oper == 'ALL_THINGS_OFF' or oper == 'ALL_THINGS_ON':
        macaddr = caller_info['macaddr']
    elif oper == 'PARTY_MODE_OFF' or oper == 'PARTY_MODE_ON':
        RSTOR.set('party_mode', oper.split('_')[2].lower())
        sleep(2)
        return redirect('/things', code=302)
    else:
        return 'Invalid request.\n'

    RDYNA.publish('command-fifo-pipe', 'CMD,%s,%s,%d,%s,%s' %
                  (caller_info['ip4'], oper, int(time()), macaddr, ipb))
    # print('CMD,%s,%s,%d,%s' % (caller_info['ip4'], oper, int(time()), macaddr))
    sleep(2)

    return redirect('/things', code=302)
Exemple #2
0
def helppage():
    """
    Renders the help page
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])

    return render_template('help.html', cur_info=caller_info)
Exemple #3
0
def cmd():
    """
    Executes commands called from the webui
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info['isadmin'] != 'yes':
        return 'You are unauthorized to perform this action.\n'

    ipb = ''
    oper = request.args.get('op')
    if oper == 'THING_OFF' or oper == 'THING_ON':
        macaddr = request.args.get('macaddr')
        ipb = RSTOR.hget('thing_%s' % macaddr, 'ip4')
        ip4 = request.args.get('ip4')
        if not macaddr:
            return 'Missing MAC address in request.\n'
        if not ip4:
            return 'Missing IP address in request.\n'
    elif oper == 'ALL_THINGS_OFF' or oper == 'ALL_THINGS_ON':
        macaddr = caller_info['macaddr']
    elif oper == 'PARTY_MODE_OFF' or oper == 'PARTY_MODE_ON':
        RSTOR.set('party_mode', oper.split('_')[2].lower())
        sleep(2)
        return redirect('/things', code=302)
    else:
        return 'Invalid request.\n'

    RDYNA.publish(
        'command-fifo-pipe', 'CMD,%s,%s,%d,%s,%s' %
        (caller_info['ip4'], oper, int(time()), macaddr, ipb))
    # print('CMD,%s,%s,%d,%s' % (caller_info['ip4'], oper, int(time()), macaddr))
    sleep(2)

    return redirect('/things', code=302)
Exemple #4
0
def helppage():
    """
    Renders the help page
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])

    return render_template('help.html', cur_info=caller_info)
Exemple #5
0
def things():
    """
    Table and control of things
    """
    thingslist = []
    keys = RSTOR.keys('thing_*')
    for i in keys:
        sinthing = RSTOR.hgetall(i)
        mac = sinthing.get('macaddr')
        if not mac:
            continue  # perhaps log; this means an incomplete thing
        thingslist.append(sinthing)

    thingslist_sorted = sort_things(thingslist)

    thingslist = []
    for i in thingslist_sorted:
        i['last'] = parsetime(i['last'])
        thingslist.append(i)

    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    isadmin = caller_info['isadmin'] == 'yes'

    cur_state = RSTOR.get('state_all_things')
    party_mode = RSTOR.get('party_mode')

    return render_template('things.html', things=thingslist,
                           isadmin=isadmin, cur_state=cur_state,
                           party_mode=party_mode, cur_info=caller_info)
Exemple #6
0
def things():
    """
    Table and control of things
    """
    thingslist = []
    keys = RSTOR.keys('thing_*')
    for i in keys:
        sinthing = RSTOR.hgetall(i)
        mac = sinthing.get('macaddr')
        if not mac:
            continue  # perhaps log; this means an incomplete thing
        thingslist.append(sinthing)

    thingslist_sorted = sort_things(thingslist)

    thingslist = []
    for i in thingslist_sorted:
        i['last'] = parsetime(i['last'])
        thingslist.append(i)

    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    isadmin = caller_info['isadmin'] == 'yes'

    cur_state = RSTOR.get('state_all_things')
    party_mode = RSTOR.get('party_mode')

    return render_template('things.html',
                           things=thingslist,
                           isadmin=isadmin,
                           cur_state=cur_state,
                           party_mode=party_mode,
                           cur_info=caller_info)
Exemple #7
0
def nmap():
    """
    Renders the nmap scan log
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])

    return render_template('nmap.html', cur_info=caller_info,
                           srv=request.host.split(':')[0])
Exemple #8
0
def websocket():
    """
    Renders the websocket example
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])

    return render_template('websocket.html', cur_info=caller_info,
                           srv=request.host.split(':')[0])
Exemple #9
0
def websocket():
    """
    Renders the websocket example
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])

    return render_template('websocket.html',
                           cur_info=caller_info,
                           srv=request.host.split(':')[0])
Exemple #10
0
def captive_portal():
    """
    Renders the actual captive portal page
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    resp = make_response(
        render_template('captive_portal.html', cur_info=caller_info))
    resp.headers = fill_http_headers(resp.headers)
    return resp
Exemple #11
0
def nmap():
    """
    Renders the nmap scan log
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])

    return render_template('nmap.html',
                           cur_info=caller_info,
                           srv=request.host.split(':')[0])
Exemple #12
0
def captive_portal():
    """
    Renders the actual captive portal page
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    resp = make_response(render_template('captive_portal.html',
                                         cur_info=caller_info))
    resp.headers = fill_http_headers(resp.headers)
    return resp
Exemple #13
0
def reset_admin():
    """
    Procedure to reset all admin devices
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info['isadmin'] != 'yes':
        return 'You are unauthorized to perform this action.\n'

    for i in RSTOR.keys('thing_*'):
        RSTOR.hmset(i, {'isadmin': 'no'})

    sleep(5)
    return redirect('/', code=302)
Exemple #14
0
def reset_admin():
    """
    Procedure to reset all admin devices
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info['isadmin'] != 'yes':
        return 'You are unauthorized to perform this action.\n'

    for i in RSTOR.keys('thing_*'):
        RSTOR.hmset(i, {'isadmin': 'no'})

    sleep(5)
    return redirect('/', code=302)
Exemple #15
0
def thing_show():
    """
    Shows information about a specific thing
    """
    mac = request.args.get('mac')
    if not mac:
        return 'Invalid MAC address\n'

    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    isadmin = caller_info['isadmin'] == 'yes'

    thinginfo = RSTOR.hgetall('thing_%s' % mac)
    return render_template('thing_show.html', thing=thinginfo,
                           cur_info=caller_info, isadmin=isadmin)
Exemple #16
0
def thing_show():
    """
    Shows information about a specific thing
    """
    mac = request.args.get('mac')
    if not mac:
        return 'Invalid MAC address\n'

    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    isadmin = caller_info['isadmin'] == 'yes'

    thinginfo = RSTOR.hgetall('thing_%s' % mac)
    return render_template('thing_show.html',
                           thing=thinginfo,
                           cur_info=caller_info,
                           isadmin=isadmin)
Exemple #17
0
def main():
    """
    Main routine
    """
    admin_devices = []
    for i in RSTOR.keys('thing_*'):
        if RSTOR.hget(i, 'isadmin') == 'yes':
            admin_devices.append(RSTOR.hgetall(i))

    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info.get('enable_to_browse', 'no') != 'yes' \
        and caller_info.get('isadmin', 'no') != 'yes' \
        and admin_devices:
        return redirect('http://dowse.it/captive_portal', code=302)


    return render_template('welcome.html', admin_devices=admin_devices,
                           cur_info=caller_info)
Exemple #18
0
def main():
    """
    Main routine
    """
    admin_devices = []
    for i in RSTOR.keys('thing_*'):
        if RSTOR.hget(i, 'isadmin') == 'yes':
            admin_devices.append(RSTOR.hgetall(i))

    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info.get('enable_to_browse', 'no') != 'yes' \
        and caller_info.get('isadmin', 'no') != 'yes' \
        and admin_devices:
        return redirect('http://dowse.it/captive_portal', code=302)

    return render_template('welcome.html',
                           admin_devices=admin_devices,
                           cur_info=caller_info)
Exemple #19
0
def modify_priv_things():
    """
    Modifies thing privileges
    This currently handles admin/nonadmin
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info['isadmin'] != 'yes':
        return 'You are unauthorized to perform this action.\n'

    thing_mac = request.form['macaddr']
    if request.form['column'] != 'admin':
        return '<h1>400 - Bad request</h1>\n'

    state = request.form['value']
    if not state:
        return '<h1>400 - Bad request</h1>\n'

    RSTOR.hset('thing_%s' % thing_mac, 'isadmin', state)

    return redirect(request.form['url_from'], code=302)
Exemple #20
0
def modify_priv_things():
    """
    Modifies thing privileges
    This currently handles admin/nonadmin
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info['isadmin'] != 'yes':
        return 'You are unauthorized to perform this action.\n'

    thing_mac = request.form['macaddr']
    if request.form['column'] != 'admin':
        return '<h1>400 - Bad request</h1>\n'

    state = request.form['value']
    if not state:
        return '<h1>400 - Bad request</h1>\n'

    RSTOR.hset('thing_%s' % thing_mac, 'isadmin', state)

    return redirect(request.form['url_from'], code=302)
Exemple #21
0
def page_not_found(e):
    """
    HTTP 404 handling function

    Returns actual 404, or directs you to the captive portal, depending if you
    are enabled to browse or should be redirected.
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info.get('enable_to_browse', 'no') != 'yes':
        definfo = fill_default_thing(request.environ['REMOTE_ADDR'])
        RSTOR.hmset('thing_%s' % definfo['macaddr'], definfo)
        RDYNA.publish('command-fifo-pipe', 'CMD,%s,%s,%d,%s,%s' %
                      (definfo['ip4'], 'THING_OFF', int(time()),
                       definfo['macaddr'], definfo['ip4']))
        RSTOR.hset('thing_%s' % definfo['macaddr'], 'enable_to_browse', 'no')
        sleep(3)

    if caller_info.get('enable_to_browse', 'no') == 'yes':
        return render_template('404.html', cur_info=caller_info, msg=e), 404

    return redirect('http://dowse.it/captive_portal', code=302)
Exemple #22
0
def page_not_found(e):
    """
    HTTP 404 handling function

    Returns actual 404, or directs you to the captive portal, depending if you
    are enabled to browse or should be redirected.
    """
    caller_info = get_caller_info(request.environ['REMOTE_ADDR'])
    if caller_info.get('enable_to_browse', 'no') != 'yes':
        definfo = fill_default_thing(request.environ['REMOTE_ADDR'])
        RSTOR.hmset('thing_%s' % definfo['macaddr'], definfo)
        RDYNA.publish(
            'command-fifo-pipe',
            'CMD,%s,%s,%d,%s,%s' % (definfo['ip4'], 'THING_OFF', int(
                time()), definfo['macaddr'], definfo['ip4']))
        RSTOR.hset('thing_%s' % definfo['macaddr'], 'enable_to_browse', 'no')
        sleep(3)

    if caller_info.get('enable_to_browse', 'no') == 'yes':
        return render_template('404.html', cur_info=caller_info, msg=e), 404

    return redirect('http://dowse.it/captive_portal', code=302)