Mercurial > traipse_dev
comparison orpg/tools/passtool.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | c54768cffbd4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: passtool.py | |
21 # Author: Todd "Snowdog" Faris | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: passtool.py,v 1.9 2006/11/04 21:24:22 digitalxero Exp $ | |
25 # | |
26 # Description: password helper. remembers passwords so user | |
27 # doesn't have to type passwords over and over | |
28 | |
29 import orpg.orpg_windows | |
30 from orpg.orpgCore import open_rpg | |
31 import traceback | |
32 | |
33 ##################### | |
34 ## Password Assistant | |
35 ##################### | |
36 class PassSet: | |
37 "set of passwords for a given room id on a server" | |
38 def __init__(self): | |
39 #room admin password (aka boot password) | |
40 self.admin = None | |
41 | |
42 #room password | |
43 self.room = None | |
44 | |
45 | |
46 | |
47 class PassTool: | |
48 "Password Management System" | |
49 def __init__(self): | |
50 self.settings = open_rpg.get_component("settings") | |
51 #server admin password | |
52 self.server = None | |
53 self.groups = {} | |
54 if self.settings.get_setting('PWMannager') == 'On': | |
55 self.enabled = 1 | |
56 else: | |
57 self.enabled = 0 | |
58 | |
59 | |
60 def DumpPasswords(self): | |
61 "Debugging Routine" | |
62 print("Password Manager Dump\nServer: \""+self.server+"\"") | |
63 for c in self.groups: | |
64 ad = self.groups[c].admin | |
65 rm = self.groups[c].room | |
66 print( " #"+str(c)+" R:\""+str(rm)+"\" A:\""+str(ad)+"\"") | |
67 | |
68 def ClearPassword( self, type="ALL", groupid=0): | |
69 if type == "ALL" and groupid == 0: | |
70 self.server = None | |
71 self.groups={} | |
72 elif type == "ALL": | |
73 self.groups[ int(groupid) ].admin= None | |
74 self.groups[ int(groupid) ].room= None | |
75 elif type == "server": self.server = None | |
76 elif type == "admin": self.groups[ int(groupid) ].admin = None | |
77 elif type == "room": | |
78 self.groups[ int(groupid) ].room = None | |
79 else: pass | |
80 | |
81 def QueryUser(self,info_string): | |
82 pwd_dialog = orpg.orpg_windows.wx.TextEntryDialog(None,info_string,"Password Required") | |
83 if pwd_dialog.ShowModal() == orpg.orpg_windows.wx.ID_OK: | |
84 pwd_dialog.Destroy() | |
85 return str(pwd_dialog.GetValue()) | |
86 else: | |
87 pwd_dialog.Destroy() | |
88 return None | |
89 | |
90 def CheckGroupData(self, id ): | |
91 try: #see if group exists | |
92 group=self.groups[ int(id) ] | |
93 except: #group doesn't exist... create it | |
94 self.groups[ int(id) ] = PassSet() | |
95 | |
96 def RemoveGroupData(self, id ): | |
97 try: | |
98 #if PassSet exists for group remove it. | |
99 del self.groups[int(id)] | |
100 except: | |
101 pass | |
102 | |
103 def GetSilentPassword( self, type="server", groupid = 0): | |
104 try: | |
105 self.CheckGroupData( groupid ) | |
106 if type == "admin": | |
107 if self.groups[int(groupid)].admin != None: return str(self.groups[int(groupid)].admin) | |
108 else: return None | |
109 elif type == "room": | |
110 if self.groups[int(groupid)].room != None: return str(self.groups[int(groupid)].room) | |
111 else: return None | |
112 elif type == "server": | |
113 if self.server != None: return str(self.server) | |
114 else: return None | |
115 except: | |
116 traceback.print_exc() | |
117 #return None | |
118 | |
119 def GetPassword(self, type="room", groupid=0): | |
120 if self.Is_Enabled(): | |
121 self.CheckGroupData( groupid ) | |
122 if type == "admin": return self.AdminPass(int(groupid)) | |
123 elif type == "room": return self.RoomPass(int(groupid)) | |
124 elif type == "server": return self.ServerPass() | |
125 else: | |
126 querystring = "Enter password for \""+str(type)+"\"" | |
127 return self.QueryUser( querystring ) | |
128 else: | |
129 if type == "admin": return self.QueryUser( "Enter Admin(Boot) Password" ) | |
130 elif type == "room": return self.QueryUser("Enter Room Password" ) | |
131 elif type == "server": return self.QueryUser( "Enter Server Administrator Password" ) | |
132 else: | |
133 querystring = "Enter password for \""+str(type)+"\"" | |
134 return self.QueryUser( querystring ) | |
135 | |
136 | |
137 def Is_Enabled(self): | |
138 return int(self.enabled) | |
139 | |
140 def Enable(self): | |
141 self.enabled = 1 | |
142 self.settings.set_setting('PWMannager', 'On') | |
143 | |
144 def Disable(self): | |
145 self.enabled = 0 | |
146 self.settings.set_setting('PWMannager', 'Off') | |
147 | |
148 | |
149 def AdminPass( self, groupid ): | |
150 self.CheckGroupData( groupid ) | |
151 if self.groups[ int(groupid) ].admin != None: return str(self.groups[ int(groupid) ].admin) | |
152 else: | |
153 self.groups[ int(groupid) ].admin = self.QueryUser("Please enter the Room Administrator Password:") | |
154 return str(self.groups[ int(groupid) ].admin) | |
155 | |
156 | |
157 def RoomPass( self, groupid): | |
158 self.CheckGroupData( groupid ) | |
159 if self.groups[ int(groupid) ].room != None: return str(self.groups[ int(groupid) ].room) | |
160 else: | |
161 self.groups[ int(groupid) ].room = self.QueryUser("Please enter the Room Password:") | |
162 return str(self.groups[ int(groupid) ].room) | |
163 | |
164 | |
165 def ServerPass( self ): | |
166 if self.server != None: return str(self.server) | |
167 else: | |
168 self.server = self.QueryUser("Please enter the Server Administrator password:") | |
169 return str(self.server) | |
170 | |
171 def FailPassword( self, type="room", groupid=0): | |
172 self.CheckGroupData( groupid ) | |
173 if type == "admin": | |
174 self.ClearPassword( type, groupid ) | |
175 return self.AdminPass() | |
176 elif type == "room": | |
177 self.ClearPassword( type, groupid ) | |
178 return self.RoomPass() | |
179 elif type == "server": | |
180 self.ClearPassword( type, groupid ) | |
181 return self.ServerPass() |