-
Notifications
You must be signed in to change notification settings - Fork 0
/
MySTUserHandler.py
executable file
·148 lines (122 loc) · 3.81 KB
/
MySTUserHandler.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
145
146
147
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
This file is part of MyServerTalks.
MyServerTalks 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; either version 2 of the License, or
(at your option) any later version.
MyServerTalks 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 MyServerTalks; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
'''
# TODO: get user rights
class MySTUserHandler:
def __init__(self, config):
self.escope = {}
self.rights = {}
self.environment = {}
# Call method to get user rights
self.loadUserRights()
self.contact_handler = None
self.config = config
def userLoad(self):
roster_contacts = self.contact_handler.getContacts()
contacts = self.config.get('contacts')
# Exclude contacts not enabled in roster
for rct in roster_contacts:
if not self.isUserEnabled(rct):
self.contact_handler.removeContact(rct)
# Add roster contacts into roster
for uct in contacts:
if self.isUserEnabled(uct):
found = False
for rct in roster_contacts:
if (rct == uct):
found = True
if not found:
self.contact_handler.addContact(uct)
def setContactHandler(self, contact_handler):
self.contact_handler = contact_handler
self.userLoad()
# TODO: Compare user configuration agains contacts. Remove contacts not present into contacts.ini and add new ones.
def getContactHandler(self):
return self.contact_handler
def addContact(self,contact):
self.contact_handler.addContact(contact)
# TODO: Insert contact into config file
def removeContact(self, contact):
self.contact_handler.removeContact(contact)
# TODO: Remove contact from config file
def getContactList(self):
try:
return self.contact_handler.getContacts()
except Exception:
return []
def isUserEnabled(self, user):
try:
status = self.config.get('contacts', user, 'status')
if (status.lower().strip() == 'enabled'):
return True
else:
return False
except Exception:
return False
def setUserEscope(self, user, escope):
self.escope[user] = escope
return escope
def getUserEscope(self, user):
escope = ''
try:
escope = self.escope[user]
except Exception:
try:
status = self.config.get('contacts', user, 'status')
if (status.lower().strip() == 'enabled'):
escope = self.setUserEscope(user, 'user')
except Exception:
pass
return escope
def escopeAuth(self, user, secret):
result = False
try:
status = self.config.get('contacts', user, 'status')
super_secret = self.config.get('contacts', user, 'super-secret')
if (status.lower().strip() == 'enabled'):
if (secret.strip() == super_secret.strip()):
result = True
except Exception:
pass
return result
def loadUserRights(self):
return
def getUserRights(self, user):
return
def userHasRights(self, user, command):
return True
def setUserEnvironment(self, user, var, val):
try:
self.environment[user][var] = val
except Exception:
self.environment[user] = {}
self.environment[user][var] = val
def getUserEnvironment(self, user, var=None):
if (var == None):
try:
return self.environment[user]
except Exception:
return {}
try:
return self.environment[user][var]
except Exception:
return ''
def saveUserEnvironment(self, user):
pass
def loadUserEnvironment(self, user):
pass
def cleanUserEnvironment(self, user):
self.environment[user] = {}