From bfeea3c0e7de722efc05e4c3e5a3bc246783dbc4 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 24 Apr 2017 23:48:13 +0200 Subject: [PATCH] Fix getenv string call --- app/config/bootstrap/connections.php | 20 +++++++++------ cli/verify_permissions.php | 2 +- misc/testing/DB/check_unique_indexes.php | 8 +++--- misc/testing/DB/mysqldump_tables.php | 30 +++++++++++----------- misc/testing/DB/rename_to_lower.php | 2 +- misc/testing/DB/show_table_sizes.php | 2 +- misc/update/nix/tmux/monitor.php | 4 +-- nntmux/NNTP.php | 32 ++++++++++++------------ nntmux/Tmux.php | 8 +++--- nntmux/db/DB.php | 14 +++++------ www/admin/site-edit.php | 2 +- 11 files changed, 65 insertions(+), 59 deletions(-) diff --git a/app/config/bootstrap/connections.php b/app/config/bootstrap/connections.php index eb8464699..7f4d2f067 100644 --- a/app/config/bootstrap/connections.php +++ b/app/config/bootstrap/connections.php @@ -83,8 +83,14 @@ $config2 = NN_ROOT . '.env'; $config = file_exists($config1) ? $config1 : $config2; if (!defined('NN_INSTALLER')) { + if (!file_exists($config)) { + throw new \ErrorException( + "No valid configuration file found at '$config'" + ); + } + require_once $config; - switch (getenv(DB_SYSTEM)) { + switch (getenv('DB_SYSTEM')) { case 'mysql': $adapter = 'MySql'; break; @@ -96,10 +102,10 @@ if (!defined('NN_INSTALLER')) { } if (isset($adapter)) { - if (empty(getenv(DB_SOCKET))) { - $host = empty(getenv(DB_PORT)) ? getenv(DB_HOST) : getenv(DB_HOST) . ':' . getenv(DB_PORT); + if (empty(getenv('DB_SOCKET'))) { + $host = empty(getenv('DB_PORT')) ? getenv('DB_HOST') : getenv('DB_HOST') . ':' . getenv('DB_PORT'); } else { - $host = getenv(DB_SOCKET); + $host = getenv('DB_SOCKET'); } Connections::add('default', @@ -107,9 +113,9 @@ if (!defined('NN_INSTALLER')) { 'type' => 'database', 'adapter' => $adapter, 'host' => $host, - 'login' => getenv(DB_USER), - 'password' => getenv(DB_PASSWORD), - 'database' => getenv(DB_NAME), + 'login' => getenv('DB_USER'), + 'password' => getenv('DB_PASSWORD'), + 'database' => getenv('DB_NAME'), 'encoding' => 'UTF-8', 'persistent' => false, ] diff --git a/cli/verify_permissions.php b/cli/verify_permissions.php index 708b270c3..76aa36960 100644 --- a/cli/verify_permissions.php +++ b/cli/verify_permissions.php @@ -58,7 +58,7 @@ foreach (['anime', 'audio', 'audiosample', 'book', 'console', 'games', 'movies', } // Set up covers paths. -if (getenv(DB_PASSWORD) !== '') { +if (getenv('DB_PASSWORD') !== '') { $ri = new ReleaseImage(); $folders[$ri->audSavePath] = [R, W]; diff --git a/misc/testing/DB/check_unique_indexes.php b/misc/testing/DB/check_unique_indexes.php index c63e2147a..4f0753f90 100755 --- a/misc/testing/DB/check_unique_indexes.php +++ b/misc/testing/DB/check_unique_indexes.php @@ -53,7 +53,7 @@ if ($handle) { if (trim($match['table']) === 'collections') { $tables = $pdo->query("SHOW TABLES"); foreach ($tables as $row) { - $tbl = $row['tables_in_' . getenv(DB_NAME)]; + $tbl = $row['tables_in_' . getenv('DB_NAME')]; if (preg_match('/collections_\d+/', $tbl)) { $check = $pdo->checkColumnIndex($tbl, $column); if (!isset($check_collections['key_name'])) { @@ -67,7 +67,7 @@ if ($handle) { } else if (trim($match['table']) === 'binaries') { $tables = $pdo->query("SHOW TABLES"); foreach ($tables as $row) { - $tbl = $row['tables_in_' . getenv(DB_NAME)]; + $tbl = $row['tables_in_' . getenv('DB_NAME')]; if (preg_match('/binaries_\d+/', $tbl)) { $checkBinaries = $pdo->checkColumnIndex($tbl, $column); if (!isset($checkBinaries['key_name'])) { @@ -81,7 +81,7 @@ if ($handle) { } else if (trim($match['table']) === 'parts') { $tables = $pdo->query("SHOW TABLES"); foreach ($tables as $row) { - $tbl = $row['tables_in_' . getenv(DB_NAME)]; + $tbl = $row['tables_in_' . getenv('DB_NAME')]; if (preg_match('/parts_\d+/', $tbl)) { $checkParts = $pdo->checkColumnIndex($tbl, $column); if (!isset($checkParts['key_name'])) { @@ -95,7 +95,7 @@ if ($handle) { } else if (trim($match['table']) === 'missed_parts') { $tables = $pdo->query("SHOW TABLES"); foreach ($tables as $row) { - $tbl = $row['tables_in_' . getenv(DB_NAME)]; + $tbl = $row['tables_in_' . getenv('DB_NAME')]; if (preg_match('/partrepair_\d+/', $tbl)) { $checkPartRepair = $pdo->checkColumnIndex($tbl, $column); if (!isset($checkPartRepair['key_name'])) { diff --git a/misc/testing/DB/mysqldump_tables.php b/misc/testing/DB/mysqldump_tables.php index 9b7edaa44..807f5666c 100644 --- a/misc/testing/DB/mysqldump_tables.php +++ b/misc/testing/DB/mysqldump_tables.php @@ -32,14 +32,14 @@ function builddefaultsfile() //generate file contents $filetext = "[mysqldump]" ."\n" - ."user = " . getenv(DB_USER) + ."user = " . getenv('DB_USER') ."\n" - ."password = " . getenv(DB_PASSWORD) + ."password = " . getenv('DB_PASSWORD') ."\n[mysql]" ."\n" - ."user = " . getenv(DB_USER) + ."user = " . getenv('DB_USER') ."\n" - ."password = " . getenv(DB_PASSWORD); + ."password = " . getenv('DB_PASSWORD'); $filehandle = fopen("mysql-defaults.txt", "w+"); if(!$filehandle) { @@ -51,14 +51,14 @@ function builddefaultsfile() } } -$dbhost = getenv(DB_HOST); -$dbport = getenv(DB_PORT); -$dbsocket = getenv(DB_SOCKET); -$dbuser = getenv(DB_USER); -$dbpass = getenv(DB_PASSWORD); -$dbname = getenv(getenv(DB_NAME)); +$dbhost = getenv('DB_HOST'); +$dbport = getenv('DB_PORT'); +$dbsocket = getenv('DB_SOCKET'); +$dbuser = getenv('DB_USER'); +$dbpass = getenv('DB_PASSWORD'); +$dbname = getenv(getenv('DB_NAME')); -if (getenv(DB_SOCKET) !== '') { +if (getenv('DB_SOCKET') !== '') { $use = "-S $dbsocket"; } else { $use = "-P$dbport"; @@ -88,7 +88,7 @@ if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dum $sql = "SHOW tables"; $tables = $pdo->query($sql); foreach($tables as $row) { - $tbl = $row['Tables_in_'. getenv(DB_NAME)]; + $tbl = $row['Tables_in_'. getenv('DB_NAME')]; $filename = $argv[3]."/".$tbl.".gz"; echo $pdo->log->header("Dumping $tbl."); if (file_exists($filename)) { @@ -102,7 +102,7 @@ if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dum $tables = $pdo->query($sql); $pdo->queryExec("SET FOREIGN_KEY_CHECKS=0"); foreach($tables as $row) { - $tbl = $row['Tables_in_'.getenv(DB_NAME)]; + $tbl = $row['Tables_in_'.getenv('DB_NAME')]; $filename = $argv[3]."/".$tbl.".gz"; if (file_exists($filename)) { echo $pdo->log->header("Restoring $tbl."); @@ -138,7 +138,7 @@ if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dum $sql = "SHOW tables"; $tables = $pdo->query($sql); foreach($tables as $row) { - $tbl = $row['Tables_in_'.getenv(DB_NAME)]; + $tbl = $row['Tables_in_'.getenv('DB_NAME')]; $filename = $argv[3].$tbl.".csv"; echo $pdo->log->header("Dumping $tbl."); if (file_exists($filename)) { @@ -151,7 +151,7 @@ if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dum $tables = $pdo->query($sql); $pdo->queryExec("SET FOREIGN_KEY_CHECKS=0"); foreach($tables as $row) { - $tbl = $row['Tables_in_'.getenv(DB_NAME)]; + $tbl = $row['Tables_in_'.getenv('DB_NAME')]; $filename = $argv[3].$tbl.".csv"; if (file_exists($filename)) { echo $pdo->log->header("Restoring $tbl."); diff --git a/misc/testing/DB/rename_to_lower.php b/misc/testing/DB/rename_to_lower.php index a44c08993..c186f6935 100644 --- a/misc/testing/DB/rename_to_lower.php +++ b/misc/testing/DB/rename_to_lower.php @@ -27,7 +27,7 @@ if ($argc == 1 || $argv[1] != 'true') { exit($pdo->log->error("\nThis script will rename every table column to lowercase that is not already lowercase.\nTo run:\nphp $argv[0] true\n")); } -$database = getenv(DB_NAME); +$database = getenv('DB_NAME'); $count = 0; $list = $pdo->query("SELECT TABLE_NAME, COLUMN_NAME, UPPER(COLUMN_TYPE), EXTRA FROM information_schema.columns WHERE table_schema = '" . $database . "'"); diff --git a/misc/testing/DB/show_table_sizes.php b/misc/testing/DB/show_table_sizes.php index 43e73af2c..7e7a4cf05 100644 --- a/misc/testing/DB/show_table_sizes.php +++ b/misc/testing/DB/show_table_sizes.php @@ -20,7 +20,7 @@ $table_data = "SELECT TABLE_NAME AS 'Table', TABLE_ROWS AS 'Rows', " . "((INDEX_LENGTH) / POWER(1024,2)) AS 'index', " . "((DATA_FREE) / POWER(1024,2)) AS 'free', " . "((DATA_LENGTH + INDEX_LENGTH) / POWER(1024,2)) AS 'total' " - . "FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema = '" . getenv(DB_NAME) . "' " + . "FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema = '" . getenv('DB_NAME') . "' " . "ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC"; $run = $pdo->queryDirect($table_data); diff --git a/misc/update/nix/tmux/monitor.php b/misc/update/nix/tmux/monitor.php index 22dd7f4e3..41c1f2efd 100644 --- a/misc/update/nix/tmux/monitor.php +++ b/misc/update/nix/tmux/monitor.php @@ -18,8 +18,8 @@ $runVar['paths']['misc'] = NN_MISC; $runVar['paths']['cli'] = NN_ROOT . 'cli/'; $runVar['paths']['scraper'] = NN_MISC . 'IRCScraper' . DS . 'scrape.php'; -$db_name = getenv(DB_NAME); -$dbtype = getenv(DB_SYSTEM); +$db_name = getenv('DB_NAME'); +$dbtype = getenv('DB_SYSTEM'); $tmux = $tRun->get('niceness'); $tmux_niceness = $tmux->niceness ?? 2; diff --git a/nntmux/NNTP.php b/nntmux/NNTP.php index be573e534..7c4757cb4 100755 --- a/nntmux/NNTP.php +++ b/nntmux/NNTP.php @@ -148,7 +148,7 @@ class NNTP extends \Net_NNTP_Client public function doConnect($compression = true, $alternate = false) { if (// (Alternate is wanted, AND current server is alt, OR Alternate is not wanted AND current is main.) AND - (($alternate && $this->_currentServer === getenv(NNTP_SERVER_A)) || (!$alternate && $this->_currentServer === getenv(NNTP_SERVER))) && + (($alternate && $this->_currentServer === getenv('NNTP_SERVER_A')) || (!$alternate && $this->_currentServer === getenv('NNTP_SERVER'))) && // Don't reconnect to usenet if: // We are already connected to usenet. parent::_isConnected() @@ -163,19 +163,19 @@ class NNTP extends \Net_NNTP_Client // Set variables to connect based on if we are using the alternate provider or not. if (!$alternate) { - $sslEnabled = getenv(NNTP_SSLENABLED) ? true : false; - $this->_currentServer = getenv(NNTP_SERVER); - $this->_currentPort = getenv(NNTP_PORT); - $userName = getenv(NNTP_USERNAME); - $password = getenv(NNTP_PASSWORD); - $socketTimeout = !empty(getenv(NNTP_SOCKET_TIMEOUT)) ? getenv(NNTP_SOCKET_TIMEOUT) : $this->_socketTimeout; + $sslEnabled = getenv('NNTP_SSLENABLED') ? true : false; + $this->_currentServer = getenv('NNTP_SERVER'); + $this->_currentPort = getenv('NNTP_PORT'); + $userName = getenv('NNTP_USERNAME'); + $password = getenv('NNTP_PASSWORD'); + $socketTimeout = !empty(getenv('NNTP_SOCKET_TIMEOUT')) ? getenv('NNTP_SOCKET_TIMEOUT') : $this->_socketTimeout; } else { - $sslEnabled = getenv(NNTP_SSLENABLED_A) ? true : false; - $this->_currentServer = getenv(NNTP_SERVER_A); - $this->_currentPort = getenv(NNTP_PORT_A); - $userName = getenv(NNTP_USERNAME_A); - $password = getenv(NNTP_PASSWORD_A); - $socketTimeout = !empty(getenv(NNTP_SOCKET_TIMEOUT_A)) ? getenv(NNTP_SOCKET_TIMEOUT_A) : $this->_socketTimeout; + $sslEnabled = getenv('NNTP_SSLENABLED_A') ? true : false; + $this->_currentServer = getenv('NNTP_SERVER_A'); + $this->_currentPort = getenv('NNTP_PORT_A'); + $userName = getenv('NNTP_USERNAME_A'); + $password = getenv('NNTP_PASSWORD_A'); + $socketTimeout = !empty(getenv('NNTP_SOCKET_TIMEOUT_A')) ? getenv('NNTP_SOCKET_TIMEOUT_A') : $this->_socketTimeout; } $enc = ($sslEnabled ? ' (ssl)' : ' (non-ssl)'); @@ -581,7 +581,7 @@ class NNTP extends \Net_NNTP_Client if ($alternate === true) { if ($aConnected === false) { // Check if the current connected server is the alternate or not. - if ($this->_currentServer === getenv(NNTP_SERVER)) { + if ($this->_currentServer === getenv('NNTP_SERVER')) { // It's the main so connect to the alternate. $aConnected = $nntp->doConnect(true, true); } else { @@ -1483,13 +1483,13 @@ class NNTP extends \Net_NNTP_Client $retVal = true; } else { switch ($this->_currentServer) { - case getenv(NNTP_SERVER): + case getenv('NNTP_SERVER'): if (is_resource($this->_socket)) { $this->doQuit(true); } $retVal = $this->doConnect(); break; - case getenv(NNTP_SERVER_A): + case getenv('NNTP_SERVER_A'): if (is_resource($this->_socket)) { $this->doQuit(true); } diff --git a/nntmux/Tmux.php b/nntmux/Tmux.php index d1d991288..5d7f19d01 100755 --- a/nntmux/Tmux.php +++ b/nntmux/Tmux.php @@ -90,12 +90,12 @@ class Tmux public function getConnectionsInfo($constants) { $runVar['connections']['port_a'] = $runVar['connections']['host_a'] = $runVar['connections']['ip_a'] = false; - $runVar['connections']['port'] = getenv(NNTP_PORT); - $runVar['connections']['host'] = getenv(NNTP_SERVER); + $runVar['connections']['port'] = getenv('NNTP_PORT'); + $runVar['connections']['host'] = getenv('NNTP_SERVER'); $runVar['connections']['ip'] = gethostbyname($runVar['connections']['host']); if ($constants['alternate_nntp'] === '1') { - $runVar['connections']['port_a'] = getenv(NNTP_PORT_A); - $runVar['connections']['host_a'] = getenv(NNTP_SERVER_A); + $runVar['connections']['port_a'] = getenv('NNTP_PORT_A'); + $runVar['connections']['host_a'] = getenv('NNTP_SERVER_A'); $runVar['connections']['ip_a'] = gethostbyname($runVar['connections']['host_a']); } return $runVar['connections']; diff --git a/nntmux/db/DB.php b/nntmux/db/DB.php index 595f12237..c7075fff3 100755 --- a/nntmux/db/DB.php +++ b/nntmux/db/DB.php @@ -112,13 +112,13 @@ class DB extends \PDO 'checkVersion' => false, 'createDb' => false, // create dbname if it does not exist? 'ct' => new ConsoleTools(), - 'dbhost' => getenv(DB_HOST), - 'dbname' => getenv(DB_NAME), - 'dbpass' => getenv(DB_PASSWORD), - 'dbport' => getenv(DB_PORT), - 'dbsock' => getenv(DB_SOCKET), - 'dbtype' => getenv(DB_SYSTEM), - 'dbuser' => getenv(DB_USER), + 'dbhost' => getenv('DB_HOST'), + 'dbname' => getenv('DB_NAME'), + 'dbpass' => getenv('DB_PASSWORD'), + 'dbport' => getenv('DB_PORT'), + 'dbsock' => getenv('DB_SOCKET'), + 'dbtype' => getenv('DB_SYSTEM'), + 'dbuser' => getenv('DB_USER'), 'log' => new ColorCLI(), 'persist' => false, ]; diff --git a/www/admin/site-edit.php b/www/admin/site-edit.php index c1a01e3ba..ccc76fa94 100644 --- a/www/admin/site-edit.php +++ b/www/admin/site-edit.php @@ -171,7 +171,7 @@ $page->smarty->assign('book_reqids_selected', $books_selected); $page->smarty->assign('themelist', Utility::getThemesList()); -if (strpos(getenv(NNTP_SERVER), "astra") === false) { +if (strpos(getenv('NNTP_SERVER'), "astra") === false) { $page->smarty->assign('compress_headers_warning', "compress_headers_warning"); }