Skip to content

Commit

Permalink
Implement /get_router_by_mac/<mac>
Browse files Browse the repository at this point in the history
- To allow hotlink from router webui
- Will redirect to router page when there is
  exactly one router with this mac
- Otherwise redirect to router list with mac
  set as filter
  • Loading branch information
asdil12 committed Jan 25, 2016
1 parent 1e9f43f commit 4984d61
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ffmap/web/api.py
Expand Up @@ -5,7 +5,7 @@
from ffmap.dbtools import FreifunkDB
from ffmap.stattools import record_global_stats

from flask import Blueprint, request, make_response
from flask import Blueprint, request, make_response, redirect, url_for
from pymongo import MongoClient
from bson.json_util import dumps as bson2json
import json
Expand All @@ -14,6 +14,7 @@

db = FreifunkDB().handle()

# map ajax
@api.route('/get_nearest_router')
def get_nearest_router():
res_router = db.routers.find_one(
Expand All @@ -31,6 +32,15 @@ def get_nearest_router():
r.mimetype = 'application/json'
return r

# router by mac (link from router webui)
@api.route('/get_router_by_mac/<mac>')
def get_router_by_mac(mac):
res_routers = db.routers.find({"netifs.mac": mac.lower()}, {"_id": 1})
if res_routers.count() != 1:
return redirect(url_for("router_list", q="netifs.mac=%s" % mac))
else:
return redirect(url_for("router_info", dbid=next(res_routers)["_id"]))

@api.route('/alfred', methods=['GET', 'POST'])
def alfred():
#set_alfred_data = {65: "hallo", 66: "welt"}
Expand Down

0 comments on commit 4984d61

Please sign in to comment.