function login_POST(Web &$w) { if ($_POST['login'] && $_POST['password']) { $client_timezone = "Australia/Sydney"; //$_POST['user_timezone']; $user = $w->Auth->login($_POST['login'], $_POST['password'], $client_timezone); if ($user) { if ($w->session('orig_path') != "auth/login") { $url = $w->session('orig_path'); $w->Log->debug("Original path: " . $url); // If no url specified, go to the users defined url if (empty($url) || $url == "/") { $url = $user->redirect_url; } $w->sessionUnset('orig_path'); $w->redirect($w->localUrl($url)); } else { $w->redirect(!empty($user->redirect_url) ? $w->localUrl($user->redirect_url) : $w->localUrl()); } } else { $w->error("Login or Password incorrect", "/auth/login"); } } else { $w->error("Please enter your login and password", "/auth/login"); } }
function logout_GET(Web &$w) { if ($w->Auth->loggedIn()) { // Unset all of the session variables. $w->sessionDestroy(); } $w->redirect($w->localUrl("/auth/login")); }
/** * This function is called AFTER the action was executed * * @param unknown $w */ function example_listener_POST_ACTION(Web $w) { // you can find out which objects have changed $updated = $w->ctx("db_updated"); // returns array("classname" => array($id1, $id2, ..), ..); $deleted = $w->ctx("db_deleted"); // returns array("classname" => array($id1, $id2, ..), ..); $inserts = $w->ctx("db_inserts"); // returns array("classname" => array($id1, $id2, ..), ..); // you can redirect the request.. but maybe you shouldn't! $w->redirect("/main"); }
function forgotpassword_GET(Web $w) { // Check if logged in already $user = $w->Auth->user(); if ($w->Auth->loggedIn() && $w->Auth->allowed($user->redirect_url)) { $w->redirect($w->localUrl(!empty($user->redirect_url) ? $user->redirect_url : "/main")); } // $loginform = Html::form(array( // array("Reset Password","section"), // array("Your Login","text","login"), // ),$w->localUrl("auth/forgotpassword"),"POST","Reset"); // $w->out($loginform); $w->ctx("pagetitle", "Forgot Password"); }
function index_ALL(Web $w) { $p = $w->pathMatch("install", "step", "step_number"); if (empty($p['install'])) { $w->redirect('install/step/1'); } $step = $p['step_number']; $w->ctx("step", $step); $w->ctx("form_action", "/install/step/" + ($step + 1)); if ($step == 2) { if (!empty($_POST)) { $config =& $_POST; $port = isset($config['db_port']) && !empty($config['db_port']) ? ";port=" . $config['db_port'] : ""; $url = "{$config['db_driver']}:host={$config['db_hostname']}{$port}"; try { $pdo = new PDO($url, $config['db_username'], $config['db_password']); } catch (PDOException $e) { $w->ctx('error', "Couldn't connect to the database!<br />" . $e->getMessage()); return; } $w->ctx('info', 'Successfully connected to database'); $sql = 'SHOW databases;'; $databases = array(); foreach ($pdo->query($sql) as $row) { if ($row['0'] != 'information_schema') { $databases[$row[0]] = array(); } } foreach ($databases as $database => $tables) { $pdo->exec("USE {$database};"); foreach ($pdo->query('SHOW TABLES;') as $row) { $databases[$database][] = $row[0]; } } $w->ctx('databases', $databases); } } else { if ($step == 3) { if (!empty($_POST)) { $config =& $_POST; $port = isset($config['db_port']) && !empty($config['db_port']) ? ";port=" . $config['db_port'] : ""; $url = "{$config['db_driver']}:dbname={$config['db_database']};host={$config['db_hostname']}{$port}"; try { $pdo = new PDO($url, $config['db_username'], $config['db_password']); } catch (PDOException $e) { $w->ctx('error', "Couldn't connect to the database!<br />" . $e->getMessage()); return; } //Make sure database is empty... $sql = 'SHOW TABLES;'; foreach ($pdo->query($sql) as $row) { $pdo->exec("DROP TABLE {$row[0]};"); } $pdo->exec(file_get_contents('system/install/db.sql')); foreach (glob('system/install/updates/*.sql') as $file) { $pdo->exec(file_get_contents($file)); } $pdo->exec(file_get_contents('system/install/dbseed.sql')); $pdo->exec(file_get_contents('system/install/userscontactsroles.sql')); $w->ctx('info', 'Database tables successfully imported'); } } else { if ($step == 4) { $tpl = new WebTemplate(); $tpl->set_vars($_POST); $config = "<?php\n"; $config .= $tpl->fetch('system/modules/install/templates/config.tpl.php'); file_put_contents('config.php', $config); } } } }
$this->response->status($code); $this->response->headers->set("Content-Type", "application/json"); echo json_encode(array("errors" => array($err))); } function authed() { return isset($_SESSION["adminid"]); } } $app = new Web(array("debug" => false)); $app->add(new Slim\Middleware\ContentTypes()); $app->notFound(function () use($app) { echo "Requested resource not found"; }); $app->get("/", function () use($app) { $app->redirect("/"); }); $app->get("/plans", function () use($app) { if (!$app->authed()) { $app->makeError("Access denied"); return; } $qres = mysql_query("SELECT * FROM `tblproducts` p WHERE p.`type` IN ( 'hostingaccount','reselleraccount') and p.`configoption1` != '' and p.`servertype` = 'cpanel';"); if ($qres === FALSE) { $app->makeError("Unable to get the list of hosting packages"); return; } $plans = array(); while (($row = mysql_fetch_assoc($qres)) !== FALSE) { $plans[] = array("id" => intval($row["id"]), "label" => $row["name"], "description" => $row["description"], "name" => $row["configoption1"], "limits" => array("ftp" => intval($row["configoption2"]), "disk" => intval($row["configoption3"]), "email" => intval($row["configoption4"]), "bandwidth" => intval($row["configoption5"]), "dedicated_ip" => onoffval($row["configoption6"]), "ssh" => onoffval($row["configoption7"]), "databases" => intval($row["configoption8"]), "cgi" => onoffval($row["configoption9"]), "subdomains" => intval($row["configoption10"]), "frontpage" => onoffval($row["configoption11"]), "parked" => intval($row["configoption12"]), "addon" => intval($row["configoption14"]), "overage" => strval($row["overagesenabled"][0]) === "1")); }