mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
Dont use exec() in system/wan module
Also make the form submission actually work by adding hidden form value and '/' at the end of form submission URL.
This commit is contained in:
parent
2079b3639a
commit
c0ea7ee298
@ -5,7 +5,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import json
|
import json
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
from filedict import FileDict
|
|
||||||
from modules.auth import require
|
from modules.auth import require
|
||||||
from plugin_mount import PagePlugin, FormPlugin
|
from plugin_mount import PagePlugin, FormPlugin
|
||||||
import cfg
|
import cfg
|
||||||
@ -45,32 +44,35 @@ class wan(FormPlugin, PagePlugin):
|
|||||||
def main(self, message='', **kwargs):
|
def main(self, message='', **kwargs):
|
||||||
store = filedict_con(cfg.store_file, 'sys')
|
store = filedict_con(cfg.store_file, 'sys')
|
||||||
|
|
||||||
defaults = {'wan_admin': "''",
|
defaults = {'wan_admin': '',
|
||||||
'wan_ssh': "''",
|
'wan_ssh': '',
|
||||||
'lan_ssh': "''",
|
'lan_ssh': '',
|
||||||
}
|
}
|
||||||
for k,c in defaults.items():
|
for key, value in defaults.items():
|
||||||
if not k in kwargs:
|
if not key in kwargs:
|
||||||
try:
|
try:
|
||||||
kwargs[k] = store[k]
|
kwargs[key] = store[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
exec("if not '%(k)s' in kwargs: store['%(k)s'] = kwargs['%(k)s'] = %(c)s" % {'k':k, 'c':c})
|
store[key] = kwargs[key] = value
|
||||||
|
|
||||||
form = Form(title=_("Accessing the %s" % cfg.box_name),
|
form = Form(title=_("Accessing the %s" % cfg.box_name),
|
||||||
action=cfg.server_dir + "/sys/config/wan",
|
action=cfg.server_dir + "/sys/config/wan/",
|
||||||
name="admin_wan_form",
|
name="admin_wan_form",
|
||||||
message=message )
|
message=message)
|
||||||
form.html(self.help())
|
form.html(self.help())
|
||||||
if cfg.users.expert():
|
if cfg.users.expert():
|
||||||
form.checkbox(_("Allow access to Plinth from WAN"), name="wan_admin", checked=kwargs['wan_admin'])
|
form.checkbox(_("Allow access to Plinth from WAN"), name="wan_admin", checked=kwargs['wan_admin'])
|
||||||
form.checkbox(_("Allow SSH access from LAN"), name="lan_ssh", checked=kwargs['lan_ssh'])
|
form.checkbox(_("Allow SSH access from LAN"), name="lan_ssh", checked=kwargs['lan_ssh'])
|
||||||
form.checkbox(_("Allow SSH access from WAN"), name="wan_ssh", checked=kwargs['wan_ssh'])
|
form.checkbox(_("Allow SSH access from WAN"), name="wan_ssh", checked=kwargs['wan_ssh'])
|
||||||
|
|
||||||
|
# Hidden field is needed because checkbox doesn't post if not checked
|
||||||
|
form.hidden(name="submitted", value="True")
|
||||||
|
|
||||||
form.submit(_("Submit"))
|
form.submit(_("Submit"))
|
||||||
return form.render()
|
return form.render()
|
||||||
|
|
||||||
def process_form(self, wan_admin='', wan_ssh='', lan_ssh='', *args, **kwargs):
|
def process_form(self, wan_admin='', wan_ssh='', lan_ssh='', *args, **kwargs):
|
||||||
store = filedict_con(cfg.store_file, 'sys')
|
store = filedict_con(cfg.store_file, 'sys')
|
||||||
for field in ['wan_admin', 'wan_ssh', 'lan_ssh']:
|
for field in ['wan_admin', 'wan_ssh', 'lan_ssh']:
|
||||||
exec("store['%s'] = %s" % (field, field))
|
store[field] = locals()[field]
|
||||||
return "Settings updated."
|
return "Settings updated."
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user