diff --git a/app/Lib/Tools/PubSubTool.php b/app/Lib/Tools/PubSubTool.php index f60db152a..87752fa3f 100644 --- a/app/Lib/Tools/PubSubTool.php +++ b/app/Lib/Tools/PubSubTool.php @@ -84,7 +84,8 @@ class PubSubTool public function checkIfPythonLibInstalled() { - $result = trim(shell_exec('python3 ' . APP . 'files' . DS . 'scripts' . DS . 'mispzmq' . DS . 'mispzmqtest.py')); + $my_server = ClassRegistry::init('Server'); + $result = trim(shell_exec($my_server->getPythonVersion() . ' ' . APP . 'files' . DS . 'scripts' . DS . 'mispzmq' . DS . 'mispzmqtest.py')); if ($result === "OK") { return true; } @@ -94,9 +95,10 @@ class PubSubTool private function __setupPubServer() { App::uses('File', 'Utility'); + $my_server = ClassRegistry::init('Server'); $settings = $this->__getSetSettings(); if ($this->checkIfRunning() === false) { - shell_exec('python3 ' . APP . 'files' . DS . 'scripts' . DS . 'mispzmq' . DS . 'mispzmq.py > ' . APP . 'tmp' . DS . 'logs' . DS . 'mispzmq.log 2> ' . APP . 'tmp' . DS . 'logs' . DS . 'mispzmq.error.log &'); + shell_exec($my_server->getPythonVersion() . ' ' . APP . 'files' . DS . 'scripts' . DS . 'mispzmq' . DS . 'mispzmq.py > ' . APP . 'tmp' . DS . 'logs' . DS . 'mispzmq.log 2> ' . APP . 'tmp' . DS . 'logs' . DS . 'mispzmq.error.log &'); } return $settings; } diff --git a/app/Model/Server.php b/app/Model/Server.php index 687be3a00..2a398cb92 100644 --- a/app/Model/Server.php +++ b/app/Model/Server.php @@ -168,10 +168,11 @@ class Server extends AppModel 'python_bin' => array( 'level' => 1, 'description' => __('It is highly recommended to install all the python dependencies in a virtualenv. The recommended location is: %s/venv', ROOT), - 'value' => ROOT . '/venv/bin/python', # GUI display purpose only. + 'value' => false, 'errorMessage' => '', 'null' => false, - 'test' => 'testForEmpty', + 'test' => 'testForBinExec', + 'beforeHook' => 'beforeHookBinExec', 'type' => 'string', ), 'disable_auto_logout' => array( @@ -2676,6 +2677,30 @@ class Server extends AppModel return 'Invalid characters in the path.'; } + public function beforeHookBinExec($setting, $value) + { + return $this->testForBinExec($value); + } + + public function testForBinExec($value) + { + $finfo = finfo_open(FILEINFO_MIME_TYPE); + if ($value === '') { + return true; + } + if (is_executable($value)) { + if (finfo_file($finfo, $value) == "application/x-executable") { + finfo_close($finfo); + return true; + } else { + return 'Binary file not executable.'; + } + } + else { + return false; + } + } + public function testForWritableDir($value) { if (!is_dir($value)) {