| 1 |
from Table import * |
|---|
| 2 |
from ModuleHandler import * |
|---|
| 3 |
from validations import * |
|---|
| 4 |
|
|---|
| 5 |
NOTE_SCRIPT_ALIAS = 'Path to an executable that will be run with the CGI as parameter.' |
|---|
| 6 |
NOTE_CHANGE_USER = 'Execute the CGI under its owner user ID.' |
|---|
| 7 |
NOTE_ERROR_HANDLER = 'Send errors exactly as they are generated.' |
|---|
| 8 |
NOTE_CHECK_FILE = 'Check whether the file is in place.' |
|---|
| 9 |
NOTE_PASS_REQ = 'Pass all the headers to the CGI as they were received by the web server.' |
|---|
| 10 |
NOTE_XSENDFILE = 'Allow the use of the non-standard X-Sendfile header.' |
|---|
| 11 |
|
|---|
| 12 |
HELPS = [ |
|---|
| 13 |
('modules_handlers_cgi', "CGIs") |
|---|
| 14 |
] |
|---|
| 15 |
|
|---|
| 16 |
class ModuleCgiBase (ModuleHandler): |
|---|
| 17 |
PROPERTIES = [ |
|---|
| 18 |
'script_alias', |
|---|
| 19 |
'change_user', |
|---|
| 20 |
'error_handler', |
|---|
| 21 |
'check_file', |
|---|
| 22 |
'pass_req_headers', |
|---|
| 23 |
'xsendfile', |
|---|
| 24 |
'env' |
|---|
| 25 |
] |
|---|
| 26 |
|
|---|
| 27 |
def __init__ (self, cfg, prefix, name, submit_url): |
|---|
| 28 |
ModuleHandler.__init__ (self, name, cfg, prefix, submit_url) |
|---|
| 29 |
|
|---|
| 30 |
self.fixed_check_file = None |
|---|
| 31 |
self.show_script_alias = True |
|---|
| 32 |
self.show_change_uid = True |
|---|
| 33 |
|
|---|
| 34 |
def _op_render (self): |
|---|
| 35 |
txt = "<h2>Common CGI options</h2>" |
|---|
| 36 |
|
|---|
| 37 |
table = TableProps() |
|---|
| 38 |
if self.show_script_alias: |
|---|
| 39 |
self.AddPropEntry (table, "Script Alias", "%s!script_alias" % (self._prefix), NOTE_SCRIPT_ALIAS) |
|---|
| 40 |
if self.show_change_uid: |
|---|
| 41 |
self.AddPropEntry (table, "Change to UID", "%s!change_user" % (self._prefix), NOTE_CHANGE_USER) |
|---|
| 42 |
|
|---|
| 43 |
self.AddPropCheck (table, "Error handler", "%s!error_handler"% (self._prefix), False, NOTE_ERROR_HANDLER) |
|---|
| 44 |
|
|---|
| 45 |
if self.fixed_check_file == None: |
|---|
| 46 |
self.AddPropCheck (table, "Check file", "%s!check_file" % (self._prefix), True, NOTE_CHECK_FILE) |
|---|
| 47 |
|
|---|
| 48 |
self.AddPropCheck (table, "Pass Request", "%s!pass_req_headers" % (self._prefix), False, NOTE_PASS_REQ) |
|---|
| 49 |
self.AddPropCheck (table, "Allow X-Sendfile", "%s!xsendfile" % (self._prefix), False, NOTE_XSENDFILE) |
|---|
| 50 |
txt += self.Indent(table) |
|---|
| 51 |
|
|---|
| 52 |
txt1 = '<h2>Custom environment variables</h2>' |
|---|
| 53 |
envs = self._cfg.keys('%s!env'%(self._prefix)) |
|---|
| 54 |
if envs: |
|---|
| 55 |
table = Table(3, title_left=1, style='width="90%"') |
|---|
| 56 |
|
|---|
| 57 |
for env in envs: |
|---|
| 58 |
pre = '%s!env!%s'%(self._prefix,env) |
|---|
| 59 |
val = self.InstanceEntry(pre, 'text', size=25) |
|---|
| 60 |
js = "post_del_key('/ajax/update', '%s');"%(pre) |
|---|
| 61 |
link_del = self.InstanceImage ("bin.png", "Delete", border="0", onClick=js) |
|---|
| 62 |
table += (env, val, link_del) |
|---|
| 63 |
|
|---|
| 64 |
txt1 += self.Indent(table) |
|---|
| 65 |
|
|---|
| 66 |
txt1 += '<h3>Add new custom environment variable</h3>'; |
|---|
| 67 |
name = self.InstanceEntry('new_custom_env_name', 'text', size=25, noautosubmit=True) |
|---|
| 68 |
value = self.InstanceEntry('new_custom_env_value', 'text', size=25, noautosubmit=True) |
|---|
| 69 |
|
|---|
| 70 |
table = Table(3, 1, style='width="90%"') |
|---|
| 71 |
table += ('Name', 'Value', '') |
|---|
| 72 |
table += (name, value, SUBMIT_ADD) |
|---|
| 73 |
txt1 += self.Indent(table) |
|---|
| 74 |
txt += txt1 |
|---|
| 75 |
|
|---|
| 76 |
return txt |
|---|
| 77 |
|
|---|
| 78 |
def _op_apply_changes (self, uri, post): |
|---|
| 79 |
new_name = post.pop('new_custom_env_name') |
|---|
| 80 |
new_value = post.pop('new_custom_env_value') |
|---|
| 81 |
|
|---|
| 82 |
if new_name and new_value: |
|---|
| 83 |
self._cfg['%s!env!%s'%(self._prefix, new_name)] = new_value |
|---|
| 84 |
|
|---|
| 85 |
checkboxes = ['error_handler', 'pass_req_headers', 'xsendfile'] |
|---|
| 86 |
|
|---|
| 87 |
if self.fixed_check_file == None: |
|---|
| 88 |
checkboxes += ['check_file'] |
|---|
| 89 |
else: |
|---|
| 90 |
self._cfg['%s!check_file'%(self._prefix)] = self.fixed_check_file |
|---|
| 91 |
|
|---|
| 92 |
self.ApplyChangesPrefix (self._prefix, checkboxes, post) |
|---|
| 93 |
|
|---|
| 94 |
def _util__set_fixed_check_file (self): |
|---|
| 95 |
# No need to show 'check file' when the handler is an extension |
|---|
| 96 |
p = '!'.join(self._prefix.split('!')[:-1]) |
|---|
| 97 |
match = self._cfg.get_val("%s!match"%(p)) |
|---|
| 98 |
if match.lower() in ['extensions']: |
|---|
| 99 |
self.fixed_check_file = "1" |
|---|
| 100 |
|
|---|
| 101 |
class ModuleCgi (ModuleCgiBase): |
|---|
| 102 |
def __init__ (self, cfg, prefix, submit_url): |
|---|
| 103 |
ModuleCgiBase.__init__ (self, cfg, prefix, 'cgi', submit_url) |
|---|
| 104 |
|
|---|
| 105 |
def _op_render (self): |
|---|
| 106 |
return ModuleCgiBase._op_render (self) |
|---|
| 107 |
|
|---|
| 108 |
def _op_apply_changes (self, uri, post): |
|---|
| 109 |
return ModuleCgiBase._op_apply_changes (self, uri, post) |
|---|