Skip to content

Commit

Permalink
git-svn-id: svn://cherokee-project.com/cherokee/trunk@1415 5dc97367-9…
Browse files Browse the repository at this point in the history
…7f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Apr 27, 2008
1 parent 6b65481 commit 54846fd
Show file tree
Hide file tree
Showing 135 changed files with 565 additions and 340 deletions.
28 changes: 28 additions & 0 deletions ChangeLog
@@ -1,3 +1,31 @@
2008-04-26 Alvaro Lopez Ortega <alvaro@alobbs.com>

* admin/ModuleDirlist.py (ModuleDirlist._op_render),
admin/ModuleRedir.py (ModuleRedir._op_render): Updated to use the
new TableProps class instead of the plain old Table.

* cherokee/virtual_server.c (configure_rule_match), qa/*.py,
cherokee.conf.sample.pre, cherokee/main_admin.c, cherokee/admin.c:
Configuration format has changed again. The new entries weren't
following the style of the rest of the configuration. The change
is really small; however it impacts almost all of the QA cases.
Now, rules are defined like: "rule!<num>!match = <TYPE>" instead
of "rule!<num>!match!type = <TYPE>".

* admin/ModuleHeader.py, admin/Makefile.am: Added support of
header rules. This is a new module.

* admin/static/css/cherokee.css: This couple of minor changes make
the interface look much better. It basically improves the
PropertyTable look.

* qa/PageEntry.py, qa/config.py, qa/ModuleDefault.py,
qa/ModuleRequest.py, qa/ModuleExtensions.py, qa/consts.py,
qa/PageVServer.py, qa/static/js/common.js, qa/RuleList.py,
qa/Form.py, qa/ModuleDirectory.py, qa/Makefile.am: Rule types are
no longer hardcoded. They are independed modules, as in the the
server.

2008-04-25 Alvaro Lopez Ortega <alvaro@alobbs.com>

* cherokee/main_admin.c (main): There was a unneeded Win32
Expand Down
6 changes: 3 additions & 3 deletions admin/Form.py
Expand Up @@ -181,10 +181,10 @@ def InstanceOptions (self, cfg_key, options, *args, **kwargs):
FormHelper.options_wrap_num += 1

ops = '<div id="%s" name="%s">%s</div>'%(auto_wrap_id, auto_wrap_id, ops)
return (ops, value)
return (ops, value, auto_wrap_id)

def AddTableOptions (self, table, title, cfg_key, options, *args, **kwargs):
entry, value = self.InstanceOptions (cfg_key, options, *args, **kwargs)
entry, value, wrap = self.InstanceOptions (cfg_key, options, *args, **kwargs)

label = self.Label(title, cfg_key)
table += (label, entry)
Expand Down Expand Up @@ -406,7 +406,7 @@ def AddPropCheck (self, table, title, cfg_key, default, comment=None):
self.AddProp (table, title, cfg_key, entry, comment)

def AddPropOptions (self, table, title, cfg_key, options, comment=None, **kwargs):
entry, v = self.InstanceOptions (cfg_key, options, **kwargs)
entry, v, w = self.InstanceOptions (cfg_key, options, **kwargs)
self.AddProp (table, title, cfg_key, entry, comment)
return v

Expand Down
4 changes: 4 additions & 0 deletions admin/Makefile.am
Expand Up @@ -60,6 +60,10 @@ ModuleHtpasswd.py \
ModuleMysql.py \
ModulePam.py \
ModuleRoundRobin.py \
ModuleDefault.py \
ModuleRequest.py \
ModuleDirectory.py \
ModuleExtensions.py \
config.py \
pyscgi.py \
validations.py \
Expand Down
10 changes: 7 additions & 3 deletions admin/ModuleCommon.py
Expand Up @@ -4,6 +4,8 @@
from ModuleFile import *
from ModuleDirlist import *

NOTE_PATHINFO = "Allow extra tailing paths"

class ModuleCommon (Module, FormHelper):
PROPERTIES = ModuleFile.PROPERTIES + ModuleDirlist.PROPERTIES + [
'allow_pathinfo'
Expand All @@ -20,9 +22,11 @@ def _op_render (self):
txt = ''

# Local properties
table = Table(2)
self.AddTableCheckbox (table, 'Allow PathInfo', '%s!allow_pathinfo'%(self._prefix), False)
txt += str(table)
table = TableProps()
self.AddPropCheck (table, 'Allow PathInfo', '%s!allow_pathinfo'%(self._prefix), False, NOTE_PATHINFO)

txt = '<h2>Parsing</h2>'
txt += self.Indent(table)

# Copy errors to the modules,
# they may need to print them
Expand Down
22 changes: 22 additions & 0 deletions admin/ModuleDefault.py
@@ -0,0 +1,22 @@
from Form import *
from Table import *
from Module import *

class ModuleDefault (Module, FormHelper):
validation = []

def __init__ (self, cfg, prefix, submit_url):
Module.__init__ (self, 'default', cfg, prefix, submit_url)
FormHelper.__init__ (self, 'default', cfg)

def _op_render (self):
return ""

def apply_cfg (self, values):
None

def get_name (self):
return self._id.capitalize()

def get_type_name (self):
return self._id.capitalize()
32 changes: 32 additions & 0 deletions admin/ModuleDirectory.py
@@ -0,0 +1,32 @@
from Form import *
from Table import *
from Module import *
import validations

NOTE_DIRECTORY = "Public Web Directory to which content the configuration will be applied."

class ModuleDirectory (Module, FormHelper):
validation = [('tmp!new_rule!value', validations.is_dir_formated)]

def __init__ (self, cfg, prefix, submit_url):
Module.__init__ (self, 'directory', cfg, prefix, submit_url)
FormHelper.__init__ (self, 'directory', cfg)

def _op_render (self):
table = TableProps()
if self._prefix.startswith('tmp!'):
self.AddPropEntry (table, 'Web Directory', '%s!value'%(self._prefix), NOTE_DIRECTORY)
else:
self.AddPropEntry (table, 'Web Directory', '%s!directory'%(self._prefix), NOTE_DIRECTORY)
return str(table)

def apply_cfg (self, values):
if values.has_key('value'):
dir_name = values['value']
self._cfg['%s!match!directory'%(self._prefix)] = dir_name

def get_name (self):
return self._cfg.get_val ('%s!match!directory'%(self._prefix))

def get_type_name (self):
return self._id.capitalize()
34 changes: 19 additions & 15 deletions admin/ModuleDirlist.py
Expand Up @@ -13,6 +13,10 @@

DEFAULT_THEME = "default"

NOTE_THEME = "Choose the listing theme."
NOTE_ICON_DIR = "Web directory where the icon files are located. Default: <i>/icons</i>."
NOTE_NOTICE_FILES = "List of notice files to be inserted."

class ModuleDirlist (Module, FormHelper):
PROPERTIES = [
'size', 'date',
Expand All @@ -26,22 +30,22 @@ def __init__ (self, cfg, prefix, submit_url):
FormHelper.__init__ (self, 'dirlist', cfg)

def _op_render (self):
txt = '<h3>Listing</h3>'
table = Table(2)
self.AddTableCheckbox (table, "Show Size", "%s!size" %(self._prefix), True)
self.AddTableCheckbox (table, "Show Date", "%s!date" %(self._prefix), True)
self.AddTableCheckbox (table, "Show User", "%s!user" %(self._prefix), False)
self.AddTableCheckbox (table, "Show Group", "%s!group"%(self._prefix), False)
self.AddTableCheckbox (table, "Allow symbolic links", "%s!symlinks"%(self._prefix), True)
txt += str(table)

txt += '<h3>Theming</h3>'
table = Table(2)
txt = '<h2>Listing</h2>'
table = TableProps()
self.AddPropCheck (table, "Show Size", "%s!size" %(self._prefix), True, '')
self.AddPropCheck (table, "Show Date", "%s!date" %(self._prefix), True, '')
self.AddPropCheck (table, "Show User", "%s!user" %(self._prefix), False, '')
self.AddPropCheck (table, "Show Group", "%s!group"%(self._prefix), False, '')
self.AddPropCheck (table, "Allow symbolic links", "%s!symlinks"%(self._prefix), True, '')
txt += self.Indent(table)

txt += '<h2>Theming</h2>'
table = TableProps()
themes = self._get_theme_list()
self.AddTableOptions (table, 'Theme', "%s!theme" % (self._prefix), themes)
self.AddTableEntry (table, 'Icons dir', "%s!icon_dir" % (self._prefix))
self.AddTableEntry (table, 'Notice files', "%s!notice_files" % (self._prefix))
txt += str(table)
self.AddPropOptions (table, 'Theme', "%s!theme" % (self._prefix), themes, NOTE_THEME)
self.AddPropEntry (table, 'Icons dir', "%s!icon_dir" % (self._prefix), NOTE_ICON_DIR)
self.AddPropEntry (table, 'Notice files', "%s!notice_files" % (self._prefix), NOTE_NOTICE_FILES)
txt += self.Indent(table)

return txt

Expand Down
37 changes: 37 additions & 0 deletions admin/ModuleExtensions.py
@@ -0,0 +1,37 @@
from Form import *
from Table import *
from Module import *
import validations

NOTE_EXTENSIONS = "File extension list to which content the configuration will be applied."

class ModuleExtensions (Module, FormHelper):
validation = [('tmp!new_rule!value', validations.is_safe_id_list)]

def __init__ (self, cfg, prefix, submit_url):
Module.__init__ (self, 'extensions', cfg, prefix, submit_url)
FormHelper.__init__ (self, 'extensions', cfg)

def _op_render (self):
table = TableProps()
if self._prefix.startswith('tmp!'):
self.AddPropEntry (table, 'Extensions', '%s!value'%(self._prefix), NOTE_EXTENSIONS)
else:
self.AddPropEntry (table, 'Extensions', '%s!extensions'%(self._prefix), NOTE_EXTENSIONS)
return str(table)

def _op_apply_changes (self, uri, post):
self.ApplyChangesPrefix (self._prefix, None, post)

def apply_cfg (self, values):
if not values.has_key('value'):
print "ERROR, a 'value' entry is needed!"

exts = values['value']
self._cfg['%s!match!extensions'%(self._prefix)] = exts

def get_name (self):
return self._cfg.get_val ('%s!match!extensions'%(self._prefix))

def get_type_name (self):
return self._id.capitalize()
7 changes: 6 additions & 1 deletion admin/ModuleFile.py
Expand Up @@ -14,9 +14,14 @@ def __init__ (self, cfg, prefix, submit_url):
FormHelper.__init__ (self, 'file', cfg)

def _op_render (self):
txt = ''

table = TableProps()
self.AddPropCheck (table, "Use I/O cache", "%s!iocache" % (self._prefix), True, NOTE_IO_CACHE)
return str(table)

txt += '<h2>File Sending</h2>'
txt += self.Indent(table)
return txt

def _op_apply_changes (self, uri, post):
self.ApplyChangesPrefix (self._prefix, ['iocache'], post)
Expand Down
56 changes: 56 additions & 0 deletions admin/ModuleHeader.py
@@ -0,0 +1,56 @@
from Form import *
from Table import *
from Module import *
import validations

NOTE_HEADER = "Header against which the regular expression will be evaluated."
NOTE_MATCH = "Regular expression."

LENGHT_LIMIT = 10

HEADERS = [
('Accept-Encoding', 'Accept-Encoding'),
('Accept-Charset', 'Accept-Charset'),
('Accept-Language', 'Accept-Language'),
('Referer', 'Referer'),
('User-Agent', 'User-Agent')
]

class ModuleHeader (Module, FormHelper):
validation = [('tmp!new_rule!value', validations.is_dir_formated)]

def __init__ (self, cfg, prefix, submit_url):
Module.__init__ (self, 'header', cfg, prefix, submit_url)
FormHelper.__init__ (self, 'header', cfg)

def _op_render (self):
table = TableProps()
if self._prefix.startswith('tmp!'):
self.AddPropOptions (table, 'Header', '%s!value'%(self._prefix), HEADERS, NOTE_HEADER)
else:
self.AddPropOptions (table, 'Header', '%s!header'%(self._prefix), HEADERS, NOTE_HEADER)
self.AddPropEntry (table, 'Regular Expression', '%s!match'%(self._prefix), NOTE_MATCH)
return str(table)

def apply_cfg (self, values):
if values.has_key('value'):
header = values['value']
self._cfg['%s!match!header'%(self._prefix)] = header

if values.has_key('match'):
match = values['match']
self._cfg['%s!match!match'%(self._prefix)] = match

def get_name (self):
header = self._cfg.get_val ('%s!match!header'%(self._prefix))
if not header:
return ''

tmp = self._cfg.get_val ('%s!match!match'%(self._prefix), '')
if len(tmp) > LENGHT_LIMIT:
return "%s (%s..)" % (header, tmp[:5])

return "%s (%s)" % (header, tmp)

def get_type_name (self):
return self._id.capitalize()
34 changes: 9 additions & 25 deletions admin/ModuleRedir.py
@@ -1,17 +1,11 @@
from Form import *
from Table import *
from Module import *

from consts import *


NOTE_ON_PCRE = """
<p>Regular expressions must be written using the <a href="http://www.pcre.org/">
PCRE</a> syntax. Here you can find information on the
<a target="_blank" href="http://perldoc.perl.org/perlre.html"> regular expression
format</a>.</p>
"""

NOTE_SHOW = "Defined whether the redirection will be seen by the client."
NOTE_REGEX = "Regular expression. Check out the <a target=\"_blank\" href=\"http://perldoc.perl.org/perlre.html\">Reference</a>."
NOTE_SUBSTITUTION = "Target address. It can use Regular Expression substitution sub-strings."

class ModuleRedir (Module, FormHelper):
PROPERTIES = [
Expand All @@ -35,7 +29,7 @@ def _op_render (self):
for rule in cfg:
cfg_key_rule = "%s!%s" % (cfg_key, rule)

show = self._get_show_option ('%s!show'%(cfg_key_rule))
show, _,_ = self.InstanceOptions ('%s!show'%(cfg_key_rule), REDIR_SHOW)
regex = self._cfg.get_val('%s!regex' %(cfg_key_rule))
substring = self._cfg.get_val('%s!substring'%(cfg_key_rule))
js = "post_del_key('/ajax/update', '%s');" % (cfg_key_rule)
Expand All @@ -46,16 +40,12 @@ def _op_render (self):
txt += self.Indent(table)

# Add new rule
en_reg = self.InstanceEntry('rewrite_new_regex', 'text', size=28)
en_sub = self.InstanceEntry('rewrite_new_substring', 'text', size=28)
en_show = self._get_show_option ('rewrite_new_show')
table = TableProps()
self.AddPropOptions (table, 'Show', "rewrite_new_show", REDIR_SHOW, NOTE_SHOW)
self.AddPropEntry (table, 'Regular Expression', 'rewrite_new_regex', NOTE_REGEX)
self.AddPropEntry (table, 'Substitution', 'rewrite_new_substring', NOTE_SUBSTITUTION)

table = Table(3,1)
table += ('Type', 'Regular Expression', 'Substitution')
table += (en_show, en_reg, en_sub)

txt += "<h3>Add new rule</h3>"
txt += self.Dialog(NOTE_ON_PCRE)
txt += "<h2>Add new rule</h2>"
txt += self.Indent(table)
return txt

Expand All @@ -68,12 +58,6 @@ def __find_name (self):
return str(i)
i += 1

def _get_show_option (self, cfg_key):
show_val = self._cfg.get_val(cfg_key)
if show_val:
return EntryOptions (cfg_key, REDIR_SHOW, selected=show_val)
return EntryOptions (cfg_key, REDIR_SHOW)

def _op_apply_changes (self, uri, post):
regex = post.pop('rewrite_new_regex')
substr = post.pop('rewrite_new_substring')
Expand Down

0 comments on commit 54846fd

Please sign in to comment.