class VSFTPDExtension (BaseExtension): default_config = { 'created': False, 'user': None, 'password': None, } name = 'FTP' def init(self): self.append(self.ui.inflate('vh-vsftpd:ext')) self.binder = Binder(self, self) self.binder.autodiscover() if not self.config['created']: self.config['username'] = self.website.slug self.config['password'] = str(uuid.uuid4()) self.config['created'] = True self.refresh() def refresh(self): self.binder.reset().populate() def update(self): pass
class SimpleDemo (SectionPlugin): def init(self): self.title = 'Binder' self.icon = 'question' self.category = 'Demo' self.append(self.ui.inflate('test:binder-main')) self.data = [ Person('Alice', '123'), Person('Bob', '234'), ] self.find('data').text = repr(self.data) self.binder = Binder(self, self.find('bindroot')) self.binder.autodiscover() @on('populate', 'click') def on_populate(self): self.binder.populate() @on('unpopulate', 'click') def on_unpopulate(self): self.binder.unpopulate() @on('update', 'click') def on_update(self): self.binder.update() self.find('data').text = repr(self.data)
class Test (SectionPlugin): def init(self): self.title = 'Test' self.icon = 'question' self.category = 'Demo' self.append(self.ui.inflate('test:main')) alice = Person('Alice', [Phone('123')]) bob = Person('Bob', [Phone('234'), Phone('345')]) book = AddressBook([alice, bob]) self.find('persons-collection').new_item = lambda c: Person('New person', []) self.find('phones-collection').new_item = lambda c: Phone('123') self.binder = Binder(book, self.find('addressbook')) self.binder.autodiscover().populate()
class VSFTPDExtension(BaseExtension): default_config = {"created": False, "user": None, "password": None} name = "FTP" def init(self): self.append(self.ui.inflate("vh-vsftpd:ext")) self.binder = Binder(self, self) self.binder.autodiscover() if not self.config["created"]: self.config["username"] = self.website.slug self.config["password"] = str(uuid.uuid4()) self.config["created"] = True self.refresh() def refresh(self): self.binder.reset().populate() def update(self): pass
class Firewall(SectionPlugin): platforms = ['centos', 'debian'] def init(self): self.title = _('Firewall') self.icon = 'fire' self.category = _('System') self.append(self.ui.inflate('iptables:main')) self.fw_mgr = FirewallManager.get() self.config = IPTablesConfig(path=self.fw_mgr.config_path_ajenti) self.binder = Binder(None, self.find('config')) self.find('tables').new_item = lambda c: TableData() self.find('chains').new_item = lambda c: ChainData() self.find('rules').new_item = lambda c: RuleData() self.find('options').new_item = lambda c: OptionData() self.find('options').binding = OptionsBinding self.find('options').filter = lambda i: not i.name in ['j', 'jump'] def post_rule_bind(o, c, i, u): u.find('add-option').on('change', self.on_add_option, c, i, u) action = '' j_option = i.get_option('j', 'jump') if j_option: action = j_option.arguments[0].value u.find('action').text = action u.find('action').style = 'iptables-action iptables-%s' % action u.find('action-select').value = action u.find('title').text = i.comment if i.comment else i.summary def post_rule_update(o, c, i, u): action = u.find('action-select').value j_option = i.get_option('j', 'jump') if j_option: j_option.arguments[0].value = action else: if action: o = OptionData.create_destination() o.arguments[0].value = action i.options.append(o) self.find('rules').post_item_bind = post_rule_bind self.find('rules').post_item_update = post_rule_update self.find('add-option').values = self.find('add-option').labels = [ _('Add option') ] + sorted(OptionData.templates.keys()) def on_page_load(self): if not os.path.exists(self.fw_mgr.config_path_ajenti): if not os.path.exists(self.fw_mgr.config_path): open(self.fw_mgr.config_path, 'w').write(""" *mangle :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] COMMIT *nat :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] COMMIT *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] COMMIT """) open(self.fw_mgr.config_path_ajenti, 'w').write(open(self.fw_mgr.config_path).read()) self.config.load() self.refresh() @on('load-current', 'click') def on_load_current(self): subprocess.call('iptables-save > %s' % self.fw_mgr.config_path, shell=True) self.config.load() self.refresh() def refresh(self): self.find('autostart').text = (_('Disable') if self.fw_mgr.get_autostart_state() else _('Enable')) + _(' autostart') self.binder.reset(self.config.tree) actions = ['ACCEPT', 'DROP', 'REJECT', 'LOG', 'MASQUERADE', 'DNAT', 'SNAT'] + \ list(set(itertools.chain.from_iterable([[c.name for c in t.chains] for t in self.config.tree.tables]))) self.find('action-select').labels = actions self.find('action-select').values = actions self.find('chain-action-select').labels = actions self.find('chain-action-select').values = actions self.binder.autodiscover().populate() @on('autostart', 'click') def on_autostart_change(self): self.fw_mgr.set_autostart_state(not self.fw_mgr.get_autostart_state()) self.refresh() def on_add_option(self, options, rule, ui): o = OptionData.create(ui.find('add-option').value) ui.find('add-option').value = '' rule.options.append(o) self.binder.populate() @on('save', 'click') def save(self): self.binder.update() for t in self.config.tree.tables: for c in t.chains: for r in c.rules: r.verify() self.config.save() open(self.fw_mgr.config_path, 'w').write(''.join( l.split('#')[0] + '\n' for l in open(self.fw_mgr.config_path_ajenti).read().splitlines())) self.refresh() self.context.notify('info', _('Saved')) @on('edit', 'click') def raw_edit(self): self.context.launch('notepad', path='/etc/iptables.up.rules') @on('apply', 'click') def apply(self): self.save() cmd = 'cat %s | iptables-restore' % self.fw_mgr.config_path if subprocess.call(cmd, shell=True) != 0: self.context.launch('terminal', command=cmd) else: self.context.notify('info', _('Applied successfully'))
class Firewall (SectionPlugin): platforms = ['centos', 'debian'] def init(self): self.title = _('Firewall') self.icon = 'fire' self.category = _('System') self.append(self.ui.inflate('iptables:main')) self.fw_mgr = FirewallManager.get() self.config = IPTablesConfig(path=self.fw_mgr.config_path_ajenti) self.binder = Binder(None, self.find('config')) self.find('tables').new_item = lambda c: TableData() self.find('chains').new_item = lambda c: ChainData() self.find('rules').new_item = lambda c: RuleData() self.find('options').new_item = lambda c: OptionData() self.find('options').binding = OptionsBinding self.find('options').filter = lambda i: not i.name in ['j', 'jump'] def post_rule_bind(o, c, i, u): u.find('add-option').on('change', self.on_add_option, c, i, u) action = '' j_option = i.get_option('j', 'jump') if j_option: action = j_option.arguments[0].value u.find('action').text = action u.find('action').style = 'iptables-action iptables-%s' % action u.find('action-select').value = action u.find('title').text = i.comment if i.comment else i.summary def post_rule_update(o, c, i, u): action = u.find('action-select').value j_option = i.get_option('j', 'jump') if j_option: j_option.arguments[0].value = action else: if action: o = OptionData.create_destination() o.arguments[0].value = action i.options.append(o) self.find('rules').post_item_bind = post_rule_bind self.find('rules').post_item_update = post_rule_update self.find('add-option').values = self.find('add-option').labels = [_('Add option')] + sorted(OptionData.templates.keys()) def on_page_load(self): if not os.path.exists(self.fw_mgr.config_path_ajenti): if not os.path.exists(self.fw_mgr.config_path): open(self.fw_mgr.config_path, 'w').write(""" *mangle :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] COMMIT *nat :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] COMMIT *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] COMMIT """) open(self.fw_mgr.config_path_ajenti, 'w').write(open(self.fw_mgr.config_path).read()) self.config.load() self.refresh() @on('load-current', 'click') def on_load_current(self): subprocess.call('iptables-save > %s' % self.fw_mgr.config_path, shell=True) self.config.load() self.refresh() def refresh(self): self.find('autostart').text = (_('Disable') if self.fw_mgr.get_autostart_state() else _('Enable')) + _(' autostart') self.binder.reset(self.config.tree) actions = ['ACCEPT', 'DROP', 'REJECT', 'LOG', 'MASQUERADE', 'DNAT', 'SNAT'] + \ list(set(itertools.chain.from_iterable([[c.name for c in t.chains] for t in self.config.tree.tables]))) self.find('action-select').labels = actions self.find('action-select').values = actions self.find('chain-action-select').labels = actions self.find('chain-action-select').values = actions self.binder.autodiscover().populate() @on('autostart', 'click') def on_autostart_change(self): self.fw_mgr.set_autostart_state(not self.fw_mgr.get_autostart_state()) self.refresh() def on_add_option(self, options, rule, ui): o = OptionData.create(ui.find('add-option').value) ui.find('add-option').value = '' rule.options.append(o) self.binder.populate() @on('save', 'click') def save(self): self.binder.update() for t in self.config.tree.tables: for c in t.chains: for r in c.rules: r.verify() self.config.save() open(self.fw_mgr.config_path, 'w').write( ''.join( l.split('#')[0] + '\n' for l in open(self.fw_mgr.config_path_ajenti).read().splitlines() ) ) self.refresh() self.context.notify('info', _('Saved')) @on('edit', 'click') def raw_edit(self): self.context.launch('notepad', path='/etc/iptables.up.rules') @on('apply', 'click') def apply(self): self.save() cmd = 'cat %s | iptables-restore' % self.fw_mgr.config_path if subprocess.call(cmd, shell=True) != 0: self.context.launch('terminal', command=cmd) else: self.context.notify('info', _('Applied successfully'))
class Tasks(SectionPlugin): def init(self): self.title = _("Tasks") self.icon = "cog" self.category = _("Tools") self.append(self.ui.inflate("tasks:main")) self.manager = TaskManager.get(manager.context) self.binder = Binder(None, self) def post_td_bind(object, collection, item, ui): if item.get_class(): params_ui = self.ui.inflate(item.get_class().ui) item.binder = DictAutoBinding(item, "params", params_ui.find("bind")) item.binder.populate() ui.find("slot").empty() ui.find("slot").append(params_ui) def post_td_update(object, collection, item, ui): if hasattr(item, "binder"): item.binder.update() def post_rt_bind(object, collection, item, ui): def abort(): item.abort() self.refresh() ui.find("abort").on("click", abort) self.find("task_definitions").post_item_bind = post_td_bind self.find("task_definitions").post_item_update = post_td_update self.find("running_tasks").post_item_bind = post_rt_bind self.find("job_definitions").new_item = lambda c: JobDefinition() def on_page_load(self): self.refresh() @on("refresh", "click") def refresh(self): self.binder.reset(self.manager) self.manager.refresh() dd = self.find("task-classes") dd.labels = [] dd.values = [] for task in Task.get_classes(): if not task.hidden: dd.labels.append(task.name) dd.values.append(task.classname) dd = self.find("task-selector") dd.labels = [_.name for _ in self.manager.task_definitions] dd.values = [_.id for _ in self.manager.task_definitions] self.find("run-task-selector").labels = dd.labels self.find("run-task-selector").values = dd.values self.binder.autodiscover().populate() @on("run-task", "click") def on_run_task(self): self.manager.run(task_id=self.find("run-task-selector").value, context=self.context) self.refresh() @on("create-task", "click") def on_create_task(self): cls = self.find("task-classes").value td = TaskDefinition(task_class=cls) td.name = td.get_class().name self.manager.task_definitions.append(td) self.refresh() @on("save", "click") def on_save(self): self.binder.update() self.manager.save() self.refresh()
class Tasks (SectionPlugin): def init(self): self.title = _('Tasks') self.icon = 'cog' self.category = _('Tools') self.append(self.ui.inflate('tasks:main')) self.manager = TaskManager.get(manager.context) self.binder = Binder(None, self) def post_td_bind(object, collection, item, ui): if item.get_class(): params_ui = self.ui.inflate(item.get_class().ui) item.binder = DictAutoBinding(item, 'params', params_ui.find('bind')) item.binder.populate() ui.find('slot').empty() ui.find('slot').append(params_ui) def post_td_update(object, collection, item, ui): if hasattr(item, 'binder'): item.binder.update() def post_rt_bind(object, collection, item, ui): def abort(): item.abort() self.refresh() ui.find('abort').on('click', abort) self.find('task_definitions').post_item_bind = post_td_bind self.find('task_definitions').post_item_update = post_td_update self.find('running_tasks').post_item_bind = post_rt_bind self.find('job_definitions').new_item = lambda c: JobDefinition() def on_page_load(self): self.refresh() @on('refresh', 'click') def refresh(self): self.binder.reset(self.manager) self.manager.refresh() dd = self.find('task-classes') dd.labels = [] dd.values = [] for task in Task.get_classes(): if not task.hidden: dd.labels.append(task.name) dd.values.append(task.classname) dd = self.find('task-selector') dd.labels = [_.name for _ in self.manager.task_definitions] dd.values = [_.id for _ in self.manager.task_definitions] self.find('run-task-selector').labels = dd.labels self.find('run-task-selector').values = dd.values self.binder.autodiscover().populate() @on('run-task', 'click') def on_run_task(self): self.manager.run(task_id=self.find('run-task-selector').value, context=self.context) self.refresh() @on('create-task', 'click') def on_create_task(self): cls = self.find('task-classes').value td = TaskDefinition(task_class=cls) td.name = td.get_class().name self.manager.task_definitions.append(td) self.refresh() @on('save', 'click') def on_save(self): self.binder.update() self.manager.save() self.refresh()
class Configurator (SectionPlugin): def init(self): self.title = _('Configure') self.icon = 'wrench' self.category = '' self.order = 50 self.append(self.ui.inflate('configurator:main')) self.binder = Binder(ajenti.config.tree, self.find('ajenti-config')) self.ccmgr = ClassConfigManager.get() self.classconfig_binding = Binder(self.ccmgr, self.find('classconfigs')) def post_classconfig_bind(object, collection, item, ui): def configure(): self.configure_plugin(item, notify=False) ui.find('configure').on('click', configure) self.find('classconfigs').find('classes').post_item_bind = post_classconfig_bind self.find('users').new_item = lambda c: UserData() def post_user_bind(object, collection, item, ui): provider = UserManager.get(manager.context).get_sync_provider() editable = item.name != 'root' renameable = editable and provider.allows_renaming deletable = renameable ui.find('name-edit').visible = renameable ui.find('name-label').visible = not renameable ui.find('delete').visible = deletable box = ui.find('permissions') box.empty() p = PermissionProvider.get_all() for prov in p: line = self.ui.create('tab', title=prov.get_name()) box.append(line) for perm in prov.get_permissions(): line.append( self.ui.create('checkbox', id=perm[0], text=perm[1], value=(perm[0] in item.permissions)) ) def copy(): self.save() newuser = deepcopy(item) newuser.name += '_' collection[newuser.name] = newuser self.refresh() ui.find('copy').on('click', copy) self.find('users').post_item_bind = post_user_bind def post_user_update(object, collection, item, ui): box = ui.find('permissions') for prov in PermissionProvider.get_all(): for perm in prov.get_permissions(): has = box.find(perm[0]).value if has and not perm[0] in item.permissions: item.permissions.append(perm[0]) if not has and perm[0] in item.permissions: item.permissions.remove(perm[0]) if ui.find('password').value: item.password = ui.find('password').value self.find('users').post_item_update = post_user_update def on_page_load(self): self.refresh() @on('sync-users-button', 'click') def on_sync_users(self): self.save() prov = UserManager.get(manager.context).get_sync_provider() try: prov.test() prov.sync() except Exception as e: self.context.notify('error', str(e)) self.refresh() @on('configure-sync-button', 'click') def on_configure_sync(self): self.save() self.configure_plugin(UserManager.get(manager.context).get_sync_provider(), notify=False) self.refresh() def refresh(self): self.binder.reset() self.find('sync-providers').labels = [x.title for x in UserSyncProvider.get_classes()] self.find('sync-providers').values = [x.id for x in UserSyncProvider.get_classes()] provider = UserManager.get(manager.context).get_sync_provider() self.find('sync-providers').value = provider.id self.find('add-user-button').visible = provider.id == '' self.find('sync-users-button').visible = provider.id != '' self.find('password').visible = provider.id == '' self.find('configure-sync-button').visible = provider.classconfig_editor is not None try: provider.test() sync_ok = True except Exception as e: self.context.notify('error', str(e)) sync_ok = False self.find('sync-status-ok').visible = sync_ok self.find('sync-status-fail').visible = not sync_ok languages = sorted(ajenti.locales.list_locales()) self.find('language').labels = [_('Auto'), 'en_US'] + languages self.find('language').values = ['', 'en_US'] + languages self.binder.autodiscover().populate() self.ccmgr.reload() self.classconfig_binding.reset().autodiscover().populate() @on('save-button', 'click') @restrict('configurator:configure') def save(self): self.binder.update() UserManager.get(manager.context).set_sync_provider(self.find('sync-providers').value) for user in ajenti.config.tree.users.values(): if not '|' in user.password: user.password = UserManager.get(manager.context).hash_password(user.password) self.refresh() ajenti.config.save() self.context.notify('info', _('Saved. Please restart Ajenti for changes to take effect.')) @on('fake-ssl', 'click') def on_gen_ssl(self): host = self.find('fake-ssl-host').value if host == '': self.context.notify('error', _('Please supply hostname')) else: self.gen_ssl(host) @on('restart-button', 'click') def on_restart(self): ajenti.restart() @intent('configure-plugin') def configure_plugin(self, plugin=None, notify=True): self.find('tabs').active = 1 self.refresh() if plugin and notify: self.context.notify('info', _('Please configure %s plugin!') % plugin.classconfig_editor.title) self.activate() dialog = self.find('classconfigs').find('dialog') dialog.find('container').empty() dialog.visible = True editor = plugin.classconfig_editor.new(self.ui) dialog.find('container').append(editor) binder = DictAutoBinding(plugin, 'classconfig', editor.find('bind')) binder.populate() def save(button=None): dialog.visible = False binder.update() plugin.save_classconfig() self.save() dialog.on('button', save) @intent('setup-fake-ssl') def gen_ssl(self, host): self.save() subprocess.call(['ajenti-ssl-gen', host, '-f']) ajenti.config.load() self.refresh()
class Tasks(SectionPlugin): def init(self): self.title = _('Tasks') self.icon = 'cog' self.category = _('Tools') self.append(self.ui.inflate('tasks:main')) self.manager = TaskManager.get(manager.context) self.binder = Binder(None, self) def post_td_bind(object, collection, item, ui): if item.get_class(): params_ui = self.ui.inflate(item.get_class().ui) item.binder = DictAutoBinding(item, 'params', params_ui.find('bind')) item.binder.populate() ui.find('slot').empty() ui.find('slot').append(params_ui) def post_td_update(object, collection, item, ui): if hasattr(item, 'binder'): item.binder.update() def post_rt_bind(object, collection, item, ui): def abort(): item.abort() self.refresh() ui.find('abort').on('click', abort) self.find('task_definitions').post_item_bind = post_td_bind self.find('task_definitions').post_item_update = post_td_update self.find('running_tasks').post_item_bind = post_rt_bind self.find('job_definitions').new_item = lambda c: JobDefinition() def on_page_load(self): self.refresh() @on('refresh', 'click') def refresh(self): self.binder.reset(self.manager) self.manager.refresh() dd = self.find('task-classes') dd.labels = [] dd.values = [] for task in Task.get_classes(): if not task.hidden: dd.labels.append(task.name) dd.values.append(task.classname) dd = self.find('task-selector') dd.labels = [_.name for _ in self.manager.task_definitions] dd.values = [_.id for _ in self.manager.task_definitions] self.find('run-task-selector').labels = dd.labels self.find('run-task-selector').values = dd.values self.binder.autodiscover().populate() @on('run-task', 'click') def on_run_task(self): self.manager.run(task_id=self.find('run-task-selector').value, context=self.context) self.refresh() @on('create-task', 'click') def on_create_task(self): cls = self.find('task-classes').value td = TaskDefinition(task_class=cls) td.name = td.get_class().name self.manager.task_definitions.append(td) self.refresh() @on('save', 'click') def on_save(self): self.binder.update() self.manager.save() self.refresh()
class Configurator (SectionPlugin): def init(self): self.title = _('Configure') self.icon = 'wrench' self.category = '' self.order = 50 self.append(self.ui.inflate('configurator:main')) self.binder = Binder(ajenti.config.tree, self.find('ajenti-config')) self.ccmgr = ClassConfigManager.get() self.classconfig_binding = Binder(self.ccmgr, self.find('classconfigs')) def post_classconfig_bind(object, collection, item, ui): def configure(): self.configure_plugin(item, notify=False) ui.find('configure').on('click', configure) self.find('classconfigs').find('classes').post_item_bind = post_classconfig_bind self.find('users').new_item = lambda c: UserData() def post_user_bind(object, collection, item, ui): box = ui.find('permissions') box.empty() ui.find('name-edit').visible = item.name != 'root' ui.find('name-label').visible = item.name == 'root' for prov in PermissionProvider.get_all(): line = self.ui.create('tab', title=prov.get_name()) box.append(line) for perm in prov.get_permissions(): line.append( self.ui.create('checkbox', id=perm[0], text=perm[1], value=(perm[0] in item.permissions)) ) self.find('users').post_item_bind = post_user_bind def post_user_update(object, collection, item, ui): box = ui.find('permissions') for prov in PermissionProvider.get_all(): for perm in prov.get_permissions(): has = box.find(perm[0]).value if has and not perm[0] in item.permissions: item.permissions.append(perm[0]) if not has and perm[0] in item.permissions: item.permissions.remove(perm[0]) if ui.find('password').value: item.password = ui.find('password').value self.find('users').post_item_update = post_user_update def on_page_load(self): self.refresh() @on('sync-users-button', 'click') def on_sync_users(self): self.save() UserManager.get(manager.context).get_sync_provider().sync() self.refresh() @on('configure-sync-button', 'click') def on_configure_sync(self): self.save() self.configure_plugin(UserManager.get(manager.context).get_sync_provider(), notify=False) self.refresh() def refresh(self): self.binder.reset() self.find('sync-providers').labels = [x.title for x in UserSyncProvider.get_classes()] self.find('sync-providers').values = [x.id for x in UserSyncProvider.get_classes()] provider = UserManager.get(manager.context).get_sync_provider() self.find('sync-providers').value = provider.id self.find('add-user-button').visible = provider.id == '' self.find('sync-users-button').visible = provider.id != '' self.find('password').visible = provider.id == '' self.find('configure-sync-button').visible = provider.classconfig_editor is not None sync_ok = provider.test() self.find('sync-status-ok').visible = sync_ok self.find('sync-status-fail').visible = not sync_ok languages = sorted(ajenti.locales.list_locales()) self.find('language').labels = [_('Auto')] + languages self.find('language').values = [''] + languages self.binder.autodiscover().populate() self.ccmgr.reload() self.classconfig_binding.reset().autodiscover().populate() @on('save-button', 'click') @restrict('configurator:configure') def save(self): self.binder.update() UserManager.get(manager.context).set_sync_provider(self.find('sync-providers').value) for user in ajenti.config.tree.users.values(): if not '|' in user.password: user.password = UserManager.get(manager.context).hash_password(user.password) self.refresh() ajenti.config.save() self.context.notify('info', _('Saved. Please restart Ajenti for changes to take effect.')) @on('fake-ssl', 'click') def on_gen_ssl(self): host = self.find('fake-ssl-host').value if host == '': self.context.notify('error', _('Please supply hostname')) else: self.gen_ssl(host) @on('restart-button', 'click') def on_restart(self): ajenti.restart() @intent('configure-plugin') def configure_plugin(self, plugin=None, notify=True): self.find('tabs').active = 1 self.refresh() if plugin and notify: self.context.notify('info', _('Please configure %s plugin!') % plugin.classconfig_editor.title) self.activate() dialog = self.find('classconfigs').find('dialog') dialog.find('container').empty() dialog.visible = True editor = plugin.classconfig_editor.new(self.ui) dialog.find('container').append(editor) binder = DictAutoBinding(plugin, 'classconfig', editor.find('bind')) binder.populate() def save(button=None): dialog.visible = False binder.update() plugin.save_classconfig() self.save() dialog.on('button', save) @intent('setup-fake-ssl') def gen_ssl(self, host): self.save() subprocess.call(['ajenti-ssl-gen', host, '-f']) ajenti.config.load() self.refresh()
class MySQLExtension (BaseExtension): default_config = { 'created': False, 'name': None, 'user': None, 'password': None, } name = 'MySQL' def init(self): self.append(self.ui.inflate('vh-mysql:ext')) self.binder = Binder(self, self) self.binder.autodiscover() self.refresh() self.db = MySQLDB.get() @staticmethod def selftest(): try: MySQLDB.get().query_databases() except: pass def refresh(self): self.binder.reset().populate() def update(self): self.binder.update() def on_destroy(self): if self.config['created']: self.on_delete() @on('create', 'click') def on_create(self): try: self.db.query_databases() except Exception, e: self.context.notify('error', str(e)) self.context.launch('configure-plugin', plugin=self.db) return self.config['username'] = self.website.slug self.config['password'] = str(uuid.uuid4()) self.config['name'] = self.website.slug while True: exists = False for db in self.db.query_databases(): if db.name == self.config['name']: exists = True break if not exists: break else: self.config['name'] += '_' self.db.query_create(self.config['name']) self.config['created'] = True db = Database() db.name = self.config['name'] while True: exists = False for user in self.db.query_users(): if user.name == self.config['username']: exists = True break if not exists: break else: self.config['username'] += '_' user = User() user.name = self.config['username'] user.password = self.config['password'] user.host = 'localhost' self.db.query_create_user(user) self.db.query_grant(user, db) self.refresh()