Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5f97dcf9da
Fetching contributors…

Cannot retrieve contributors at this time

file 66 lines (48 sloc) 1.528 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#!/usr/bin/python

import bottle
bottle.debug(True)

from bottle import route, run, response, request
import locDb, time, sys




@route('/found/:loc')
def found(loc):
    if(isAuthorized()):
        return updateLoc(loc)
    else:
        return "NOT AUTHORIZED"

@route('/where')
def where():
if (isAuthorized()):
return getLastKnownLoc()
else:
return "NOT AUTHORIZED"
    
    
    

def getLastKnownLoc():
    resultsPage = ""
    sql = """select * from location order by id desc limit 1"""
    db = locDb.locDb()
    results = db.execute(sql)
    
    for result in results:
        id, timestamp, loc, ip, agent = result[:]
        resultsPage += time.strftime("%a, %b %d %I:%M%p",time.localtime(float(timestamp))) + ": " + loc + " (" + ip + "/" + agent + ") <br>"
    return resultsPage

def updateLoc(loc):
    ip = bottle.request.environ.get('REMOTE_ADDR')
    agent = request.GET.get('agent')
    sql = """insert into location values (null, "%s", "%s", "%s", "%s")""" % (time.time(), loc, ip, agent)
    db = locDb.locDb()
    db.execute(sql)
    return "SUCCESS"

def isAuthorized():
    agent = request.GET.get('agent')
    passw = request.GET.get('pass')
    
    db = locDb.locDb()
    sql = '''select agent from users where agent="%s" and password="%s"'''%(agent, passw)
    result = db.execute(sql)
    if len(result) > 0:
        return True
    else:
        return False

@route('/createDb')
def create():
    db = locDb.locDb()
    db.createTables()
    

bottle.run(host=sys.argv[1], port=sys.argv[2])
Something went wrong with that request. Please try again.