forked from EternityForest/KaithemAutomation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManageUsers.py
144 lines (120 loc) · 5.56 KB
/
ManageUsers.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
142
143
144
#Copyright Daniel Black 2013
#This file is part of Kaithem Automation.
#Kaithem Automation is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, version 3.
#Kaithem Automation is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with Kaithem Automation. If not, see <http://www.gnu.org/licenses/>.
import cherrypy, auth ,pages
from util import quote
class ManageAuthorization():
@cherrypy.expose
def index(self):
pages.require("/admin/users.edit")
return pages.get_template("auth/index.html").render(auth = auth)
#The actual POST target to delete a user
@cherrypy.expose
def deluser(self,**kwargs):
pages.require("/admin/users.edit")
auth.removeUser(kwargs['user'])
raise cherrypy.HTTPRedirect("/auth")
#POST target for deleting a group
@cherrypy.expose
def delgroup(self,**kwargs):
pages.require("/admin/users.edit")
auth.removeGroup(kwargs['group'])
raise cherrypy.HTTPRedirect("/auth")
#INterface to select a user to delete
@cherrypy.expose
def deleteuser(self,**kwargs):
pages.require("/admin/users.edit")
return pages.get_template("auth/deleteuser.html").render()
#Interface to select a group to delete
@cherrypy.expose
def deletegroup(self,**kwargs):
pages.require("/admin/users.edit")
return pages.get_template("auth/deletegroup.html").render()
#Add user interface
@cherrypy.expose
def newuser(self):
pages.require("/admin/users.edit")
return pages.get_template("auth/adduser.html").render()
#add group interface
@cherrypy.expose
def newgroup(self):
pages.require("/admin/users.edit")
return pages.get_template("auth/newgroup.html").render()
@cherrypy.expose
#handler for the POST request to change user settings
def newusertarget(self,**kwargs):
#THIS IS A HACK TO PREVENT UNICODE STRINGS IN PY2.XX FROM GETTING THROUGH
#BECAUSE QUOTE() IS USUALLY WHERE THEY CRASH. #AWFULHACK
quote(kwargs['username'])
pages.require("/admin/users.edit")
#create the new user
auth.addUser(kwargs['username'],kwargs['password'])
#Take the user back to the users page
raise cherrypy.HTTPRedirect("/auth/")
@cherrypy.expose
#handler for the POST request to change user settings
def newgrouptarget(self,**kwargs):
#THIS IS A HACK TO PREVENT UNICODE STRINGS IN PY2.XX FROM GETTING THROUGH
#BECAUSE QUOTE() IS USUALLY WHERE THEY CRASH. #AWFULHACK
quote(kwargs['groupname'])
pages.require("/admin/users.edit")
#create the new user
auth.addGroup(kwargs['groupname'])
#Take the user back to the users page
raise cherrypy.HTTPRedirect("/auth/")
@cherrypy.expose
#handler for the POST request to change user settings
def updateuser(self,user,**kwargs):
#THIS IS A HACK TO PREVENT UNICODE STRINGS IN PY2.XX FROM GETTING THROUGH
#BECAUSE QUOTE() IS USUALLY WHERE THEY CRASH. #AWFULHACK
quote(kwargs['username'])
#Remove the user from all groups that the checkbox was not checked for
for i in auth.Users[user]['groups']:
if not ('Group'+i) in kwargs:
auth.removeUserFromGroup(user,i)
#Add the user to all checked groups
for i in kwargs:
if i[:5] == 'Group':
if kwargs[i] == 'true':
auth.addUserToGroup(user,i[5:])
auth.changePassword(user,kwargs['password'])
auth.changeUsername(user,kwargs['username'])
#Take the user back to the users page
raise cherrypy.HTTPRedirect("/auth")
@cherrypy.expose
#handler for the POST request to change user settings
def updategroup(self,group,**kwargs):
pages.require("/admin/users.edit")
auth.Groups[group]['permissions'] = []
#Handle all the group permission checkboxes
for i in kwargs:
#Since HTTP args don't have namespaces we prefix all the permission checkboxes with permission
if i[:10] == 'Permission':
if kwargs[i] == 'true':
auth.addGroupPermission(group,i[10:])
#Take the user back to the users page
auth.generateUserPermissions() #update all users to have the new permissions lists
raise cherrypy.HTTPRedirect("/auth")
#Settings page for one individual user
@cherrypy.expose
def user(self,username):
pages.require("/admin/users.edit")
return pages.get_template("auth/user.html").render(
usergroups=auth.Users[username]['groups'],
groups= sorted(auth.Groups.keys()),
password = auth.Users[username]['password'],
username = username)
#Settings page for one individual group
@cherrypy.expose
def group(self,group):
pages.require("/admin/users.edit")
return pages.get_template("auth/group.html").render(
auth = auth, name = group)