Exemple #1
0
def writeResult(field, key, val):
    with open('/home/' + getUser() + '/wifi_monitor/output.json', 'r') as f:
        j = eval("".join(f.readlines()))
        if not field in j:
            j[field] = {}
        j[field][key] = val
    with open('/home/' + getUser() + '/wifi_monitor/output.json', 'w') as f:
        f.truncate()
        f.write(json.dumps(j))
def setup():
    global accountSid, authToken, client, myPhoneNumber, toPhoneNumbers

    with open('/home/' + getUser() + '/wifi_monitor/.twilio.tokens', 'r') as f:
        accountSid = f.readline().strip()
        authToken = f.readline().strip()
        myPhoneNumber = f.readline().strip()

    with open('/home/' + getUser() + '/wifi_monitor/.phone.numbers', 'r') as f:
        toPhoneNumbers = [i.split() for i in f.readlines()]

    client = Client(accountSid, authToken)
Exemple #3
0
def home():
    udict = {'uname':False}
    if 'username' in session:
        username = escape(session['username'])
        udict = util.getUser(username)
        return redirect('/events')
    return render_template('home.html', udict = udict)
def getCurrentDownloadSpeed():
    os.chdir('/home/' + getUser() + '/wifi_monitor/')
    result = subprocess.run([
        'bash', '-c', 'time wget ' + fileLink,
        '-U "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-GB; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1"',
        '--no-check-certificate'
    ],
                            stderr=subprocess.PIPE)
    try:

        stderr = str(result.stderr.decode('utf-8'))
        outputGarbage = stderr.split(' ')[-1]
        splitGarbage = outputGarbage.split('\n')

        time = [i for i in splitGarbage if 'real' in i][0].split('\t')[1]

        seconds = parseTimeToSeconds(time)
        downloadSpeed = (fileSize / seconds) * 8 * magicRatio

        if (downloadSpeed > 150): return  # this is clearly an error

        cleanup()
        writeSpeedResult(downloadSpeed)
        checkForAlert(downloadSpeed)

        return downloadSpeed
    except:
        pass  # we'll get it later
def pull():
    try:
        os.chdir('/home/' + getUser() + '/wifi_monitor')
        subprocess.run(['git', 'fetch'])
        subprocess.run(['git', 'rebase', 'origin/master'])
    except:
        # well rip
        pass
Exemple #6
0
def user_page(uname = None):

    #if util. ---this will check if the uname exists
    if util.getUser(uname) == None:
        flash("That's not a user")
        return redirect('/events')
    else:
        username = escape(session['username'])
        udict = util.getUser(username)
        pdict = util.getUser(uname)
        pic = util.getPicture (udict['uname'])

    if request.method=="POST":
            print(request.form["rating"])


    return render_template('user.html', udict = udict, pdict=pdict, profile = pic)
Exemple #7
0
def your_event():
    username = escape(session['username'])
    udict = util.getUser(username)
    all_lists =[]
    all_lists.append(util.getHostedEvents(username))
    all_lists.append(util.getApprovedEvents(username))
    all_lists.append(util.getRequestedEvents(username))

    return render_template('your_events.html', udict = udict, alist = all_lists)
def upload():
    try:
        os.chdir('/home/' + getUser() + '/wifi_monitor')
        subprocess.run(['git', 'add', 'output.json'], stdout=subprocess.DEVNULL)
        subprocess.run(['git', 'commit', '-m', '"Another speed test"'], stdout=subprocess.DEVNULL)
        subprocess.run(['git', 'push', 'origin', 'master'], stdout=subprocess.DEVNULL)
    except Exception as e:
        # oh well, we can try again next time
        pass
Exemple #9
0
def addreview(uname = None):
    username = escape(session['username'])
    udict = util.getUser(username)
    review = {}
    review['user'] = username
    review['rating'] = int(request.form["rating"])
    review['comment'] = request.form["comment"]
    util.updateReview(uname, review)
    return redirect('/user/'+ uname)
Exemple #10
0
def newmsg(eventid = None):
    username = escape(session['username'])
    udict = util.getUser(username)
    msg = {}
    msg['user'] = username
    msg['msg'] = request.form["msg"]
    msg['time'] = datetime.today()
    util.updateEField(eventid, 'msgs', msg)

    return redirect('/event_page/'+ eventid )
Exemple #11
0
def joinevent():
    username = escape(session['username'])
    udict = util.getUser(username)
    elist = util.validEvents(username)
    if request.method=="POST":
        event = request.form["submit"] # objectid
        util.updateEField(event, 'requests', username)
        util.addEventUserList(username, 'revents', event)
        return render_template('events.html', udict=udict, elist=elist,
                               name = util.getEventAttribute(event, "ename"))
Exemple #12
0
def event_page(id = None):
    if request.method=="POST":
        value = request.form["submit"]
        if (value == "close"):
            util.updateEventField(id, "open", False)
        elif (value == "start"):
            util.startEvent(id);
    username = escape(session['username'])
    udict = util.getUser(username)
    event = util.getEvent(id)
    return render_template('event_page.html', udict = udict, event = event)
Exemple #13
0
def joinevent():
    username = escape(session['username'])
    udict = util.getUser(username)
    #elist = util.listEvents(); # do we need this?
    elist = util.validEvents(username)
    if request.method=="POST":
        event = request.form["submit"] # objectid
        #print event
        util.updateEField(event, 'requests', username)
        #util.updateUField(username, 'requests', event) #event doesn't include objectid
        util.addEventUserList(username, 'revents', event)
        #util.addEventPerson(event, username)
        return render_template('events.html', udict=udict, elist=elist,
                               name = util.getEventAttribute(event, "ename"))
Exemple #14
0
def events():
    username = escape(session['username'])
    udict = util.getUser(username)
    #elist = util.listEvents();
    elist = util.validEvents(username)
    return render_template('events.html', udict=udict, elist=elist)
Exemple #15
0
def event_create():
    username = escape(session['username'])

    return render_template('eventCreate.html', udict=util.getUser(username))
Exemple #16
0
def personal(thing = None):
    username = escape(session['username'])
    udict = util.getUser(username)
    pic = util.getPicture (udict['uname'])
    print pic
    return render_template('personal.html', udict=udict, change=thing, profile = pic)
Exemple #17
0
def ajax():
    udict = {'uname':False}
    if 'username' in session:
        username = escape(session['username'])
        udict = util.getUser(username)
    return render_template('ajaxTest.html', udict=udict)
def releaseLock():
    os.chdir('/home/' + getUser() + '/wifi_monitor')
    subprocess.run(['rm', 'alert.lock'])
Exemple #19
0
def getUserInfo():
    username = session["user"]
    print util.getUser(username)
    return json.dumps(util.getUser(username))
def acquireLock():
    os.chdir('/home/' + getUser() + '/wifi_monitor')
    subprocess.run(['touch', 'alert.lock'])
def cleanup():
    os.chdir('/home/' + getUser() + '/wifi_monitor/')
    filename = fileLink.split('/')[-1]
    subprocess.run(['rm', filename])
def isLocked():
    os.chdir('/home/' + getUser() + '/wifi_monitor')
    run = subprocess.run(['test', '-f', 'alert.lock'])
    if run.returncode == 1:
        return False
    return True
Exemple #23
0
def getOtherInfo():
    otherUser = request.args.get("otherUser", "").strip()
    print otherUser #to make sure we're looking for the right other user
    return json.dumps(util.getUser(otherUser))
Exemple #24
0
def p():
    username = escape(session['username'])
    picture = util.getPicture (session['username'])
    return render_template('personal.html', udict=util.getUser(username), change = "Null", profile = picture)