runtime/WampClient.py
author Edouard Tisserant <edouard@beremiz.fr>
Fri, 28 Feb 2025 16:41:26 +0100 (2 months ago)
changeset 4121 ef48f96ccf06
parent 4118 f9f116d8a022
child 4122 e2a9eaf4889a
permissions -rw-r--r--
python runtime: fix behaviour of -c when given file do not exist yet
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
     3
1667
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
     4
# This file is part of Beremiz runtime.
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
     5
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
     6
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
     7
#
1667
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
     8
# See COPYING.Runtime file for copyrights details.
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
     9
#
1667
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    10
# This library is free software; you can redistribute it and/or
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    11
# modify it under the terms of the GNU Lesser General Public
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    12
# License as published by the Free Software Foundation; either
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    13
# version 2.1 of the License, or (at your option) any later version.
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    14
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    15
# This library is distributed in the hope that it will be useful,
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
    16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1667
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    18
# Lesser General Public License for more details.
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    19
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    20
# You should have received a copy of the GNU Lesser General Public
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    21
# License along with this library; if not, write to the Free Software
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    22
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
    23
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    24
1899
ff4410112b67 runtime/WAMP : was 'Added time print on session left.' from dporopat. Purpose is to log (dis/re)connection, to help debugging connection problem
Edouard Tisserant
parents: 1898
diff changeset
    25
import time
1893
971de876b1af WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents: 1892
diff changeset
    26
import json
2203
c8a32ad27c0a #2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents: 2202
diff changeset
    27
import os
2201
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
    28
import re
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
    29
import shutil
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    30
from autobahn.twisted import wamp
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    31
from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS
1893
971de876b1af WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents: 1892
diff changeset
    32
from autobahn.wamp import types, auth
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    33
from autobahn.wamp.serializer import MsgPackSerializer
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    34
from twisted.internet.protocol import ReconnectingClientFactory
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    35
from twisted.python.components import registerAdapter
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
    36
from twisted.internet.ssl import optionsForClientTLS, CertificateOptions
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
    37
from twisted.internet._sslverify import OpenSSLCertificateAuthorities
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
    38
from OpenSSL import crypto
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1826
diff changeset
    39
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    40
from formless import annotate, webform
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    41
import formless
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    42
from nevow import tags, url, static
2306
908471b344ba Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents: 2265
diff changeset
    43
from runtime import GetPLCObjectSingleton
4115
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
    44
from runtime.Stunnel import getPSKID
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    45
2212
cf1718962567 WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents: 2207
diff changeset
    46
mandatoryConfigItems = ["ID", "active", "realm", "url"]
cf1718962567 WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents: 2207
diff changeset
    47
2201
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
    48
_transportFactory = None
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    49
_WampSession = None
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    50
WorkingDir = None
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    51
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    52
# Find pre-existing project WAMP config file
2202
237c1a2de1c8 #2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents: 2201
diff changeset
    53
_WampConf = None
237c1a2de1c8 #2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents: 2201
diff changeset
    54
_WampSecret = None
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
    55
_WampTrust = None
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    56
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    57
ExposedCalls = [
2206
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    58
    ("StartPLC", {}),
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    59
    ("StopPLC", {}),
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    60
    ("GetPLCstatus", {}),
2471
9d5c291b510f Expose new PLCObject API members to WAMP interface.
Edouard Tisserant
parents: 2459
diff changeset
    61
    ("GetPLCID", {}),
2487
6a4f9a061994 Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents: 2474
diff changeset
    62
    ("SeedBlob", {}),
2471
9d5c291b510f Expose new PLCObject API members to WAMP interface.
Edouard Tisserant
parents: 2459
diff changeset
    63
    ("AppendChunkToBlob", {}),
9d5c291b510f Expose new PLCObject API members to WAMP interface.
Edouard Tisserant
parents: 2459
diff changeset
    64
    ("PurgeBlobs", {}),
2206
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    65
    ("NewPLC", {}),
2607
bf0c1a40cf37 Add Repair() to WAMP interface
Edouard Tisserant
parents: 2581
diff changeset
    66
    ("RepairPLC", {}),
2206
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    67
    ("MatchMD5", {}),
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    68
    ("SetTraceVariablesList", {}),
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    69
    ("GetTraceVariables", {}),
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    70
    ("RemoteExec", {}),
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    71
    ("GetLogMessage", {}),
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
    72
    ("ResetLogCount", {})
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    73
]
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    74
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    75
# de-activated dumb wamp config
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    76
defaultWampConfig = {
4116
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
    77
    "ID": "wamptest", # replaced by service name (-n in CLI)
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
    78
    "active": False,
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
    79
    "realm": "Automation",
3343
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
    80
    "url": "ws://127.0.0.1:8888",
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
    81
    "clientFactoryOptions": {
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
    82
        "maxDelay": 300
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
    83
    },
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
    84
    "protocolOptions": {
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
    85
        "autoPingInterval": 10,
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
    86
        "autoPingTimeout": 5
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
    87
    },
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
    88
    "verifyHostname": True
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    89
}
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
    90
1898
d2dbdeffc426 runtime/Wamp : adapt to unicode being enforced in latest crossbar API. Updated some documentation, to explain why there is unused definitions like SubscribedEvents or DoOnJoin.
Edouard Tisserant
parents: 1894
diff changeset
    91
# Those two lists are meant to be filled by customized runtime
1901
e8cf68d69447 Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents: 1900
diff changeset
    92
# or User python code.
1898
d2dbdeffc426 runtime/Wamp : adapt to unicode being enforced in latest crossbar API. Updated some documentation, to explain why there is unused definitions like SubscribedEvents or DoOnJoin.
Edouard Tisserant
parents: 1894
diff changeset
    93
1901
e8cf68d69447 Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents: 1900
diff changeset
    94
""" crossbar Events to register to """
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    95
SubscribedEvents = []
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    96
1901
e8cf68d69447 Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents: 1900
diff changeset
    97
""" things to do on join (callables) """
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    98
DoOnJoin = []
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    99
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   100
lastKnownConfig = None
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   101
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   102
1445
e25479e3fe11 More versatile registering of wamp callees
Edouard Tisserant
parents: 1443
diff changeset
   103
def GetCallee(name):
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   104
    """ Get Callee or Subscriber corresponding to '.' spearated object path """
1445
e25479e3fe11 More versatile registering of wamp callees
Edouard Tisserant
parents: 1443
diff changeset
   105
    names = name.split('.')
2306
908471b344ba Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents: 2265
diff changeset
   106
    obj = GetPLCObjectSingleton()
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   107
    while names:
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   108
        obj = getattr(obj, names.pop(0))
1445
e25479e3fe11 More versatile registering of wamp callees
Edouard Tisserant
parents: 1443
diff changeset
   109
    return obj
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
   110
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   111
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   112
class WampSession(wamp.ApplicationSession):
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   113
1893
971de876b1af WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents: 1892
diff changeset
   114
    def onConnect(self):
4116
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   115
        user = self.config.extra["ID"]
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   116
        self.join(self.config.realm, ["wampcra"], user)
1893
971de876b1af WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents: 1892
diff changeset
   117
971de876b1af WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents: 1892
diff changeset
   118
    def onChallenge(self, challenge):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3440
diff changeset
   119
        if challenge.method == "wampcra":
4116
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   120
            secret = self.config.extra["secret"]
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   121
            if 'salt' in challenge.extra:
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   122
                # salted secret
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   123
                key = auth.derive_key(secret,
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   124
                                      challenge.extra['salt'],
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   125
                                      challenge.extra['iterations'],
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   126
                                      challenge.extra['keylen'])
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   127
            else:
4116
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   128
                # plain, unsalted secret
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   129
                key = secret
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   130
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   131
            signature = auth.compute_wcs(key, challenge.extra['challenge'])
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   132
            return signature
1893
971de876b1af WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents: 1892
diff changeset
   133
        else:
4116
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   134
            raise Exception("Invalid authmethod {}".format(challenge.method))
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
   135
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   136
    def onJoin(self, details):
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   137
        global _WampSession
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   138
        _WampSession = self
1901
e8cf68d69447 Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents: 1900
diff changeset
   139
        ID = self.config.extra["ID"]
2206
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
   140
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
   141
        for name, kwargs in ExposedCalls:
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
   142
            try:
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
   143
                registerOptions = types.RegisterOptions(**kwargs)
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
   144
            except TypeError as e:
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
   145
                registerOptions = None
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
   146
                print(_("TypeError register option: {}".format(e)))
1e397afc36a9 #2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents: 2205
diff changeset
   147
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3440
diff changeset
   148
            self.register(GetCallee(name), '.'.join((ID, name)), registerOptions)
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   149
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   150
        for name in SubscribedEvents:
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
   151
            self.subscribe(GetCallee(name), str(name))
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   152
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   153
        for func in DoOnJoin:
2306
908471b344ba Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents: 2265
diff changeset
   154
            func(self)
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   155
2194
35d6b9321ffd #2486 Updated wamp test project to work with the latest Crossbar version.
dporopat <denis.poropat@smarteh.si>
parents: 2193
diff changeset
   156
        print(_('WAMP session joined (%s) by:' % time.ctime()), ID)
35d6b9321ffd #2486 Updated wamp test project to work with the latest Crossbar version.
dporopat <denis.poropat@smarteh.si>
parents: 2193
diff changeset
   157
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   158
    def onLeave(self, details):
2201
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
   159
        global _WampSession, _transportFactory
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
   160
        super(WampSession, self).onLeave(details)
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   161
        _WampSession = None
2201
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
   162
        _transportFactory = None
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   163
2310
f9f9f5856032 Fixed typo in Wampclient.py
Edouard Tisserant
parents: 2308
diff changeset
   164
    def publishWithOwnID(self, eventID, value):
2306
908471b344ba Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents: 2265
diff changeset
   165
        ID = self.config.extra["ID"]
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
   166
        self.publish(str(ID+'.'+eventID), value)
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   167
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   168
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   169
class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory):
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   170
2195
2cef75d036c2 #2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents: 2194
diff changeset
   171
    def __init__(self, config, *args, **kwargs):
2201
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
   172
        global _transportFactory
2195
2cef75d036c2 #2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents: 2194
diff changeset
   173
        WampWebSocketClientFactory.__init__(self, *args, **kwargs)
2cef75d036c2 #2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents: 2194
diff changeset
   174
2207
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   175
        try:
3342
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   176
            clientFactoryOptions = config.extra.get("clientFactoryOptions")
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   177
            if clientFactoryOptions:
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   178
                self.setClientFactoryOptions(clientFactoryOptions)
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   179
        except Exception as e:
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   180
            print(_("Custom client factory options failed : "), e)
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   181
            _transportFactory = None
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   182
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   183
        try:
2207
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   184
            protocolOptions = config.extra.get('protocolOptions', None)
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   185
            if protocolOptions:
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   186
                self.setProtocolOptions(**protocolOptions)
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   187
            _transportFactory = self
2418
5587c490a070 Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2287
diff changeset
   188
        except Exception as e:
2207
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   189
            print(_("Custom protocol options failed :"), e)
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   190
            _transportFactory = None
2195
2cef75d036c2 #2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents: 2194
diff changeset
   191
3342
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   192
    def setClientFactoryOptions(self, options):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3440
diff changeset
   193
        for key, value in list(options.items()):
3343
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   194
            if key in ["maxDelay", "initialDelay", "maxRetries", "factor", "jitter"]:
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   195
                setattr(self, key, value)
3342
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   196
2193
259df9ecf9ca #2486 Reset delay function added. It resets the delay and the retry counter on reconnect.
dporopat <denis.poropat@smarteh.si>
parents: 1955
diff changeset
   197
    def buildProtocol(self, addr):
259df9ecf9ca #2486 Reset delay function added. It resets the delay and the retry counter on reconnect.
dporopat <denis.poropat@smarteh.si>
parents: 1955
diff changeset
   198
        self.resetDelay()
259df9ecf9ca #2486 Reset delay function added. It resets the delay and the retry counter on reconnect.
dporopat <denis.poropat@smarteh.si>
parents: 1955
diff changeset
   199
        return ReconnectingClientFactory.buildProtocol(self, addr)
259df9ecf9ca #2486 Reset delay function added. It resets the delay and the retry counter on reconnect.
dporopat <denis.poropat@smarteh.si>
parents: 1955
diff changeset
   200
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   201
    def clientConnectionFailed(self, connector, reason):
2473
1d64d283d0bd Removed nonsense code, that I should have check more in details before merging m(
Edouard Tisserant
parents: 2471
diff changeset
   202
        print(_("WAMP Client connection failed (%s) .. retrying ..") %
1d64d283d0bd Removed nonsense code, that I should have check more in details before merging m(
Edouard Tisserant
parents: 2471
diff changeset
   203
              time.ctime())
1d64d283d0bd Removed nonsense code, that I should have check more in details before merging m(
Edouard Tisserant
parents: 2471
diff changeset
   204
        super(ReconnectingWampWebSocketClientFactory,
1d64d283d0bd Removed nonsense code, that I should have check more in details before merging m(
Edouard Tisserant
parents: 2471
diff changeset
   205
              self).clientConnectionFailed(connector, reason)
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1748
diff changeset
   206
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   207
    def clientConnectionLost(self, connector, reason):
2473
1d64d283d0bd Removed nonsense code, that I should have check more in details before merging m(
Edouard Tisserant
parents: 2471
diff changeset
   208
        print(_("WAMP Client connection lost (%s) .. retrying ..") %
1d64d283d0bd Removed nonsense code, that I should have check more in details before merging m(
Edouard Tisserant
parents: 2471
diff changeset
   209
              time.ctime())
1d64d283d0bd Removed nonsense code, that I should have check more in details before merging m(
Edouard Tisserant
parents: 2471
diff changeset
   210
        super(ReconnectingWampWebSocketClientFactory,
1d64d283d0bd Removed nonsense code, that I should have check more in details before merging m(
Edouard Tisserant
parents: 2471
diff changeset
   211
              self).clientConnectionFailed(connector, reason)
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   212
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   213
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   214
def CheckConfiguration(WampClientConf):
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   215
    url = WampClientConf["url"]
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   216
    if not IsCorrectUri(url):
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   217
        raise annotate.ValidateError(
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   218
            {"url": "Invalid URL: {}".format(url)},
2223
909216419e45 Fixed small typo in error message.
Edouard Tisserant
parents: 2221
diff changeset
   219
            _("WAMP configuration error:"))
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   220
3342
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   221
def UpdateWithDefault(d1, d2):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3440
diff changeset
   222
    for k, v in list(d2.items()):
3342
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   223
        d1.setdefault(k, v)
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   224
2212
cf1718962567 WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents: 2207
diff changeset
   225
def GetConfiguration():
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   226
    global lastKnownConfig
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   227
3285
d6612579f1d4 Runtime: more robust loading of Wamp config, specially in case config file was corrupted.
Edouard Tisserant
parents: 2607
diff changeset
   228
    WampClientConf = None
d6612579f1d4 Runtime: more robust loading of Wamp config, specially in case config file was corrupted.
Edouard Tisserant
parents: 2607
diff changeset
   229
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   230
    if os.path.exists(_WampConf):
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   231
        try:
3285
d6612579f1d4 Runtime: more robust loading of Wamp config, specially in case config file was corrupted.
Edouard Tisserant
parents: 2607
diff changeset
   232
            WampClientConf = json.load(open(_WampConf))
3343
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   233
            UpdateWithDefault(WampClientConf, defaultWampConfig)
3285
d6612579f1d4 Runtime: more robust loading of Wamp config, specially in case config file was corrupted.
Edouard Tisserant
parents: 2607
diff changeset
   234
        except ValueError:
d6612579f1d4 Runtime: more robust loading of Wamp config, specially in case config file was corrupted.
Edouard Tisserant
parents: 2607
diff changeset
   235
            pass
d6612579f1d4 Runtime: more robust loading of Wamp config, specially in case config file was corrupted.
Edouard Tisserant
parents: 2607
diff changeset
   236
d6612579f1d4 Runtime: more robust loading of Wamp config, specially in case config file was corrupted.
Edouard Tisserant
parents: 2607
diff changeset
   237
    if WampClientConf is None:
2221
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   238
        WampClientConf = defaultWampConfig.copy()
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   239
2212
cf1718962567 WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents: 2207
diff changeset
   240
    for itemName in mandatoryConfigItems:
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   241
        if WampClientConf.get(itemName, None) is None:
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   242
            raise Exception(
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   243
                _("WAMP configuration error : missing '{}' parameter.").format(itemName))
2212
cf1718962567 WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents: 2207
diff changeset
   244
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   245
    CheckConfiguration(WampClientConf)
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   246
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   247
    lastKnownConfig = WampClientConf.copy()
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   248
    return WampClientConf
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   249
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   250
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   251
def SetConfiguration(WampClientConf):
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   252
    global lastKnownConfig
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   253
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   254
    CheckConfiguration(WampClientConf)
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   255
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   256
    lastKnownConfig = WampClientConf.copy()
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   257
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   258
    with open(os.path.realpath(_WampConf), 'w') as f:
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   259
        json.dump(WampClientConf, f, sort_keys=True, indent=4)
2474
347b03f7e0e8 Fixed runtime's reconnecting loop not stopping when re-configuring WAMP.
Edouard Tisserant
parents: 2473
diff changeset
   260
    StopReconnectWampClient()
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   261
    if 'active' in WampClientConf and WampClientConf['active']:
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   262
        StartReconnectWampClient()
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   263
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   264
    return WampClientConf
1901
e8cf68d69447 Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents: 1900
diff changeset
   265
2212
cf1718962567 WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents: 2207
diff changeset
   266
1893
971de876b1af WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents: 1892
diff changeset
   267
def LoadWampSecret(secretfname):
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   268
    WSClientWampSecret = open(secretfname, 'rb').read()
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   269
    if len(WSClientWampSecret) == 0:
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   270
        raise Exception(_("WAMP secret empty"))
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   271
    return WSClientWampSecret
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   272
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   273
2201
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
   274
def IsCorrectUri(uri):
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   275
    return re.match(r'wss?://[^\s?:#-]+(:[0-9]+)?(/[^\s]*)?$', uri) is not None
2201
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
   276
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
   277
4117
49e297aaf694 python runtime: use given service name (-n CLI option) as CRA ID by default.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4116
diff changeset
   278
def RegisterWampClient(wampconf=None, wampsecret=None, ConfDir=None, KeyStore=None, servicename=None):
49e297aaf694 python runtime: use given service name (-n CLI option) as CRA ID by default.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4116
diff changeset
   279
    global _WampConf, _WampSecret, _WampTrust, defaultWampConfig
49e297aaf694 python runtime: use given service name (-n CLI option) as CRA ID by default.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4116
diff changeset
   280
49e297aaf694 python runtime: use given service name (-n CLI option) as CRA ID by default.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4116
diff changeset
   281
    if servicename:
49e297aaf694 python runtime: use given service name (-n CLI option) as CRA ID by default.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4116
diff changeset
   282
        defaultWampConfig["ID"] = servicename
49e297aaf694 python runtime: use given service name (-n CLI option) as CRA ID by default.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4116
diff changeset
   283
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   284
    ConfDir = ConfDir if ConfDir else WorkingDir
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   285
    KeyStore = KeyStore if KeyStore else WorkingDir
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   286
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   287
    _WampConfDefault = os.path.join(ConfDir, "wampconf.json")
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   288
    _WampSecretDefault = os.path.join(KeyStore, "wamp.secret")
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   289
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   290
    if _WampTrust is None:
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   291
        _WampTrust = os.path.join(KeyStore, "wampTrustStore.crt")
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   292
2221
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   293
    # set config file path only if not already set
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   294
    if _WampConf is None:
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   295
        # default project's wampconf has precedance over commandline given
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   296
        if os.path.exists(_WampConfDefault) or wampconf is None:
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   297
            _WampConf = _WampConfDefault
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   298
        else:
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   299
            _WampConf = wampconf
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   300
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   301
    WampClientConf = GetConfiguration()
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   302
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   303
    # set secret file path only if not already set
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   304
    if _WampSecret is None:
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   305
        # default project's wamp secret also
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   306
        # has precedance over commandline given
2221
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   307
        if os.path.exists(_WampSecretDefault):
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   308
            _WampSecret = _WampSecretDefault
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   309
        else:
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   310
            _WampSecret = wampsecret
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   311
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   312
    if _WampSecret is not None:
4115
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   313
        if _WampSecret == _WampSecretDefault:
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   314
            # secret from project dir is raw (no ID prefix)
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   315
            secret = LoadWampSecret(_WampSecret)
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   316
        else:
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   317
            # secret from command line is formated ID:PSK
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   318
            # fall back to PSK data (works because wampsecret is PSKpath)
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   319
            _ID, secret = getPSKID()
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   320
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   321
        WampClientConf["secret"] = secret
a734a4d3ef23 python runtime: Wamp client now parses PSK file to extract secret from it instead of using the whole file as a secret.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4113
diff changeset
   322
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   323
    else:
4116
78e331383533 python runtime: Wamp CRA authentication is now mandatory, no connection if secret is missing.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4115
diff changeset
   324
        raise Exception(_("WAMP no secret file given"))
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   325
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   326
    if not WampClientConf["active"]:
2212
cf1718962567 WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents: 2207
diff changeset
   327
        print(_("WAMP deactivated in configuration"))
cf1718962567 WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents: 2207
diff changeset
   328
        return
cf1718962567 WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents: 2207
diff changeset
   329
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
   330
    # create a WAMP application session factory
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   331
    component_config = types.ComponentConfig(
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   332
        realm=WampClientConf["realm"],
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   333
        extra=WampClientConf)
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   334
    session_factory = wamp.ApplicationSessionFactory(
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   335
        config=component_config)
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   336
    session_factory.session = WampSession
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   337
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
   338
    # create a WAMP-over-WebSocket transport client factory
2207
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   339
    ReconnectingWampWebSocketClientFactory(
2195
2cef75d036c2 #2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents: 2194
diff changeset
   340
        component_config,
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   341
        session_factory,
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   342
        url=WampClientConf["url"],
1893
971de876b1af WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents: 1892
diff changeset
   343
        serializers=[MsgPackSerializer()])
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   344
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
   345
    # start the client from a Twisted endpoint
2207
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   346
    if _transportFactory:
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   347
        contextFactory=None
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   348
        if _transportFactory.isSecure:
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   349
            contextFactory = MakeSecureContextFactory(WampClientConf["verifyHostname"])
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   350
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   351
        connectWS(_transportFactory, contextFactory)
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   352
        print(_("WAMP client connecting to :"), WampClientConf["url"])
2207
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   353
        return True
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   354
    else:
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   355
        print(_("WAMP client can not connect to :"), WampClientConf["url"])
2207
c27b820cb96b #2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents: 2206
diff changeset
   356
        return False
2204
25dafeb98b55 #2486 Reconnect funtion in SaveWampClientConf function.
dporopat <denis.poropat@smarteh.si>
parents: 2203
diff changeset
   357
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   358
def MakeSecureContextFactory(verifyHostname):
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   359
    if not verifyHostname:
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   360
        return None
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   361
    trustRoot=None
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   362
    if os.path.exists(_WampTrust):
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   363
        cert = crypto.load_certificate(
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   364
            crypto.FILETYPE_PEM,
4118
f9f116d8a022 fix random python 3 porting consequences.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4117
diff changeset
   365
            open(_WampTrust, 'rb').read()
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   366
        )
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   367
        trustRoot=OpenSSLCertificateAuthorities([cert])
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   368
    return optionsForClientTLS(_transportFactory.host, trustRoot=trustRoot)
2201
4e511f5aad19 #2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents: 2199
diff changeset
   369
2203
c8a32ad27c0a #2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents: 2202
diff changeset
   370
def StopReconnectWampClient():
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   371
    if _transportFactory is not None:
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   372
        _transportFactory.stopTrying()
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   373
    if _WampSession is not None:
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   374
        _WampSession.leave()
2203
c8a32ad27c0a #2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents: 2202
diff changeset
   375
2204
25dafeb98b55 #2486 Reconnect funtion in SaveWampClientConf function.
dporopat <denis.poropat@smarteh.si>
parents: 2203
diff changeset
   376
2203
c8a32ad27c0a #2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents: 2202
diff changeset
   377
def StartReconnectWampClient():
c8a32ad27c0a #2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents: 2202
diff changeset
   378
    if _WampSession:
3342
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   379
        # do reconnect and reset continueTrying and initialDelay parameter
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   380
        if _transportFactory is not None:
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   381
            _transportFactory.resetDelay()
2202
237c1a2de1c8 #2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents: 2201
diff changeset
   382
        _WampSession.disconnect()
237c1a2de1c8 #2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents: 2201
diff changeset
   383
        return True
2204
25dafeb98b55 #2486 Reconnect funtion in SaveWampClientConf function.
dporopat <denis.poropat@smarteh.si>
parents: 2203
diff changeset
   384
    else:
2203
c8a32ad27c0a #2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents: 2202
diff changeset
   385
        # do connect
2202
237c1a2de1c8 #2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents: 2201
diff changeset
   386
        RegisterWampClient()
237c1a2de1c8 #2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents: 2201
diff changeset
   387
        return True
2203
c8a32ad27c0a #2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents: 2202
diff changeset
   388
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   389
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   390
def GetSession():
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   391
    return _WampSession
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   392
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   393
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   394
def getWampStatus():
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   395
    if _transportFactory is not None:
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   396
        if _WampSession is not None:
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   397
            if _WampSession.is_attached():
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   398
                return "Attached"
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   399
            return "Established"
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   400
        return "Connecting"
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   401
    return "Disconnected"
2202
237c1a2de1c8 #2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents: 2201
diff changeset
   402
2204
25dafeb98b55 #2486 Reconnect funtion in SaveWampClientConf function.
dporopat <denis.poropat@smarteh.si>
parents: 2203
diff changeset
   403
2306
908471b344ba Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents: 2265
diff changeset
   404
def PublishEvent(eventID, value):
908471b344ba Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents: 2265
diff changeset
   405
    if getWampStatus() == "Attached":
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
   406
        _WampSession.publish(str(eventID), value)
2309
d8fb90a2e11f Please pylint and pep8
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2308
diff changeset
   407
2306
908471b344ba Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents: 2265
diff changeset
   408
908471b344ba Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents: 2265
diff changeset
   409
def PublishEventWithOwnID(eventID, value):
908471b344ba Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents: 2265
diff changeset
   410
    if getWampStatus() == "Attached":
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
   411
        _WampSession.publishWithOwnID(str(eventID), value)
2309
d8fb90a2e11f Please pylint and pep8
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2308
diff changeset
   412
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   413
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   414
# WEB CONFIGURATION INTERFACE
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   415
WAMP_SECRET_URL = "secret"
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   416
WAMP_DELETE_TRUSTSTORE_URL = "delete_truststore"
3343
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   417
webExposedConfigItems = [
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   418
    'active', 'url', 'ID',
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   419
    "clientFactoryOptions.maxDelay",
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   420
    "protocolOptions.autoPingInterval",
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   421
    "protocolOptions.autoPingTimeout",
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   422
    "verifyHostname"
3343
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   423
]
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   424
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   425
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   426
def wampConfigDefault(ctx, argument):
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   427
    if lastKnownConfig is not None:
3342
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   428
        # Check if name is composed with an intermediate dot symbol and go deep in lastKnownConfig if it is
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   429
        argument_name_path = argument.name.split(".")
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   430
        searchValue = lastKnownConfig
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   431
        while argument_name_path:
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   432
            if searchValue:
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   433
                searchValue = searchValue.get(argument_name_path.pop(0), None)
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   434
            else:
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   435
                break
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   436
        return searchValue
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   437
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   438
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   439
def wampConfig(**kwargs):
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   440
    secretfile_field = kwargs["secretfile"]
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   441
    if secretfile_field is not None:
2221
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   442
        secretfile = getattr(secretfile_field, "file", None)
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   443
        if secretfile is not None:
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   444
            with open(os.path.realpath(_WampSecret), 'w') as destfd:
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   445
                secretfile.seek(0)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   446
                shutil.copyfileobj(secretfile,destfd)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   447
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   448
    trustStore_field = kwargs["trustStore"]
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   449
    if trustStore_field is not None:
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   450
        trustStore_file = getattr(trustStore_field, "file", None)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   451
        if trustStore_file is not None:
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   452
            with open(os.path.realpath(_WampTrust), 'w') as destfd:
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   453
                trustStore_file.seek(0)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   454
                shutil.copyfileobj(trustStore_file,destfd)
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   455
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   456
    newConfig = lastKnownConfig.copy()
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   457
    for argname in webExposedConfigItems:
3342
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   458
        # Check if name is composed with an intermediate dot symbol and go deep in lastKnownConfig if it is
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   459
        #  and then set a new value.
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   460
        argname_path = argname.split(".")
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   461
        arg_last = argname_path.pop()
2221
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   462
        arg = kwargs.get(argname, None)
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   463
        if arg is not None:
3342
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   464
            tmpConf = newConfig
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   465
            while argname_path:
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   466
                tmpConf = tmpConf.setdefault(argname_path.pop(0), {})
d8e99ecde9a2 Fixed Wamp reconnect on lost connection.
dgaberscek
parents: 3285
diff changeset
   467
            tmpConf[arg_last] = arg
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   468
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   469
    SetConfiguration(newConfig)
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   470
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   471
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   472
class FileUploadDownload(annotate.FileUpload):
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   473
    pass
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   474
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   475
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   476
class FileUploadDownloadRenderer(webform.FileUploadRenderer):
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   477
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   478
    def input(self, context, slot, data, name, value):
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   479
        # pylint: disable=expression-not-assigned
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   480
        slot[_("Upload:")]
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   481
        slot = webform.FileUploadRenderer.input(
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   482
            self, context, slot, data, name, value)
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   483
        download_url = data.typedValue.getAttribute('download_url')
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   484
        return slot[tags.a(href=download_url)[_("Download")]]
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   485
2260
74205edac761 Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents: 2248
diff changeset
   486
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   487
registerAdapter(FileUploadDownloadRenderer, FileUploadDownload,
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   488
                formless.iformless.ITypedRenderer)
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   489
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   490
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   491
def getDownloadUrl(ctx, argument):
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   492
    if lastKnownConfig is not None:
3883
a6e7dd8bac36 Fix blind replace ('text' into 'str') from py3 port
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3881
diff changeset
   493
        return url.URL.fromContext(ctx).\
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   494
            child(WAMP_SECRET_URL).\
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   495
            child(lastKnownConfig["ID"] + ".secret")
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   496
2260
74205edac761 Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents: 2248
diff changeset
   497
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   498
class FileUploadDelete(annotate.FileUpload):
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   499
    pass
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   500
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   501
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   502
class FileUploadDeleteRenderer(webform.FileUploadRenderer):
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   503
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   504
    def input(self, context, slot, data, name, value):
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   505
        # pylint: disable=expression-not-assigned
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   506
        slot[_("Upload:")]
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   507
        slot = webform.FileUploadRenderer.input(
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   508
            self, context, slot, data, name, value)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   509
        file_exists = data.typedValue.getAttribute('file_exists')
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   510
        if file_exists and file_exists():
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   511
            unique = str(id(self))
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   512
            file_delete = data.typedValue.getAttribute('file_delete')
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   513
            slot = slot[
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   514
                tags.a(href=file_delete, target=unique)[_("Delete")],
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   515
                tags.iframe(srcdoc="File exists", name=unique,
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   516
                            height="20", width="150",
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   517
                            marginheight="5", marginwidth="5",
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   518
                            scrolling="no", frameborder="0")
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   519
            ]
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   520
        return slot
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   521
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   522
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   523
registerAdapter(FileUploadDeleteRenderer, FileUploadDelete,
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   524
                formless.iformless.ITypedRenderer)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   525
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   526
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   527
def getTrustStorePresence():
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   528
    return os.path.exists(_WampTrust)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   529
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   530
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   531
def getTrustStoreDeleteUrl(ctx, argument):
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   532
    return url.URL.fromContext(ctx).child(WAMP_DELETE_TRUSTSTORE_URL)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   533
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   534
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   535
webFormInterface = [
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   536
    ("status",
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   537
     annotate.String(label=_("Current status"),
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   538
                     immutable=True,
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   539
                     default=lambda *k:getWampStatus())),
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   540
    ("ID",
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   541
     annotate.String(label=_("ID"),
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   542
                     default=wampConfigDefault)),
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   543
    ("secretfile",
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   544
     FileUploadDownload(label=_("File containing secret for that ID"),
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   545
                        download_url=getDownloadUrl)),
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   546
    ("active",
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   547
     annotate.Boolean(label=_("Enable WAMP connection"),
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   548
                      default=wampConfigDefault)),
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   549
    ("url",
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   550
     annotate.String(label=_("WAMP Server URL"),
3343
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   551
                     default=wampConfigDefault)),
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   552
    ("clientFactoryOptions.maxDelay",
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   553
     annotate.Integer(label=_("Max reconnection delay (s)"),
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   554
                      default=wampConfigDefault)),
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   555
    ("protocolOptions.autoPingInterval",
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   556
     annotate.Integer(label=_("Auto ping interval (s)"),
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   557
                      default=wampConfigDefault)),
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   558
    ("protocolOptions.autoPingTimeout",
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   559
     annotate.Integer(label=_("Auto ping timeout (s)"),
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   560
                      default=wampConfigDefault)),
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   561
    ("trustStore",
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   562
     FileUploadDelete(label=_("File containing server certificate"),
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   563
                      file_exists=getTrustStorePresence,
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   564
                      file_delete=getTrustStoreDeleteUrl)),
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   565
    ("verifyHostname",
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   566
     annotate.Boolean(label=_("Verify hostname matches certificate hostname"),
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   567
                      default=wampConfigDefault)),
3343
c6de1a6cb655 Merge changes about wamp reconnecting options, and added missing parts so that these changes make sense.
Edouard Tisserant
parents: 3342
diff changeset
   568
    ]
2218
7a4deed94eb2 Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents: 2215
diff changeset
   569
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   570
def deliverWampSecret(ctx, segments):
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   571
    # filename = segments[1].decode('utf-8')
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   572
2221
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   573
    # FIXME: compare filename to ID+".secret"
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   574
    # for now all url under /secret returns the secret
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   575
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   576
    # TODO: make beautifull message in case of exception
2221
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   577
    # while loading secret (if empty or dont exist)
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   578
    secret = LoadWampSecret(_WampSecret)
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   579
    return static.Data(secret, 'application/octet-stream'), ()
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   580
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   581
def deleteTrustStore(ctx, segments):
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   582
    if os.path.exists(_WampTrust):
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   583
        os.remove(_WampTrust)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   584
    return static.Data("TrustStore deleted", 'text/html'), ()
2220
985f234b0d09 Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents: 2218
diff changeset
   585
2221
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   586
def RegisterWebSettings(NS):
2262
4195545e2d17 NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents: 2260
diff changeset
   587
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3440
diff changeset
   588
    WebSettings = NS.newExtensionSetting("Wamp Extension Settings", "wamp_settings")
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3440
diff changeset
   589
    WebSettings.addSettings(
2248
d9353e440887 autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents: 2223
diff changeset
   590
        "wamp",
2221
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   591
        _("Wamp Settings"),
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   592
        webFormInterface,
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   593
        _("Set"),
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   594
        wampConfig)
e03f7649bfb3 WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents: 2220
diff changeset
   595
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3440
diff changeset
   596
    WebSettings.addCustomURL(WAMP_SECRET_URL, deliverWampSecret)
4113
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   597
    WebSettings.addCustomURL(WAMP_DELETE_TRUSTSTORE_URL, deleteTrustStore)
fe41562050ed WAMP: enable TLS support. Add web settings for hostname verification and server certificate.
Edouard Tisserant <edouard@beremiz.fr>
parents: 4094
diff changeset
   598