1 # vim: set encoding=utf-8 et sw=4 sts=4 :
5 from pymin.seqtools import Sequence
6 from pymin.dispatcher import Handler, handler, HandlerError
7 from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \
8 TransactionalHandler, ParametersHandler, \
13 __ALL__ = ('ProxyHandler',)
16 def __init__(self,ip):
21 # TODO convert to a SetSubHandler
23 class HostHandler(DictSubHandler):
25 handler_help = u"Manage proxy hosts"
27 _cont_subhandler_attr = 'hosts'
28 _cont_subhandler_class = Host
31 def __init__(self, name, password):
33 self.password = crypt.crypt(password,'BA')
35 return (self.name, self.password)
36 def update(self, password=None):
37 if password is not None:
38 self.password = crypt.crypt(password,'BA')
40 class UserHandler(DictSubHandler):
42 handler_help = u"Manage proxy users"
44 _cont_subhandler_attr = 'users'
45 _cont_subhandler_class = User
47 class ProxyHandler(Restorable, ConfigWriter, InitdHandler,
48 TransactionalHandler, ParametersHandler):
50 handler_help = u"Manage proxy service"
54 _persistent_attrs = ('params', 'hosts', 'users')
56 _restorable_defaults = dict(
65 _config_writer_files = ('squid.conf','users.conf')
66 _config_writer_tpl_dir = path.join(path.dirname(__file__), 'templates')
68 def __init__(self, pickle_dir='.', config_dir='.'):
69 r"Initialize DhcpHandler object, see class documentation for details."
70 self._persistent_dir = pickle_dir
71 self._config_writer_cfg_dir = config_dir
72 self._config_build_templates()
73 InitdHandler.__init__(self)
74 self.host = HostHandler(self)
75 self.user = UserHandler(self)
77 def _get_config_vars(self, config_file):
78 if config_file == 'squid.conf':
79 return dict(hosts=self.hosts.values(), **self.params)
80 return dict(users=self.users)
83 if __name__ == '__main__':
86 px.set('ip','192.66.66.66')
88 px.host.add('192.168.0.25.25')
89 px.host.add('192.168.0.25.26')
90 px.host.add('192.168.0.25.27')
91 px.host.delete('192.168.0.25.27')
92 px.user.add('lala','soronga')
93 px.user.add('culo','sarasa')