root / pykota / trunk / pykota / storages / ldap.py @ 983

Revision 983, 9.6 kB (checked in by jalet, 21 years ago)

More work on LDAP

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# PyKota
2#
3# PyKota : Print Quotas for CUPS and LPRng
4#
5# (c) 2003 Jerome Alet <alet@librelogiciel.com>
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19#
20# $Id$
21#
22# $Log$
23# Revision 1.4  2003/05/01 21:08:44  jalet
24# More work on LDAP
25#
26# Revision 1.3  2003/04/30 17:40:02  jalet
27# I've got my assigned number for LDAP by the IANA.
28#
29# Revision 1.2  2003/04/27 08:27:34  jalet
30# connection to LDAP backend
31#
32# Revision 1.1  2003/04/27 08:04:15  jalet
33# LDAP storage backend's skeleton added. DOESN'T WORK.
34#
35#
36#
37
38#
39# My IANA assigned number, for
40# "Conseil Internet & Logiciels Libres, J�me Alet"
41# is 16868. Use this as a base to create the LDAP schema.
42#
43
44import fnmatch
45
46from pykota.storage import PyKotaStorageError
47
48try :
49    import ldap
50except ImportError :   
51    import sys
52    # TODO : to translate or not to translate ?
53    raise PyKotaStorageError, "This python version (%s) doesn't seem to have the python-ldap module installed correctly." % sys.version.split()[0]
54   
55class Storage :
56    def __init__(self, host, dbname, user, passwd) :
57        """Opens the LDAP connection."""
58        raise PyKotaStorageError, "Sorry, the LDAP backend for PyKota is not yet implemented !"
59        self.closed = 1
60        try :
61            self.database = ldap.initialize(host) 
62            self.database.simple_bind_s(user, passwd)
63            self.basedn = dbname
64        except ldap.SERVER_DOWN :   
65            raise PyKotaStorageError, "LDAP backend for PyKota seems to be down !" # TODO : translate
66        else :   
67            self.closed = 0
68           
69    def __del__(self) :       
70        """Closes the database connection."""
71        if not self.closed :
72            del self.database
73            self.closed = 1
74       
75    def doSearch(self, key, fields, base="") :
76        """Does an LDAP search query."""
77        try :
78            # prepends something more restrictive at the beginning of the base dn
79            newbase = ",".join([base, self.basedn])
80            if newbase.startswith(",") :
81                newbase = newbase[1:]
82            result = self.database.search_s(newbase, ldap.SCOPE_SUBTREE, key, fields)
83        except ldap.NO_SUCH_OBJECT :   
84            return
85        else :     
86            return result
87       
88    def getMatchingPrinters(self, printerpattern) :
89        """Returns the list of all printers as tuples (id, name) for printer names which match a certain pattern."""
90        pass
91           
92    def getPrinterId(self, printername) :       
93        """Returns a printerid given a printername."""
94        pass
95           
96    def getPrinterPrices(self, printerid) :       
97        """Returns a printer prices per page and per job given a printerid."""
98        pass
99           
100    def setPrinterPrices(self, printerid, perpage, perjob) :
101        """Sets prices per job and per page for a given printer."""
102        pass
103   
104    def getUserId(self, username) :
105        """Returns a userid given a username."""
106        result = self.doSearch("uid=%s" % username, ["uid"], base="ou=People")
107        if result is not None :
108            (userid, dummy) = result[0]
109            return userid
110           
111    def getGroupId(self, groupname) :
112        """Returns a groupid given a grupname."""
113        result = self.doSearch("cn=%s" % groupname, ["cn"], base="ou=Group")
114        if result is not None :
115            (groupid, dummy) = result[0]
116            return groupid
117           
118    def getJobHistoryId(self, jobid, userid, printerid) :       
119        """Returns the history line's id given a (jobid, userid, printerid)."""
120        pass
121           
122    def getPrinterUsers(self, printerid) :       
123        """Returns the list of usernames which uses a given printer."""
124        pass
125       
126    def getPrinterGroups(self, printerid) :       
127        """Returns the list of groups which uses a given printer."""
128        pass
129       
130    def getGroupMembersNames(self, groupname) :       
131        """Returns the list of user's names which are member of this group."""
132        pass
133       
134    def getUserGroupsNames(self, userid) :       
135        """Returns the list of groups' names the user is a member of."""
136        pass
137       
138    def addPrinter(self, printername) :       
139        """Adds a printer to the quota storage, returns its id."""
140        pass
141       
142    def addUser(self, username) :       
143        """Adds a user to the quota storage, returns its id."""
144        pass
145       
146    def addGroup(self, groupname) :       
147        """Adds a group to the quota storage, returns its id."""
148        pass
149       
150    def addUserPQuota(self, username, printerid) :
151        """Initializes a user print quota on a printer, adds the user to the quota storage if needed."""
152        pass
153       
154    def addGroupPQuota(self, groupname, printerid) :
155        """Initializes a group print quota on a printer, adds the group to the quota storage if needed."""
156        pass
157       
158    def increaseUserBalance(self, userid, amount) :   
159        """Increases (or decreases) an user's account balance by a given amount."""
160        pass
161       
162    def getUserBalance(self, userid) :   
163        """Returns the current account balance for a given user."""
164        pass
165       
166    def getGroupBalance(self, groupid) :   
167        """Returns the current account balance for a given group, as the sum of each of its users' account balance."""
168        pass
169       
170    def getUserLimitBy(self, userid) :   
171        """Returns the way in which user printing is limited."""
172        pass
173       
174    def getGroupLimitBy(self, groupid) :   
175        """Returns the way in which group printing is limited."""
176        pass
177       
178    def setUserBalance(self, userid, balance) :   
179        """Sets the account balance for a given user to a fixed value."""
180        pass
181       
182    def limitUserBy(self, userid, limitby) :   
183        """Limits a given user based either on print quota or on account balance."""
184        pass
185       
186    def limitGroupBy(self, groupid, limitby) :   
187        """Limits a given group based either on print quota or on sum of its users' account balances."""
188        pass
189       
190    def setUserPQuota(self, userid, printerid, softlimit, hardlimit) :
191        """Sets soft and hard limits for a user quota on a specific printer given (userid, printerid)."""
192        pass
193       
194    def setGroupPQuota(self, groupid, printerid, softlimit, hardlimit) :
195        """Sets soft and hard limits for a group quota on a specific printer given (groupid, printerid)."""
196        pass
197       
198    def resetUserPQuota(self, userid, printerid) :   
199        """Resets the page counter to zero for a user on a printer. Life time page counter is kept unchanged."""
200        pass
201       
202    def resetGroupPQuota(self, groupid, printerid) :   
203        """Resets the page counter to zero for a group on a printer. Life time page counter is kept unchanged."""
204        pass
205       
206    def updateUserPQuota(self, userid, printerid, pagecount) :
207        """Updates the used user Quota information given (userid, printerid) and a job size in pages."""
208        pass
209       
210    def getUserPQuota(self, userid, printerid) :
211        """Returns the Print Quota information for a given (userid, printerid)."""
212        pass
213       
214    def getGroupPQuota(self, groupid, printerid) :
215        """Returns the Print Quota information for a given (groupid, printerid)."""
216        pass
217       
218    def setUserDateLimit(self, userid, printerid, datelimit) :
219        """Sets the limit date for a soft limit to become an hard one given (userid, printerid)."""
220        pass
221       
222    def setGroupDateLimit(self, groupid, printerid, datelimit) :
223        """Sets the limit date for a soft limit to become an hard one given (groupid, printerid)."""
224        pass
225       
226    def addJobToHistory(self, jobid, userid, printerid, pagecounter, action) :
227        """Adds a job to the history: (jobid, userid, printerid, last page counter taken from requester)."""
228        pass
229   
230    def updateJobSizeInHistory(self, historyid, jobsize) :
231        """Updates a job size in the history given the history line's id."""
232        pass
233   
234    def getPrinterPageCounter(self, printerid) :
235        """Returns the last page counter value for a printer given its id, also returns last username, last jobid and history line id."""
236        pass
237       
238    def addUserToGroup(self, userid, groupid) :   
239        """Adds an user to a group."""
240        pass
241       
242    def deleteUser(self, userid) :   
243        """Completely deletes an user from the Quota Storage."""
244        pass
245       
246    def deleteGroup(self, groupid) :   
247        """Completely deletes an user from the Quota Storage."""
248        pass
249       
250    def computePrinterJobPrice(self, printerid, jobsize) :   
251        """Returns the price for a job on a given printer."""
252        # TODO : create a base class with things like this
253        prices = self.getPrinterPrices(printerid)
254        if prices is None :
255            perpage = perjob = 0.0
256        else :   
257            (perpage, perjob) = prices
258        return perjob + (perpage * jobsize)
Note: See TracBrowser for help on using the browser.