moar
[kismet-logviewer.git] / logviewer / devices / views.py
1 from django.shortcuts import render
2 from django.http import HttpResponse, HttpRequest
3 import os
4 import sqlite3
5 import time
6 import json
7 import pprint
8
9 from django.views.decorators.csrf import csrf_exempt
10
11 def load_db(query):
12     connection = sqlite3.connect("logs/Kismet-20221208-22-56-36-1.kismet")
13     #connection.row_factory = lambda cursor, row: row[0]
14     cursor = connection.cursor()
15     rows = cursor.execute(query).fetchall()
16     return(rows)
17
18 @csrf_exempt
19 def index(request,devicename):
20     dev=list(load_db("select cast(device as text) from devices where devkey = \""+devicename+"\""))
21     (dev_info,) = dev[0]
22     #dev_string = "{ \"recordsTotal\": "+str(dev_count)+", \"data\": ["
23     #dev_list = list(load_db("select cast(device as text) from devices limit 50"))
24     #for device in dev_list:
25     #    (dev,) = device
26     #    dev_string = dev_string + dev + ","
27     #dev_string = dev_string[:-1]
28     #dev_string = dev_string + "],\"draw\": 5,\"recordsFiltered\": "+str(dev_count)+"}"
29     return HttpResponse(dev_info, content_type='text/json')
30