Skip to content

Commit

Permalink
WEBUI: adding delete API
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdilauters committed Jun 4, 2016
1 parent f7161ca commit f62a3fa
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bower.json
Expand Up @@ -8,6 +8,7 @@
"ol3": "ol3-bower#^3.14.2",
"jquery-ui": "^1.11.4",
"jquery": "^2.2.3",
"angular-chart.js": "^0.10.2"
"angular-chart.js": "^0.10.2",
"font-awesome": "fontawesome#^4.6.3"
}
}
16 changes: 12 additions & 4 deletions scanmap.py
Expand Up @@ -625,6 +625,14 @@ def update_bt_station(self, station):
return True
return False

def delete(self, bssid):
q = 'delete from wifis where bssid = "%s"'%bssid
self.query(q)
q = 'delete from stations where bssid = "%s"'%bssid
self.query(q)
q = 'delete from bt_stations where bssid = "%s"'%bssid
self.query(q)

def update(self, wifi):
if wifi['essid'] == 'encoding_error':
return False
Expand All @@ -637,7 +645,7 @@ def update(self, wifi):
if(wifi.has_key('date')):
date_str = '"%s"'%wifi['date']

q = '''select * from wifis where bssid="%s" and essid="%s"'''%(wifi["bssid"], wifi["essid"])
q = '''select * from wifis where bssid="%s" and ( essid="%s" or bssid == "" )'''%(wifi["bssid"], wifi["essid"])
res = self.fetchone(q)
if res is None:
gps = 0
Expand Down Expand Up @@ -783,12 +791,12 @@ def parseIwlistOutput(self, data):


def getWifiPosition(self, wifis):
bssid = []
where = []
if len(wifis) < 3:
return None
for n in wifis:
bssid.append("\"%s\""%n["bssid"])
q = "select sum(-signal*latitude)/sum(-signal), sum(-signal*longitude)/sum(-signal), max(latitude)-min(latitude), max(longitude)-min(longitude) from wifis where bssid in ( %s )"%(','.join(bssid))
where.append('( bssid = "%s" and essid = "%s")'%(n["bssid"],n["essid"]))
q = "select sum(-signal*latitude)/sum(-signal), sum(-signal*longitude)/sum(-signal), max(latitude)-min(latitude), max(longitude)-min(longitude) from wifis where %s"%(' or '.join(where))
res = self.fetchone(q)
if res is not None:
if res[0] is None:
Expand Down
12 changes: 11 additions & 1 deletion src/WebUi.py
Expand Up @@ -274,7 +274,13 @@ def _get_sync(self, hostname):
sync = self.server.app.synchronizer.get_sync(hostname)
self.wfile.write(json.dumps(sync, ensure_ascii=False))


def _get_delete(self, bssid):
self.send_response(200)
self.send_header('Content-type','application/json')
self.send_header('Access-Control-Allow-Origin','*')
self.end_headers()
delete = self.server.app.delete(bssid)
self.wfile.write(json.dumps(delete, ensure_ascii=False))

def do_GET(self):
path,params,args = self._parse_url()
Expand Down Expand Up @@ -323,6 +329,10 @@ def do_GET(self):
if params is not None:
params = params.split('hostname=')[1]
return self._get_sync(params)
elif len(args) == 1 and args[0] == 'delete.json':
if params is not None:
params = params.split('bssid=')[1]
return self._get_delete(params)
else:
return self._get_file(path)

Expand Down
1 change: 1 addition & 0 deletions www/index.html
Expand Up @@ -12,6 +12,7 @@
<script src="/js/app.js"></script>
<script src="/js/index/controller.js"></script>
<link rel="stylesheet" href="/js/components/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="/js/components/font-awesome/css/font-awesome.min.css" />
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/index.css" />
</head>
Expand Down
2 changes: 1 addition & 1 deletion www/js/index/controller.js
Expand Up @@ -249,7 +249,7 @@
if(wifis[i]["encryption"] == 0) {
encryption = "open";
}
html += "<li class="+encryption+" >"+ wifis[i]["essid"] +"</li>";
html += '<li class="'+encryption+'" >'+ wifis[i]["essid"] + ' ' + wifis[i]["bssid"] +' <a class="fa fa-minus-circle" href="#" onclick="delete(\"'+wifis[i]["bssid"]+'\",\"'+wifis[i]["essid"]+'\")" ></a><hr/></li>';
}
} else {
if ('station' in feature.getProperties()) {
Expand Down

0 comments on commit f62a3fa

Please sign in to comment.