diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | management-interface/api/models/Main.php | 17 | ||||
-rw-r--r-- | management-interface/api/models/Master.php | 63 | ||||
-rw-r--r-- | management-interface/api/models/Util.php | 11 | ||||
-rw-r--r-- | management-interface/config/.global.cfg.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | management-interface/config/global.cfg | 10 | ||||
-rw-r--r-- | management-interface/css/custom.css | 57 | ||||
-rw-r--r-- | management-interface/index.php | 42 | ||||
-rw-r--r-- | management-interface/template/footer.php | 3 | ||||
-rw-r--r-- | management-interface/template/header.php | 4 | ||||
-rw-r--r-- | management-interface/template/message.php | 5 | ||||
-rw-r--r-- | management-interface/views/home.htm | 2 | ||||
-rw-r--r-- | management-interface/views/login.htm | 22 | ||||
-rw-r--r-- | management-interface/views/menu.php | 19 | ||||
-rw-r--r-- | management-interface/views/template.htm | 8 |
15 files changed, 223 insertions, 41 deletions
@@ -11,3 +11,4 @@ /config/ftp.jks /config/ldap.jks /config/servers.jks +/management-interface/tmp diff --git a/management-interface/api/models/Main.php b/management-interface/api/models/Main.php deleted file mode 100644 index cca7542..0000000 --- a/management-interface/api/models/Main.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -class Main { - $view; - - function __construct() { - echo "test"; - $view = new View; - } - - function home() { - echo $view->render('views/index.php'); - } - -} - -?> diff --git a/management-interface/api/models/Master.php b/management-interface/api/models/Master.php new file mode 100644 index 0000000..4ee2943 --- /dev/null +++ b/management-interface/api/models/Master.php @@ -0,0 +1,63 @@ +<?php + +class Master { + + public $view; + + public function __construct() { + $this->view = new View; + } + + public function parse($f3, $params) { + $f3->set('_title', $f3->get('title')); + + // set view if item exists + if (in_array($params['m'], $f3->get('item'))) { + if (!file_exists('views/' . $params['m'] . '.htm')) { + // if file does not exists, create a template + copy('views/template.htm', 'views/' . $params['m'] . '.htm'); + } + $f3->set('_module', $params['m']); + } elseif ($params['m'] === 'login') { + $f3->set('_module', 'login'); + } else { + $f3->set('_module', 'home'); + } + + echo $this->view->render('template/header.php'); + + echo $this->view->render('views/menu.php'); + + if (!empty($f3->get('message'))) { + echo $this->view->render('template/message.php'); + } + + echo Template::instance()->render('views/' . $f3->get('_module') . '.htm'); + + echo $this->view->render('template/footer.php'); + + } + + public function dologin($f3, $username, $password) { + if (isset($f3->get('user')[$username]) && $f3->get('user')[$username] == sha1($password)) { + $_SESSION['username'] = $username; + $f3->set('loggedin', (isset($f3->get('SESSION')['username']))?true:false); + $f3->set('username', (isset($f3->get('SESSION')['username']))?$f3->get('SESSION')['username']:'Guest'); + $this->parse($f3, array('m' => 'home')); + } else { + $f3->set('message', 'Login invalid.'); + $this->parse($f3, array('m' => 'login')); + } + } + + public function dologout($f3) { + $_SESSION = array(); + $f3->set('message', 'Logout successful'); + $f3->set('loggedin', (isset($f3->get('SESSION')['username']))?true:false); + $f3->set('username', (isset($f3->get('SESSION')['username']))?$f3->get('SESSION')['username']:'Guest'); + $this->parse($f3, array('m' => 'login')); + } + +} + +?> diff --git a/management-interface/api/models/Util.php b/management-interface/api/models/Util.php new file mode 100644 index 0000000..d97cfe2 --- /dev/null +++ b/management-interface/api/models/Util.php @@ -0,0 +1,11 @@ +<?php + +class Util { + + public static function firstCap($string) { + return strtoupper(substr($string, 0, 1)) . substr($string, 1, strlen($string)); + } + +} + +?> diff --git a/management-interface/config/.global.cfg.swp b/management-interface/config/.global.cfg.swp Binary files differdeleted file mode 100644 index d8973b4..0000000 --- a/management-interface/config/.global.cfg.swp +++ /dev/null diff --git a/management-interface/config/global.cfg b/management-interface/config/global.cfg index a339e2e..eede8c9 100644 --- a/management-interface/config/global.cfg +++ b/management-interface/config/global.cfg @@ -3,3 +3,13 @@ item[0]="home" item[1]="users" item[2]="about" +;item[3]="test" + +; title +title="Masterserver Management" + +;accounts +user["nils"]="f58cf5e7e10f195e21b553096d092c763ed18b0e" + +;hostname +hostname="http://localhost/if/" diff --git a/management-interface/css/custom.css b/management-interface/css/custom.css new file mode 100644 index 0000000..56b22d2 --- /dev/null +++ b/management-interface/css/custom.css @@ -0,0 +1,57 @@ +/* login template fix */ +.form-signin { + max-width: 330px; + padding: 15px; + margin: 0 auto; +} +.form-adduser { + max-width: 600px; + padding: 10px; + margin: 0 auto; +} +.form-signin .form-signin-heading, +.form-signin .checkbox { + margin-bottom: 10px; +} +.form-signin .checkbox { + font-weight: normal; +} +.form-signin .form-control, +.form-adduser .form-control { + position: relative; + font-size: 16px; + height: auto; + padding: 10px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +.form-control:focus { + z-index: 2; +} +.form-signin input[type="text"] { + margin-bottom: -1px; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; +} +.form-signin input[type="password"] { + margin-bottom: 10px; + border-top-left-radius: 0; + border-top-right-radius: 0; +} + +/* static navbar */ +.navbar-static-top { + margin-bottom: 19px; +} + +/* always vertical scrollbars */ +html { + overflow-y: scroll; +} + +/* fixing in danger boxes */ +.bg-danger { + padding: 15px; + text-align: center; +} diff --git a/management-interface/index.php b/management-interface/index.php index 6c4964e..d7d0b62 100644 --- a/management-interface/index.php +++ b/management-interface/index.php @@ -1,10 +1,16 @@ <?php
+session_start();
$f3 = require('lib/base.php');
$f3->set('DEBUG', 3);
-$f3->set('AUTOLOAD', 'api/models');
+$f3->set('AUTOLOAD', 'api/models/');
+
+// set defaults
+$f3->set('loggedin', (isset($f3->get('SESSION')['username']))?true:false);
+$f3->set('username', (isset($f3->get('SESSION')['username']))?$f3->get('SESSION')['username']:'Guest');
+$f3->set('message', '');
$f3->config('config/global.cfg');
@@ -16,27 +22,25 @@ $f3->set('DB', new DB\SQL( ));
*/
+$f3->route('POST /do/@action',
+ function($f3, $params) {
+ $master = new Master;
+ if ($params['action'] === 'login') {
+ if (isset($_POST['user']) && isset($_POST['pass'])) {
+ $master->dologin($f3, $f3->get('POST')['user'], $f3->get('POST')['pass']);
+ }
+ }
+ }
+);
+
$f3->route('GET @module: /@m',
function($f3, $params) {
- $view = new View;
-
- // set the title
- $f3->set('_title', 'Masterserver Management');
-
- // set view if item exists
- if (in_array($params['m'], $f3->get('item')) && file_exists('views/' . $params['m'] . '.htm')) {
- $f3->set('_module', $params['m']);
+ $master = new Master;
+ if ($params['m'] === 'logout') {
+ $master->dologout($f3);
} else {
- $f3->set('_module', 'home');
+ $master->parse($f3, $params);
}
-
- echo $view->render('template/header.php');
-
- echo $view->render('views/menu.php');
-
- echo Template::instance()->render('views/' . $f3->get('_module') . '.htm');
-
- echo $view->render('template/footer.php');
}
);
@@ -46,6 +50,7 @@ $f3->route('GET /', }
);
+/*
$f3->set('ONERROR',
function($f3) {
// recursively clear existing output buffers:
@@ -53,6 +58,7 @@ $f3->set('ONERROR', echo $f3->get('ERROR.title');
}
);
+*/
$f3->run();
diff --git a/management-interface/template/footer.php b/management-interface/template/footer.php index b605728..be0cfea 100644 --- a/management-interface/template/footer.php +++ b/management-interface/template/footer.php @@ -1,2 +1,5 @@ +<?php +//var_dump($_SESSION); +?> </body> </html> diff --git a/management-interface/template/header.php b/management-interface/template/header.php index db43469..12ea523 100644 --- a/management-interface/template/header.php +++ b/management-interface/template/header.php @@ -10,10 +10,10 @@ <title><?php echo $_title ?></title> <!-- Bootstrap core CSS --> - <link href="./css/bootstrap.min.css" rel="stylesheet"> + <link href="/css/bootstrap.min.css" rel="stylesheet"> <!-- Custom styles for this template --> - <link href="./css/navbar-static-top.css" rel="stylesheet"> + <link href="/css/custom.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> diff --git a/management-interface/template/message.php b/management-interface/template/message.php new file mode 100644 index 0000000..105345d --- /dev/null +++ b/management-interface/template/message.php @@ -0,0 +1,5 @@ + <div class="container"> + + <p class="bg-danger"><?=$message ?></p> + + </div> <!-- /container --> diff --git a/management-interface/views/home.htm b/management-interface/views/home.htm index f9c8ac6..229e427 100644 --- a/management-interface/views/home.htm +++ b/management-interface/views/home.htm @@ -2,7 +2,7 @@ <div class="jumbotron"> <h1>{{ strtoupper(@_module) }}</h1> - <p><p> + <p>Hello {{ @username }}<p> </div> </div> <!-- /container --> diff --git a/management-interface/views/login.htm b/management-interface/views/login.htm new file mode 100644 index 0000000..f447cb8 --- /dev/null +++ b/management-interface/views/login.htm @@ -0,0 +1,22 @@ +<check if="{{ @loggedin }}"> +<true> +<div class="container"> + <div class="jumbotron"> + <h1>Already logged in.</h1> + </div> +</div> +</true> +<false> +<div class="container"> + <form class="form-signin" action="{{ @hostname }}do/login" method="post"> + <h2 class="form-signin-heading">Login</h2> + <input type="text" name="user" class="form-control" placeholder="Username" autofocus> + <input type="password" name="pass" class="form-control" placeholder="Password"> + <label class="checkbox"> + <input type="checkbox" name="remember" value="remember-me">Remember me</input> + </label> + <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button> + </form> +</div> +</false> +</check> diff --git a/management-interface/views/menu.php b/management-interface/views/menu.php index b6af1be..9ef4068 100644 --- a/management-interface/views/menu.php +++ b/management-interface/views/menu.php @@ -8,7 +8,7 @@ <span class="icon-bar"></span> <span class="icon-bar"></span> </button> - <a class="navbar-brand" href="#">Project name</a> + <a class="navbar-brand" href="#"><?= $_title ?></a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> @@ -17,13 +17,26 @@ echo '<li'; echo ($value === $_module)? ' class="active"':''; echo '>'; - echo '<a href="'.$value.'">'; - echo strtoupper($value); + echo '<a href="'.$hostname.$value.'">'; + echo Util::firstcap($value); echo '</a>'; echo '</li>'; } ?> </ul> + <ul class="nav navbar-nav navbar-right"> + <?php + if (!isset($_SESSION['username'])) { + echo '<li'; + echo ('login' === $_module)? ' class="active"':''; + echo '>'; + echo '<a href="'.$hostname.'login">Login</a></li>'; + } else { + echo '<li>'; + echo '<a href="'.$hostname.'logout">Logout</a></li>'; + } + ?> + </ul> </div><!--/.nav-collapse --> </div> </div> diff --git a/management-interface/views/template.htm b/management-interface/views/template.htm new file mode 100644 index 0000000..27affb5 --- /dev/null +++ b/management-interface/views/template.htm @@ -0,0 +1,8 @@ + <div class="container"> + + <div class="jumbotron"> + <h1>{{ strtoupper(@_module) }}</h1> + <p>Please fill this with content.</p> + </div> + + </div> <!-- /container --> |