From 287b58c76832e18479bfd54b7389a4c816388591 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 20 Sep 2016 14:13:40 +0200 Subject: [PATCH] Change missed files --- _install/Autoloader_Class.php | 199 +++++++++++++++++++++++++++ app/config/bootstrap/connections.php | 2 +- app/config/bootstrap/libraries.php | 16 +-- www/install/config.php.tpl | 10 +- www/install/index.php | 8 +- www/install/install.php | 4 +- www/install/step1.php | 20 +-- www/install/step2.php | 6 +- www/install/step3.php | 32 ++--- www/install/step7.php | 8 +- www/install/templates/step3.tpl | 12 +- www/install/templates/step5.tpl | 4 +- www/pages/InstallPage.php | 50 +++++++ 13 files changed, 309 insertions(+), 62 deletions(-) create mode 100755 _install/Autoloader_Class.php create mode 100755 www/pages/InstallPage.php diff --git a/_install/Autoloader_Class.php b/_install/Autoloader_Class.php new file mode 100755 index 000000000..5cea8b2b0 --- /dev/null +++ b/_install/Autoloader_Class.php @@ -0,0 +1,199 @@ +register(); + * + * // register the base directories for the namespace prefix + * $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/src'); + * $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/tests'); + * + * The following line would cause the autoloader to attempt to load the + * \Foo\Bar\Qux\Quux class from /path/to/packages/foo-bar/src/Qux/Quux.php: + * + * prefixes[$prefix]) === false) { + $this->prefixes[$prefix] = []; + } + + // retain the base directory for the namespace prefix + if ($prepend) { + array_unshift($this->prefixes[$prefix], $base_dir); + } else { + array_push($this->prefixes[$prefix], $base_dir); + } + } + + /** + * Loads the class file for a given class name. + * + * @param string $class The fully-qualified class name. + * + * @return string|false The mapped file name on success, or boolean false on + * failure. + */ + public function loadClass($class) + { + // the current namespace prefix + $prefix = $class; + + // work backwards through the namespace names of the fully-qualified + // class name to find a mapped file name + while (false !== $pos = strrpos($prefix, '\\')) { + + // retain the trailing namespace separator in the prefix + $prefix = substr($class, 0, $pos + 1); + + // the rest is the relative class name + $relative_class = substr($class, $pos + 1); + + // try to load a mapped file for the prefix and relative class + $mapped_file = $this->loadMappedFile($prefix, $relative_class); + if ($mapped_file) { + return $mapped_file; + } + + // remove the trailing namespace separator for the next iteration + // of strrpos() + $prefix = rtrim($prefix, '\\'); + } + + // never found a mapped file + return false; + } + + /** + * Load the mapped file for a namespace prefix and relative class. + * + * @param string $prefix The namespace prefix. + * @param string $relative_class The relative class name. + * + * @return string|false Boolean false if no mapped file can be loaded, or the + * name of the mapped file that was loaded. + */ + protected function loadMappedFile($prefix, $relative_class) + { + // are there any base directories for this namespace prefix? + if (isset($this->prefixes[$prefix]) === false) { + return false; + } + + // look through base directories for this namespace prefix + foreach ($this->prefixes[$prefix] as $base_dir) { + + // replace the namespace prefix with the base directory, + // replace namespace separators with directory separators + // in the relative class name, append with .php + $file = $base_dir + . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) + . '.php'; + $file = $base_dir + . str_replace('\\', '/', $relative_class) + . '.php'; + + // if the mapped file exists, require it + if ($this->requireFile($file)) { + // yes, we're done + return $file; + } + } + + // never found it + return false; + } + + /** + * If a file exists, require it from the file system. + * + * @param string $file The file to require. + * + * @return bool True if the file exists, false if not. + */ + protected function requireFile($file) + { + if (file_exists($file)) { + require $file; + + return true; + } + + return false; + } +} + +?> diff --git a/app/config/bootstrap/connections.php b/app/config/bootstrap/connections.php index 62469bb27..5d790d6d2 100644 --- a/app/config/bootstrap/connections.php +++ b/app/config/bootstrap/connections.php @@ -77,7 +77,7 @@ $config1 = LITHIUM_APP_PATH . DS . 'config' . DS . 'db-config.php'; $config2 = NN_ROOT . 'nntmux' . DS . 'config' . DS . 'config.php'; $config = file_exists($config1) ? $config1 : $config2; -if (file_exists($config)) { +if (file_exists($config) && !defined('NN_INSTALLER')) { require_once $config; switch (DB_SYSTEM) { case 'mysql': diff --git a/app/config/bootstrap/libraries.php b/app/config/bootstrap/libraries.php index 9fece3a25..ff33a0e7b 100644 --- a/app/config/bootstrap/libraries.php +++ b/app/config/bootstrap/libraries.php @@ -53,10 +53,6 @@ */ define('LITHIUM_APP_PATH', realpath(dirname(dirname(__DIR__)))); -if (!defined('NN_ROOT')) { - define('NN_ROOT', realpath(dirname(LITHIUM_APP_PATH)) . DS); -} - /** * This is the path to the class libraries used by your application, and must contain a copy of the * Lithium core. By default, this directory is named `libraries`, and resides in the same @@ -128,11 +124,13 @@ Libraries::add('app', array('default' => true)); // Libraries::add(basename($path), array('path' => $path)); // } -Libraries::add('nntmux', - [ - 'bootstrap' => 'bootstrap.php', - 'path' => NN_ROOT . 'nntmux', - ]); +if (!defined('NN_INSTALLER') || NN_INSTALLER !== true) { + Libraries::add('nntmux', + [ + 'bootstrap' => 'bootstrap.php', + 'path' => NN_ROOT . 'nntmux', + ]); +} require_once LITHIUM_APP_PATH . DS . 'libraries' . DS . 'autoload.php'; /** diff --git a/www/install/config.php.tpl b/www/install/config.php.tpl index 2720d2e0d..a7a4d5d83 100755 --- a/www/install/config.php.tpl +++ b/www/install/config.php.tpl @@ -29,12 +29,12 @@ define('NNTP_SSLENABLED_A', %%NNTP_SSLENABLED_A%%); define('NNTP_SOCKET_TIMEOUT_A', '%%NNTP_SOCKET_TIMEOUT_A%%'); // Location to CA bundle file on your system. You can download one here: http://curl.haxx.se/docs/caextract.html -define('nZEDb_SSL_CAFILE', '%%nZEDb_SSL_CAFILE%%'); +define('NN_SSL_CAFILE', '%%NN_SSL_CAFILE%%'); // Path where openssl cert files are stored on your system, this is a fall back if the CAFILE is not found. -define('nZEDb_SSL_CAPATH', '%%nZEDb_SSL_CAPATH%%'); +define('NN_SSL_CAPATH', '%%NN_SSL_CAPATH%%'); // Use the aforementioned CA bundle file to verify remote SSL certificates when connecting to a server using TLS/SSL. -define('nZEDb_SSL_VERIFY_PEER', '%%nZEDb_SSL_VERIFY_PEER%%'); +define('NN_SSL_VERIFY_PEER', '%%NN_SSL_VERIFY_PEER%%'); // Verify the host is who they say they are. -define('nZEDb_SSL_VERIFY_HOST', '%%nZEDb_SSL_VERIFY_HOST%%'); +define('NN_SSL_VERIFY_HOST', '%%NN_SSL_VERIFY_HOST%%'); // Allow self signed certificates. Note this does not work on CURL as CURL does not have this option. -define('nZEDb_SSL_ALLOW_SELF_SIGNED', '%%nZEDb_SSL_ALLOW_SELF_SIGNED%%'); +define('NN_SSL_ALLOW_SELF_SIGNED', '%%NN_SSL_ALLOW_SELF_SIGNED%%'); diff --git a/www/install/index.php b/www/install/index.php index f4b0a8da3..b665ade1c 100755 --- a/www/install/index.php +++ b/www/install/index.php @@ -11,7 +11,7 @@ if ($cfg->isLocked()) { $cfg->error = true; } -$cfg->cacheCheck = is_writable(nZEDb_RES . 'smarty' . DS . 'templates_c'); +$cfg->cacheCheck = is_writable(NN_RES . 'smarty' . DS . 'templates_c'); if ($cfg->cacheCheck === false) { $cfg->error = true; } @@ -70,13 +70,13 @@ if (!$cfg->error) {
The template compile dir must be writable.
A quick solution is to run:

Another solution is to run:
chown -R YourUnixUserName:' . $group['name'] . ' ' . nZEDb_ROOT . + '

Another solution is to run:
chown -R YourUnixUserName:' . $group['name'] . ' ' . NN_ROOT . '
Then give your user access to the group:
usermod -a -G ' . $group['name'] . ' YourUnixUserName' . - '
Finally give read/write access to your user/group:
chmod -R 774 ' . nZEDb_ROOT; + '
Finally give read/write access to your user/group:
chmod -R 774 ' . NN_ROOT; } ?>
diff --git a/www/install/install.php b/www/install/install.php index 32e2a5c51..3209438ba 100644 --- a/www/install/install.php +++ b/www/install/install.php @@ -19,8 +19,8 @@ * @copyright 2015 nZEDb */ -if (!defined('nZEDb_INSTALLER')) { - define('nZEDb_INSTALLER', true); +if (!defined('NN_INSTALLER')) { + define('NN_INSTALLER', true); } require_once realpath(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'bootstrap.php'); diff --git a/www/install/step1.php b/www/install/step1.php index 8b5bc242f..a605b4c9d 100755 --- a/www/install/step1.php +++ b/www/install/step1.php @@ -62,17 +62,17 @@ $cfg->curlCheck = function_exists('curl_init'); if (extension_loaded('posix') && strtolower(substr(PHP_OS, 0, 3)) !== 'win') { $group = posix_getgrgid(posix_getgid()); - $fixString = '

Another solution is to run:
chown -R YourUnixUserName:' . $group['name'] . ' ' . nZEDb_ROOT . + $fixString = '

Another solution is to run:
chown -R YourUnixUserName:' . $group['name'] . ' ' . NN_ROOT . '
Then give your user access to the group:
usermod -a -G ' . $group['name'] . ' YourUnixUserName' . - '
Finally give read/write access to your user/group:
chmod -R 774 ' . nZEDb_ROOT; + '
Finally give read/write access to your user/group:
chmod -R 774 ' . NN_ROOT; $page->smarty->assign('fixString', $fixString); $page->smarty->assign('unixGroup', $group['name']); - $page->smarty->assign('rootPath', nZEDb_ROOT); + $page->smarty->assign('rootPath', NN_ROOT); } else { $page->smarty->assign('fixString', false); } -$cfg->cacheCheck = is_writable(nZEDb_RES . 'smarty' . DS . 'templates_c'); +$cfg->cacheCheck = is_writable(NN_RES . 'smarty' . DS . 'templates_c'); if ($cfg->cacheCheck === false) { $cfg->error = true; } @@ -127,14 +127,14 @@ if ($cfg->videoCoversCheck === false) { $cfg->error = true; } -$cfg->configCheck = is_writable(nZEDb_CONFIGS); +$cfg->configCheck = is_writable(NN_CONFIGS); if ($cfg->configCheck === false) { - $cfg->configCheck = is_file(nZEDb_CONFIGS); + $cfg->configCheck = is_file(NN_CONFIGS); if ($cfg->configCheck === true) { $cfg->configCheck = false; $cfg->error = true; } else { - $cfg->configCheck = is_writable(nZEDb_CONFIGS); + $cfg->configCheck = is_writable(NN_CONFIGS); if ($cfg->configCheck === false) { $cfg->error = true; } @@ -170,7 +170,7 @@ if ($cfg->schemaCheck === false) { } // Don't set error = true for these as we only want to display a warning. -$cfg->phpCheck = (version_compare(PHP_VERSION, nZEDb_MINIMUM_PHP_VERSION, '>=')) ? true : false; +$cfg->phpCheck = (version_compare(PHP_VERSION, NN_MINIMUM_PHP_VERSION, '>=')) ? true : false; $cfg->timelimitCheck = (ini_get('max_execution_time') >= 120) ? true : false; $cfg->memlimitCheck = (ini_get('memory_limit') >= 1024 || ini_get('memory_limit') == -1) ? true : false; $cfg->opensslCheck = extension_loaded("openssl"); @@ -184,8 +184,8 @@ if (preg_match('/apache/i', $_SERVER['SERVER_SOFTWARE'])) { } // Load previous config.php. -if (file_exists(nZEDb_CONFIGS . 'config.php') && is_readable(nZEDb_CONFIGS . 'config.php')) { - $tmpCfg = file_get_contents(nZEDb_CONFIGS . 'config.php'); +if (file_exists(NN_CONFIGS . 'config.php') && is_readable(NN_CONFIGS . 'config.php')) { + $tmpCfg = file_get_contents(NN_CONFIGS . 'config.php'); $cfg->setConfig($tmpCfg); } diff --git a/www/install/step2.php b/www/install/step2.php index 87556eb0b..33d64ad63 100755 --- a/www/install/step2.php +++ b/www/install/step2.php @@ -125,7 +125,7 @@ if ($page->isPostBack()) { $goodVersion = false; if (!$cfg->error) { try { - $goodVersion = $pdo->isDbVersionAtLeast(nZEDb_MINIMUM_MYSQL_VERSION); + $goodVersion = $pdo->isDbVersionAtLeast(NN_MINIMUM_MYSQL_VERSION); } catch (\PDOException $e) { $goodVersion = false; $cfg->error = true; @@ -138,7 +138,7 @@ if ($page->isPostBack()) { 'You are using an unsupported version of ' . $cfg->DB_SYSTEM . ' the minimum allowed version is ' . - nZEDb_MINIMUM_MYSQL_VERSION; + NN_MINIMUM_MYSQL_VERSION; } } } @@ -158,7 +158,7 @@ if ($page->isPostBack()) { $DbSetup->processSQLFile(); // Setup default schema $DbSetup->processSQLFile( // Process any custom stuff. [ - 'filepath' => nZEDb_RES . 'db' . DS . 'schema' . DS . 'mysql-data.sql' + 'filepath' => NN_RES . 'db' . DS . 'schema' . DS . 'mysql-data.sql' ] ); $DbSetup->loadTables(); // Load default data files diff --git a/www/install/step3.php b/www/install/step3.php index 6f7b4e65e..0b7ea30cb 100755 --- a/www/install/step3.php +++ b/www/install/step3.php @@ -18,35 +18,35 @@ $cfg = $cfg->getSession(); if ($page->isPostBack()) { $cfg->doCheck = true; - $cfg->nZEDb_SSL_CAFILE = trim($_POST['cafile']); - $cfg->nZEDb_SSL_CAPATH = trim($_POST['capath']); - $cfg->nZEDb_SSL_VERIFY_PEER = (isset($_POST['verifypeer']) ? (trim($_POST['verifypeer']) == '1' ? true : false) : false); - $cfg->nZEDb_SSL_VERIFY_HOST = (isset($_POST['verifyhost']) ? (trim($_POST['verifyhost']) == '1' ? true : false) : false); - $cfg->nZEDb_SSL_ALLOW_SELF_SIGNED = (isset($_POST['allowselfsigned']) ? (trim($_POST['allowselfsigned']) == '1' ? true : false) : false); + $cfg->NN_SSL_CAFILE = trim($_POST['cafile']); + $cfg->NN_SSL_CAPATH = trim($_POST['capath']); + $cfg->NN_SSL_VERIFY_PEER = (isset($_POST['verifypeer']) ? (trim($_POST['verifypeer']) == '1' ? true : false) : false); + $cfg->NN_SSL_VERIFY_HOST = (isset($_POST['verifyhost']) ? (trim($_POST['verifyhost']) == '1' ? true : false) : false); + $cfg->NN_SSL_ALLOW_SELF_SIGNED = (isset($_POST['allowselfsigned']) ? (trim($_POST['allowselfsigned']) == '1' ? true : false) : false); // If the user doesn't want to verify peer, disable everything. - if (!$cfg->nZEDb_SSL_VERIFY_PEER) { - $cfg->nZEDb_SSL_ALLOW_SELF_SIGNED = true; - $cfg->nZEDb_SSL_VERIFY_HOST = false; - $cfg->nZEDb_SSL_CAFILE = $cfg->nZEDb_SSL_CAPATH = ''; + if (!$cfg->NN_SSL_VERIFY_PEER) { + $cfg->NN_SSL_ALLOW_SELF_SIGNED = true; + $cfg->NN_SSL_VERIFY_HOST = false; + $cfg->NN_SSL_CAFILE = $cfg->NN_SSL_CAPATH = ''; } // If both paths are empty, disable everything. - if (!$cfg->nZEDb_SSL_CAPATH && !$cfg->nZEDb_SSL_CAFILE) { - $cfg->nZEDb_SSL_VERIFY_PEER = $cfg->nZEDb_SSL_VERIFY_HOST = false; - $cfg->nZEDb_SSL_ALLOW_SELF_SIGNED = true; - $cfg->nZEDb_SSL_CAFILE = $cfg->nZEDb_SSL_CAPATH = ''; + if (!$cfg->NN_SSL_CAPATH && !$cfg->NN_SSL_CAFILE) { + $cfg->NN_SSL_VERIFY_PEER = $cfg->NN_SSL_VERIFY_HOST = false; + $cfg->NN_SSL_ALLOW_SELF_SIGNED = true; + $cfg->NN_SSL_CAFILE = $cfg->NN_SSL_CAPATH = ''; } // Make sure the files and all paths are readable. - if ($cfg->nZEDb_SSL_CAFILE != '') { - if (!checkPathsReadable($cfg->nZEDb_SSL_CAFILE)) { + if ($cfg->NN_SSL_CAFILE != '') { + if (!checkPathsReadable($cfg->NN_SSL_CAFILE)) { $cfg->error = 'Invalid ca file path or it is not readable or the folders up to it are not readable.'; } else if (1) { } } - if ($cfg->nZEDb_SSL_CAPATH != '' && !checkPathsReadable($cfg->nZEDb_SSL_CAPATH)) { + if ($cfg->NN_SSL_CAPATH != '' && !checkPathsReadable($cfg->NN_SSL_CAPATH)) { $cfg->error = 'Invalid ca folder path or it is not readable or the folders up to it are not readable.'; } diff --git a/www/install/step7.php b/www/install/step7.php index aae2da541..a19b8be10 100755 --- a/www/install/step7.php +++ b/www/install/step7.php @@ -29,9 +29,9 @@ if ($page->isPostBack()) { if (extension_loaded('posix') && strtolower(substr(PHP_OS, 0, 3)) !== 'win') { $group = posix_getgrgid(posix_getgid()); - $fixString = '

Another solution is to run:
chown -R YourUnixUserName:' . $group['name'] . ' ' . nZEDb_ROOT . + $fixString = '

Another solution is to run:
chown -R YourUnixUserName:' . $group['name'] . ' ' . NN_ROOT . '
Then give your user access to the group:
usermod -a -G ' . $group['name'] . ' YourUnixUserName' . - '
Finally give read/write access to your user/group:
chmod -R 774 ' . nZEDb_ROOT; + '
Finally give read/write access to your user/group:
chmod -R 774 ' . NN_ROOT; $page->smarty->assign('fixString', $fixString); } @@ -89,11 +89,11 @@ if ($page->isPostBack()) { } if ($cfg->error !== true) { - if ($cfg->COVERS_PATH != nZEDb_WWW . 'covers' . DS) { + if ($cfg->COVERS_PATH != NN_WWW . 'covers' . DS) { // TODO clean up old covers location if 'empty' (i.e. only contains the versioned files). } - if ($cfg->NZB_PATH != nZEDb_ROOT . 'nzbfiles' . DS) { + if ($cfg->NZB_PATH != NN_ROOT . 'nzbfiles' . DS) { // TODO clean up old nzbfiles location if 'empty' (i.e. only contains the versioned files). } } diff --git a/www/install/templates/step3.tpl b/www/install/templates/step3.tpl index 2a37238bc..c141b68d4 100755 --- a/www/install/templates/step3.tpl +++ b/www/install/templates/step3.tpl @@ -20,7 +20,7 @@ - +
Location of Certificate Authority file on local filesystem which will be used if the Verify Peer option is enabled to authenticate the identity of the remote peer.
Example: /etc/ssl/certs/cacert.pem @@ -30,7 +30,7 @@ - +
If the ca bundle cert file is not specified or if the certificate is not found there, you can specify a directory here which will be searched for a suitable certificate.
Example: /etc/ssl/certs/
@@ -39,7 +39,7 @@ - nZEDb_SSL_VERIFY_PEER=="true"}checked="checked"{/if} /> + NN_SSL_VERIFY_PEER=="true"}checked="checked"{/if} />
Enabling this requires the ca bundle cert file path to be set.
Disabling this will disable TLS/SSL remote certificate verification which is not recommended. @@ -49,7 +49,7 @@ - nZEDb_SSL_VERIFY_HOST=="true"}checked="checked"{/if} /> + NN_SSL_VERIFY_HOST=="true"}checked="checked"{/if} />
This makes sure the host is who they say they are.
See this link for detailed info.
@@ -61,7 +61,7 @@ - nZEDb_SSL_ALLOW_SELF_SIGNED=="true"}checked="checked"{/if} /> + NN_SSL_ALLOW_SELF_SIGNED=="true"}checked="checked"{/if} />
Enabling this will not verify self-signed openssl certificates.
Note that you will require non self-signed certificates for sabnzbd/nzbget/etc if you disable this. @@ -79,4 +79,4 @@
-{/if} \ No newline at end of file +{/if} diff --git a/www/install/templates/step5.tpl b/www/install/templates/step5.tpl index 19066c02c..7def0e790 100755 --- a/www/install/templates/step5.tpl +++ b/www/install/templates/step5.tpl @@ -4,8 +4,8 @@
{else} {if !$cfg->saveConfigCheck} -

Error saving {$cfg->nZEDb_WWW}/config.php.

-

Please save the config.php yourself by creating:
{$cfg->nZEDb_WWW}/config.php
and setting its contents to the following:

+

Error saving {$cfg->NN_WWW}/config.php.

+

Please save the config.php yourself by creating:
{$cfg->NN_WWW}/config.php
and setting its contents to the following:

{/if} {if !$cfg->saveLockCheck} diff --git a/www/pages/InstallPage.php b/www/pages/InstallPage.php new file mode 100755 index 000000000..59399ceb3 --- /dev/null +++ b/www/pages/InstallPage.php @@ -0,0 +1,50 @@ +smarty = new Smarty(); + + $this->smarty->setTemplateDir(realpath('../install/templates/')); + $this->smarty->setCompileDir(NN_RES . 'smarty/templates_c/'); + $this->smarty->setConfigDir(NN_RES . 'smarty/configs/'); + $this->smarty->setCacheDir(NN_RES . 'smarty/cache/'); + } + + public function addToHead($headcontent) + { + $this->head = $this->head . "\n" . $headcontent; + } + + public function render() + { + $this->page_template = "installpage.tpl"; + $this->smarty->display($this->page_template); + } + + public function isPostBack() + { + return (strtoupper($_SERVER["REQUEST_METHOD"]) === "POST"); + } + + public function isSuccess() + { + return isset($_GET['success']); + } +}