From 6319a6a58a39375d2955617447d9725503660fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sun, 15 Jun 2014 01:02:59 +0200 Subject: [PATCH] check for function availability before trying to restart --- application/core/ManiaControl.php | 11 ++++++++++- application/core/Utils/SystemUtil.php | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 1af0a121..8cd67ea0 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -246,11 +246,20 @@ class ManiaControl implements CommandListener, TimerListener { $this->log('Restarting ManiaControl!'); // Execute start script in background - // TODO: restart the .php script itself ($_SERVER['scriptname'] or something + $argv) if (SystemUtil::isUnix()) { + // Unix + if (!SystemUtil::checkFunctionAvailability('exec')) { + $this->log("Can't restart ManiaControl because the function 'exec' is disabled!"); + return; + } $command = 'sh ' . escapeshellarg(ManiaControlDir . 'ManiaControl.sh') . ' > /dev/null &'; exec($command); } else { + // Windows + if (!SystemUtil::checkFunctionAvailability('system')) { + $this->log("Can't restart ManiaControl because the function 'system' is disabled!"); + return; + } $command = escapeshellarg(ManiaControlDir . "ManiaControl.bat"); system($command); // TODO: windows gets stuck here as long controller is running } diff --git a/application/core/Utils/SystemUtil.php b/application/core/Utils/SystemUtil.php index 0312782f..cd55b6b8 100644 --- a/application/core/Utils/SystemUtil.php +++ b/application/core/Utils/SystemUtil.php @@ -45,4 +45,24 @@ class SystemUtil { public static function isUnix() { return (self::getOS() === self::OS_UNIX); } + + /** + * Check whether the given Function is available + * + * @param string $functionName + * @return bool + */ + public static function checkFunctionAvailability($functionName) { + return (function_exists($functionName) && !in_array($functionName, self::getDisabledFunctions())); + } + + /** + * Get the Array of Disabled Functions + * + * @return array + */ + public static function getDisabledFunctions() { + $disabledText = ini_get('disable_functions'); + return explode(',', $disabledText); + } }