--- a/Beremiz_service.py Tue Jul 10 12:54:05 2018 +0200
+++ b/Beremiz_service.py Wed Jul 11 14:32:19 2018 +0200
@@ -45,17 +45,17 @@
Usage of Beremiz PLC execution service :\n
%s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir
- -n - zeroconf service name (default:disabled)
- -i - IP address of interface to bind to (default:localhost)
- -p - port number default:3000
- -h - print this help text and quit
- -a - autostart PLC (0:disable 1:enable) (default:0)
- -x - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1)
- -t - enable/disable Twisted web interface (0:disable 1:enable) (default:1)
- -w - web server port or "off" to disable web server (default:8009)
- -c - WAMP client default config file (default:wampconf.json)
- -s - WAMP client secret, given as a file
- -e - python extension (absolute path .py)
+ -n zeroconf service name (default:disabled) + -i IP address of interface to bind to (default:localhost) + -p port number default:3000 + -h print this help text and quit + -a autostart PLC (0:disable 1:enable) (default:0) + -x enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1) + -t enable/disable Twisted web interface (0:disable 1:enable) (default:1) + -w web server port or "off" to disable web server (default:8009) + -c WAMP client config file (can be overriden by wampconf.json in project) + -s WAMP client secret, given as a file (can be overriden by wamp.secret in project) + -e python extension (absolute path .py) working_dir - directory where are stored PLC files
@@ -616,6 +616,7 @@
WC.RegisterWampClient(wampconf, wampsecret)
+ WC.RegisterWebSettings(NS) LogMessageAndException(_("WAMP client startup failed. "))
--- a/runtime/WampClient.py Tue Jul 10 12:54:05 2018 +0200
+++ b/runtime/WampClient.py Wed Jul 11 14:32:19 2018 +0200
@@ -36,8 +36,6 @@
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.python.components import registerAdapter
-import runtime.NevowServer as NS
from formless import annotate, webform
from nevow import tags, url, static
@@ -191,7 +189,7 @@
if os.path.exists(_WampConf):
WampClientConf = json.load(open(_WampConf))
- WampClientConf = defaultWampConfig
+ WampClientConf = defaultWampConfig.copy() for itemName in mandatoryConfigItems:
if WampClientConf.get(itemName, None) is None :
@@ -242,22 +240,28 @@
_WampConfDefault = os.path.join(WorkingDir, "wampconf.json")
_WampSecretDefault = os.path.join(WorkingDir, "wamp.secret")
- # default project's wampconf has precedance over commandline given
- if os.path.exists(_WampConfDefault) or wampconf is None:
- _WampConf = _WampConfDefault
+ # set config file path only if not already set + # default project's wampconf has precedance over commandline given + if os.path.exists(_WampConfDefault) or wampconf is None: + _WampConf = _WampConfDefault WampClientConf = GetConfiguration()
- if wampsecret is not None:
- WampClientConf["secret"] = LoadWampSecret(wampsecret)
- _WampSecret = wampsecret
+ # set secret file path only if not already set + if _WampSecret is None: + # default project's wamp secret also has precedance over commandline given + if os.path.exists(_WampSecretDefault): + _WampSecret = _WampSecretDefault + _WampSecret = wampsecret + if _WampSecret is not None: + WampClientConf["secret"] = LoadWampSecret(_WampSecret) - if os.path.exists(_WampSecretDefault):
- WampClientConf["secret"] = LoadWampSecret(_WampSecretDefault)
- print(_("WAMP authentication has no secret configured"))
+ print(_("WAMP authentication has no secret configured")) _WampSecret = _WampSecretDefault
if not WampClientConf["active"]:
@@ -335,12 +339,16 @@
def wampConfig(**kwargs):
secretfile_field = kwargs["secretfile"]
if secretfile_field is not None:
- secret = secretfile_field.file.read()
+ secretfile = getattr(secretfile_field, "file", None) + if secretfile is not None: + secret = secretfile_field.file.read() newConfig = lastKnownConfig.copy()
for argname in webExposedConfigItems:
- newConfig[argname] = kwargs[argname]
+ arg = kwargs.get(argname, None) + newConfig[argname] = arg SetConfiguration(newConfig)
@@ -359,7 +367,6 @@
def getDownloadUrl(ctx, argument):
if lastKnownConfig is not None :
- currentID = lastKnownConfig.get("ID", None)
return url.URL.fromContext(ctx).\
child(lastKnownConfig["ID"]+".secret")
@@ -385,19 +392,24 @@
default=wampConfigDefault))]
-NS.ConfigurableSettings.addExtension(
def deliverWampSecret(ctx, segments):
filename = segments[1].decode('utf-8')
- # TODO : SECURITY compare filename to ID and blah...
+ # FIXME: compare filename to ID+".secret" + # for now all url under /secret returns the secret + # TODO: make beutifull message in case of exception + # while loading secret (if empty or dont exist) secret = LoadWampSecret(_WampSecret)
return static.Data(secret, 'application/octet-stream'),()
-NS.customSettingsURLs[WAMP_SECRET_URL] = deliverWampSecret
+def RegisterWebSettings(NS): + NS.ConfigurableSettings.addExtension( + NS.customSettingsURLs[WAMP_SECRET_URL] = deliverWampSecret