Salome HOME
[EDF] Taking SALOME launcher options into account through environment variable SALOME...
[modules/kernel.git] / bin / nameserver.py
old mode 100755 (executable)
new mode 100644 (file)
index 19fde8e..7af790a
@@ -1,6 +1,5 @@
-#!/usr/bin/env python3
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -25,7 +24,7 @@
 import os, sys, re, socket
 #import commands
 from server import Server
-from salome_utils import getHostName
+from salome_utils import getHostName, makeDir
 from launchConfigureParser import verbose
 
 # -----------------------------------------------------------------------------
@@ -41,10 +40,7 @@ class NamingServer(Server):
     def initNSArgs(self):
         from salome_utils import getLogDir
         upath = getLogDir()
-        try:
-            os.makedirs(upath, mode=0o777)
-        except:
-            pass
+        makeDir(upath)
 
         if verbose(): print("Name Service... ", end =' ')
         hname = getHostName()
@@ -67,7 +63,7 @@ class NamingServer(Server):
         upath = os.path.join(upath, "omniNames_%s"%(aPort))
         try:
           os.mkdir(upath)
-        except:
+        except Exception:
           # print("Can't create " + upath)
           pass
 
@@ -75,7 +71,7 @@ class NamingServer(Server):
         for fname in os.listdir(upath):
           try:
             os.remove(upath + "/" + fname)
-          except:
+          except Exception:
             pass
         #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
 
@@ -88,9 +84,16 @@ class NamingServer(Server):
           self.CMD = ['omniNames', '-start' , aPort , '-nohostname', '-logdir' , os.path.realpath(upath), '-errlog', os.path.realpath(os.path.join(upath,'omniNameErrors.log'))]
           #os.system("start omniNames -start " + aPort + " -logdir " + upath)
         else:
-          #self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &']
-          self.CMD = ['omniNames','-start' , aPort, '-logdir' , upath, '-errlog', upath+'/omniNameErrors.log']
-          #os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
+          # get ip address on default interface (for instance eth0) to limit listening on this interface (cyber security request)
+          from subprocess import check_output
+          ips = check_output(['hostname', '--all-ip-addresses'])
+          if ips.strip():
+            ipDefault = ips.split()[0].decode()
+          else:
+            ip = check_output(['hostname', '--ip-address'])
+            ipDefault = ip.split()[-1].decode()
+          self.CMD = ['omniNames','-start' , aPort]
+          self.CMD += ['-logdir' , upath, '-errlog', upath+'/omniNameErrors.log']
 
         if verbose(): print("... ok")
         if verbose(): print("to list contexts and objects bound into the context with the specified name : showNS ")