This repository was archived by the owner on Dec 23, 2025. It is now read-only.
forked from nebhead/garage-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
154 lines (115 loc) · 4.77 KB
/
Copy pathapp.py
File metadata and controls
154 lines (115 loc) · 4.77 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
from flask import Flask, request, render_template, make_response
import time
import datetime
import os
from common import *
app = Flask(__name__)
@app.route('/')
def index():
door_history, events = ReadLog()
states = ReadStates()
settings = ReadSettings()
if(states['inputs']['switch'] == True):
door_state = True
else:
door_state = False
return render_template('index.html', state=door_state, events=events, door_history=door_history, camera_url=settings['misc']['CameraURL'])
@app.route('/button')
def button():
states = ReadStates()
states['outputs']['button'] = True # Button pressed - Set state to 'on'
WriteStates(states) # Write button press to file
return render_template('button.html')
@app.route('/history')
def history():
door_history, events = ReadLog()
return render_template('door-log.html', door_history=door_history, events=events)
@app.route('/admin/<action>', methods=['POST','GET'])
@app.route('/admin', methods=['POST','GET'])
def admin(action=None):
states = ReadStates()
settings = ReadSettings()
if action == 'reboot':
event = "Reboot Requested."
WriteLog(event)
os.system("sleep 3 && sudo reboot &")
#Show Reboot Splash
return render_template('shutdown.html', action=action)
if action == 'shutdown':
event = "Shutdown Requested."
WriteLog(event)
os.system("sleep 3 && sudo shutdown -h now &")
#Show Shutdown Splash
return render_template('shutdown.html', action=action)
if (request.method == 'POST') and (action == 'settings'):
response = request.form
if('from_email' in response):
if(response['from_email']!=''):
print("from_email: " + response['from_email'])
settings['email']['FromEmail'] = response['from_email']
if('to_email' in response):
if(response['to_email']!=''):
print("to_email: " + response['to_email'])
settings['email']['ToEmail'] = response['to_email']
if('server' in response):
if(response['server']!=''):
print("Server: " + response['server'])
settings['email']['SMTPServer'] = response['server']
if('port' in response):
if(response['port']!=''):
print("Port: " + response['port'])
settings['email']['SMTPPort'] = int(response['port'])
if('username' in response):
if(response['username']!=''):
print("username: " + response['username'])
settings['email']['Username'] = response['username']
if('password' in response):
if(response['password']!=''):
print("password: " + response['password'])
settings['email']['Password'] = response['password']
use_tls = 'use_tls' in response
if(use_tls!=settings['email']['UseTLS']):
print("useTLS: %s" % use_tls)
settings['email']['UseTLS'] = use_tls
if('public_url' in response):
if(response['public_url']!=''):
print("public_url: " + response['public_url'])
settings['misc']['PublicURL'] = response['public_url']
if('timeout' in response):
if(response['timeout']!=''):
print("Timeout: " + response['timeout'])
settings['notification']['minutes'] = int(response['timeout'])
if('reminder' in response):
if(response['reminder']!=''):
print("Reminder: " + response['reminder'])
settings['notification']['reminder'] = int(response['reminder'])
if('iftttapi' in response):
if(response['iftttapi']!=''):
print("IFTTT API Key: " + response['iftttapi'])
settings['ifttt']['APIKey'] = response['iftttapi']
settings['ifttt']['notify_on_open'] = "off" # Turn off notify_on_open if no response from POST
if('notify_on_open' in response):
if(response['notify_on_open']!=''):
print("Notify on Open: " + response['notify_on_open'])
settings['ifttt']['notify_on_open'] = response['notify_on_open']
if('pushover_apikey' in response):
if(response['pushover_apikey']!=settings['pushover']['APIKey']):
print("Pushover API key: " + response['pushover_apikey'])
settings['pushover']['APIKey'] = response['pushover_apikey']
if('pushover_userkeys' in response):
if(response['pushover_userkeys']!=settings['pushover']['UserKeys']):
print("Pushover User keys: " + response['pushover_userkeys'])
settings['pushover']['UserKeys'] = response['pushover_userkeys']
WriteSettings(settings)
event = "Settings Updated."
WriteLog(event)
uptime = os.popen('uptime').readline()
cpuinfo = os.popen('cat /proc/cpuinfo').readlines()
return render_template('admin.html', action=action, uptime=uptime, cpuinfo=cpuinfo, settings=settings)
@app.route('/manifest')
def manifest():
res = make_response(render_template('manifest.json'), 200)
res.headers["Content-Type"] = "text/cache-manifest"
return res
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True) # use ,debug=True for debug mode