diff --git a/registration-system/admin/commons_admin.php b/registration-system/admin/commons_admin.php new file mode 100644 index 0000000000000000000000000000000000000000..2da001fdcba159037f0404217d8c5b67fde38317 --- /dev/null +++ b/registration-system/admin/commons_admin.php @@ -0,0 +1,71 @@ +<?php + +require_once("../config.inc.php"); + +function generateNavigationItems($page, $menu) +{ + $text = ''; + foreach($menu as $name => $page) + { + $text .= "<a href='?page=$page'>$name</a>"; + } + return $text; +} + +function checkIfLogin() +{ + if(!isset($_POST['user']) || !isset($_POST['password'])) + return; + + $user = $_POST['user']; + $password = $_POST['password']; + + if (isValidUser($user, $password)) + setLoggedIn($user); +} + +function isValidUser($user, $password) +{ + global $config_admins; + foreach($config_admins as $cfg_user => $cfg_password) + { + if ($cfg_user != $user) + continue; + + if ($cfg_password[0] == '{') + { + if (strpos($cfg_password, "{SHA254}") >= 0) + { + $beginOfSalt = strpos($cfg_password, "$"); + $salt = substr($cfg_password, 9, strpos($cfg_password, "$") - 9); + $hash = substr($cfg_password, $beginOfSalt + 1); + + if (hash('sha256', $password . $salt) == $hash) + return true; + } + } + else + { + // TODO: ONLY sha256 yet, others not implemented + } + } + return false; +} + +function isLoggedIn() +{ + return isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] != ''; +} + +function setLoggedIn($user) +{ + if ($user != "") + $_SESSION['loggedIn'] = $user; + else + { + session_destroy(); + header("location: .."); + } +} + + diff --git a/registration-system/admin/index.php b/registration-system/admin/index.php new file mode 100644 index 0000000000000000000000000000000000000000..a4231700d14b36857cccd5990bbda233a5951cf9 --- /dev/null +++ b/registration-system/admin/index.php @@ -0,0 +1,51 @@ +<?php +/** + * Created by PhpStorm. + * User: it + * Date: 8/8/14 + * Time: 4:19 PM + */ + +session_start(); +require_once("commons_admin.php"); +require_once("pages.php"); + +$template = file_get_contents("../view/admin_template.html"); +$navigation = ""; +$text = ""; + +checkIfLogin(); + +if (isLoggedIn()) +{ + $menu = array( + "Ãœbersicht" => "stuff", + "Meldeliste" => "list", + "Kosten" => "cost", + "Rundmail" => "mail" + ); + + $page = isset($_GET['page']) ? $_GET['page'] : ""; + $navigation = generateNavigationItems($page, $menu); + + switch($page) + { + case "": + case "stuff": + page_stuff(); break; + case "list": + page_list(); break; + //case "cost": + //page_cost(); break; + //case "mail": + //page_mail(); break; + default: + page_404(); + } +} +else +{ + $text .= file_get_contents("../view/admin_login_form.html"); +} + +echo str_replace("{text}", $text, str_replace("{navigation}", $navigation, $template)); \ No newline at end of file diff --git a/registration-system/admin/pages.php b/registration-system/admin/pages.php new file mode 100644 index 0000000000000000000000000000000000000000..05ff2b8c8013e733efbaf89fac576a59b361d780 --- /dev/null +++ b/registration-system/admin/pages.php @@ -0,0 +1,21 @@ +<?php + +function page_stuff() +{ + global $text; + $text .= "Ãœbersichtsseite"; +} + +function page_list() +{ + global $text; + $text .= "Meldeliste"; +} + +function page_404() +{ + global $text; + $text .= "404 Seite nicht gefunden..."; +} + +?> \ No newline at end of file diff --git a/registration-system/config.inc.php b/registration-system/config.inc.php index ecfb0215d744cef810e7dca47d552ef50dea17fb..ac97684506d9ffe0e2f3acb59e9b50396ce54c13 100644 --- a/registration-system/config.inc.php +++ b/registration-system/config.inc.php @@ -41,6 +41,7 @@ $config_reisearten = array( $config_admins = array( // username => password "george" => "peter", - "tim" => "meter" + "tim" => "meter", + "manu" => '{SHA-256}12c9b021c42741545f9f01e2afd67aa2$7112be28c0c11f987de4401798a2ba041e518bb3f22bcb8cf4f3bf3f590b65b9' // mepmepmep ); diff --git a/registration-system/view/admin_login_form.html b/registration-system/view/admin_login_form.html new file mode 100644 index 0000000000000000000000000000000000000000..fe1603de3eb190afe31fa0b9706a1f9e91492623 --- /dev/null +++ b/registration-system/view/admin_login_form.html @@ -0,0 +1,5 @@ +<form method="post"> + <input name="user" type="text" /> + <input name="password" type="password" /> + <input type="submit" value="anmelden" /> +</form> \ No newline at end of file diff --git a/registration-system/view/admin_template.html b/registration-system/view/admin_template.html index 88a02f4cec164cc5ad1d02204f4eb48343ebd41c..e0911ca2d006cc1b18a6f7a393022a419677e0cd 100644 --- a/registration-system/view/admin_template.html +++ b/registration-system/view/admin_template.html @@ -3,6 +3,7 @@ <html> <head> <title>FSFahrt - Admin Panel</title> + <meta charset="UTF-8" /> <style type="text/css"> body { font-family:Verdana,Helvetica,sans-serif;