Add title

This commit is contained in:
Chocobozzz 2016-08-24 17:35:32 +02:00
parent c6b626077b
commit a2e20d9c2c

View File

@ -1,23 +1,23 @@
<?php <?php
session_start(); session_start();
require(dirname(__FILE__) . '/include/functions.php'); require(dirname(__FILE__) . '/include/functions.php');
require(dirname(__FILE__) . '/include/connect.php'); require(dirname(__FILE__) . '/include/connect.php');
// Disconnecting ? // Disconnecting ?
if(isset($_GET['logout'])){ if(isset($_GET['logout'])){
session_destroy(); session_destroy();
header("Location: ."); header("Location: .");
exit -1; exit -1;
} }
// Get the configuration files ? // Get the configuration files ?
if(isset($_POST['configuration_get'], $_POST['configuration_username'], $_POST['configuration_pass'], $_POST['configuration_os']) if(isset($_POST['configuration_get'], $_POST['configuration_username'], $_POST['configuration_pass'], $_POST['configuration_os'])
&& !empty($_POST['configuration_pass'])) { && !empty($_POST['configuration_pass'])) {
$req = $bdd->prepare('SELECT * FROM user WHERE user_id = ?'); $req = $bdd->prepare('SELECT * FROM user WHERE user_id = ?');
$req->execute(array($_POST['configuration_username'])); $req->execute(array($_POST['configuration_username']));
$data = $req->fetch(); $data = $req->fetch();
// Error ? // Error ?
if($data && passEqual($_POST['configuration_pass'], $data['user_pass'])) { if($data && passEqual($_POST['configuration_pass'], $data['user_pass'])) {
// Thanks http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php // Thanks http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php
@ -28,52 +28,52 @@
$conf_dir = 'windows'; $conf_dir = 'windows';
} }
$rootPath = realpath("./client-conf/$conf_dir"); $rootPath = realpath("./client-conf/$conf_dir");
// Initialize archive object // Initialize archive object
$archive_name = "openvpn-$conf_dir.zip"; $archive_name = "openvpn-$conf_dir.zip";
$archive_path = "./client-conf/$archive_name"; $archive_path = "./client-conf/$archive_name";
$zip = new ZipArchive(); $zip = new ZipArchive();
$zip->open($archive_path, ZipArchive::CREATE | ZipArchive::OVERWRITE); $zip->open($archive_path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator( $files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath), new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY RecursiveIteratorIterator::LEAVES_ONLY
); );
foreach ($files as $name => $file) { foreach ($files as $name => $file) {
// Skip directories (they would be added automatically) // Skip directories (they would be added automatically)
if (!$file->isDir()) { if (!$file->isDir()) {
// Get real and relative path for current file // Get real and relative path for current file
$filePath = $file->getRealPath(); $filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1); $relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive // Add current file to archive
$zip->addFile($filePath, $relativePath); $zip->addFile($filePath, $relativePath);
} }
} }
// Zip archive will be created only after closing object // Zip archive will be created only after closing object
$zip->close(); $zip->close();
//then send the headers to foce download the zip file //then send the headers to foce download the zip file
header("Content-type: application/zip"); header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_name"); header("Content-Disposition: attachment; filename=$archive_name");
header("Pragma: no-cache"); header("Pragma: no-cache");
header("Expires: 0"); header("Expires: 0");
readfile($archive_path); readfile($archive_path);
} }
else { else {
$error = true; $error = true;
} }
} }
// Admin login attempt ? // Admin login attempt ?
else if(isset($_POST['admin_login'], $_POST['admin_username'], $_POST['admin_pass']) && !empty($_POST['admin_pass'])){ else if(isset($_POST['admin_login'], $_POST['admin_username'], $_POST['admin_pass']) && !empty($_POST['admin_pass'])){
$req = $bdd->prepare('SELECT * FROM admin WHERE admin_id = ?'); $req = $bdd->prepare('SELECT * FROM admin WHERE admin_id = ?');
$req->execute(array($_POST['admin_username'])); $req->execute(array($_POST['admin_username']));
$data = $req->fetch(); $data = $req->fetch();
// Error ? // Error ?
if($data && passEqual($_POST['admin_pass'], $data['admin_pass'])) { if($data && passEqual($_POST['admin_pass'], $data['admin_pass'])) {
$_SESSION['admin_id'] = $data['admin_id']; $_SESSION['admin_id'] = $data['admin_id'];
@ -90,38 +90,40 @@
<html> <html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>OpenVPN-Admin</title>
<link rel="stylesheet" href="vendor/bootstrap/dist/css/bootstrap.min.css" type="text/css" /> <link rel="stylesheet" href="vendor/bootstrap/dist/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="css/index.css" type="text/css"/> <link rel="stylesheet" href="css/index.css" type="text/css"/>
<link rel="stylesheet" href="vendor/slickgrid/slick.grid.css" type="text/css" /> <link rel="stylesheet" href="vendor/slickgrid/slick.grid.css" type="text/css" />
<link rel="stylesheet" href="vendor/slickgrid/slick-default-theme.css" type="text/css" /> <link rel="stylesheet" href="vendor/slickgrid/slick-default-theme.css" type="text/css" />
<link rel="stylesheet" href="vendor/slickgrid/css/smoothness/jquery-ui-1.8.16.custom.css" type="text/css" /> <link rel="stylesheet" href="vendor/slickgrid/css/smoothness/jquery-ui-1.8.16.custom.css" type="text/css" />
<link rel="stylesheet" href="vendor/slickgrid-enhancement-pager/libs/dropkick.css" type="text/css" /> <link rel="stylesheet" href="vendor/slickgrid-enhancement-pager/libs/dropkick.css" type="text/css" />
<link rel="stylesheet" href="vendor/slickgrid-enhancement-pager/libs/enhancementpager.css" type="text/css" /> <link rel="stylesheet" href="vendor/slickgrid-enhancement-pager/libs/enhancementpager.css" type="text/css" />
</head> </head>
<body class='container-fluid'> <body class='container-fluid'>
<?php <?php
// --------------- INSTALLATION --------------- // --------------- INSTALLATION ---------------
if(isset($_GET['installation'])) { if(isset($_GET['installation'])) {
if(isInstalled($bdd) == true) { if(isInstalled($bdd) == true) {
printError('OpenVPN-admin is already installed.'); printError('OpenVPN-admin is already installed.');
exit -1; exit -1;
} }
// If the user sent the installation form // If the user sent the installation form
if(isset($_POST['admin_username'])) { if(isset($_POST['admin_username'])) {
$admin_username = $_POST['admin_username']; $admin_username = $_POST['admin_username'];
$admin_pass = $_POST['admin_pass']; $admin_pass = $_POST['admin_pass'];
$admin_repeat_pass = $_POST['repeat_admin_pass']; $admin_repeat_pass = $_POST['repeat_admin_pass'];
if($admin_pass != $admin_repeat_pass) { if($admin_pass != $admin_repeat_pass) {
printError('The passwords do not correspond.'); printError('The passwords do not correspond.');
exit -1; exit -1;
} }
// Create the tables or die // Create the tables or die
$sql_file = dirname(__FILE__) . '/sql/import.sql'; $sql_file = dirname(__FILE__) . '/sql/import.sql';
try { try {
@ -132,14 +134,14 @@
printError($e->getMessage()); printError($e->getMessage());
exit -1; exit -1;
} }
// Generate the hash // Generate the hash
$hash_pass = hashPass($admin_pass); $hash_pass = hashPass($admin_pass);
// Insert the new admin // Insert the new admin
$req = $bdd->prepare('INSERT INTO admin (admin_id, admin_pass) VALUES (?, ?)'); $req = $bdd->prepare('INSERT INTO admin (admin_id, admin_pass) VALUES (?, ?)');
$req->execute(array($admin_username, $hash_pass)); $req->execute(array($admin_username, $hash_pass));
unlink($sql_file); unlink($sql_file);
rmdir(dirname(__FILE__) . '/sql'); rmdir(dirname(__FILE__) . '/sql');
printSuccess('Well done, OpenVPN-Admin is installed.'); printSuccess('Well done, OpenVPN-Admin is installed.');
@ -149,38 +151,38 @@
require(dirname(__FILE__) . '/include/html/menu.php'); require(dirname(__FILE__) . '/include/html/menu.php');
require(dirname(__FILE__) . '/include/html/form/installation.php'); require(dirname(__FILE__) . '/include/html/form/installation.php');
} }
exit -1; exit -1;
} }
// --------------- CONFIGURATION --------------- // --------------- CONFIGURATION ---------------
if(!isset($_GET['admin'])) { if(!isset($_GET['admin'])) {
if(isset($error) && $error == true) if(isset($error) && $error == true)
printError('Login error'); printError('Login error');
require(dirname(__FILE__) . '/include/html/menu.php'); require(dirname(__FILE__) . '/include/html/menu.php');
require(dirname(__FILE__) . '/include/html/form/configuration.php'); require(dirname(__FILE__) . '/include/html/form/configuration.php');
} }
// --------------- LOGIN --------------- // --------------- LOGIN ---------------
else if(!isset($_SESSION['admin_id'])){ else if(!isset($_SESSION['admin_id'])){
if(isset($error) && $error == true) if(isset($error) && $error == true)
printError('Login error'); printError('Login error');
require(dirname(__FILE__) . '/include/html/menu.php'); require(dirname(__FILE__) . '/include/html/menu.php');
require(dirname(__FILE__) . '/include/html/form/login.php'); require(dirname(__FILE__) . '/include/html/form/login.php');
} }
// --------------- GRIDS --------------- // --------------- GRIDS ---------------
else{ else{
?> ?>
<nav class="navbar navbar-default"> <nav class="navbar navbar-default">
<p class="navbar-text">Signed as <?php echo $_SESSION['admin_id']; ?> / <p class="navbar-text">Signed as <?php echo $_SESSION['admin_id']; ?> /
<a class="navbar-link" href="index.php?logout" title="Logout ?">logout ?</a> <a class="navbar-link" href="index.php?logout" title="Logout ?">logout ?</a>
</p> </p>
</nav> </nav>
<?php <?php
require(dirname(__FILE__) . '/include/html/grids.php'); require(dirname(__FILE__) . '/include/html/grids.php');
} }