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', 'Error')
15 class Error(HandlerError):
17 Error(command) -> Error instance :: Base DnsHandler exception class.
19 All exceptions raised by the DnsHandler inherits from this one, so you can
20 easily catch any DnsHandler exception.
22 message - A descriptive error message.
27 def __init__(self,ip):
32 # TODO convert to a SetSubHandler
34 class HostHandler(DictSubHandler):
36 handler_help = u"Manage proxy hosts"
38 _dict_subhandler_attr = 'hosts'
39 _dict_subhandler_class = Host
42 def __init__(self, name, password):
44 self.password = crypt.crypt(password,'BA')
46 return (self.name, self.password)
47 def update(self, password=None):
48 if password is not None:
49 self.password = crypt.crypt(password,'BA')
51 class UserHandler(DictSubHandler):
53 handler_help = u"Manage proxy users"
55 _dict_subhandler_attr = 'users'
56 _dict_subhandler_class = User
58 class ProxyHandler(Restorable, ConfigWriter, InitdHandler,
59 TransactionalHandler, ParametersHandler):
61 handler_help = u"Manage proxy service"
65 _persistent_attrs = ('params', 'hosts', 'users')
67 _restorable_defaults = dict(
76 _config_writer_files = ('squid.conf','users.conf')
77 _config_writer_tpl_dir = path.join(path.dirname(__file__), 'templates')
79 def __init__(self, pickle_dir='.', config_dir='.'):
80 r"Initialize DhcpHandler object, see class documentation for details."
81 self._persistent_dir = pickle_dir
82 self._config_writer_cfg_dir = config_dir
83 self._config_build_templates()
85 self.host = HostHandler(self)
86 self.user = UserHandler(self)
88 def _get_config_vars(self, config_file):
89 if config_file == 'squid.conf':
90 return dict(hosts=self.hosts.values(), **self.params)
91 return dict(users=self.users)
94 if __name__ == '__main__':
97 px.set('ip','192.66.66.66')
99 px.host.add('192.168.0.25.25')
100 px.host.add('192.168.0.25.26')
101 px.host.add('192.168.0.25.27')
102 px.host.delete('192.168.0.25.27')
103 px.user.add('lala','soronga')
104 px.user.add('culo','sarasa')