]> git.llucax.com Git - software/pymin.git/commitdiff
Se agrega el manejo de usuarios al proxy
authorNicolas Emiliani <nemiliani@integratech.com.ar>
Thu, 4 Oct 2007 19:21:14 +0000 (16:21 -0300)
committerNicolas Emiliani <nemiliani@integratech.com.ar>
Thu, 4 Oct 2007 19:21:14 +0000 (16:21 -0300)
pymin/services/proxy/__init__.py

index b3b1172bc74474752890f5ccd48fd8f2fd32ec6a..5e8460e21ac075fd5ae1f288cc16fd249fe44abd 100644 (file)
@@ -7,6 +7,8 @@ from pymin.dispatcher import Handler, handler, HandlerError
 from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \
                                 TransactionalHandler, ParametersHandler
 
 from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \
                                 TransactionalHandler, ParametersHandler
 
+import crypt
+
 __ALL__ = ('ProxyHandler', 'Error', 'HostError', 'HostAlreadyExistsError',
             'HostNotFoundError')
 
 __ALL__ = ('ProxyHandler', 'Error', 'HostError', 'HostAlreadyExistsError',
             'HostNotFoundError')
 
@@ -96,12 +98,27 @@ class HostHandler(Handler):
         return self.hosts.items()
 
 
         return self.hosts.items()
 
 
+class UserHandler(Handler):
+
+    def __init__(self, users):
+        self.users = users
+
+    def add(self, user, password):
+        if user in self.users:
+            raise UserAlreadyExistsError(user)
+        self.users[user] = crypt.crypt(password,'BA')
+
+    def delete(self, user):
+        if not user in self.users:
+            raise UserNotFound(user)
+        del self.users[user]
+
 class ProxyHandler(Restorable, ConfigWriter, InitdHandler,
                    TransactionalHandler, ParametersHandler):
 
     _initd_name = 'squid'
 
 class ProxyHandler(Restorable, ConfigWriter, InitdHandler,
                    TransactionalHandler, ParametersHandler):
 
     _initd_name = 'squid'
 
-    _persistent_attrs = ('params', 'hosts')
+    _persistent_attrs = ('params', 'hosts', 'users')
 
     _restorable_defaults = dict(
             hosts = dict(),
 
     _restorable_defaults = dict(
             hosts = dict(),
@@ -109,9 +126,10 @@ class ProxyHandler(Restorable, ConfigWriter, InitdHandler,
                 ip   = '192.168.0.1',
                 port = '8080',
             ),
                 ip   = '192.168.0.1',
                 port = '8080',
             ),
+            users = dict(),
     )
 
     )
 
-    _config_writer_files = 'squid.conf'
+    _config_writer_files = ('squid.conf','users.conf')
     _config_writer_tpl_dir = path.join(path.dirname(__file__), 'templates')
 
     def __init__(self, pickle_dir='.', config_dir='.'):
     _config_writer_tpl_dir = path.join(path.dirname(__file__), 'templates')
 
     def __init__(self, pickle_dir='.', config_dir='.'):
@@ -121,9 +139,12 @@ class ProxyHandler(Restorable, ConfigWriter, InitdHandler,
         self._config_build_templates()
         self._restore()
         self.host = HostHandler(self.hosts)
         self._config_build_templates()
         self._restore()
         self.host = HostHandler(self.hosts)
+        self.user = UserHandler(self.users)
 
     def _get_config_vars(self, config_file):
 
     def _get_config_vars(self, config_file):
-        return dict(hosts=self.hosts.values(), **self.params)
+        if config_file == 'squid.conf':
+            return dict(hosts=self.hosts.values(), **self.params)
+        return dict(users=self.users)
 
 
 if __name__ == '__main__':
 
 
 if __name__ == '__main__':
@@ -135,4 +156,6 @@ if __name__ == '__main__':
     px.host.add('192.168.0.25.26')
     px.host.add('192.168.0.25.27')
     px.host.delete('192.168.0.25.27')
     px.host.add('192.168.0.25.26')
     px.host.add('192.168.0.25.27')
     px.host.delete('192.168.0.25.27')
+    px.user.add('lala','soronga')
+    px.user.add('culo','sarasa')
     px.commit()
\ No newline at end of file
     px.commit()
\ No newline at end of file