Skip to content
Snippets Groups Projects
Commit 2f8d3395 authored by Tim Repke's avatar Tim Repke
Browse files
parents bbc6f4a4 c3a23b52
No related branches found
No related tags found
No related merge requests found
<?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: ..");
}
}
<?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
<?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
......@@ -41,6 +41,7 @@ $config_reisearten = array(
$config_admins = array(
// username => password
"george" => "peter",
"tim" => "meter"
"tim" => "meter",
"manu" => '{SHA-256}12c9b021c42741545f9f01e2afd67aa2$7112be28c0c11f987de4401798a2ba041e518bb3f22bcb8cf4f3bf3f590b65b9' // mepmepmep
);
<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
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment