diff --git a/Changelog b/Changelog index 78a42bc6e..4cc414e45 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2017-08-09 DariusIII + * Chg: Add maintenance mode with custom page displayed * Chg: Add UserRequest model and use it in Users class * Chg: Update jquery-goup to latest version * Chg: Remove confusing error message from sendEmail function diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index 1ff814c38..71358b46f 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -4,9 +4,11 @@ require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'nntmux' . DIRECTORY_SEPAR require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'nntmux' . DIRECTORY_SEPARATOR . 'bootstrap.php'; require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'nntmux.php'; require_once __DIR__ . DIRECTORY_SEPARATOR . 'yenc.php'; +require __DIR__ . DIRECTORY_SEPARATOR . 'app.php'; use Dotenv\Dotenv; +use Illuminate\Contracts\Console\Kernel; $dotenv = new Dotenv(dirname(__DIR__, 1)); $dotenv->load(); @@ -20,3 +22,5 @@ if (!defined('NN_ROOT')) { } require_once NN_ROOT . DS . 'vendor' . DS . 'autoload.php'; + +$app->make(Kernel::class)->bootstrap(); diff --git a/public/index.php b/public/index.php index 25bf6a3e2..3c370fcb9 100644 --- a/public/index.php +++ b/public/index.php @@ -5,6 +5,9 @@ use App\Models\Settings; $page = new Page; +if ($app->isDownForMaintenance()) { + $page->showMaintenance(); +} switch ($page->page) { case 'ajax_mediainfo': diff --git a/public/pages/BasePage.php b/public/pages/BasePage.php index afdc674af..1d9c71d4a 100644 --- a/public/pages/BasePage.php +++ b/public/pages/BasePage.php @@ -4,8 +4,8 @@ require_once NN_LIB . 'utility' . DS . 'SmartyUtils.php'; use App\Models\Settings; use nntmux\db\DB; -use nntmux\Users; use nntmux\SABnzbd; +use nntmux\Users; class BasePage { @@ -37,6 +37,7 @@ class BasePage /** * Current page the user is browsing. ie browse + * * @var string */ public $page = ''; @@ -45,24 +46,28 @@ class BasePage /** * User settings from the MySQL DB. + * * @var array|bool */ public $userdata = []; /** * URL of the server. ie http://localhost/ + * * @var string */ public $serverurl = ''; /** * Whether to trim white space before rendering the page or not. + * * @var bool */ public $trimWhiteSpace = true; /** * Is the current session HTTPS? + * * @var bool */ public $https = false; @@ -107,9 +112,10 @@ class BasePage $this->smarty->setConfigDir(NN_SMARTY_CONFIGS); $this->smarty->setCacheDir(NN_SMARTY_CACHE); $this->smarty->setPluginsDir([ - NN_WWW . 'plugins/', - SMARTY_DIR . 'plugins/', - ]); + NN_WWW . 'plugins/', + SMARTY_DIR . 'plugins/', + ] + ); $this->smarty->error_reporting = (NN_DEBUG ? E_ALL : E_ALL - E_NOTICE); if (isset($_SERVER['SERVER_NAME'])) { @@ -211,7 +217,7 @@ class BasePage */ public function addToHead($headcontent): void { - $this->head = $this->head."\n".$headcontent; + $this->head = $this->head . "\n" . $headcontent; } /** @@ -221,7 +227,7 @@ class BasePage */ public function addToBody($attr): void { - $this->body = $this->body. ' ' .$attr; + $this->body = $this->body . ' ' . $attr; } /** @@ -296,14 +302,67 @@ class BasePage ); } + /** + * Show maintenance page. + * + */ + public function showMaintenance(): void + { + header('HTTP/1.1 503 Service Temporarily Unavailable'); + die(' + + + Be right back. + + + + + + +
+
+
We are currently having an maintenance. Please try later!
+
+
+ + ' + ); + } + /** * @param string $retry */ - public function show429($retry=''): void + public function show429($retry = ''): void { header('HTTP/1.1 429 Too Many Requests'); if ($retry !== '') - header('Retry-After: '.$retry); + header('Retry-After: ' . $retry); echo ' @@ -314,7 +373,7 @@ class BasePage

Too Many Requests

-

Wait ' .(($retry !== '') ? ceil($retry/60) . ' minutes ' : '') . 'or risk being temporarily banned.

+

Wait ' . (($retry !== '') ? ceil($retry / 60) . ' minutes ' : '') . 'or risk being temporarily banned.

'; @@ -354,8 +413,8 @@ class BasePage $this->users->updateSiteAccessed($this->userdata['id']); } - $this->smarty->assign('userdata',$this->userdata); - $this->smarty->assign('loggedin',"true"); + $this->smarty->assign('userdata', $this->userdata); + $this->smarty->assign('loggedin', "true"); if ($this->userdata['nzbvortex_api_key'] !== '' && $this->userdata['nzbvortex_server_url'] !== '') { $this->smarty->assign('weHasVortex', true); @@ -393,7 +452,8 @@ class BasePage if (strpos($setting, '.') === false) { trigger_error( 'You should update your template to use the newer method "$page->getSettingValue()"" of fetching values from the "settings" table! This method *will* be removed in a future version.', - E_USER_WARNING); + E_USER_WARNING + ); } else { return $this->getSettingValue($setting); }