-
Notifications
You must be signed in to change notification settings - Fork 1
/
iButton.py
65 lines (52 loc) · 1.55 KB
/
iButton.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
import os
import time
import csh_ldap as ldap
import login
def main():
global cshldap
cshldap = ldap.CSHLDAP(login.ldap_user, login.ldap_pass)
get_ibutton()
def find_user(varID):
ibutton = varID.strip()
ibutton = "*" + ibutton[3:] + "01"
try:
member = cshldap.get_member_ibutton(ibutton)
return member.homeDirectory
except Exception as e:
print(e)
return None
def get_ibutton():
base_dir = '/sys/devices/w1_bus_master1/w1_master_slaves'
delete_dir = '/sys/devices/w1_bus_master1/w1_master_remove'
while True:
data = open(base_dir, "r")
ibutton = data.read()
ibutton = ibutton.strip()
data.close()
d = open(delete_dir, "w")
if ibutton != "not found.":
print(ibutton)
d.write(ibutton)
d.flush()
try:
find_colors(find_user(ibutton))
except Exception as e:
print(e)
time.sleep(3)
d.close()
def find_colors(user_dir):
if user_dir is not None:
cfile = os.path.join(user_dir, ".colors")
temp = os.popen("ssh -i /home/sgreen/.ssh/id_rsa "
+ login.file_server + " cat " + cfile)
colors = temp.read().split()
temp.close()
for line in colors:
if(line[:5] is "delay"):
time.sleep(float(line[7:]))
else:
print(line)
os.system("curl -X POST -d 'color=" + line +
"' localhost:80")
if __name__ == "__main__":
main()