1 # vim: set encoding=utf-8 et sw=4 sts=4 :
4 import logging ; log = logging.getLogger('pymin.services.proxy')
6 from pymin.seqtools import Sequence
7 from pymin.dispatcher import Handler, handler, HandlerError
8 from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \
9 TransactionalHandler, ParametersHandler, \
14 __all__ = ('ProxyHandler',)
17 def __init__(self,ip):
22 # TODO convert to a SetSubHandler
24 class HostHandler(DictSubHandler):
26 handler_help = u"Manage proxy hosts"
28 _cont_subhandler_attr = 'hosts'
29 _cont_subhandler_class = Host
32 def __init__(self, name, password):
34 self.password = crypt.crypt(password,'BA')
36 return (self.name, self.password)
37 def update(self, password=None):
38 if password is not None:
39 self.password = crypt.crypt(password,'BA')
41 class UserHandler(DictSubHandler):
43 handler_help = u"Manage proxy users"
45 _cont_subhandler_attr = 'users'
46 _cont_subhandler_class = User
48 class ProxyHandler(Restorable, ConfigWriter, InitdHandler,
49 TransactionalHandler, ParametersHandler):
51 handler_help = u"Manage proxy service"
55 _persistent_attrs = ('params', 'hosts', 'users')
57 _restorable_defaults = dict(
66 _config_writer_files = ('squid.conf','users.conf')
67 _config_writer_tpl_dir = path.join(path.dirname(__file__), 'templates')
69 def __init__(self, pickle_dir='.', config_dir='.'):
70 r"Initialize DhcpHandler object, see class documentation for details."
71 log.debug(u'ProxyHandler(%r, %r)', pickle_dir, config_dir)
72 self._persistent_dir = pickle_dir
73 self._config_writer_cfg_dir = config_dir
74 self._config_build_templates()
75 InitdHandler.__init__(self)
76 self.host = HostHandler(self)
77 self.user = UserHandler(self)
79 def _get_config_vars(self, config_file):
80 if config_file == 'squid.conf':
81 return dict(hosts=self.hosts.values(), **self.params)
82 return dict(users=self.users)
85 if __name__ == '__main__':
88 level = logging.DEBUG,
89 format = '%(asctime)s %(levelname)-8s %(message)s',
94 px.set('ip','192.66.66.66')
96 px.host.add('192.168.0.25.25')
97 px.host.add('192.168.0.25.26')
98 px.host.add('192.168.0.25.27')
99 px.host.delete('192.168.0.25.27')
100 px.user.add('lala','soronga')
101 px.user.add('culo','sarasa')