def __call__ (self): tmp = re.findall (r'^/vserver/([\d]+)/rule/content/([\d]+)/', CTK.request.url) vsrv = tmp[0][0] rule = tmp[0][1] # Main operarion op = CTK.post.pop('op') if op == "docache_add": # Validation new_docache = CTK.post.pop('new_flcache_docache') if not new_docache: return {'ret':'error', 'errors': {'new_flcache_docache': _("Can not be empty")}} # Add the configuration entries next_pre = CTK.cfg.get_next_entry_prefix ('vserver!%s!rule!%s!flcache!cookies!do_cache'%(vsrv, rule)) CTK.cfg['%s!regex'%(next_pre)] = new_docache return CTK.cfg_reply_ajax_ok() elif op == "docache_del": pre = 'vserver!%s!rule!%s!flcache!cookies!do_cache'%(vsrv, rule) to_del = CTK.post.pop('to_del') if to_del: del (CTK.cfg['%s!%s'%(pre, to_del)]) return CTK.cfg_reply_ajax_ok() return CTK.cfg_apply_post()
def commit(): # New Rewrite for e in ('in_rewrite_request', 'out_rewrite_request'): key = CTK.post.pop ('tmp!new!%s!key'%(e)) regex = CTK.post.pop ('tmp!new!%s!regex'%(e)) subst = CTK.post.pop ('tmp!new!%s!substring'%(e)) if regex: next = CTK.cfg.get_next_entry_prefix ('%s!%s'%(key, e)) CTK.cfg['%s!regex'%(next)] = regex CTK.cfg['%s!substring'%(next)] = subst return CTK.cfg_reply_ajax_ok() # New Header for e in ('in_header_add', 'out_header_add'): key = CTK.post.pop ('tmp!new!%s!key'%(e)) header = CTK.post.pop ('tmp!new!%s!header'%(e)) value = CTK.post.pop ('tmp!new!%s!value'%(e)) if header and value: CTK.cfg['%s!%s!%s'%(key, e, header)] = value return CTK.cfg_reply_ajax_ok() # New Hide for e in ('in_header_hide', 'out_header_hide'): key = CTK.post.pop ('tmp!new!%s!key'%(e)) hide = CTK.post.pop ('tmp!new!%s!hide'%(e)) if hide: next = CTK.cfg.get_next_entry_prefix ('%s!%s'%(key, e)) CTK.cfg[next] = hide return CTK.cfg_reply_ajax_ok() # Modification return CTK.cfg_apply_post()
def __init__ (self, key, **kwargs): kwargs['show_document_root'] = False Handler.PluginHandler.__init__ (self, key, **kwargs) Handler.PluginHandler.AddCommon (self) table = CTK.PropsTable() table.Add (_('SubscriberID'), CTK.TextCfg('%s!subscriberid'%(key), False), _(NOTE_SUBSCRIBERID)) table.Add (_('Version'), CTK.TextCfg('%s!version'%(key), False), _(NOTE_VERSION)) table.Add (_('Dossier Name'), CTK.TextCfg('%s!dossiername'%(key), False), _(NOTE_DOSSIERNAME)) table.Add (_('Endpoint'), CTK.TextCfg('%s!endpoint'%(key), False), _(NOTE_ENDPOINT)) table.Add (_('Validate XML'), CTK.CheckCfgText('%s!validate_xml'%(key), False), _(NOTE_VALIDATE_XML)) table.Add (_('I/O Threads'), CTK.TextCfg('%s!io_threads'%(key), True), _(NOTE_IO_THREADS)) table.Add (_("Compression Level"), CTK.ComboCfg('%s!encoder!compression_level'%(key), consts.COMPRESSION_LEVELS), _(NOTE_LEVEL)) submit = CTK.Submitter (URL_APPLY) submit += table self += CTK.RawHTML ('<h2>%s</h2>' %(_('Transmodel parameters'))) self += CTK.Indenter (submit) VALS = [("%s!subscriberid"%(key), validations.is_not_empty), ("%s!version"%(key), validations.is_not_empty), ("%s!dossiername"%(key), validations.is_not_empty), ("%s!endpoint"%(key), validations.is_not_empty), ("%s!io_threads"%(key), validations.is_number_gt_0)] CTK.cfg['%s!encoder' % (key)] = 'allow' CTK.publish ('^%s'%(URL_APPLY), CTK.cfg_apply_post, validation=VALS, method="POST")
def __init__ (self, key, **kwargs): Auth.PluginAuth.__init__ (self, key, **kwargs) self.AddCommon (supported_methods=('basic',)) table = CTK.PropsTable() table.Add (_("Server"), CTK.TextCfg("%s!server" %(self.key), False), _(NOTE_SERVER)) table.Add (_("Port"), CTK.TextCfg("%s!port" %(self.key), True), _(NOTE_PORT)) table.Add (_("Bind Domain"), CTK.TextCfg("%s!bind_dn" %(self.key), True), _(NOTE_BIND_DOMAIN)) table.Add (_("Bind Password"), CTK.TextCfg("%s!bind_pw" %(self.key), True), _(NOTE_BIND_PASSWD)) table.Add (_("Base Domain"), CTK.TextCfg("%s!base_dn" %(self.key), False), _(NOTE_BIND_DOMAIN)) table.Add (_("Filter"), CTK.TextCfg("%s!filter" %(self.key), True), _(NOTE_FILTER)) table.Add (_("Use TLS"), CTK.CheckCfgText("%s!tls"%(self.key), False, _('Enabled')), _(NOTE_USE_TLS)) table.Add (_("CA File"), CTK.TextCfg("%s!ca_file" %(self.key), True), _(NOTE_CA_FILE)) submit = CTK.Submitter (URL_APPLY) submit += table self += CTK.RawHTML ("<h2>%s</h2>" % (_('LDAP Connection'))) self += CTK.Indenter (submit) # Publish VALS = [("%s!ca_file"%(self.key), validations.is_local_file_exists), ("%s!port"%(self.key), validations.is_tcp_port)] CTK.publish ('^%s'%(URL_APPLY), CTK.cfg_apply_post, validation=VALS, method="POST")
def __init__ (self, key, **kwargs): Auth.PluginAuth.__init__ (self, key, **kwargs) self.AddCommon (supported_methods=('basic','digest')) # List refresh = CTK.Refreshable ({'id': 'authlist'}) refresh.register (lambda: self.Content(refresh, key).Render()) self += CTK.RawHTML ("<h2>%s</h2>" % (_('Fixed Authentication List'))) self += refresh # New new_user = CTK.TextField({'name': 'tmp!new_user', 'class': 'noauto'}) new_pass = CTK.TextField({'name': 'tmp!new_pass', 'class': 'noauto'}) new_add = CTK.SubmitterButton (_('Add')) table = CTK.Table() table.set_header(1) table += [CTK.RawHTML(x) for x in (_('User'), _('Password'))] table += [new_user, new_pass, new_add] submit = CTK.Submitter (URL_APPLY) submit += CTK.Hidden ('key', '%s!list'%(key)) submit += table submit.bind ('submit_success', refresh.JS_to_refresh() + new_user.JS_to_clean() + new_pass.JS_to_clean()) self += CTK.RawHTML ("<h3>%s</h3>" % (_('Add New Pair'))) self += CTK.Indenter (submit) # Publish VALS = [("%s!passwdfile"%(self.key), validations.is_local_file_exists)] CTK.publish ('^%s'%(URL_APPLY), commit, validation=VALS, method="POST")
def __call__ (self): if CTK.post.pop('final'): # Apply POST CTK.cfg_apply_post() return self.Commit_Rule() return CTK.cfg_apply_post()
def init(): global _is_init _is_init = True wizards = [x[:-3] for x in os.listdir('wizards') if x.endswith('.py')] for w in wizards: CTK.load_module (w, 'wizards')
def Commit_VServer (self): # Create the new Virtual Server next = CTK.cfg.get_next_entry_prefix('vserver') CTK.cfg['%s!nick'%(next)] = CTK.cfg.get_val('%s!host'%(PREFIX)) Wizard.CloneLogsCfg_Apply ('%s!logs_as_vsrv'%(PREFIX), next) # PHP php = CTK.load_module ('php', 'wizards') error = php.wizard_php_add (next) if error: return {'ret': 'error', 'errors': {'msg': error}} php_info = php.get_info (next) # phpBB props = cfg_get_surrounding_repls ('pre_rule', php_info['rule']) props['pre_vsrv'] = next props['host'] = CTK.cfg.get_val('%s!host' %(PREFIX)) props['local_src_dir'] = CTK.cfg.get_val('%s!sources' %(PREFIX)) config = CONFIG_VSERVER %(props) CTK.cfg.apply_chunk (config) # Common static Wizard.AddUsualStaticFiles(props['pre_rule_plus9']) # Clean up CTK.cfg.normalize ('%s!rule'%(next)) CTK.cfg.normalize ('vserver') del (CTK.cfg[PREFIX]) return CTK.cfg_reply_ajax_ok()
def Commit_Rule (self): vsrv_num = CTK.cfg.get_val ('%s!vsrv_num'%(PREFIX)) next = 'vserver!%s' %(vsrv_num) # PHP php = CTK.load_module ('php', 'wizards') error = php.wizard_php_add (next) if error: return {'ret': 'error', 'errors': {'msg': error}} php_info = php.get_info (next) # Symfony props = cfg_get_surrounding_repls ('pre_rule', php_info['rule']) props['pre_vsrv'] = next props['web_dir'] = CTK.cfg.get_val('%s!web_dir' %(PREFIX)) props['local_src_dir'] = CTK.cfg.get_val('%s!sources' %(PREFIX)) props['document_root'] = CTK.cfg.get_val('%s!document_root'%(PREFIX)) config = CONFIG_DIR %(props) CTK.cfg.apply_chunk (config) # Clean up CTK.cfg.normalize ('%s!rule'%(next)) del (CTK.cfg[PREFIX]) return CTK.cfg_reply_ajax_ok()
def commit(): new_nick = CTK.post.pop('tmp!new_nick') new_host = CTK.post.pop('tmp!new_host') # New source if new_nick and new_host: next = CTK.cfg.get_next_entry_prefix ('source') CTK.cfg['%s!nick'%(next)] = new_nick CTK.cfg['%s!host'%(next)] = new_host CTK.cfg['%s!type'%(next)] = 'host' return CTK.cfg_reply_ajax_ok() # New variable new_variable = CTK.post.pop('tmp!new_variable') new_value = CTK.post.pop('tmp!new_value') source_pre = CTK.post.pop('tmp!source_pre') if new_variable and new_value: CTK.cfg['%s!%s'%(source_pre,new_variable)] = new_value return CTK.cfg_reply_ajax_ok() # Modification errors = {} for key in CTK.post.keys(): try: value = CTK.post.get_val (key) if key.endswith('!nick'): validations.is_safe_information_source_nick (value, key) elif key.endswith('!host'): validations.is_safe_information_source_host (value, key) except ValueError, e: errors[key] = str(e)
def __call__(self): tmp = re.findall(r"^/vserver/([\d]+)/rule/content/([\d]+)/", CTK.request.url) vsrv = tmp[0][0] rule = tmp[0][1] # Main operarion op = CTK.post.pop("op") if op == "docache_add": # Validation new_docache = CTK.post.pop("new_flcache_docache") if not new_docache: return {"ret": "error", "errors": {"new_flcache_docache": _("Can not be empty")}} # Add the configuration entries next_pre = CTK.cfg.get_next_entry_prefix("vserver!%s!rule!%s!flcache!cookies!do_cache" % (vsrv, rule)) CTK.cfg["%s!regex" % (next_pre)] = new_docache return CTK.cfg_reply_ajax_ok() elif op == "docache_del": pre = "vserver!%s!rule!%s!flcache!cookies!do_cache" % (vsrv, rule) to_del = CTK.post.pop("to_del") if to_del: del (CTK.cfg["%s!%s" % (pre, to_del)]) return CTK.cfg_reply_ajax_ok() return CTK.cfg_apply_post()
def commit(): # New extension new_exts = CTK.post.pop('new_exts') if new_exts: icon = CTK.post.get_val('new_exts_icon') if not icon: return CTK.cfg_reply_ajax_ok() CTK.cfg['icons!suffix!%s'%(icon)] = new_exts return CTK.cfg_reply_ajax_ok() # New file new_file = CTK.post.pop('new_file') if new_file: icon = CTK.post.get_val('new_file_icon') if not icon: return CTK.cfg_reply_ajax_ok() CTK.cfg['icons!file!%s'%(icon)] = new_file return CTK.cfg_reply_ajax_ok() # Modifications updates = modify() if updates: return updates return CTK.cfg_apply_post()
def __init__ (self, key, **kwargs): RulePlugin.__init__ (self, key) is_new = key.startswith('tmp') props = ({},{'class': 'noauto'})[is_new] type_widget = CTK.ComboCfg ('%s!type'%(key), TYPES, props) type_val = CTK.cfg.get_val ('%s!type'%(key), 'regex') table = CTK.PropsTable() table.Add (_('Header'), CTK.ComboCfg('%s!header'%(key), HEADERS, props), _(NOTE_HEADER)) table.Add (_('Type'), type_widget, _(NOTE_TYPES)) if is_new or type_val == 'regex': table.Add (_('Regular Expression'), CTK.TextCfg('%s!match'%(key), False, props), _(NOTE_MATCH)) if is_new: type_widget.bind ('change', """if ($('#%(type_widget)s').val() == 'regex') { $('#%(regex)s').show(); } else { $('#%(regex)s').hide(); }""" %({'type_widget': type_widget.id, 'regex': table[2].id})) submit = CTK.Submitter (URL_APPLY) submit += CTK.Hidden ('key', key) submit += CTK.Hidden ('vsrv_num', kwargs.pop('vsrv_num', '')) submit += table self += submit # Validation, and Public URLs CTK.publish (URL_APPLY, commit, method="POST")
def __init__ (self, key, **kwargs): Handler.PluginHandler.__init__ (self, key, **kwargs) Handler.PluginHandler.AddCommon (self) rate = CTK.CheckCfgText("%s!rate"%(key), True, _('Enabled')) table = CTK.PropsTable() table.Add (_("Auto Rate"), rate, _(NOTE_RATE)) table.Add (_("Speedup Factor"), CTK.TextCfg("%s!rate_factor"%(key), True), _(NOTE_RATE_FACTOR)) table.Add (_("Initial Boost"), CTK.TextCfg("%s!rate_boost"%(key), True), _(NOTE_RATE_BOOST)) rate.bind ('change', """if ($('#%(rate)s :checkbox')[0].checked) { $('#%(row1)s').show(); $('#%(row2)s').show(); } else { $('#%(row1)s').hide(); $('#%(row2)s').hide(); }""" %({'rate': rate.id, 'row1': table[1].id, 'row2': table[2].id})) submit = CTK.Submitter (URL_APPLY) submit += table # Streaming self += CTK.RawHTML ('<h2>%s</h2>' %(_('Audio/Video Streaming'))) self += CTK.Indenter (submit) # File self += instance_plugin('file', key, show_document_root=False) # Publish VALS = [("%s!rate_factor"%(key), validations.is_float), ("%s!rate_boost"%(key), validations.is_number_gt_0)] CTK.publish ('^%s'%(URL_APPLY), CTK.cfg_apply_post, validation=VALS, method="POST")
def Commit_VServer (self): # Create the new Virtual Server next = CTK.cfg.get_next_entry_prefix('vserver') CTK.cfg['%s!nick'%(next)] = CTK.cfg.get_val('%s!host'%(PREFIX)) Wizard.CloneLogsCfg_Apply ('%s!logs_as_vsrv'%(PREFIX), next) # PHP php = CTK.load_module ('php', 'wizards') error = php.wizard_php_add (next) if error: return {'ret': 'error', 'errors': {'msg': error}} php_info = php.get_info (next) # Drupal props = cfg_get_surrounding_repls ('pre_rule', php_info['rule']) props['pre_vsrv'] = next props['host'] = CTK.cfg.get_val('%s!host' %(PREFIX)) props['local_dir'] = CTK.cfg.get_val('%s!local_dir' %(PREFIX)) config = CONFIG_VSERVER %(props) CTK.cfg.apply_chunk (config) # Fixes Drupal bug for multilingual content CTK.cfg['%s!encoder!gzip' %(php_info['rule'])] = '0' # Clean up CTK.cfg.normalize ('%s!rule'%(next)) CTK.cfg.normalize ('vserver') del (CTK.cfg[PREFIX]) return CTK.cfg_reply_ajax_ok()
def __init__(self, key, **kwargs): Auth.PluginAuth.__init__(self, key, **kwargs) self.AddCommon(supported_methods=("basic", "digest")) # List refresh = CTK.Refreshable({"id": "authlist"}) refresh.register(lambda: self.Content(refresh, key).Render()) self += CTK.RawHTML("<h2>%s</h2>" % (_("Fixed Authentication List"))) self += refresh # New new_user = CTK.TextField({"name": "tmp!new_user", "class": "noauto"}) new_pass = CTK.TextField({"name": "tmp!new_pass", "class": "noauto"}) new_add = CTK.SubmitterButton(_("Add")) table = CTK.Table() table.set_header(1) table += [CTK.RawHTML(x) for x in (_("User"), _("Password"))] table += [new_user, new_pass, new_add] submit = CTK.Submitter(URL_APPLY) submit += CTK.Hidden("key", "%s!list" % (key)) submit += table submit.bind("submit_success", refresh.JS_to_refresh() + new_user.JS_to_clean() + new_pass.JS_to_clean()) self += CTK.RawHTML("<h3>%s</h3>" % (_("Add New Pair"))) self += CTK.Indenter(submit) # Publish VALS = [("%s!passwdfile" % (self.key), validations.is_local_file_exists)] CTK.publish("^%s" % (URL_APPLY), commit, validation=VALS, method="POST")
def __init__ (self, key, title, extension, note, name_desc, validation_fn=None, **kwargs): RulePlugin.__init__ (self, key) self.extension = extension self.name_desc = name_desc url_apply = URL_APPLY %(extension) props = ({},{'class': 'noauto'})[key.startswith('tmp')] table = CTK.PropsTable() table.Add (title, CTK.TextCfg('%s!%s'%(key, extension), False, props), note) submit = CTK.Submitter (url_apply) submit += CTK.Hidden ('key', key) submit += CTK.Hidden ('vsrv_num', kwargs.pop('vsrv_num', '')) submit += table self += submit # Build validation if validation_fn: validation = [('tmp!%s'%(extension), validation_fn), ('vserver![\d]+!rule![\d]+!match!%s'%(extension), validation_fn)] else: validation = [] # Public URL CTK.publish (url_apply, apply, method="POST", validation=validation, extension=extension)
def Commit_Rule(self): vsrv_num = CTK.cfg.get_val("%s!vsrv_num" % (PREFIX)) next = "vserver!%s" % (vsrv_num) # PHP php = CTK.load_module("php", "wizards") error = php.wizard_php_add(next) if error: return {"ret": "error", "errors": {"msg": error}} php_info = php.get_info(next) # MediaWiki props = cfg_get_surrounding_repls("pre_rule", php_info["rule"]) props["pre_vsrv"] = next props["web_dir"] = CTK.cfg.get_val("%s!web_dir" % (PREFIX)) props["local_dir"] = CTK.cfg.get_val("%s!local_dir" % (PREFIX)) props["aux_dir"] = CTK.cfg.get_val("%s!aux_dir" % (PREFIX)) config = CONFIG_DIR % (props) CTK.cfg.apply_chunk(config) # Clean up CTK.cfg.normalize("%s!rule" % (next)) del (CTK.cfg[PREFIX]) return CTK.cfg_reply_ajax_ok()
def Commit_VServer(self): # Create the new Virtual Server next = CTK.cfg.get_next_entry_prefix("vserver") CTK.cfg["%s!nick" % (next)] = CTK.cfg.get_val("%s!host" % (PREFIX)) Wizard.CloneLogsCfg_Apply("%s!logs_as_vsrv" % (PREFIX), next) # PHP php = CTK.load_module("php", "wizards") error = php.wizard_php_add(next) if error: return {"ret": "error", "errors": {"msg": error}} php_info = php.get_info(next) # MediaWiki props = cfg_get_surrounding_repls("pre_rule", php_info["rule"]) props["pre_vsrv"] = next props["host"] = CTK.cfg.get_val("%s!host" % (PREFIX)) props["local_dir"] = CTK.cfg.get_val("%s!local_dir" % (PREFIX)) props["web_dir"] = CTK.cfg.get_val("%s!web_dir" % (PREFIX)) props["aux_dir"] = CTK.cfg.get_val("%s!aux_dir" % (PREFIX)) config = CONFIG_VSERVER % (props) CTK.cfg.apply_chunk(config) Wizard.AddUsualStaticFiles(props["pre_rule_minus1"]) # Clean up CTK.cfg.normalize("%s!rule" % (next)) CTK.cfg.normalize("vserver") del (CTK.cfg[PREFIX]) return CTK.cfg_reply_ajax_ok()
def Commit(): # New Virtual Server new_nick = CTK.post.pop("tmp!new_nick") new_droot = CTK.post.pop("tmp!new_droot") if new_nick and new_droot: next = CTK.cfg.get_next_entry_prefix("vserver") CTK.cfg["%s!nick" % (next)] = new_nick CTK.cfg["%s!document_root" % (next)] = new_droot CTK.cfg["%s!rule!1!match" % (next)] = "default" CTK.cfg["%s!rule!1!handler" % (next)] = "common" CTK.cfg["%s!rule!2!match" % (next)] = "directory" CTK.cfg["%s!rule!2!match!directory" % (next)] = "/icons" CTK.cfg["%s!rule!2!handler" % (next)] = "file" CTK.cfg["%s!rule!2!document_root" % (next)] = CHEROKEE_ICONSDIR CTK.cfg["%s!rule!3!match" % (next)] = "directory" CTK.cfg["%s!rule!3!match!directory" % (next)] = "/cherokee_themes" CTK.cfg["%s!rule!3!handler" % (next)] = "file" CTK.cfg["%s!rule!3!document_root" % (next)] = CHEROKEE_THEMEDIR return CTK.cfg_reply_ajax_ok() # Modifications return CTK.cfg_apply_post()
def Commit(): # New Virtual Server new_nick = CTK.post.pop('tmp!new_nick') new_droot = CTK.post.pop('tmp!new_droot') if new_nick and new_droot: next = CTK.cfg.get_next_entry_prefix ('vserver') CTK.cfg['%s!nick' %(next)] = new_nick CTK.cfg['%s!document_root' %(next)] = new_droot CTK.cfg['%s!rule!1!match' %(next)] = 'default' CTK.cfg['%s!rule!1!handler' %(next)] = 'common' CTK.cfg['%s!rule!2!match' %(next)] = 'directory' CTK.cfg['%s!rule!2!match!directory' %(next)] = '/icons' CTK.cfg['%s!rule!2!handler' %(next)] = 'file' CTK.cfg['%s!rule!2!document_root' %(next)] = CHEROKEE_ICONSDIR CTK.cfg['%s!rule!3!match' %(next)] = 'directory' CTK.cfg['%s!rule!3!match!directory' %(next)] = '/cherokee_themes' CTK.cfg['%s!rule!3!handler' %(next)] = 'file' CTK.cfg['%s!rule!3!document_root' %(next)] = CHEROKEE_THEMEDIR return CTK.cfg_reply_ajax_ok() # Modifications return CTK.cfg_apply_post()
def Commit_Rule (self): vsrv_num = CTK.cfg.get_val ('%s!vsrv_num'%(PREFIX)) next = 'vserver!%s' %(vsrv_num) # PHP php = CTK.load_module ('php', 'wizards') error = php.wizard_php_add (next) if error: return {'ret': 'error', 'errors': {'msg': error}} php_info = php.get_info (next) # Drupal props = cfg_get_surrounding_repls ('pre_rule', php_info['rule']) props['pre_vsrv'] = next props['web_dir'] = CTK.cfg.get_val('%s!web_dir' %(PREFIX)) props['local_dir'] = CTK.cfg.get_val('%s!local_dir' %(PREFIX)) config = CONFIG_DIR %(props) CTK.cfg.apply_chunk (config) # Fixes Drupal bug for multilingual content CTK.cfg['%s!encoder!gzip' %(php_info['rule'])] = '0' # Clean up CTK.cfg.normalize ('%s!rule'%(next)) del (CTK.cfg[PREFIX]) return CTK.cfg_reply_ajax_ok()
def __init__ (self, refresh, right_box): CTK.Container.__init__ (self) # Sanity check if not CTK.cfg.keys('vserver'): CTK.cfg['vserver!1!nick'] = 'default' CTK.cfg['vserver!1!document_root'] = '/tmp' CTK.cfg['vserver!1!rule!1!match'] = 'default' CTK.cfg['vserver!1!rule!1!handler'] = 'common' # Helper entry = lambda klass, key: CTK.Box ({'class': klass}, CTK.RawHTML (CTK.escape_html (CTK.cfg.get_val(key, '')))) # Build the panel list panel = SelectionPanel.SelectionPanel (reorder, right_box.id, URL_BASE, '', container='vservers_panel') self += panel # Build the Virtual Server list vservers = CTK.cfg.keys('vserver') vservers.sort (lambda x,y: cmp(int(x), int(y))) vservers.reverse() for k in vservers: # Document root widget droot_str = CTK.cfg.get_val ('vserver!%s!document_root'%(k), '') # Market install base scenario if self.__is_market_installation (k, droot_str): droot_widget = CTK.Box ({'class': 'droot'}, CTK.RawHTML(_('Market installation'))) else: droot_widget = CTK.Box ({'class': 'droot'}, CTK.RawHTML(CTK.escape_html (droot_str))) if k == vservers[-1]: content = [entry('nick', 'vserver!%s!nick'%(k)), droot_widget] panel.Add (k, '/vserver/content/%s'%(k), content, draggable=False) else: nick = CTK.cfg.get_val ('vserver!%s!nick'%(k), _('Unknown')) nick_esc = CTK.escape_html (nick) # Remove dialog = CTK.Dialog ({'title': _('Do you really want to remove it?'), 'width': 480}) dialog.AddButton (_('Cancel'), "close") dialog.AddButton (_('Remove'), CTK.JS.Ajax (URL_APPLY, async=True, data = {'vserver!%s'%(k):''}, success = dialog.JS_to_close() + \ refresh.JS_to_refresh())) dialog += CTK.RawHTML (_(NOTE_DELETE_DIALOG) %(locals())) self += dialog remove = CTK.ImageStock('del') remove.bind ('click', dialog.JS_to_show() + "return false;") # Disable is_disabled = bool (int (CTK.cfg.get_val('vserver!%s!disabled'%(k), "0"))) disclass = ('','vserver-inactive')[is_disabled][:] disabled = CTK.ToggleButtonOnOff (not is_disabled) disabled.bind ('changed', CTK.JS.Ajax (URL_APPLY, async=True, data = '{"vserver!%s!disabled": event.value}'%(k)))
def __init__(self, refresh, right_box): CTK.Container.__init__(self) # Sanity check if not CTK.cfg.keys("vserver"): CTK.cfg["vserver!1!nick"] = "default" CTK.cfg["vserver!1!document_root"] = "/tmp" CTK.cfg["vserver!1!rule!1!match"] = "default" CTK.cfg["vserver!1!rule!1!handler"] = "common" # Helper entry = lambda klass, key: CTK.Box({"class": klass}, CTK.RawHTML(CTK.escape_html(CTK.cfg.get_val(key, "")))) # Build the panel list panel = SelectionPanel.SelectionPanel(reorder, right_box.id, URL_BASE, "", container="vservers_panel") self += panel # Build the Virtual Server list vservers = CTK.cfg.keys("vserver") vservers.sort(lambda x, y: cmp(int(x), int(y))) vservers.reverse() for k in vservers: # Document root widget droot_str = CTK.cfg.get_val("vserver!%s!document_root" % (k), "") droot_widget = CTK.Box({"class": "droot"}, CTK.RawHTML(CTK.escape_html(droot_str))) if k == vservers[-1]: content = [entry("nick", "vserver!%s!nick" % (k)), droot_widget] panel.Add(k, "/vserver/content/%s" % (k), content, draggable=False) else: nick = CTK.cfg.get_val("vserver!%s!nick" % (k), _("Unknown")) nick_esc = CTK.escape_html(nick) # Remove dialog = CTK.Dialog({"title": _("Do you really want to remove it?"), "width": 480}) dialog.AddButton(_("Cancel"), "close") dialog.AddButton( _("Remove"), CTK.JS.Ajax( URL_APPLY, async=True, data={"vserver!%s" % (k): ""}, success=dialog.JS_to_close() + refresh.JS_to_refresh(), ), ) dialog += CTK.RawHTML(_(NOTE_DELETE_DIALOG) % (locals())) self += dialog remove = CTK.ImageStock("del") remove.bind("click", dialog.JS_to_show() + "return false;") # Disable is_disabled = bool(int(CTK.cfg.get_val("vserver!%s!disabled" % (k), "0"))) disclass = ("", "vserver-inactive")[is_disabled][:] disabled = CTK.ToggleButtonOnOff(not is_disabled) disabled.bind( "changed", CTK.JS.Ajax(URL_APPLY, async=True, data='{"vserver!%s!disabled": event.value}' % (k)) )
def __call__ (self): dir_type = CTK.post.get_val ('%s!install_dir_type'%(CFG_PREFIX)) if dir_type == 'auto': del (CTK.cfg['%s!app_dir'%(CFG_PREFIX)]) return CTK.cfg_reply_ajax_ok() return CTK.cfg_apply_post()
def apply (): graph_type = CTK.post.get_val('graph_type') if graph_type: CTK.cfg['tmp!graph_type'] = graph_type return CTK.cfg_reply_ajax_ok() # Modifications return CTK.cfg_apply_post()
def AddCommon (self): # Parent's AddComon Handler.PluginHandler.AddCommon (self) # Add CGI related stuff table = CTK.PropsTable() if self.show_script_alias: table.Add (_("Script Alias"), CTK.TextCfg('%s!script_alias'%(self.key), True), _(NOTE_SCRIPT_ALIAS)) if self.show_change_uid: table.Add (_("Change UID"), CTK.CheckCfgText('%s!change_user'%(self.key), False, _('Change')), _(NOTE_CHANGE_USER)) table.Add (_('Error handler'), CTK.CheckCfgText('%s!error_handler'%(self.key), True, _('Enabled')), _(NOTE_ERROR_HANDLER)) table.Add (_('Check file'), CTK.CheckCfgText('%s!check_file'%(self.key), True, _('Enabled')), _(NOTE_CHECK_FILE)) table.Add (_('Pass Request Headers'), CTK.CheckCfgText('%s!pass_req_headers'%(self.key), True, _('Enabled')), _(NOTE_PASS_REQ)) table.Add (_('Allow X-Sendfile'), CTK.CheckCfgText('%s!xsendfile'%(self.key), False, _('Enabled')), _(NOTE_XSENDFILE)) table.Add (_('Use I/O cache'), CTK.CheckCfgText('%s!iocache'%(self.key), True, _('Enabled')), _(NOTE_IOCACHE)) submit = CTK.Submitter (URL_APPLY) submit += CTK.Indenter (table) self += CTK.RawHTML ("<h2>%s</h2>" %(_('Common CGI Options'))) self += submit # X-Real-IP refresh = CTK.Refreshable ({'id': 'x_real_ip'}) refresh.register (lambda: self.X_Real_IP(refresh, self.key).Render()) self += CTK.RawHTML ("<h2>%s</h2>" % (_('Fixed Authentication List'))) self += CTK.Indenter (refresh) # Environment refresh = CTK.Refreshable ({'id': 'cgi_environ_list'}) refresh.register (lambda: self.Environ(refresh, self.key).Render()) self += CTK.RawHTML ("<h2>%s</h2>" % (_('Custom Environment Variables'))) self += CTK.Indenter (refresh) new_name = CTK.TextField ({'name': 'tmp!new_name', 'class': 'noauto'}) new_value = CTK.TextField ({'name': 'tmp!new_value', 'class': 'noauto'}) new_add = CTK.SubmitterButton (_('Add')) table = CTK.Table() table.set_header(1) table += [CTK.RawHTML(x) for x in (_('Name'), _('Value'))] table += [new_name, new_value, new_add] submit = CTK.Submitter (URL_APPLY) submit += CTK.Hidden('key', '%s!env'%(self.key)) submit += table submit.bind ('submit_success', refresh.JS_to_refresh() + new_name.JS_to_clean() + new_value.JS_to_clean()) self += CTK.RawHTML ("<h3>%s</h3>" % (_('Add New Custom Environment Variable'))) self += CTK.Indenter(submit) # Publish VALS = [("%s!script_alias"%(self.key), validations.is_path)] CTK.publish ('^%s'%(URL_APPLY), commit, validation=VALS, method="POST")
def __init__ (self, title, headers=[], body_id=None, **kwargs): # Look for the theme file srcdir = os.path.dirname (os.path.realpath (__file__)) theme_file = os.path.join (srcdir, 'theme.html') # Set up the template template = CTK.Template (filename = theme_file) template['title'] = title template['save'] = _('Save') template['home'] = _('Home') template['status'] = _('Status') template['market'] = _('Market') template['general'] = _('General') template['vservers'] = _('vServers') template['sources'] = _('Sources') template['advanced'] = _('Advanced') template['help'] = _('Help') template['updating'] = _('Updating...') template['HELP_HTML'] = kwargs.has_key('helps') and HELP_HTML or '' template['HELP_JS'] = kwargs.has_key('helps') and HELP_JS or '' # <body> property if body_id: template['body_props'] = ' id="body-%s"' %(body_id) # Hide/Show Market icon if int (CTK.cfg.get_val("admin!ows!enabled", OWS_ENABLE)): template['market_menu_entry'] = '<li id="nav-market"><a href="/market">%(market)s</a></li>' else: template['market_menu_entry'] = '' # Save dialog dialog = CTK.DialogProxyLazy (URL_SAVE, {'title': _(SAVED_NOTICE), 'autoOpen': False, 'draggable': False, 'width': 500}) CTK.publish (URL_SAVE, Save, dialog=dialog) # Default headers heads = copy.copy (headers) heads.append ('<link rel="stylesheet" type="text/css" href="/static/css/cherokee-admin.css" />') # Help translation if kwargs.has_key('helps'): helps = [(x[0], _(x[1])) for x in kwargs['helps']] kwargs['helps'] = helps # Parent's constructor CTK.Page.__init__ (self, template, heads, **kwargs) # Add the 'Save' dialog js = SAVE_BUTTON %({'show_dialog_js': dialog.JS_to_show()}) if CTK.cfg.has_changed(): js += ".removeClass('saved');" else: js += ".addClass('saved');" self += dialog self += CTK.RawHTML (js=js)
def __call__ (self): if CTK.post.pop('final'): CTK.cfg_apply_post() # VServer or Rule? if CTK.cfg.get_val ('%s!vsrv_num'%(PREFIX)): return self.Commit_Rule() return self.Commit_VServer() return CTK.cfg_apply_post()
def __init__ (self, command_progress): CTK.Container.__init__ (self) # Length and current commands_len = len(command_progress.commands) if command_progress.error or \ command_progress.executed >= commands_len: command_entry = command_progress.commands [command_progress.executed - 1] else: command_entry = command_progress.commands [command_progress.executed] # Title if command_entry.has_key('description'): title = CTK.escape_html (command_entry['description']) elif command_entry.has_key('command'): title = CTK.escape_html (command_entry['command']) elif command_entry.has_key('function'): title = CTK.escape_html (command_entry['function'].__name__) else: assert False, 'Unknown command entry type' # Error if command_progress.error: ret = command_progress.last_popen_ret percent = command_progress.executed * 100.0 / (commands_len + 1) if ret.get('command'): title_error = CTK.escape_html (ret['command']) elif command_entry.has_key ('function'): title_error = CTK.escape_html (command_entry['function'].__name__) else: title_error = _("Unknown Error") error_content = CTK.Box ({'class': 'market-commands-exec-error-details'}) error_content += CTK.RawHTML ("<pre>%s</pre>" %(error_to_HTML(ret['stderr']))) details = CTK.CollapsibleEasy ((_(MORE), _(LESS))) details += error_content self += CTK.ProgressBar ({'value': percent}) self += CTK.RawHTML ("<p><b>%s</b>: %s</p>" %(_("Error executing"), title_error)) self += details return # Regular percent = (command_progress.executed + 1) * 100.0 / (commands_len + 1) self += CTK.ProgressBar ({'value': percent}) self += CTK.Box ({'class': 'market-commands-exec-command'}, CTK.RawHTML ("<p>%s</p>" %(title))) # Next step if command_progress.executed < commands_len: JS = "update = function(){%s}; setTimeout ('update()', %s);" self += CTK.RawHTML (js = JS%(command_progress.refresh.JS_to_refresh(), DELAY)) else: self += CTK.RawHTML (js = CTK.DruidContent__JS_to_goto (command_progress.id, command_progress.finished_url))
cf_host = urllib.urlopen("http://%s" % host) except: raise ValueError, _(ERROR_NO_SRC) headers = str(cf_host.headers).lower() cf_host.close() if not "jrun" in headers: raise ValueError, _(ERROR_NO_SRC) return host VALS = [ ("%s!new_host" % (PREFIX), validations.is_not_empty), ("%s!new_source" % (PREFIX), validations.is_not_empty), ("%s!new_host" % (PREFIX), validations.is_new_vserver_nick), ("%s!new_source" % (PREFIX), is_coldfusion_host), ] # VServer CTK.publish('^/wizard/vserver/coldfusion$', Welcome) CTK.publish('^/wizard/vserver/coldfusion/2$', Common) CTK.publish('^/wizard/vserver/coldfusion/3$', Host) # Rule CTK.publish('^/wizard/vserver/(\d+)/coldfusion$', Welcome) CTK.publish('^/wizard/vserver/(\d+)/coldfusion/2$', Common) CTK.publish('^/wizard/vserver/(\d+)/coldfusion/3$', WebDirectory) # Common CTK.publish(r'^%s$' % (URL_APPLY), Commit, method="POST", validation=VALS)
def __init__ (self): CTK.Box.__init__ (self, {'id': 'license'}) self += CTK.Box ({'id': 'license-text'}, CTK.RawHTML (GPL2_LICENSE))
def url3(): cont = CTK.Container() cont += CTK.RawHTML ('Thank you, the value is <b>%s</b>.'%(name)) cont += CTK.DruidButtonsPanel_PrevCreate ('/url2') return cont.Render().toStr()
URL_APPLY = '/plugin/tile/apply' HELPS = [] VALIDATIONS = [ ("vserver![\d]+!rule![\d]+!handler!timeout", validations.is_number), ("vserver![\d]+!rule![\d]+!handler!expiration", validations.is_time) ] class Plugin_tile (Handler.PluginHandler): def __init__ (self, key, **kwargs): kwargs['show_document_root'] = False Handler.PluginHandler.__init__ (self, key, **kwargs) Handler.PluginHandler.AddCommon (self) # GUI table = CTK.PropsAuto (URL_APPLY) table.Add (_("Static Tile Expiration"), CTK.TextCfg('%s!expiration'%(key), True), _(NOTE_EXPIRATION_TIME)) table.Add (_("Render Timeout"), CTK.TextCfg('%s!timeout'%(key), True), _(NOTE_TIMEOUT)) self += CTK.Indenter (table) # Load Balancing modul = CTK.PluginSelector('%s!balancer'%(key), trans_options(Cherokee.support.filter_available (BALANCERS))) table = CTK.PropsTable() table.Add (_("Balancer"), modul.selector_widget, _(Balancer.NOTE_BALANCER)) self += CTK.RawHTML ('<h2>%s</h2>' %(_('Renderd Balancing'))) self += CTK.Indenter (table) self += modul CTK.publish ('^%s$'%(URL_APPLY), CTK.cfg_apply_post, validation=VALIDATIONS, method="POST")
buttons += CTK.DruidButton_Close(_('Cancel')) cont += buttons return cont.Render().toStr() class Finished: def __call__(self): # Clean up del (CTK.cfg['tmp!market!maintenance']) # The cache is no longer valid Invalidate_Cache() # Close dialog box = CTK.Box() box += CTK.RawHTML(js=CTK.DruidContent__JS_to_close(box.id)) return box.Render().toStr() CTK.publish('^%s$' % (URL_MAINTENANCE_LIST), ListApps) CTK.publish('^%s$' % (URL_MAINTENANCE_LIST_APPLY), ListApps_Apply, method="POST") CTK.publish('^%s$' % (URL_MAINTENANCE_DB), DatabaseRemoval) CTK.publish('^%s$' % (URL_MAINTENANCE_DB_APPLY), DatabaseRemoval_Apply, method="POST") CTK.publish('^%s$' % (URL_MAINTENANCE_REMOVE), RemoveApps) CTK.publish('^%s$' % (URL_MAINTENANCE_FINISHED), Finished)
def __call__(self): # Check the application db_type = None db_found = False for app in CTK.cfg.keys('tmp!market!maintenance!remove'): tmp = CTK.cfg.get_val('tmp!market!maintenance!remove!%s!db' % (app)) if not tmp: continue if not CTK.cfg.get_val('tmp!market!maintenance!db!%s!user' % (tmp)): db_found = True db_type = tmp # No DBs, we are done here if not db_found: box = CTK.Box() box += CTK.RawHTML(js=CTK.DruidContent__JS_to_goto( box.id, URL_MAINTENANCE_REMOVE)) return box.Render().toStr() # Ask for the user and password table = CTK.PropsTable() table.Add( _('DB user'), CTK.TextField({ 'name': 'db_user', 'class': 'noauto', 'value': 'root' }), _(NOTE_DBUSER)) table.Add( _('DB password'), CTK.TextFieldPassword({ 'name': 'db_pass', 'class': 'noauto' }), _(NOTE_DBPASS)) # Reload its content on submit success submit = CTK.Submitter(URL_MAINTENANCE_DB_APPLY) submit.bind('submit_success', CTK.DruidContent__JS_to_goto(table.id, URL_MAINTENANCE_DB)) submit += CTK.Hidden('db_type', db_type) submit += table cont = CTK.Container() cont += CTK.RawHTML('<h2>%s (%s)</h2>' % (_("Database Credentials"), db_type)) cont += CTK.RawHTML('<p>%s</p>' % (_(DB_DEL_P1))) cont += submit return cont.Render().toStr()
def halt(self): CTK.stop()
def error_to_HTML(error): # error = error.replace ('\n', '<br/>') error = error.replace('\x07', '') error = error.replace('\r', '') error = error.replace('', '') return CTK.escape_html(error)
def __call__ (self): if CTK.post.pop('final'): CTK.cfg_apply_post() return self.Commit_Rule() return CTK.cfg_apply_post()
cont += CTK.DruidButtonsPanel_PrevCreate_Auto() else: cont += CTK.RawHTML ('<p>%s</p>'%(_(NOTE_CREATE_ERR))) cont += CTK.DruidButtonsPanel_Cancel() return cont.Render().toStr() class Welcome: def __call__ (self): cont = CTK.Container() cont += CTK.RawHTML ('<h2>%s</h2>' %(_(NOTE_WELCOME_H1))) cont += Wizard.Icon ('static', {'class': 'wizard-descr'}) box = CTK.Box ({'class': 'wizard-welcome'}) box += CTK.RawHTML ('<p>%s</p>' %(_(NOTE_WELCOME_P1))) cont += box # Send the VServer num tmp = re.findall (r'^/wizard/vserver/(\d+)/', CTK.request.url) submit = CTK.Submitter (URL_APPLY) submit += CTK.Hidden('%s!vsrv_num'%(PREFIX), tmp[0]) cont += submit cont += CTK.DruidButtonsPanel_Next_Auto() return cont.Render().toStr() # Rule CTK.publish ('^/wizard/vserver/(\d+)/static$', Welcome) CTK.publish ('^/wizard/vserver/(\d+)/static/2', Create) CTK.publish (r'^%s'%(URL_APPLY), Commit, method="POST")
# DB-Slayer alike table = CTK.PropsTable() table.Add( _('Language'), CTK.ComboCfg('%s!lang' % (key), trans_options(DWRITER_LANGS)), _(NOTE_LANG)) table.Add(_('Index'), CTK.TextCfg('%s!index' % (key), True), _(NOTE_DB)) submit = CTK.Submitter(URL_APPLY) submit += table self += CTK.RawHTML("<h2>%s</h2>" % (_('Serialization'))) self += CTK.Indenter(submit) # Load Balancing (currently only one source is actually used!) modul = CTK.PluginSelector( '%s!balancer' % (key), trans_options(Cherokee.support.filter_available(BALANCERS))) table = CTK.PropsTable() table.Add(_("Balancer"), modul.selector_widget, _(Balancer.NOTE_BALANCER)) self += CTK.RawHTML('<h2>%s</h2>' % (_('Data Base Balancing'))) self += CTK.Indenter(table) self += modul CTK.publish('^%s$' % (URL_APPLY), CTK.cfg_apply_post, method="POST")
def __init__ (self, refreshable, key, url_apply, **kwargs): CTK.Container.__init__ (self, **kwargs) entries = CTK.cfg.keys (key) # Warning message if not entries: notice = CTK.Notice('warning') notice += CTK.RawHTML (_(WARNING_EMPTY)) self += notice # List else: table = CTK.Table() submit = CTK.Submitter(url_apply) submit += table self += CTK.Indenter(submit) table.set_header(1) table += [CTK.RawHTML(_('Regular Expressions'))] for i in entries: e1 = CTK.TextCfg ("%s!%s"%(key,i)) rm = None if len(entries) >= 2: rm = CTK.ImageStock('del') rm.bind('click', CTK.JS.Ajax (url_apply, data = {"%s!%s"%(key,i): ''}, complete = refreshable.JS_to_refresh())) table += [e1, rm] # Add New table = CTK.PropsTable() next = CTK.cfg.get_next_entry_prefix (key) table.Add (_('New Regular Expression'), CTK.TextCfg(next, False, {'class':'noauto'}), _(NOTE_REHOST)) submit = CTK.Submitter(url_apply) dialog = CTK.Dialog2Buttons ({'title': _('Add New Entry')}, _('Add'), submit.JS_to_submit()) submit += table submit.bind ('submit_success', refreshable.JS_to_refresh()) submit.bind ('submit_success', dialog.JS_to_close()) dialog += submit self += dialog add_new = CTK.Button(_('Add new entry…')) add_new.bind ('click', dialog.JS_to_show()) self += add_new
def __init__(self, command_progress): CTK.Container.__init__(self) # Length and current commands_len = len(command_progress.commands) if command_progress.error or \ command_progress.executed >= commands_len: command_entry = command_progress.commands[ command_progress.executed - 1] else: command_entry = command_progress.commands[ command_progress.executed] # Title if command_entry.has_key('description'): title = CTK.escape_html(command_entry['description']) elif command_entry.has_key('command'): title = CTK.escape_html(command_entry['command']) elif command_entry.has_key('function'): title = CTK.escape_html(command_entry['function'].__name__) else: assert False, 'Unknown command entry type' # Error if command_progress.error: ret = command_progress.last_popen_ret percent = command_progress.executed * 100.0 / (commands_len + 1) if ret.get('command'): title_error = CTK.escape_html(ret['command']) elif command_entry.has_key('function'): if command_entry.has_key('description'): title_error = CTK.escape_html( '%s (%s)' % (command_entry['description'], command_entry['function'].__name__)) else: title_error = CTK.escape_html( command_entry['function'].__name__) else: title_error = _("Unknown Error") error_content = CTK.Box( {'class': 'market-commands-exec-error-details'}) error_content += CTK.RawHTML("<pre>%s</pre>" % (error_to_HTML(ret['stderr']))) details = CTK.CollapsibleEasy((_(MORE), _(LESS))) details += error_content self += CTK.ProgressBar({'value': percent}) self += CTK.RawHTML("<p><b>%s</b>: %s</p>" % (_("Error executing"), title_error)) self += details return # Regular percent = (command_progress.executed + 1) * 100.0 / (commands_len + 1) self += CTK.ProgressBar({'value': percent}) self += CTK.Box({'class': 'market-commands-exec-command'}, CTK.RawHTML("<p>%s</p>" % (title))) # Next step if command_progress.executed < commands_len: JS = "update = function(){%s}; setTimeout ('update()', %s);" self += CTK.RawHTML( js=JS % (command_progress.refresh.JS_to_refresh(), DELAY)) else: self += CTK.RawHTML(js=CTK.DruidContent__JS_to_goto( command_progress.id, command_progress.finished_url))
def __init__(self, info, props): assert type(info) == dict CTK.Box.__init__(self, props.copy()) url_icon_big = '%s/%s/icons/%s' % (REPO_MAIN, info['id'], info['icon_big']) self += CTK.Box({'class': 'market-app-featured-icon'}, CTK.Image({'src': url_icon_big})) self += CTK.Box({'class': 'market-app-featured-name'}, CTK.Link('%s/%s' % (URL_APP, info['id']), CTK.RawHTML(info['name']))) self += CTK.Box({'class': 'market-app-featured-category'}, CTK.RawHTML(info['category'])) self += CTK.Box({'class': 'market-app-featured-summary'}, CTK.RawHTML(info['desc_short'])) self += CTK.Box({'class': 'market-app-featured-score'}, CTK.StarRating({'selected': info.get('score', -1)}))
# Save dialog dialog = CTK.DialogProxyLazy (URL_SAVE, {'title': _(SAVED_NOTICE), 'autoOpen': False, 'draggable': False, 'width': 500}) CTK.publish (URL_SAVE, Save, dialog=dialog) # Default headers heads = copy.copy (headers) heads.append ('<link rel="stylesheet" type="text/css" href="/static/css/cherokee-admin.css" />') # Help translation if kwargs.has_key('helps'): helps = [(x[0], _(x[1])) for x in kwargs['helps']] kwargs['helps'] = helps # Parent's constructor CTK.Page.__init__ (self, template, heads, **kwargs) # Add the 'Save' dialog js = SAVE_BUTTON %({'show_dialog_js': dialog.JS_to_show()}) if CTK.cfg.has_changed(): js += ".removeClass('saved');" else: js += ".addClass('saved');" self += dialog self += CTK.RawHTML (js=js) CTK.publish (URL_SAVE_GRACEFUL, Restart, mode='graceful') CTK.publish (URL_SAVE_HARD, Restart, mode='hard') CTK.publish (URL_SAVE_NONE, Restart, mode='none')
# Ensure OWS is enabled if not int(CTK.cfg.get_val("admin!ows!enabled", OWS_ENABLE)): return CTK.HTTP_Redir('/') page = Page_Market() # Check repository is accessible index = Distro.Index() if index.error: page.mainarea += RepoError() return page.Render() # Featured page.mainarea += FeaturedBox() # Top page.mainarea += CTK.RawHTML("<h2>%s</h2>" % (_('Top Applications'))) page.mainarea += TopApps() # Maintanance if Maintenance.does_it_need_maintenance(): refresh_maintenance = CTK.Refreshable({'id': 'market_maintenance'}) refresh_maintenance.register(lambda: Maintenance.Maintenance_Box( refresh_maintenance).Render()) page.sidebar += refresh_maintenance return page.Render() CTK.publish('^%s$' % (URL_MAIN), Main)
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # """ Detection of PHP modules """ import CTK from util import * php = CTK.load_module_pyc( os.path.join(os.path.dirname(os.path.realpath(__file__)), "php.pyo"), "php_util") PHP_GD_NOTE = N_("The 'gd' module is not supported by your PHP interpreter") PHP_GD_INST = { 'apt': "sudo apt-get install php5-gd", 'zypper': "sudo zypper install php5-gd", 'macports': "sudo port install php5-gd", 'yum': "sudo yum install php-gd", 'freebsd_pkg': "pkg_add -r php5-gd", 'freebsd_ports':
cont += submit cont += CTK.DruidButtonsPanel_Create() return cont.Render().toStr() VALS = [ ('%s!host' % (CFG_PREFIX), validations.is_not_empty), ('%s!host' % (CFG_PREFIX), validations.is_new_vserver_nick), ('%s!droot' % (CFG_PREFIX), validations.is_not_empty), ('%s!droot' % (CFG_PREFIX), validations.is_local_dir_exists), ] # Rule CTK.publish(URL_WIZARD_RULE_R, WelcomeRule) CTK.publish(URL_WIZARD_APPLY_R, Commit, method="POST") # VServer CTK.publish('^/wizard/vserver/php$', WelcomeVserver) CTK.publish('^/wizard/vserver/php/2$', DocumentRoot) CTK.publish('^/wizard/vserver/php/3$', Host) CTK.publish(r'^%s' % (URL_APPLY), Commit, method="POST", validation=VALS) # # External Stages # def External_FindPHP(): # Add PHP if needed
def __call__(self): # Check the apps orphan = check_orphan_installations() unfinished = check_unfinished_installations() # Unfinished apps are not even orphans for u in unfinished: if u in orphan: orphan.remove(u) # Build list of apps to remove remove_apps = {} for app in orphan: db = app_database_exists(app) service = self._figure_app_service(app) remove_apps[app] = {} remove_apps[app]['type'] = _('Orphan') remove_apps[app]['name'] = self._figure_app_name(app) remove_apps[app]['date'] = self._figure_app_date(app) if db: remove_apps[app]['db'] = db if service: remove_apps[app]['service'] = service for app in unfinished: if app in remove_apps: continue db = app_database_exists(app) service = self._figure_app_service(app) app_fp = os.path.join(CHEROKEE_OWS_ROOT, app) remove_apps[app] = {} remove_apps[app]['type'] = _('Unfinished') remove_apps[app]['name'] = self._figure_app_name(app) remove_apps[app]['date'] = self._figure_app_date(app) if db: remove_apps[app]['db'] = db if service: remove_apps[app]['service'] = service # Even though it's a 'unfinished' app, a virtual server # might exist already. for v in CTK.cfg['vserver'] or []: if CTK.cfg.get_val('vserver!%s!document_root' % (v)) == app_fp: remove_apps[app]['vserver'] = v # Store in CTK.cfg del (CTK.cfg['tmp!market!maintenance!remove']) for app in remove_apps: CTK.cfg['tmp!market!maintenance!remove!%s!del' % (app)] = 0 CTK.cfg['tmp!market!maintenance!remove!%s!name' % (app)] = remove_apps[app]['name'] CTK.cfg['tmp!market!maintenance!remove!%s!db' % (app)] = remove_apps[app].get('db') CTK.cfg['tmp!market!maintenance!remove!%s!service' % (app)] = remove_apps[app].get('service') CTK.cfg['tmp!market!maintenance!remove!%s!date' % (app)] = remove_apps[app].get('date') CTK.cfg['tmp!market!maintenance!remove!%s!vserver' % (app)] = remove_apps[app].get('vserver') # Dialog buttons b_next = CTK.DruidButton_Goto(_('Remove'), URL_MAINTENANCE_DB, True) b_close = CTK.DruidButton_Close(_('Close')) b_cancel = CTK.DruidButton_Close(_('Cancel')) buttons = CTK.DruidButtonsPanel() buttons += b_close buttons += b_cancel buttons += b_next # App list app_list = AppList(remove_apps, b_next, b_cancel, b_close) # Content cont = CTK.Container() cont += CTK.RawHTML('<h2>%s</h2>' % (_("Applications requiring maintenance"))) cont += CTK.Box({'id': 'maintenance-removal'}, app_list) cont += buttons cont += CTK.RawHTML(js=b_next.JS_to_hide()) cont += CTK.RawHTML(js=b_cancel.JS_to_hide()) submit = CTK.Submitter(URL_MAINTENANCE_LIST_APPLY) submit += cont return submit.Render().toStr()
def _build_error_raw(self): self += CTK.RawHTML('<h1>%s</h1>' % (_('Server Launch Error'))) self += CTK.Box({'class': 'description'}, CTK.RawHTML(_('Something unexpected just happened.'))) self += CTK.Box({'class': 'backtrace'}, CTK.RawHTML(self._error_raw))
def GUI_mod (self): pre = '%s!bind'%(self.key) tmp = CTK.cfg.keys (pre) tmp.sort(lambda x,y: cmp(int(x), int(y))) if tmp: table = CTK.Table({'id': 'rule-table-bind'}) table.set_header(1) table += [CTK.RawHTML(x) for x in (_('Port'), _('Bind to'), _('TLS'), '')] for b in tmp: server_bind = CTK.cfg.get_val('%s!%s'%(pre, b)) port = CTK.cfg.get_val ("server!bind!%s!port"%(server_bind)) bind = CTK.cfg.get_val ("server!bind!%s!interface"%(server_bind), '') tls_ = CTK.cfg.get_val ("server!bind!%s!tls"%(server_bind), False) tls = [_("No"), _("Yes")][int(tls_)] delete = None if len(tmp) > 1: delete = CTK.ImageStock('del') delete.bind('click', CTK.JS.Ajax (URL_APPLY, data = {'%s!%s'%(pre, b): ''}, complete = "$('#%s').trigger('submit_success');"%(self.id))) table += [CTK.RawHTML(port), CTK.RawHTML(bind), CTK.RawHTML(tls), delete] self += CTK.RawHTML ('<h3>%s</h3>' % (_('Selected Ports'))) self += CTK.Indenter(table) # Don't show port already being listened to left = CTK.cfg.keys("server!bind") rule_used = [] for b in CTK.cfg.keys (pre): port_num = CTK.cfg.get_val('%s!%s'%(pre,b)) if port_num in left: left.remove(port_num) if left: ports = [('', _("Choose"))] for b in left: tmp = self._render_port_name (b) ports.append (tmp) next_bind = CTK.cfg.get_next_entry_prefix ('%s!bind'%(self.key)) table = CTK.PropsTable() table.Add (_('Incoming IP/Port'), CTK.ComboCfg(next_bind, ports), '') self += CTK.RawHTML ('<h3>%s</h3>' % (_('Assign new IP/Port'))) submit = CTK.Submitter (URL_APPLY) submit += table self += CTK.Indenter(submit)
def _build_error_py(self): self += CTK.RawHTML('<h1>%s</h1>' % (self._error['title'])) self += CTK.Box({'class': 'description'}, CTK.RawHTML(self._error.get('description', ''))) admin_url = self._error.get('admin_url') if admin_url: self += CTK.Box({'class': 'admin-url'}, CTK.RawHTML( _(ERROR_LAUNCH_URL_ADMIN) % (admin_url))) debug = self._error.get('debug') if debug: self += CTK.Box({'class': 'debug'}, CTK.RawHTML(debug)) backtrace = self._error.get('backtrace') if backtrace: self += CTK.Box({'class': 'backtrace'}, CTK.RawHTML(backtrace)) self += CTK.Box({'class': 'time'}, CTK.RawHTML(self._error.get('time', '')))
def url1(): cont = CTK.Container() cont += CTK.RawHTML ('Welcome, this is a test..') cont += CTK.DruidButtonsPanel_Next('/url2') return cont.Render().toStr()
try: validations.is_local_file_exists(manage) except: raise ValueError, _( "Directory doesn't look like a Django based project.") return path VALS = [("%s!django_dir" % (PREFIX), validations.is_not_empty), ("%s!new_host" % (PREFIX), validations.is_not_empty), ("%s!webdir" % (PREFIX), validations.is_not_empty), ("%s!document_root" % (PREFIX), validations.is_not_empty), ('%s!django_dir' % (PREFIX), is_django_dir), ('%s!new_host' % (PREFIX), validations.is_new_vserver_nick), ('%s!webdir' % (PREFIX), validations.is_dir_formatted), ("%s!document_root" % (PREFIX), validations.is_local_dir_exists)] # VServer CTK.publish('^/wizard/vserver/django$', Welcome) CTK.publish('^/wizard/vserver/django/2$', LocalSource) CTK.publish('^/wizard/vserver/django/3$', Host) # Rule CTK.publish('^/wizard/vserver/(\d+)/django$', Welcome) CTK.publish('^/wizard/vserver/(\d+)/django/2$', LocalSource) CTK.publish('^/wizard/vserver/(\d+)/django/3$', WebDirectory) # Common CTK.publish(r'^%s$' % (URL_APPLY), Commit, method="POST", validation=VALS)
cont += CTK.RawHTML ('Please, fill out the following form:') cont += submit cont += CTK.DruidButtonsPanel_PrevNext ('/url1', '/url3') return cont.Render().toStr() def url1(): cont = CTK.Container() cont += CTK.RawHTML ('Welcome, this is a test..') cont += CTK.DruidButtonsPanel_Next('/url2') return cont.Render().toStr() class default: def __call__ (self): dialog = CTK.Dialog ({'title': "New Virtual Server", 'width': 500, 'autoOpen': True}) dialog += CTK.Druid (CTK.RefreshableURL ('/url1')) page = CTK.Page() page += dialog return page.Render() CTK.publish ('', default) CTK.publish ('/url1', url1) CTK.publish ('/url2', url2) CTK.publish ('/url3', url3) CTK.publish ('/apply', submit, method="POST") CTK.run (port=8000)
def __call__ (self, dialog): # Check errors = SavingChecks.check_config() if errors: # FIXME: Needs to change the dialog title to "Configuration was not saved" or something ul = CTK.List() for error in errors: link = CTK.Link (error.url, CTK.RawHTML(_("Solve"))) content = CTK.Box() content += CTK.RawHTML ('%s: '%(error.title)) content += link ul += content all = CTK.Box({'id': 'sanity-msg'}) all += CTK.RawHTML ("<h2>%s</h2>"%(SAVE_CHECK_H1)) all += CTK.RawHTML ("<p>%s</p>" %(SAVE_CHECK_P1)) all += CTK.Box ({'id': "sanity-errors"}, ul) all += CTK.RawHTML ("<p>%s</p>" %(SAVE_CHECK_P2)) render = all.Render() return render.toStr() # Save CTK.cfg.save() all = CTK.Box ({'id': "buttons"}) all += CTK.RawHTML ("<h2>%s</h2>" %(_("Configuration successfully saved"))) if Cherokee.server.is_alive(): # Prompt about the reset all += CTK.RawHTML ('<p>%s</p>' %(_(SAVED_RESTART))) submit = CTK.Submitter (URL_SAVE_NONE) submit += CTK.Hidden('none', 'foo') submit += CTK.SubmitterButton (_('Do not restart')) submit.bind ('submit_success', dialog.JS_to_close()) all += submit submit = CTK.Submitter (URL_SAVE_GRACEFUL) submit += CTK.Hidden('graceful', 'foo') submit += CTK.SubmitterButton (_('Graceful restart')) submit.bind ('submit_success', dialog.JS_to_close()) all += submit submit = CTK.Submitter (URL_SAVE_HARD) submit += CTK.Hidden('hard', 'foo') submit += CTK.SubmitterButton (_('Hard restart')) submit.bind ('submit_success', dialog.JS_to_close()) all += submit else: # Close the dialog all += CTK.RawHTML ('<p>%s</p>' %(_(SAVED_NO_RUNNING))) submit = CTK.Submitter (URL_SAVE_NONE) submit += CTK.Hidden('none', 'foo') submit.bind ('submit_success', dialog.JS_to_close()) all += submit all += CTK.RawHTML (js = submit.JS_to_submit()) render = all.Render() return render.toStr()
def __init__(self, file, **kwargs): srcdir = os.path.dirname(os.path.realpath(__file__)) theme_file = os.path.join(srcdir, 'exception.html') # Set up the template template = CTK.Template(filename=theme_file) template['body_props'] = ' id="body-error"' template['title'] = _('Configuration file is not writable') # Parent's constructor CTK.Page.__init__(self, template, **kwargs) # Body if os.path.isfile(file): self += CTK.RawHTML('<h1>%s</h1>' % (_('Configuration file is not writable'))) self += CTK.RawHTML('<p><strong>%s</strong></p>' % (NOT_WRITABLE_F_TITLE % (file))) self += CTK.RawHTML('<p>%s</p>' % (NOT_WRITABLE_F_1)) self += CTK.RawHTML('<div class="shell">chmod u+w %s</div>' % (file)) self += CTK.RawHTML('<p>%s</p>' % (NOT_WRITABLE_F_2)) else: self += CTK.RawHTML('<h1>%s</h1>' % (_('Incorrect configuration file specified'))) self += CTK.RawHTML('<p><strong>%s</strong></p>' % (NOT_WRITABLE_D_TITLE % (file))) self += CTK.RawHTML('<p>%s</p>' % (NOT_WRITABLE_D_1)) self += CTK.RawHTML('<div class="shell">mv %s %s.dir</div>' % (file, file)) self += CTK.RawHTML('<p>%s</p>' % (NOT_WRITABLE_D_2))
# Add new next_bind = CTK.cfg.get_next_entry_prefix('%s!fullpath' % (self.key)) table = CTK.PropsTable() table.Add(_('Full Path'), CTK.TextCfg(next_bind, False), _(NOTE_FULLPATH)) submit = CTK.Submitter(URL_APPLY) submit += table self += CTK.RawHTML('<h3>%s</h3>' % (_("Add another path"))) self += CTK.Indenter(submit) def GetName(self): tmp = [] for k in CTK.cfg.keys('%s!fullpath' % (self.key)): d = CTK.cfg.get_val('%s!fullpath!%s' % (self.key, k)) tmp.append(d) if len(tmp) == 1: return "%s %s" % (_("Path"), tmp[0]) elif len(tmp) > 1: txt = "%s " % (_("Paths")) txt += ', '.join(tmp[:-1]) txt += " or %s" % (tmp[-1]) return txt else: return _("Path") CTK.publish(URL_APPLY, commit, method="POST")
# along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # import os import CTK import market from util import * from market.Install import Install_Stage from Wizard import AddUsualStaticFiles # Load required modules php = CTK.load_module_pyc( os.path.join(os.path.dirname(os.path.realpath(__file__)), "php.pyo"), "php_util") target = CTK.load_module_pyc( os.path.join(os.path.dirname(os.path.realpath(__file__)), "target.pyo"), "target_util") # Ownership and permissions POST_UNPACK_COMMANDS = [ ({ 'command': 'chown -R ${root_user}:${root_group} ${app_root}' }), ] # Config chunks CONFIG_VSERVER = """ %(pre_vsrv)s!nick = %(target_vserver)s
submit += CTK.Hidden ('key', self.key) submit += CTK.Hidden ('vsrv_num', self.vsrv_num) submit += table self += submit def GUI_mod (self): table = CTK.PropsTable() table.Add (_('Match type'), CTK.ComboCfg('%s!match_any'%(self.key), trans_options(OPTIONS)), '') if not int(CTK.cfg.get_val('%s!match_any'%(self.key), 0)): table.Add (_('Argument'), CTK.TextCfg('%s!arg'%(self.key), False), _(NOTE_ARGUMENT)) table.Add (_('Regular Expression'), CTK.TextCfg('%s!match'%(self.key), False), _(NOTE_REGEX)) submit = CTK.Submitter (URL_APPLY) submit += CTK.Hidden ('key', self.key) submit += CTK.Hidden ('vsrv_num', self.vsrv_num) submit += table self += submit def GetName (self): match = CTK.cfg.get_val ('%s!match'%(self.key), '') if int(CTK.cfg.get_val ('%s!match_any'%(self.key), "0")): return "Any arg. matches ~ %s" %(match) arg = CTK.cfg.get_val ('%s!arg'%(self.key), '') return "Arg %s matches %s" %(arg, match) # Validation, and Public URLs CTK.publish ("^%s"%(URL_APPLY), commit, method="POST")