From d2193f76caf8d49ab27d8207de578db5de4fa67f Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Wed, 14 Sep 2016 10:53:04 -0500 Subject: [PATCH] feature: allow scripts to be run from any working directory (#4437) * feature: allow validate.php to be run from any working directory * remove redundant realpath() call * re-add realpath() to remove symbolic links * realpath() isn't needed... * chdir() in all php scripts in ./ and ./scripts/ * update-sql.php clearly is not used, as it was broken. * Change some scripts to executable Remove extra chdir() call in snmp-scan.php * Missed console-ui.php Kind of fixed console-ui.php help output * Re-add newline --- addhost.php | 2 +- adduser.php | 2 +- alerts.php | 2 ++ billing-calculate.php | 2 +- build-base.php | 3 +++ check-services.php | 2 +- config_to_json.php | 24 ++++++----------------- daily.php | 3 +++ delhost.php | 2 +- discovery.php | 2 +- dist-pollers.php | 2 +- irc.php | 3 ++- poll-billing.php | 2 +- poller.php | 2 +- renamehost.php | 2 +- scripts/console-ui.php | 40 +++++++++++++++++++-------------------- scripts/gen_smokeping.php | 8 +++++--- scripts/tune_port.php | 4 ++++ scripts/update-sql.php | 22 --------------------- snmp-scan.php | 4 ++-- snmptrap.php | 2 ++ syslog.php | 2 ++ validate.php | 6 ++++-- 23 files changed, 64 insertions(+), 79 deletions(-) mode change 100644 => 100755 build-base.php mode change 100644 => 100755 config_to_json.php delete mode 100755 scripts/update-sql.php diff --git a/addhost.php b/addhost.php index ab69ea2784..d7edc16ce9 100755 --- a/addhost.php +++ b/addhost.php @@ -13,7 +13,7 @@ use LibreNMS\Exceptions\HostUnreachableException; -chdir(dirname($argv[0])); +chdir(__DIR__); // cwd to the directory containing this script require 'includes/defaults.inc.php'; require 'config.php'; diff --git a/adduser.php b/adduser.php index 8ba8431ad1..a0a31d2bde 100755 --- a/adduser.php +++ b/adduser.php @@ -12,7 +12,7 @@ * */ -chdir(dirname($argv[0])); +chdir(__DIR__); // cwd to the directory containing this script require 'includes/defaults.inc.php'; require 'config.php'; diff --git a/alerts.php b/alerts.php index 143a6fcb0c..345dc7fd1a 100755 --- a/alerts.php +++ b/alerts.php @@ -25,6 +25,8 @@ * @subpackage Alerts */ +chdir(__DIR__); // cwd to the directory containing this script + require_once 'includes/defaults.inc.php'; require_once 'config.php'; diff --git a/billing-calculate.php b/billing-calculate.php index 243d7fdfc2..90058a0902 100755 --- a/billing-calculate.php +++ b/billing-calculate.php @@ -11,7 +11,7 @@ * @copyright (C) 2006 - 2012 Adam Armstrong */ -chdir(dirname($argv[0])); +chdir(__DIR__); // cwd to the directory containing this script require 'includes/defaults.inc.php'; require 'config.php'; diff --git a/build-base.php b/build-base.php old mode 100644 new mode 100755 index 3256594a8f..b1d0bdfec2 --- a/build-base.php +++ b/build-base.php @@ -1,5 +1,8 @@ +#!/usr/bin/env php . * */ -chdir(dirname($argv[0])); +chdir(__DIR__); // cwd to the directory containing this script + require_once 'includes/defaults.inc.php'; require_once 'config.php'; require_once 'includes/definitions.inc.php'; diff --git a/poll-billing.php b/poll-billing.php index d510810573..50e9c67cac 100755 --- a/poll-billing.php +++ b/poll-billing.php @@ -11,7 +11,7 @@ * @copyright (C) 2006 - 2012 Adam Armstrong */ -chdir(dirname($argv[0])); +chdir(__DIR__); // cwd to the directory containing this script // FIXME - implement cli switches, debugging, etc. require 'includes/defaults.inc.php'; diff --git a/poller.php b/poller.php index 41c25ef39a..92c3687c0c 100755 --- a/poller.php +++ b/poller.php @@ -11,7 +11,7 @@ * @copyright (C) 2006 - 2012 Adam Armstrong */ -chdir(dirname($argv[0])); +chdir(__DIR__); // cwd to the directory containing this script require 'includes/defaults.inc.php'; require 'config.php'; diff --git a/renamehost.php b/renamehost.php index 49b3929ed4..74475edfc6 100755 --- a/renamehost.php +++ b/renamehost.php @@ -11,7 +11,7 @@ * @copyright (C) 2006 - 2012 Adam Armstrong */ -chdir(dirname($argv[0])); +chdir(__DIR__); // cwd to the directory containing this script require 'includes/defaults.inc.php'; require 'config.php'; diff --git a/scripts/console-ui.php b/scripts/console-ui.php index ede19c8ecf..fba0092037 100755 --- a/scripts/console-ui.php +++ b/scripts/console-ui.php @@ -1,11 +1,13 @@ #!/usr/bin/env php convert('%rLast update at '.date('Y-m-d h:i:s')."%n\n\n"); diff --git a/scripts/gen_smokeping.php b/scripts/gen_smokeping.php index b061a4d368..424a6b8bc7 100755 --- a/scripts/gen_smokeping.php +++ b/scripts/gen_smokeping.php @@ -11,9 +11,11 @@ * the source code distribution for details. */ -include_once("../includes/defaults.inc.php"); -include_once("../config.php"); -include_once("../includes/definitions.inc.php"); +chdir(realpath(__DIR__ . '/..')); // cwd to the parent directory of this script + +include_once("includes/defaults.inc.php"); +include_once("config.php"); +include_once("includes/definitions.inc.php"); ?> diff --git a/scripts/tune_port.php b/scripts/tune_port.php index e2d6383e29..410893dfc8 100755 --- a/scripts/tune_port.php +++ b/scripts/tune_port.php @@ -1,6 +1,8 @@ #!/usr/bin/env php