Beremiz_service now binds both pyro and nevow ports to interface given with '-i' argument.
authorEdouard Tisserant
Mon, 15 Oct 2018 15:27:47 +0200
changeset 2311 bef2b4b87370
parent 2310 f9f9f5856032
child 2312 84b3cc18893b
Beremiz_service now binds both pyro and nevow ports to interface given with '-i' argument.
Beremiz_service.py
runtime/NevowServer.py
runtime/PyroServer.py
--- a/Beremiz_service.py	Mon Oct 15 15:24:52 2018 +0200
+++ b/Beremiz_service.py	Mon Oct 15 15:27:47 2018 +0200
@@ -75,7 +75,7 @@
     sys.exit(2)
 
 # default values
-given_ip = None
+interface = ''
 port = 3000
 webport = 8009
 wampsecret = None
@@ -97,8 +97,10 @@
         version()
         sys.exit()
     elif o == "-i":
-        if len(a.split(".")) == 4 or a == "localhost":
-            given_ip = a
+        if len(a.split(".")) == 4:
+            interface = a
+        elif a == "localhost":
+            interface = '127.0.0.1'
         else:
             usage()
             sys.exit()
@@ -491,7 +493,7 @@
 runtime.CreatePLCObjectSingleton(
     WorkingDir, argv, statuschange, evaluator, pyruntimevars)
 
-pyroserver = Server(servicename, given_ip, port)
+pyroserver = Server(servicename, interface, port)
 
 if havewx:
     taskbar_instance = BeremizTaskBarIcon(pyroserver)
@@ -499,7 +501,7 @@
 if havetwisted:
     if webport is not None:
         try:
-            website = NS.RegisterWebsite(webport)
+            website = NS.RegisterWebsite(interface, webport)
             pyruntimevars["website"] = website
             NS.SetServer(pyroserver)
             statuschange.append(NS.website_statuslistener_factory(website))
--- a/runtime/NevowServer.py	Mon Oct 15 15:24:52 2018 +0200
+++ b/runtime/NevowServer.py	Mon Oct 15 15:27:47 2018 +0200
@@ -333,11 +333,11 @@
         # print "We will be called back when the client disconnects"
 
 
-def RegisterWebsite(port):
+def RegisterWebsite(iface, port):
     website = WebInterface()
     site = appserver.NevowSite(website)
 
-    reactor.listenTCP(port, site)
+    reactor.listenTCP(port, site, interface=iface)
     print(_('HTTP interface port :'), port)
     return website
 
--- a/runtime/PyroServer.py	Mon Oct 15 15:24:52 2018 +0200
+++ b/runtime/PyroServer.py	Mon Oct 15 15:27:47 2018 +0200
@@ -27,9 +27,7 @@
 
     def _to_be_published(self):
         return self.servicename is not None and \
-               self.ip_addr is not None and \
-               self.ip_addr != "localhost" and \
-               self.ip_addr != "127.0.0.1"
+               self.ip_addr not in ["", "localhost", "127.0.0.1"]
 
     def PrintServerInfo(self):
         print(_("Pyro port :"), self.port)