public function get($stat) { if ($stat != "connections" && $stat != "ips") { return new Response(200, "Bad Arguments"); } return Paladin::config("stats")->get($stat); }
/** * Loads all, and redirect the user */ public function start() { // Starting the session session_start(); // If the user is logged if (isset($_SESSION["logged"]) && $_SESSION["logged"] == true) { // If the current route is 'Login' if (\Paladin\Paladin::getRouteLoader()->getCurrentRoute()['name'] == "Login") { // Redirecting him to the index header("Location: " . \Paladin\Paladin::getRootFolder()); } else { // Loading the route, normally \Paladin\Paladin::getRouteLoader()->loadRoute(); } } else { // If the current route isn't in the authorized page list if (!$this->isAuthorized(\Paladin\Paladin::getRouteLoader()->getCurrentRoute()['name'])) { // Redirecting it header("Location: " . \Paladin\Paladin::getRootFolder() . "Login"); } else { // Loading the route, normally \Paladin\Paladin::getRouteLoader()->loadRoute(); } } }
public function postLogin() { if (isset($_POST["password"]) && sha1($_POST["password"]) == Paladin::config("server")->get("password")) { $_SESSION["logged"] = true; return new RedirectResponse("../panel/home"); } else { return Paladin::view("login.twig", array("error" => true, "serverActivated" => Paladin::config("server")->get("enabled"))); } }
public function postPanel($request) { if ($request == "settings") { if (isset($_POST["password"])) { Paladin::config("server")->set("password", sha1($_POST["password"])); return new RedirectResponse("home"); } } return new RedirectResponse("home"); }
public function postInstall() { if (isset($_POST["password"])) { Paladin::config("server")->set("enabled", false); Paladin::config("server")->set("password", sha1($_POST["password"])); Paladin::config("stats")->set("connections", 0); Paladin::config("stats")->set("ips", []); return new RedirectResponse("panel/home"); } return new Response("Argument fail", 500); }
public function onCalling($args) { // Getting the Paladin version $paladinVersion = file_get_contents("paladin.version"); // Getting the Twig version $twigVersion = "1.18"; // Getting the S-Update-Server version $serverVersion = file_get_contents("s-update-server.version"); // Getting the server state $serverEnabled = \SUpdateServer\ServerState::isEnabled(); // Displaying the index page \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "Index", array("paladinVersion" => $paladinVersion, "serverVersion" => $serverVersion, "serverEnabled" => $serverEnabled)); }
public function postServer($request) { header("Content-Type: application/json"); switch ($request) { case "is-enabled": return new JsonResponse(array("enabled" => (bool) Paladin::config("server")->get("enabled"))); case "size": return $this->size(); case "version": return new JsonResponse(array("version" => SUpdateServer::SERVER_VERSION)); } return new Response("Unknown request"); }
public function load() { Paladin::getRouter()->get("/get-ignore-list", function () { // Creating the ignore list $ignoreList = array(); // Reading the ignore list $file = fopen(self::IGNORE_LIST_FILES, "a+"); while (($line = fgets($file)) !== false) { $ignoreList[sizeof($ignoreList)] = trim($line); } fclose($file); return new JsonResponse($ignoreList); }); }
public function onCalling($args) { // Getting the super folder while it ends with .. while (isset($args[sizeof($args)]) && $args[sizeof($args)] == "..") { unset($args[sizeof($args) - 1]); unset($args[sizeof($args) - 1]); // Then redirecting $redirect = true; } // Getting the path to explore $path = ""; if (sizeof($args) > 0) { foreach ($args as $f) { $path .= $f . "/"; } } else { $path = "files/"; $redirect = true; } // Replacing the // $path = str_replace("//", "/", $path); // Deleting the last / $path = substr($path, 0, strlen($path) - 1); // Redirecting if needed if (isset($redirect) && $redirect) { header("Location: " . \Paladin\Paladin::getRootFolder() . "FileExplorer/" . $path); return; } // If it doesn't exist redirecting the the main explorer if (!file_exists($path)) { header("Location: " . \Paladin\Paladin::getRootFolder() . "FileExplorer"); return; } // If it is not a directory if (!is_dir($path)) { header("Content-Type: application/force-download; name=\"" . basename($path) . "\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($path)); header("Content-Disposition: attachment; filename=\"" . basename($path) . "\""); header("Expires: 0"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); readfile($path); return; } // Then displaying the page \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "FileExplorer", array("path" => $path, "files" => self::scan($path), "root" => \Paladin\Paladin::getRootFolder())); }
private function checkFormResponse() { // If the password/laguage aren't given if (!isset($_POST["password"]) || !isset($_POST["language"])) { // Displaying the install page \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "Install", array()); } else { // Seting the user logged $_SESSION["logged"] = true; // Saving the config file_put_contents(\SUpdateServer\SessionManager::getSessionManager()->getPasswordLocation(), sha1($_POST["password"])); \SUpdateServer\LangLoader\LangLoader::getLangLoader()->setCurrentLang($_POST["language"]); // Redirecting the user header("Location: " . \Paladin\Paladin::getRootFolder()); } }
public function onCalled($route) { $isInstallPage = trim($route->getPath(), '/') == "install"; $isServerInstalled = file_exists("config/server.json"); if ($isInstallPage) { if ($isServerInstalled) { return new RedirectResponse(Paladin::getRootPath(true) . "panel"); } else { return false; } } else { if ($isServerInstalled) { return false; } else { return new RedirectResponse(Paladin::getRootPath(true) . "install"); } } }
private function checkFormResponse() { // If the password isn't given if (!isset($_POST["password"])) { // Displaying the login page \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "Login", array("badPassword" => false, "serverActivated" => \SUpdateServer\ServerState::isEnabled())); } else { if (\SUpdateServer\SessionManager::getSessionManager()->checkPassword($_POST["password"])) { // Seting the user logged $_SESSION["logged"] = true; // Going to the index page header("Location: " . \Paladin\Paladin::getRootFolder()); } else { // Displaying the login page, with a bad password message \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "Login", array("badPassword" => true, "serverActivated" => \SUpdateServer\ServerState::isEnabled())); } } }
public function onCalled($route) { $isLoginPage = trim($route->getPath(), '/') == "auth/login"; $isUserLogged = isset($_SESSION["logged"]) && $_SESSION["logged"] == true; if ($isLoginPage) { if ($isUserLogged) { return new RedirectResponse(Paladin::getRootPath(true) . "/panel"); } else { return false; } } else { if ($isUserLogged) { return false; } else { return new RedirectResponse(Paladin::getRootPath(true) . "auth/login"); } } }
/** * Start the server */ public static function start() { // Initializing session session_start(); // Setting up error handling PaladinErrorHandler::setErrorPageLocation("views/ErrorPage.html"); // Setting up debug if needed if (Paladin::config("app")->get("debug")) { $engine = Paladin::getViewingEngineManager()->getSelectedEngine(); if (get_class($engine) == 'Paladin\\Viewing\\TwigViewingEngine') { $engine->getTwig()->enableAutoReload(); $engine->getTwig()->enableDebug(); } } // Initializing CheckMethodLoader::create(); AppLoader::create(); // Creating files folder if needed if (!file_exists("files/")) { mkdir("files/"); } }
public function checkFormResponse() { // If the form variable exist if (isset($_POST["form"])) { // If the form is the password form if ($_POST["form"] == "passwordForm") { // If the password variable exist if (isset($_POST["password"])) { // Writing it file_put_contents(\SUpdateServer\SessionManager::getSessionManager()->getPasswordLocation(), sha1($_POST["password"])); // Then redirecting the user header("Location: Index"); } else { // Displaying the settings page \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "Settings", array()); } } else { if ($_POST["form"] == "langForm") { // If the language variable exist if (isset($_POST["language"])) { // Setting it \SUpdateServer\LangLoader\LangLoader::getLangLoader()->setCurrentLang($_POST["language"]); // Then redirecting the user header("Location: Index"); } else { // Displaying the settings page \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "Settings", array()); } } else { // Displaying the settings page \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "Settings", array()); } } } else { // Displaying the settings page \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "Settings", array()); } }
use Paladin\Http\RedirectResponse; use Paladin\Http\Response; use Paladin\Paladin; use SUpdateServer\SUpdateServer; $this->get("/", function () { return new RedirectResponse(Paladin::getRootPath(true) . "panel"); }); $this->get("/panel", function () { return new RedirectResponse(Paladin::getRootPath(true) . "panel/home"); }); $this->get("/panel/:request", ["middleware" => ["install", "auth"], "uses" => "PanelController@getPanel"]); $this->post("/panel/:request", ["middleware" => ["install", "auth"], "uses" => "PanelController@postPanel"]); $this->get("/aubergine", function () { return new RedirectResponse("http://www.google.fr/search?q=aubergine"); }); $this->get("/auth/logout", ["middleware" => ["install", "auth"], "uses" => "AuthController@logout"]); $this->get("/auth/login", ["middleware" => ["install", "auth"], "uses" => "AuthController@getLogin"]); $this->post("/auth/login", ["middleware" => ["install"], "uses" => "AuthController@postLogin"]); // Internal routes $this->get("/set-enabled/:enabled", ["middleware" => ["install", "auth"], "uses" => function ($enabled) { Paladin::config("server")->set("enabled", $enabled == "true"); return new Response(); }]); $this->get("/install", ["middleware" => "install", "uses" => "InstallController@getInstall"]); $this->post("/install", ["middleware" => "install", "uses" => "InstallController@postInstall"]); $this->post("/server/:request", "ServerController@postServer"); $this->post("/server/list/:checkmethod", "ServerController@listFiles"); $this->post("/server/check/:thing/:what", "ServerController@check"); $this->post("/stats/clear/:stat", ["middleware" => "auth", "uses" => "StatsController@clear"]); $this->post("/stats/update", ["middleware" => "auth", "uses" => "StatsController@update"]); $this->post("/stats/get/:stat", "StatsController@get");
<?php /* * Copyright 2015-2016 Adrien Navratil * * This file is part of S-Update-Server. * * S-Update-Server is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * S-Update-Server is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with S-Update-Server. If not, see <http://www.gnu.org/licenses/>. */ use Paladin\Paladin; use Paladin\ErrorHandling\PaladinErrorHandler; use Paladin\Viewing\ViewingEngineManager; try { Paladin::start(array("configFolder" => "config", "sourceFolder" => "src", "controllerFolder" => "Controllers", "middlewareFolder" => "Middlewares", "modelFolder" => "Models", "resourceFolder" => "resources", "viewFolder" => "views", "mainEngine" => "twig"), function () { \SUpdateServer\SUpdateServer::start(); }); } catch (\Exception $e) { PaladinErrorHandler::displayErrorPage("Exception caught ! " . get_class($e), $e->getMessage(), PaladinErrorHandler::generateBacktrace($e->getTrace())); }
/** * Display an error page * * @param errorType * The type of the error * @param errorDescription * The description of the error * @param errorBacktrace * The backtrace of the error */ public static function displayErrorPage($errorType, $errorDescription, $errorBacktrace) { // Getting the error page $errorPage = file_get_contents(self::$errorPageLocation); // Replacing the variables, with the messages, the title, etc... $errorPage = str_replace("__ROOT_DIR__", \Paladin\Paladin::getRootFolder(), $errorPage); $errorPage = str_replace("__MESSAGE__", $errorDescription, $errorPage); $errorPage = str_replace("__TITLE__", $errorType, $errorPage); $errorPage = str_replace("__BG_LOCATION__", \Paladin\Paladin::getRootFolder() . \Paladin\PaladinTwigExtension::getFile("shared", "background.png", true, "resources"), $errorPage); if (function_exists('debug_backtrace')) { $errorPage = str_replace("<!-- __BACKTRACE__ -->", $errorBacktrace, $errorPage); } // Then diplaying it echo $errorPage; }
public function onCalling($args) { \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "Dashboard", array(\SUpdateServer\Dashboard\DashboardManager::getEntries())); }
public function onCalling($args) { \Paladin\Paladin::getPageLoader()->displayPage("\\SUpdateServer\\Pages", "About", array("serverVersion" => file_get_contents("s-update-server.version"))); }
/** * The icon of the entry */ public function getIcon() { return \Paladin\Paladin::getRootFolder() . \Paladin\PaladinTwigExtension::getFile("Dashboard", "images/fileexplorer.png", true, "resources"); }
public function beforeDisplayed() { if (\SUpdateServer\ServerState::isEnabled() == false) { header("Location: " . \Paladin\Paladin::getRootFolder()); } }
/** * Loads the applications */ private function loadApps() { // Getting the files in the applications folder $apps = scandir($this->folder); // For each file in the folder for ($i = 0; $i < count($apps); $i++) { // If it is the current/parent folder if (trim($apps[$i]) == "." || trim($apps[$i]) == "..") { // Continuing the loop continue; } // If it is a directory if (is_dir($this->folder . "/" . $apps[$i])) { // Getting the application main class path $appMainClassPath = $this->folder . "/" . $apps[$i] . "/" . $apps[$i] . ".php"; // If it doesn't exists if (!file_exists($appMainClassPath)) { // Displaying an error page \Paladin\Paladin::getPageLoader()->displayPage("\\Paladin\\Pages", "ErrorPage", array("Application mistake", "Sorry ! We can't find the main class of the application : " . $apps[$i] . " ( file needed : " . $appMainClassPath . ") !")); // Stopping die; } // Loading it require $appMainClassPath; // Getting the app php name $appPhpName = "\\SUpdateServer\\Applications\\" . $apps[$i]; // Instancing it $app = new $appPhpName(); // If it is not an Application if (!$app instanceof Application) { // Displaying an error page \Paladin\Paladin::getPageLoader()->displayPage("\\Paladin\\Pages", "ErrorPage", array("Application mistake", "Sorry ! The Application " . $apps[$i] . " main class is not extending \\SUpdateServer\\AppLoader\\Application but need to !")); // Stopping die; } // Executing the preLoad event $app->preLoad(); // Adding its route folder to the Route Loader \Paladin\Paladin::getRouteLoader()->addFolder($this->folder . "/" . $apps[$i] . "/Routes/"); // Creating its Page Loader $app->setPageLoader(new \Paladin\PageLoader($this->folder . "/" . $apps[$i] . "/Pages/")); // Executing the load event $app->load(); // Adding it to the list $this->apps[sizeof($this->apps)] = $app; } } }
/** * Loads the check methods */ private function loadCheckMethods() { // Getting the files in the check methods folder $checkMethods = scandir($this->folder); // For each file in the folder for ($i = 0; $i < count($checkMethods); $i++) { // If it is the current/parent folder, or it is .htaccess if (trim($checkMethods[$i]) == "." || trim($checkMethods[$i]) == ".." || trim($checkMethods[$i]) == ".htaccess") { // Continuing the loop continue; } // Getting the check method path $checkMethodPath = $this->folder . "/" . $checkMethods[$i]; // If it is a directory if (is_dir($checkMethodPath)) { // Continuing the loop continue; } // Loading it require $checkMethodPath; // Getting the class path $classPath = '\\SUpdateServer\\Checking\\' . substr($checkMethods[$i], 0, strlen($checkMethods[$i]) - 4); // Instancing it $checkMethod = new $classPath(); // If it is not an CheckMethod if (!$checkMethod instanceof CheckMethod) { // Displaying an error page \Paladin\Paladin::getPageLoader()->displayPage("\\Paladin\\Pages", "ErrorPage", array("CheckMethod mistake", "Sorry ! The CheckMethod " . $checkMethods[$i] . " main class is not extending \\SUpdateServer\\AppLoader\\CheckLoader but need to !")); // Stopping die; } // Adding it to the list $this->checkMethods[sizeof($this->checkMethods)] = $checkMethod; } }