diff --git a/.gitignore b/.gitignore index 26a509fa5..ba85e71ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store config.php .env +install.lock error_log failed-login.log php_errors.log diff --git a/_install/install_nntmux.php b/_install/install_nntmux.php index f093f60ed..a24677e04 100644 --- a/_install/install_nntmux.php +++ b/_install/install_nntmux.php @@ -1,17 +1,32 @@ true, 'createDb' => true, 'dbhost' => getenv('DB_HOST'), - 'dbname' => getenv('DB_Name'), + 'dbname' => getenv('DB_NAME'), 'dbpass' => getenv('DB_PASSWORD'), 'dbport' => getenv('PORT'), 'dbsock' => getenv('DB_SOCKET'), @@ -41,8 +56,8 @@ if (getenv('DB_SYSTEM') === 'mysql') { case 1: case 2: case 3: - $error = true; - ColorCLI::doEcho(ColorCLI::alternate($e->getMessage())); + $error = true; + ColorCLI::doEcho(ColorCLI::alternate($e->getMessage())); break; default: var_dump($e); @@ -56,8 +71,8 @@ if (getenv('DB_SYSTEM') === 'mysql') { try { $goodVersion = $pdo->isDbVersionAtLeast(NN_MINIMUM_MYSQL_VERSION); } catch (\PDOException $e) { - $goodVersion = false; - $error = true; + $goodVersion = false; + $error = true; ColorCLI::doEcho(ColorCLI::error('Could not get version from MySQL server.')); } @@ -67,7 +82,9 @@ if (getenv('DB_SYSTEM') === 'mysql') { 'You are using an unsupported version of ' . getenv('DB_SYSTEM') . ' the minimum allowed version is ' . - NN_MINIMUM_MYSQL_VERSION)); + NN_MINIMUM_MYSQL_VERSION + ) + ); } } } @@ -128,12 +145,12 @@ if (!$error) { if ($updateSettings) { ColorCLI::doEcho(ColorCLI::info('Database updated successfully')); } else { - $error = true; + $error = true; ColorCLI::doEcho(ColorCLI::error('Could not update sqlpatch to ' . $patch . ' for your database.')); } } else { $dbCreateCheck = false; - $error = true; + $error = true; ColorCLI::doEcho(ColorCLI::warning('Could not select data from your database.')); } } @@ -192,8 +209,52 @@ if (getenv('ADMIN_USER') === '' || getenv('ADMIN_PASS') === '' || getenv('ADMIN_ $adminCheck = $user->add(getenv('ADMIN_USER'), getenv('ADMIN_PASS'), getenv('ADMIN_EMAIL'), 2, '', ''); if (!is_numeric($adminCheck)) { $error = true; - } else { - $user->login($adminCheck, '', 1); } } +} +$doCheck = true; + +$covers_path = NN_RES . 'covers' . DS; +$nzb_path = NN_RES . 'nzb' . DS; +$tmp_path = NN_RES . 'tmp' . DS; +$unrar_path = $tmp_path . 'unrar' . DS; + + +$nzbPathCheck = is_writable($nzb_path); +if ($nzbPathCheck === false) { + $error = true; +} + +$lastchar = substr($nzb_path, strlen($nzb_path) - 1); +if ($lastchar !== '/') { + $nzb_path .= '/'; +} + +$unrarPathCheck = is_writable($nzb_path); +if ($unrarPathCheck === false) { + $error = true; +} + +$lastchar = substr($unrar_path, strlen($unrar_path) - 1); +if ($lastchar !== '/') { + $unrar_path .= '/'; +} + +if (!$error) { + if (!file_exists($unrar_path)) { + mkdir($unrar_path); + } + + $sql1 = sprintf("UPDATE settings SET value = %s WHERE setting = 'nzbpath'", $pdo->escapeString($nzb_path)); + $sql2 = sprintf("UPDATE settings SET value = %s WHERE setting = 'tmpunrarpath'", $pdo->escapeString($unrar_path)); + $sql3 = sprintf("UPDATE settings SET value = %s WHERE setting = 'coverspath'", $pdo->escapeString($covers_path)); + if ($pdo->queryExec($sql1) === false || $pdo->queryExec($sql2) === false || $pdo->queryExec($sql3) === false) { + $error = true; + } else { + ColorCLI::doEcho(ColorCLI::info('Settings table updated successfully')); + } +} +if (!$error) { + @file_put_contents(NN_ROOT . '_install/install.lock', ''); + ColorCLI::doEcho(ColorCLI::alternate('NNTmux installation completed successfully')); } \ No newline at end of file diff --git a/nntmux/config/Configure.php b/nntmux/config/Configure.php index 70a1c1ee8..bef8a6be9 100755 --- a/nntmux/config/Configure.php +++ b/nntmux/config/Configure.php @@ -28,7 +28,7 @@ class Configure 'settings' => false ], 'install' => [ - '.env' => false, + '.env' => true, 'settings' => false ], 'smarty' => [ @@ -49,21 +49,19 @@ class Configure $this->loadSettings($config, $throwException); } } else { - throw new \RuntimeException("Unknown environment passed to Configure class!"); + throw new \RuntimeException('Unknown environment passed to Configure class!'); } } public function loadSettings($filename, $throwException = true) { $file = NN_ROOT . '.env'; - if (!file_exists($file)) { - if ($throwException) { - $errorCode = (int)($filename === '.env'); - throw new \RuntimeException( - "Unable to load configuration file '$file'. Make sure it has been created and contains correct settings.", - $errorCode - ); - } + if (!file_exists($file) && $throwException) { + $errorCode = (int)($filename === '.env'); + throw new \RuntimeException( + "Unable to load configuration file '$file'. Make sure it has been created and contains correct settings.", + $errorCode + ); } switch ($filename) {