Permalink
Browse files

git-svn-id: svn://cherokee-project.com/cherokee/trunk@3244 5dc97367-9…

…7f1-0310-9951-d761b3857238
  • Loading branch information...
1 parent d26c066 commit 0e5444c74c4271ee3ee21d0c3a78242314769c31 @alobbs alobbs committed May 23, 2009
View
@@ -1,5 +1,14 @@
2009-05-23 Alvaro Lopez Ortega <alvaro@octality.com>
+ * cherokee.conf.sample.pre, configure.in, admin/server.py,
+ admin/Wizard_PHP.py, admin/Page.py, admin/Wizard_WordPress.py,
+ admin/PageVServer.py, admin/static/images/wizards/php.jpg,
+ admin/Wizard.py, admin/static/images/wizards/wordpress.jpg,
+ admin/util.py, admin/static/images/wizards/Makefile.am,
+ admin/static/images/Makefile.am, admin/PageVServers.py: Initial
+ support of the Wizard mechanism. Includes two examples: PHP and
+ Wordpress.
+
* admin/PageEntry.py: Show the Document Root entry even if a
handler has not been selected. There should be possible to define
non-final rules with a custom document root.
View
@@ -157,6 +157,7 @@ def __init__ (self, id, cfg, helps=[]):
self.AddMacroContent ('_advanced', _('Advanced'))
self.AddMacroContent ('_title_save', _('Save Changes'))
self.AddMacroContent ('_button_save', _('Save'))
+ self.AddMacroContent ('_button_apply', _('Apply'))
manager = cherokee_management_get (cfg)
if manager.is_alive():
View
@@ -8,6 +8,7 @@
from Rule import *
from RuleList import *
from CherokeeManagement import *
+from Wizard import *
# For gettext
N_ = lambda x: x
@@ -95,7 +96,11 @@ def _op_handler (self, uri, post):
return '/vserver/'
default_render = False
- if post.get_val('is_submit'):
+ if '/wizard/' in uri:
+ re = self._op_apply_wizard (host, uri, post)
+ if re: return re
+
+ elif post.get_val('is_submit'):
if post.get_val('tmp!new_rule!value'):
re = self._op_add_new_entry (post = post,
cfg_prefix = 'vserver!%s!rule' %(host),
@@ -217,6 +222,7 @@ def _render_vserver_guts (self, host):
url_prefix = '/vserver/%s'%(host),
priorities = self._priorities)
tmp += self._render_add_rule ("tmp!new_rule")
+ tmp += self._render_wizards (host)
tabs += [(_('Behavior'), tmp)]
# Personal Webs
@@ -409,6 +415,18 @@ def _render_rules_generic (self, cfg_key, url_prefix, priorities):
'prefix': cfg_key}
return txt
+ def _render_wizards (self, host):
+ txt = ''
+ pre = 'vserver!%s'%(host)
+
+ mgr = WizardManager (self._cfg, "Rules", pre)
+ txt += mgr.render ("/vserver/%s"%(host))
+
+ if txt:
+ txt = _("<h2>Wizards</h2>") + txt
+
+ return txt
+
def _render_personal_webs (self, host):
txt = '<h2>%s</h2>' % (_('/~user directories'))
@@ -569,6 +587,19 @@ def _render_hosts (self, host, name):
txt += self.Indent(table) + e
return txt
+ def _op_apply_wizard (self, host, uri, post):
+ tmp = uri.split('/')
+ name = tmp[3]
+
+ mgr = WizardManager (self._cfg, "Rules", 'vserver!%s'%(host))
+ wizard = mgr.load (name)
+
+ output = wizard.run ("/vserver%s"%(uri), post)
+ if output:
+ return output
+
+ return '/vserver/%s' % (host)
+
def _op_apply_changes (self, host, uri, post):
pre = "vserver!%s" % (host)
View
@@ -4,6 +4,7 @@
from Form import *
from Table import *
from Entry import *
+from Wizard import *
# For gettext
N_ = lambda x: x
@@ -56,6 +57,10 @@ def _op_render (self):
return Page.Render(self)
def _op_handler (self, uri, post):
+ if '/wizard/' in uri:
+ re = self._op_apply_wizard (uri, post)
+ if re: return re
+
if post.get_val('is_submit'):
if post.get_val('vserver_clone_trg'):
tmp = self._op_clone_vserver (post)
@@ -78,6 +83,20 @@ def _op_handler (self, uri, post):
return self._op_render()
+ def _op_apply_wizard (self, uri, post):
+ tmp = uri.split('/')
+ name = tmp[2]
+ print "name", name
+
+ mgr = WizardManager (self._cfg, "VServer", 'vserver')
+ wizard = mgr.load (name)
+
+ output = wizard.run ("/vserver%s"%(uri), post)
+ if output:
+ return output
+
+ return '/vserver'
+
def _normailze_vservers (self):
vservers = [int(x) for x in self._cfg['vserver'].keys()]
vservers.sort ()
@@ -219,6 +238,18 @@ def sort_vservers(x,y):
txt += "<h2>%s</h2>" % (_('Clone Virtual Server'))
txt += self.Indent(fo1.Render(str(table)))
+ # Wizards
+ txt += self._render_wizards()
+ return txt
+
+ def _render_wizards (self):
+ txt = ''
+ mgr = WizardManager (self._cfg, "VServer", pre='vserver')
+ txt += mgr.render ("/vserver")
+
+ if txt:
+ txt = _("<h2>Wizards</h2>") + txt
+
return txt
def _get_vserver_for_nick (self, nick):
View
@@ -0,0 +1,86 @@
+import os, imp, sys
+
+class Wizard:
+ def __init__ (self, cfg, pre=None):
+ self.name = "Unknown wizard"
+ self._cfg = cfg
+ self._pre = pre
+ self.no_show = None
+
+ def show (self):
+ assert (False);
+
+ def run (self, uri, post):
+ self.show()
+ return self._run(uri, post)
+
+ def error (self, msg):
+ print "ERROR!! %s" % (msg)
+
+class WizardManager:
+ def __init__ (self, cfg, _type, pre):
+ self.type = _type
+ self._cfg = cfg
+ self._pre = pre
+
+ def get_available (self):
+ wizards = []
+
+ for fname in os.listdir('.'):
+ # Filter names
+ if not fname.startswith("Wizard_") or \
+ not fname.endswith('.py'):
+ continue
+
+ # Load the module source file
+ name = fname[:-3]
+ mod = imp.load_source (name, fname)
+ sys.modules[name] = mod
+
+ # Find a suitable class
+ for symbol in dir(mod):
+ if not symbol.startswith ("Wizard_%s_"%(self.type)):
+ continue
+
+ sname = name.replace("Wizard_", '')
+ if sname in [x[0] for x in wizards]:
+ continue
+
+ src = "wizard = mod.%s (self._cfg, self._pre)" % (symbol)
+ exec(src)
+ wizards.append ((sname, wizard))
+
+ return wizards
+
+ def render (self, url_pre):
+ txt = ''
+ no_show = ''
+
+ wizards = self.get_available()
+ if not wizards:
+ return ''
+
+ for tmp in wizards:
+ name, wizard = tmp
+ show = wizard.show()
+ img = "/static/images/wizards/%s" % (wizard.ICON)
+
+ if not show:
+ txt += '<tr><td rowspan="2"><img src="%s" /></td><td><b>%s</b> (disabled)</td></tr>' % (img, name)
+ txt += '<tr><td>%s <!-- NOT ADDED BECAUSE: %s --></td></tr>' % (wizard.DESC, wizard.no_show)
+ else:
+ url = "%s/wizard/%s" % (url_pre, name)
+ txt += '<tr><td rowspan="2"><a href="%s"><img src="%s" /></a></td><td><b>%s</b></td></tr>' % (url, img, name)
+ txt += '<tr><td>%s</td></tr>' % (wizard.DESC)
+
+ return '<table>%s</table>' %(txt)
+
+ def load (self, name):
+ fname = 'Wizard_%s.py' % (name)
+ mod = imp.load_source (name, fname)
+ sys.modules[name] = mod
+
+ src = "wizard = mod.Wizard_%s_%s (self._cfg, self._pre)" % (self.type, name)
+ exec(src)
+
+ return wizard
View
@@ -0,0 +1,103 @@
+from config import *
+from util import *
+from Wizard import *
+
+class Wizard_Rules_PHP (Wizard):
+ UNIX_SOCK = "/tmp/cherokee-php.socket"
+ DEFAULT_PATHS = ['/usr/bin', '/opt/php', '/usr/sfw/bin', '/usr/gnu/bin']
+ ICON = "php.jpg"
+ DESC = "Configures PHP in the current Virtual Server. It will add a new .php extension is not present."
+
+ def __init__ (self, cfg, pre):
+ Wizard.__init__ (self, cfg, pre)
+ self.name = "Add PHP support"
+ self.source = None
+
+ def show (self):
+ self.rule = None
+ self.source = None
+ self.nick = None
+
+ # Find: Source
+ self.source = cfg_source_find_interpreter (self._cfg, 'php-cgi')
+ if not self.source:
+ return True
+
+ # Find: Extension 'php' rule using prev Source
+ self.rule = cfg_vsrv_rule_find_extension (self._cfg, self._pre, 'php')
+ if not self.rule:
+ return True
+
+ # Already configured
+ self.nick = self._cfg.get_val ("%s!nick"%(self.source))
+ self.no_show = "Already configured: nick=%s" % (self.nick)
+ return False
+
+ def _run (self, uri, post):
+ def test_php_fcgi (path):
+ f = os.popen("%s -v" % (path), 'r')
+ output = f.read()
+ try: f.close()
+ except: pass
+ return "(cgi-fcgi)" in output
+
+ # Add a new Source, if needed
+ if not self.source:
+ php_path = path_find_binary (['php-cgi', 'php'],
+ extra_dirs = self.DEFAULT_PATHS,
+ custom_test = test_php_fcgi)
+ if not php_path:
+ self.error ("Couldn't find a suitable PHP interpreter.")
+ return
+
+ self.source = cfg_source_get_next (self._cfg)
+ self._cfg['%s!nick' % (self.source)] = 'PHP Interpreter'
+ self._cfg['%s!type' % (self.source)] = 'interpreter'
+ self._cfg['%s!interpreter' % (self.source)] = '%s -b %s' % (php_path, self.UNIX_SOCK)
+ self._cfg['%s!host' % (self.source)] = self.UNIX_SOCK
+
+ self._cfg['%s!env!PHP_FCGI_MAX_REQUESTS' % (self.source)] = "5000"
+ self._cfg['%s!env!PHP_FCGI_CHILDREN' % (self.source)] = "5"
+
+ # Add a new Extension PHP rule
+ if not self.rule:
+ self.rule = cfg_vsrv_rule_get_next (self._cfg, self._pre)
+ if not self.rule:
+ self.error ("Couldn't add a new rule.")
+
+ src_num = self.source.split('!')[-1]
+
+ self._cfg['%s!match' % (self.rule)] = 'extensions'
+ self._cfg['%s!match!extensions' % (self.rule)] = 'php'
+ self._cfg['%s!match!final' % (self.rule)] = '0'
+ self._cfg['%s!handler' % (self.rule)] = 'fcgi'
+ self._cfg['%s!handler!balancer' % (self.rule)] = 'round_robin'
+ self._cfg['%s!handler!balancer!source!1' % (self.rule)] = src_num
+ self._cfg['%s!handler!error_handler' % (self.rule)] = '1'
+ self._cfg['%s!encoder!gzip' % (self.rule)] = '1'
+
+
+#
+# Helpers
+#
+def wizard_php_get_info (cfg, pre):
+ wizard = Wizard_Rules_PHP (cfg, pre)
+
+ misses = wizard.show()
+ if misses:
+ return None
+
+ return {'source': wizard.source,
+ 'rule': wizard.rule,
+ 'nick': wizard.nick}
+
+def wizard_php_get_source_info (cfg):
+ wizard = Wizard_Rules_PHP (cfg, None)
+ wizard.show()
+
+ if not wizard.source:
+ return None
+
+ return {'source': wizard.source,
+ 'nick': wizard.nick}
+
Oops, something went wrong.

0 comments on commit 0e5444c

Please sign in to comment.