DVL-012 #121 Password protect the devilbox intranet

This commit is contained in:
cytopia 2017-09-09 10:40:07 +02:00
parent 0c4290b0c4
commit 63e1acc02a
No known key found for this signature in database
GPG Key ID: 6D56EDB8695128A2
27 changed files with 327 additions and 80 deletions

View File

@ -2,6 +2,9 @@
// Measure time
$TIME_START = microtime(true);
// Start session
session_start();
// Turn on all PHP errors
error_reporting(-1);

View File

@ -1,19 +1,27 @@
<?php
require '../config.php';
if (isset($_GET['database'])) {
if (isset($_GET['type']) && $_GET['type'] == 'mysql') {
echo json_encode(array(
'size' => (string)loadClass('Mysql')->getDBSize($_GET['database']),
'table' => (string)loadClass('Mysql')->getTableCount($_GET['database'])
));
} else if (isset($_GET['type']) && $_GET['type'] == 'postgres') {
$schema = isset($_GET['schema']) ? $_GET['schema'] : '';
echo json_encode(array(
'size' => (string)loadClass('Pgsql')->getSchemaSize($_GET['database'], $schema),
'table' => (string)loadClass('Pgsql')->getTableCount($_GET['database'], $schema)
));
if (loadClass('Helper')->isLoggedIn()) {
if (isset($_GET['database'])) {
if (isset($_GET['type']) && $_GET['type'] == 'mysql') {
echo json_encode(array(
'size' => (string)loadClass('Mysql')->getDBSize($_GET['database']),
'table' => (string)loadClass('Mysql')->getTableCount($_GET['database'])
));
} else if (isset($_GET['type']) && $_GET['type'] == 'postgres') {
$schema = isset($_GET['schema']) ? $_GET['schema'] : '';
echo json_encode(array(
'size' => (string)loadClass('Pgsql')->getSchemaSize($_GET['database'], $schema),
'table' => (string)loadClass('Pgsql')->getTableCount($_GET['database'], $schema)
));
}
} else if (isset($_GET['vhost'])) {
echo loadClass('Httpd')->checkVirtualHost($_GET['vhost']);
} else {
loadClass('Helper')->redirect('/');
}
} else if (isset($_GET['vhost'])) {
echo loadClass('Httpd')->checkVirtualHost($_GET['vhost']);
} else {
loadClass('Helper')->redirect('/');
}

View File

@ -1,11 +1,11 @@
.meter {
height: 20px; /* Can be anything */
position: relative;
background: #555;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
box-shadow: inset 0 -1px 1px rgba(255,255,255,0.3);
height: 20px; /* Can be anything */
position: relative;
background: #555;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
box-shadow: inset 0 -1px 1px rgba(255,255,255,0.3);
}
.meter > span {
display: block;
@ -16,49 +16,49 @@
border-bottom-left-radius: 20px;
background-color: rgb(43,194,83);
background-image: linear-gradient(
center bottom,
rgb(43,194,83) 37%,
rgb(84,240,84) 69%
center bottom,
rgb(43,194,83) 37%,
rgb(84,240,84) 69%
);
box-shadow:
inset 0 2px 9px rgba(255,255,255,0.3),
inset 0 -2px 6px rgba(0,0,0,0.4);
inset 0 2px 9px rgba(255,255,255,0.3),
inset 0 -2px 6px rgba(0,0,0,0.4);
position: relative;
overflow: hidden;
}
.dash-box {
border: 1px solid #383737;
background-color: #3d3d3d;
color: #999999;
height:100%;
border: 1px solid #383737;
background-color: #3d3d3d;
color: #999999;
height:100%;
}
.dash-box-head {
background-color: #383737;
color: #999999;
width:100%;
display: inline-block;
padding:10px;
font-weight: bold;
background-color: #383737;
color: #999999;
width:100%;
display: inline-block;
padding:10px;
font-weight: bold;
}
.dash-box-body {
padding:10px;
padding:10px;
}
.row-margin {
margin-bottom:20px;
margin-bottom:20px;
}
.col-margin {
margin-bottom:20px;
margin-bottom:20px;
}
/* Bootstrap overwrites
-------------------------------------------------- */
html, body {
font-size: 14px;
font-size: 14px;
}
@ -86,7 +86,7 @@ body {
/* Generics
-------------------------------------------------- */
.font-small {
font-size: 12px;
font-size: 12px;
}
@ -95,52 +95,52 @@ body {
-------------------------------------------------- */
.circles{
margin:0px auto;
margin:0px auto;
}
.circles > div {
overflow:hidden;
float:left;
width:auto;
height:auto;
position: relative;
border-radius:50%;
-moz-border-radius:50%;
-webkit-border-radius:50%;
-khtml-border-radius: 50%;
background:#eee;
overflow:hidden;
float:left;
width:auto;
height:auto;
position: relative;
border-radius:50%;
-moz-border-radius:50%;
-webkit-border-radius:50%;
-khtml-border-radius: 50%;
background:#eee;
}
.circles > div > div {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.circles > div > div > div {
display: table;
width: 100%;
height: 100%;
display: table;
width: 100%;
height: 100%;
}
.circles > div > div > div > div {
display: table-cell;
text-align: center;
vertical-align: middle;
display: table-cell;
text-align: center;
vertical-align: middle;
}
@media (max-width: 320px)
{
.circles > div {padding: 50%;}
.circles > div {padding: 50%;}
}
@media (min-width: 321px) and (max-width: 800px)
{
.circles > div {padding: 50%;}
.circles > div {padding: 50%;}
}
@media (min-width: 801px)
{
.circles > div {padding: 48%;}
.circles > div {padding: 48%;}
}
@ -151,17 +151,17 @@ a.navbar-brand {
background-color: transparent !important;
}
a.nav-link {
background-color: transparent !important;
background-color: transparent !important;
}
img.d-inline-block {
float: none;
float: none;
}
nav.navbar {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
font-size: 1rem;
line-height: 1.5;
color: #373a3c;
background-color: #fff;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
font-size: 1rem;
line-height: 1.5;
color: #373a3c;
background-color: #fff;
}
@ -170,26 +170,62 @@ nav.navbar {
/* mail.php;
-------------------------------------------------- */
tr.subject {
cursor: pointer;
cursor: pointer;
}
td.break-word {
word-break: break-word;
word-break: break-word;
}
/* adminer.php;
-------------------------------------------------- */
#menu {
position: absolute;
margin: 76px 0 0 !important;
position: absolute;
margin: 76px 0 0 !important;
}
#breadcrumb {
top: 60px !important;
top: 60px !important;
}
#lang {
top: 53px !important;
top: 53px !important;
}
.pages {
z-index:1000;
}
/* login.php;
-------------------------------------------------- */
/* Extra markup and styles for table-esque vertical and horizontal centering */
.site-wrapper {
display: table;
width: 100%;
height: 100%; /* For at least Firefox */
min-height: 100%;
-webkit-box-shadow: inset 0 0 5rem rgba(0,0,0,.5);
box-shadow: inset 0 0 5rem rgba(0,0,0,.5);
}
.site-wrapper-inner {
display: table-cell;
vertical-align: top;
}
.cover-container {
margin-right: auto;
margin-left: auto;
}
/* Affix and center */
@media (min-width: 40em) {
/* Start the vertical centering */
.site-wrapper-inner {
vertical-align: middle;
}
}
@media (min-width: 62em) {
.masthead,
.mastfoot,
.cover-container {
width: 32rem;
}
}

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<?php
// Also required for JS calls (see bottom of this page)
$len_table = 4;

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<?php
// Also required for JS calls (see bottom of this page)
$len_table = 4;

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<?php
/*********************************************************************************

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -0,0 +1,66 @@
<?php require '../config.php'; ?>
<?php
// If login protection is disabled or user has already logged in
if (loadClass('Helper')->isloggedIn()) {
loadClass('Helper')->redirect('/');
}
// Validate $_POST login
$login_error = '';
if (isset($_POST['username']) && isset($_POST['password'])) {
// Auth successful
if (loadClass('Helper')->login($_POST['username'], $_POST['password'])) {
loadClass('Helper')->redirect('/');
}
$login_error = 'Wrong username or password';
}
?>
<!DOCTYPE html>
<html lang="en" style="height: 100%;min-height: 100%;">
<head>
<?php echo loadClass('Html')->getHead(true); ?>
</head>
<body style="height: 100%; min-height: 100%; text-align: center; color: #fff; text-shadow: 0 .05rem .1rem rgba(0,0,0,.5); background: #1f1f1f; margin-bottom:0 !important;">
<div class="site-wrapper">
<div class="site-wrapper-inner">
<div class="cover-container">
<div class="container">
<div class="inner cover">
<img src="/assets/img/devilbox_80.png" style="width:60%; padding-bottom:20px;"/>
<h1 class="cover-heading">Devilbox Login</h1>
<div class="text-danger"><?php echo $login_error; ?></div>
<form method="POST">
<div class="form-group row">
<div class="col-sm-12">
<input type="text" class="form-control" id="inputUsername" placeholder="Username" name="username" value="<?php echo isset($_POST['username']) ? $_POST['username'] : ''; ?>">
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<input type="password" class="form-control" id="inputPassword" placeholder="Password" name="password">
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,11 @@
<?php require '../config.php'; ?>
<?php
if (isset($_GET['id'])) {
if ($_GET['id'] == session_id()) {
loadClass('Helper')->logout();
loadClass('Helper')->redirect('/login.php');
}
}
loadClass('Helper')->redirect('/');

View File

@ -1,5 +1,6 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<?php
require '../config.php';
//
// $_POST submit for sending a test email

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<?php
/**

View File

@ -1,4 +1,5 @@
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -172,4 +172,64 @@ class Helper
exec($cmd, $output, $exit_code);
return implode ("\n", $output);
}
public function redirect($url)
{
header('Location: '.$url);
exit;
}
/*********************************************************************************
*
* Login Helper Functions
*
*********************************************************************************/
public function login($username, $password)
{
$dvl_password = loadClass('Helper')->getEnv('DEVILBOX_UI_PASSWORD');
if ($username == 'devilbox' && $password == $dvl_password) {
$_SESSION['auth'] = 1;
return true;
}
return false;
}
public function logout()
{
if (isset($_SESSION['auth'])) {
$_SESSION['auth'] = 0;
unset($_SESSION['auth']);
}
}
public function isLoginProtected()
{
// No password protection enabled
if (loadClass('Helper')->getEnv('DEVILBOX_UI_PROTECT') != 1) {
return false;
}
return true;
}
public function isloggedIn()
{
// No password protection enabled
if (!$this->isLoginProtected()) {
return true;
}
// Alredy logged in
if (isset($_SESSION['auth']) && $_SESSION['auth'] == 1) {
return true;
}
return false;
}
public function authPage()
{
if (!$this->isloggedIn()) {
$this->redirect('/login.php');
}
}
}

View File

@ -183,6 +183,12 @@ HTML;
public function getNavbar()
{
$menu = $this->_buildMenu();
$logout = '';
if (loadClass('Helper')->isLoginProtected()) {
$logout = '<ul class="navbar-nav">'.
'<li class="nav-item text-right"><a class="nav-link" href="/logout.php?id='.session_id().'">Log out</a></li>'.
'</ul>';
}
$html = <<<HTML
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
@ -198,8 +204,11 @@ HTML;
{$menu}
</ul>
{$logout}
</div>
</nav>
<br/>
HTML;

View File

@ -97,6 +97,12 @@ services:
- TLD_SUFFIX=${TLD_SUFFIX:-loc}
- DNS_CHECK_TIMEOUT=${DNS_CHECK_TIMEOUT:-1}
##
## Password protect the devilbox Intranet
##
- DEVILBOX_UI_PROTECT=${DEVILBOX_UI_PROTECT:-0}
- DEVILBOX_UI_PASSWORD=${DEVILBOX_UI_PASSWORD}
##
## PHP Xdebug
##

View File

@ -102,6 +102,36 @@ NEW_GID=1000
TIMEZONE=Europe/Berlin
###
### Devilbox UI Password protection enable/disable (1/0)
###
### Set DEVILBOX_UI_PROTECT to 1 in order to password protect the
### intranet.
###
### Example:
### DEVILBOX_UI_PROTECT=1
### DEVILBOX_UI_PROTECT=0
###
DEVILBOX_UI_PROTECT=0
###
### Devilbox UI Password
###
### When DEVILBOX_UI_PROTECT=1, use the following password
### to log in. The password can always be changed.
### When changing the password, make sure to restart your
### PHP container.
###
### Example:
### DEVILBOX_UI_PASSWORD=my-very-secure-password
### DEVILBOX_UI_PASSWORD=Some pass with spaces
###
### The default username is 'devilbox'
###
DEVILBOX_UI_PASSWORD=password
################################################################################
###