-
Notifications
You must be signed in to change notification settings - Fork 0
/
Webhooker.py
executable file
·141 lines (121 loc) · 4.74 KB
/
Webhooker.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/python
from TriggerHorn import *
from SecretKey import *
import json
from flask import jsonify
import requests
import datetime
import flask
import hmac
import time
import ast
import multiprocessing
import Phone
from hashlib import sha1
from django.utils.crypto import constant_time_compare
app = flask.Flask(__name__)
###############################################################################
def isAuthorized(username):
if username in ['LOMANCER', 'MIKEKAPUSCIK', 'SLAPPLEBAGS']:
return True
elif 8 <= datetime.datetime.now().hour <= 20:
return True
else:
return False
###############################################################################
def isAuthenticated(key, nonce, networkTime, oneTimePassword):
currentTime = time.mktime(time.localtime())
localOneTimePassword = getOneTimePassword(key, nonce, networkTime)
validHash = constant_time_compare(localOneTimePassword, oneTimePassword)
validTimeDifference = abs(currentTime - networkTime) < 3
return validHash and validTimeDifference
###############################################################################
@app.route("/")
def hello():
return "Webhooks Options:\n \n/yo \n/yolights " + \
"\n/yoworkroomlights \n/yoclassroomlights \n/github \n/sendyo"
###############################################################################
def sendSMS(number, message = "Yo!"):
data = {"number":number, "message":message}
requests.post("http://textbelt.com/text", data = data)
###############################################################################
@app.route("/yo", methods=['GET'])
def yo():
username = flask.request.args.get('username')
yo_text = "Yo!"
if username is not None:
yo_text = "Yo! from " + username
data = {"callerID":yo_text, "extension":27000}
requests.post("http://asterisk-02.west.sbhackerspace.com:8080/all", data = data)
return 'yo', 200
###############################################################################
@app.route("/yolights", methods=['GET'])
def yoLights():
username = flask.request.args.get('username')
if isAuthorized(username):
requests.get("http://classroom-lights.west.sbhackerspace.com/toggle")
requests.get("http://workroom-lights.west.sbhackerspace.com/toggle")
return 'yo', 200
###############################################################################
@app.route("/yoclassroomlights", methods=['GET'])
def yoClassroomLights():
username = flask.request.args.get('username')
if isAuthorized(username):
requests.get("http://classroom-lights.west.sbhackerspace.com/toggle")
return 'yo', 200
###############################################################################
@app.route("/yoworkroomlights", methods=['GET'])
def yoWorkroomLigts():
username = flask.request.args.get('username')
if isAuthorized(username):
requests.get("http://workroom-lights.west.sbhackerspace.com/toggle")
return 'yo', 200
###############################################################################
@app.route("/github", methods=['POST'])
def github():
data = flask.request.get_json()
try:
githubSignature = flask.request.headers.get('X_HUB_SIGNATURE')[5:]
localSignature = \
hmac.new(getGithubSecretKey(), flask.request.get_data(), sha1).hexdigest()
if constant_time_compare(githubSignature, localSignature):
data = {"callerID":"Yo! from SBHXGITHUB", "extension":27000}
requests.post("http://asterisk-02.west.sbhackerspace.com:8080/all", data = data)
triggerHorn()
except Exception as e:
pass
return 'github', 200
###############################################################################
@app.route("/asterisk", methods=['GET'])
def asterisk():
try:
print 'fuck '
status = flask.request.args.get('status')
print status
if status == "incoming":
print 'starting'
gProcess = multiprocessing.Process(target=Phone.triggerPhone())
gProcess.start()
except Exception as e:
print e
print 'returning'
return 'asterisk status received', 200
###############################################################################
@app.route("/sendyo", methods=['POST'])
def sendYo():
inputData = ast.literal_eval(flask.request.form.keys()[0])
nonce = str(inputData['nonce'])
networkOneTimePassword = str(inputData['otp'])
localTime = float(inputData['time'])
if isAuthenticated(getYoSecretKey(), nonce, localTime, networkOneTimePassword):
data = {'api_token' : getYoApiKey()}
requests.post('https://api.justyo.co/yoall/', data = data)
return 'Yo Sent', 200
###############################################################################
###############################################################################
if __name__ == "__main__":
try:
app.run(host='0.0.0.0', port=80)
except:
print 'shit failed'
exit()