-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
107 lines (90 loc) · 3.25 KB
/
setup.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
import os
import ConfigParser
import socket
from Crypto.Cipher import AES
# MAKE SURE WE is in the correct directory
os.chdir('/home/pi/dashdisplay')
configsave = ConfigParser.RawConfigParser()
configsave.read('eClock.cfg')
def dovalue(nsection, nkey, nprompt):
"""Double checks the INI section is valid, creates if needed. Then prompts for value"""
if configsave.has_section(nsection) == False:
configsave.add_section(nsection)
if configsave.has_option(nsection, nkey) == False:
configsave.set(nsection, nkey, '')
newvalue = raw_input(nprompt+' ['+configsave.get(nsection, nkey)+'] ? ') or configsave.get(nsection, nkey)
configsave.set(nsection, nkey, newvalue)
def dovaluepwd(nsection, nkey, nprompt):
"""The Crypto Verion of dovalue """
mypihostname = socket.gethostname().zfill(16)
mypiserial = getserial().zfill(16)
cipherobj = AES.new(mypihostname, AES.MODE_CFB, mypiserial)
cipherobjb = AES.new(mypihostname, AES.MODE_CFB, mypiserial)
if configsave.has_section(nsection) == False:
configsave.add_section(nsection)
if configsave.has_option(nsection, nkey) == False:
configsave.set(nsection, nkey, '')
oldvalue = ''
else:
oldvalue = cipherobj.decrypt(configsave.get(nsection, nkey))
newvalue = raw_input(nprompt+' [########] ? ') or oldvalue
configsave.set(nsection, nkey, cipherobjb.encrypt(newvalue))
def getserial():
"""Extract serial from cpuinfo file"""
cpuserial = "0000000000000000"
try:
gsfile = open('/proc/cpuinfo', 'r')
for line in gsfile:
if line[0:6] == 'Serial':
cpuserial = line[10:26]
gsfile.close()
except:
cpuserial = "ERROR000000000"
return cpuserial
print 'Raspberry PI Dash Display Setup'
print 'from https://github.com/topcats/rpi_dashboard'
print ''
print 'Setup config (y) ?'
nulyi = raw_input('')
if nulyi == '' or nulyi == 'y':
#all ok
print ''
else:
quit()
#Set Weather Stuff
print 'Weather:'
dovalue('Weather', 'appid', 'App ID')
dovalue('Weather', 'TownID', 'Town ID')
dovalue('Weather', 'TownName', 'Town Name')
dovalue('Weather', 'Refresh', 'Refresh interval (minutes) (0 will disable)')
#DLNA
print 'DLNA'
dovalue('DLNA', 'url', 'MiniDLNA Web Address')
dovalue('DLNA', 'Refresh', 'Refresh interval (minutes) (0 will disable)')
#User Stuff
print 'Owner'
dovalue('Owner', 'PhoneIP', 'Phone IP Address')
dovalue('Owner', 'CheckInterval', 'Check interval (seconds) (0 will disable)')
#Office 365
print 'Office 365'
dovalue('Office365', 'email', 'Email Address')
dovaluepwd('Office365', 'password', 'Password')
dovalue('Office365', 'Refresh', 'Refresh interval (minutes) (0 will disable)')
#Z-Wave
print 'Z-Wave'
dovalue('ZWave', 'enabled', 'Z-Wave Control Enabled (0 will disable)')
dovalue('ZWave', 'url', 'Automation API Base URL Address')
dovalue('ZWave', 'username', 'Username')
dovaluepwd('ZWave', 'password', 'Password')
#Save it
print ''
print 'New Config'
for section in configsave.sections():
print section
for key, val in configsave.items(section):
print ' '+key+ "\t = " + val
nulyi = raw_input('All Ok (Enter y to save) ?')
if nulyi == 'y':
with open('eClock.cfg', 'wb') as configfile:
configsave.write(configfile)
print 'Saved'