diff --git a/include/config.php b/app/config.php similarity index 100% rename from include/config.php rename to app/config.php diff --git a/include/connect.php b/app/connect.php similarity index 100% rename from include/connect.php rename to app/connect.php diff --git a/include/functions.php b/app/functions.php similarity index 99% rename from include/functions.php rename to app/functions.php index 8729365..0d1571e 100644 --- a/include/functions.php +++ b/app/functions.php @@ -41,5 +41,3 @@ function passEqual($pass, $hash) { return password_verify($pass, $hash); } - -?> diff --git a/include/html/form/configuration.php b/app/html/form/configuration.php similarity index 100% rename from include/html/form/configuration.php rename to app/html/form/configuration.php diff --git a/include/html/form/installation.php b/app/html/form/installation.php similarity index 100% rename from include/html/form/installation.php rename to app/html/form/installation.php diff --git a/include/html/form/login.php b/app/html/form/login.php similarity index 100% rename from include/html/form/login.php rename to app/html/form/login.php diff --git a/include/html/grids.php b/app/html/grids.php similarity index 100% rename from include/html/grids.php rename to app/html/grids.php diff --git a/include/html/menu.php b/app/html/menu.php similarity index 77% rename from include/html/menu.php rename to app/html/menu.php index 295d56b..e409f6c 100644 --- a/include/html/menu.php +++ b/app/html/menu.php @@ -3,8 +3,8 @@
diff --git a/resources/css/index.css b/app/resources/css/index.css similarity index 100% rename from resources/css/index.css rename to app/resources/css/index.css diff --git a/resources/img/icon.png b/app/resources/img/icon.png similarity index 100% rename from resources/img/icon.png rename to app/resources/img/icon.png diff --git a/resources/js/grids.js b/app/resources/js/grids.js similarity index 100% rename from resources/js/grids.js rename to app/resources/js/grids.js diff --git a/gulpfile.js b/gulpfile.js index f7c279e..05ce38a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,7 +9,7 @@ gulp.task('clean:img', function () { }); gulp.task('img', ['clean:img'], function () { - return gulp.src('resources/img/**/*') + return gulp.src('app/resources/img/**/*') .pipe(gulp.dest('public/img')); }); @@ -18,7 +18,7 @@ gulp.task('clean:css', function () { }); gulp.task('css', ['clean:css'], function () { - gulp.src(['resources/css/**/*.css']) + gulp.src(['app/resources/css/**/*.css']) .pipe(gulp.dest('public/css')); gulp @@ -46,7 +46,7 @@ gulp.task('clean:js', function () { }); gulp.task('js', ['clean:js'], function () { - gulp.src(['resources/js/**/*.js']) + gulp.src(['app/resources/js/**/*.js']) .pipe(gulp.dest('public/js')); gulp diff --git a/public/grids.php b/public/grids.php index 2262410..fa06bbf 100644 --- a/public/grids.php +++ b/public/grids.php @@ -1,122 +1,112 @@ load(); - if(!isset($_SESSION['admin_id'])) - exit -1; +session_start(); - // Enable dotEnv support - require_once __DIR__ . '/../vendor/autoload.php'; - (new Dotenv\Dotenv(__DIR__ . '/../'))->load(); +if (!isset($_SESSION['admin_id'])) + exit - 1; - session_start(); +require(dirname(__FILE__) . '/../app/functions.php'); +require(dirname(__FILE__) . '/../app/connect.php'); - require(dirname(__FILE__) . '/../include/functions.php'); - require(dirname(__FILE__) . '/../include/connect.php'); - - // ---------------- SELECT ---------------- - if(isset($_GET['select'])){ +// ---------------- SELECT ---------------- +if (isset($_GET['select'])) { // Select the users - if($_GET['select'] == "user"){ - $req = $bdd->prepare('SELECT * FROM user'); - $req->execute(); - - if($data = $req->fetch()) { - do { - $list[] = array("user_id" => $data['user_id'], - "user_pass" => $data['user_pass'], - "user_mail" => $data['user_mail'], - "user_phone" => $data['user_phone'], - "user_online" => $data['user_online'], - "user_enable" => $data['user_enable'], - "user_start_date" => $data['user_start_date'], - "user_end_date" => $data['user_end_date']); - } while($data = $req->fetch()); - - echo json_encode($list); - } - // If it is an empty answer, we need to encore an empty json object - else{ - $list = array(); - echo json_encode($list); - } - } - - // Select the logs - else if($_GET['select'] == "log" && isset($_GET['offset'], $_GET['limit'])){ - $offset = intval($_GET['offset']); - $limit = intval($_GET['limit']); - - // Creation of the LIMIT for build different pages - $page = "LIMIT $offset, $limit"; - - // Select the logs - $req_string = "SELECT *, (SELECT COUNT(*) FROM log) AS nb FROM log ORDER BY log_id DESC $page"; - $req = $bdd->prepare($req_string); - $req->execute(); - - $list = array(); - - $data = $req->fetch(); - - if($data) { - $nb = $data['nb']; - - do { - // Better in Kb or Mb - $received = ($data['log_received'] > 1000000) ? $data['log_received']/1000000 . " Mo" : $data['log_received']/1000 . " Ko"; - $sent = ($data['log_send'] > 1000000) ? $data['log_send']/1000000 . " Mo" : $data['log_send']/1000 . " Ko"; - - // We add to the array the new line of logs - array_push($list, array( - "log_id" => $data['log_id'], - "user_id" => $data['user_id'], - "log_trusted_ip" => $data['log_trusted_ip'], - "log_trusted_port" => $data['log_trusted_port'], - "log_remote_ip" => $data['log_remote_ip'], - "log_remote_port" => $data['log_remote_port'], - "log_start_time" => $data['log_start_time'], - "log_end_time" => $data['log_end_time'], - "log_received" => $received, - "log_send" => $sent)); - - - } while ($data = $req->fetch()); - } - else { - $nb = 0; - } + if ($_GET['select'] == "user") { + $req = $bdd->prepare('SELECT * FROM user'); + $req->execute(); + + if ($data = $req->fetch()) { + do { + $list[] = array("user_id" => $data['user_id'], + "user_pass" => $data['user_pass'], + "user_mail" => $data['user_mail'], + "user_phone" => $data['user_phone'], + "user_online" => $data['user_online'], + "user_enable" => $data['user_enable'], + "user_start_date" => $data['user_start_date'], + "user_end_date" => $data['user_end_date']); + } while ($data = $req->fetch()); + + echo json_encode($list); + } // If it is an empty answer, we need to encore an empty json object + else { + $list = array(); + echo json_encode($list); + } + } // Select the logs + else if ($_GET['select'] == "log" && isset($_GET['offset'], $_GET['limit'])) { + $offset = intval($_GET['offset']); + $limit = intval($_GET['limit']); + + // Creation of the LIMIT for build different pages + $page = "LIMIT $offset, $limit"; + + // Select the logs + $req_string = "SELECT *, (SELECT COUNT(*) FROM log) AS nb FROM log ORDER BY log_id DESC $page"; + $req = $bdd->prepare($req_string); + $req->execute(); - // We finally print the result - $result = array('total' => intval($nb), 'rows' => $list); - - echo json_encode($result); - } - - // Select the admins - else if($_GET['select'] == "admin"){ - $req = $bdd->prepare('SELECT * FROM admin'); - $req->execute(); - - if($data = $req->fetch()) { - do{ - $list[] = array( - "admin_id" => $data['admin_id'], - "admin_pass" => $data['admin_pass'] - ); - } while($data = $req->fetch()); - - echo json_encode($list); - } - else{ $list = array(); - echo json_encode($list); - } - } - } - // ---------------- ADD USER ---------------- - else if(isset($_POST['add_user'], $_POST['user_id'], $_POST['user_pass'])){ + $data = $req->fetch(); + + if ($data) { + $nb = $data['nb']; + + do { + // Better in Kb or Mb + $received = ($data['log_received'] > 1000000) ? $data['log_received'] / 1000000 . " Mo" : $data['log_received'] / 1000 . " Ko"; + $sent = ($data['log_send'] > 1000000) ? $data['log_send'] / 1000000 . " Mo" : $data['log_send'] / 1000 . " Ko"; + + // We add to the array the new line of logs + array_push($list, array( + "log_id" => $data['log_id'], + "user_id" => $data['user_id'], + "log_trusted_ip" => $data['log_trusted_ip'], + "log_trusted_port" => $data['log_trusted_port'], + "log_remote_ip" => $data['log_remote_ip'], + "log_remote_port" => $data['log_remote_port'], + "log_start_time" => $data['log_start_time'], + "log_end_time" => $data['log_end_time'], + "log_received" => $received, + "log_send" => $sent)); + + + } while ($data = $req->fetch()); + } else { + $nb = 0; + } + + // We finally print the result + $result = array('total' => intval($nb), 'rows' => $list); + + echo json_encode($result); + } // Select the admins + else if ($_GET['select'] == "admin") { + $req = $bdd->prepare('SELECT * FROM admin'); + $req->execute(); + + if ($data = $req->fetch()) { + do { + $list[] = array( + "admin_id" => $data['admin_id'], + "admin_pass" => $data['admin_pass'] + ); + } while ($data = $req->fetch()); + + echo json_encode($list); + } else { + $list = array(); + echo json_encode($list); + } + } +} // ---------------- ADD USER ---------------- +else if (isset($_POST['add_user'], $_POST['user_id'], $_POST['user_pass'])) { // Put some default values $id = $_POST['user_id']; $pass = hashPass($_POST['user_pass']); @@ -132,20 +122,18 @@ $req->execute(array($id, $pass, $mail, $phone, $online, $enable, $start, $end)); $res = array("user_id" => $id, - "user_pass" => $pass, - "user_mail" => $mail , - "user_phone" => $phone, - "user_online" => $online, - "user_enable" => $enable, - "user_start_date" => $start, - "user_end_date" => $end + "user_pass" => $pass, + "user_mail" => $mail, + "user_phone" => $phone, + "user_online" => $online, + "user_enable" => $enable, + "user_start_date" => $start, + "user_end_date" => $end ); echo json_encode($res); - } - - // ---------------- UPDATE USER ---------------- - else if(isset($_POST['set_user'])){ +} // ---------------- UPDATE USER ---------------- +else if (isset($_POST['set_user'])) { $valid = array("user_id", "user_pass", "user_mail", "user_phone", "user_enable", "user_start_date", "user_end_date"); $field = $_POST['name']; @@ -153,36 +141,29 @@ $pk = $_POST['pk']; if (!isset($field) || !isset($pk) || !in_array($field, $valid)) { - return; + return; } if ($field === 'user_pass') { - $value = hashPass($value); - } - else if (($field === 'user_start_date' || $field === 'user_end_date') && $value === '') { - $value = NULL; + $value = hashPass($value); + } else if (($field === 'user_start_date' || $field === 'user_end_date') && $value === '') { + $value = NULL; } // /!\ SQL injection: field was checked with in_array function $req_string = 'UPDATE user SET ' . $field . ' = ? WHERE user_id = ?'; $req = $bdd->prepare($req_string); $req->execute(array($value, $pk)); - } - - // ---------------- REMOVE USER ---------------- - else if(isset($_POST['del_user'], $_POST['del_user_id'])){ +} // ---------------- REMOVE USER ---------------- +else if (isset($_POST['del_user'], $_POST['del_user_id'])) { $req = $bdd->prepare('DELETE FROM user WHERE user_id = ?'); $req->execute(array($_POST['del_user_id'])); - } - - // ---------------- ADD ADMIN ---------------- - else if(isset($_POST['add_admin'], $_POST['admin_id'], $_POST['admin_pass'])){ +} // ---------------- ADD ADMIN ---------------- +else if (isset($_POST['add_admin'], $_POST['admin_id'], $_POST['admin_pass'])) { $req = $bdd->prepare('INSERT INTO admin(admin_id, admin_pass) VALUES (?, ?)'); $req->execute(array($_POST['admin_id'], hashPass($_POST['admin_pass']))); - } - - // ---------------- UPDATE ADMIN ---------------- - else if(isset($_POST['set_admin'])){ +} // ---------------- UPDATE ADMIN ---------------- +else if (isset($_POST['set_admin'])) { $valid = array("admin_id", "admin_pass"); $field = $_POST['name']; @@ -190,22 +171,18 @@ $pk = $_POST['pk']; if (!isset($field) || !isset($pk) || !in_array($field, $valid)) { - return; + return; } if ($field === 'admin_pass') { - $value = hashPass($value); + $value = hashPass($value); } $req_string = 'UPDATE admin SET ' . $field . ' = ? WHERE admin_id = ?'; $req = $bdd->prepare($req_string); $req->execute(array($value, $pk)); - } - - // ---------------- REMOVE ADMIN ---------------- - else if(isset($_POST['del_admin'], $_POST['del_admin_id'])){ +} // ---------------- REMOVE ADMIN ---------------- +else if (isset($_POST['del_admin'], $_POST['del_admin_id'])) { $req = $bdd->prepare('DELETE FROM admin WHERE admin_id = ?'); $req->execute(array($_POST['del_admin_id'])); - } - -?> +} diff --git a/public/index.php b/public/index.php index a36880e..3768f6d 100644 --- a/public/index.php +++ b/public/index.php @@ -1,152 +1,148 @@ load(); +// Enable dotEnv support +require_once __DIR__ . '/../vendor/autoload.php'; +$dotenv = new Dotenv\Dotenv(__DIR__ . '/../'); +if (file_exists(__DIR__ . '/../.env')) $dotenv->load(); - session_start(); +session_start(); - require(dirname(__FILE__) . '/../include/functions.php'); - require(dirname(__FILE__) . '/../include/connect.php'); +require(dirname(__FILE__) . '/../app/functions.php'); +require(dirname(__FILE__) . '/../app/connect.php'); - // Disconnecting ? - if(isset($_GET['logout'])){ +// Disconnecting ? +if (isset($_GET['logout'])) { session_destroy(); header("Location: ."); exit(-1); - } +} - // Get the configuration files ? - if(isset($_POST['configuration_get'], $_POST['configuration_username'], $_POST['configuration_pass'], $_POST['configuration_os']) - && !empty($_POST['configuration_pass'])) { +// Get the configuration files ? +if (isset($_POST['configuration_get'], $_POST['configuration_username'], $_POST['configuration_pass'], $_POST['configuration_os']) + && !empty($_POST['configuration_pass'])) { $req = $bdd->prepare('SELECT * FROM user WHERE user_id = ?'); $req->execute(array($_POST['configuration_username'])); $data = $req->fetch(); // Error ? - if($data && passEqual($_POST['configuration_pass'], $data['user_pass'])) { - // Thanks http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php - if($_POST['configuration_os'] == "gnu_linux") { - $conf_dir = 'gnu-linux'; - } elseif($_POST['configuration_os'] == "osx_viscosity") { - $conf_dir = 'osx-viscosity'; - } else { - $conf_dir = 'windows'; - } - $rootPath = realpath("./client-conf/$conf_dir"); - - // Initialize archive object - $archive_base_name = "openvpn-$conf_dir"; - $archive_name = "$archive_base_name.zip"; - $archive_path = "./client-conf/$archive_name"; - $zip = new ZipArchive(); - $zip->open($archive_path, ZipArchive::CREATE | ZipArchive::OVERWRITE); - - $files = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($rootPath), - RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($files as $name => $file) { - // Skip directories (they would be added automatically) - if (!$file->isDir()) { - // Get real and relative path for current file - $filePath = $file->getRealPath(); - $relativePath = substr($filePath, strlen($rootPath) + 1); - - // Add current file to archive - $zip->addFile($filePath, "$archive_base_name/$relativePath"); + if ($data && passEqual($_POST['configuration_pass'], $data['user_pass'])) { + // Thanks http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php + if ($_POST['configuration_os'] == "gnu_linux") { + $conf_dir = 'gnu-linux'; + } elseif ($_POST['configuration_os'] == "osx_viscosity") { + $conf_dir = 'osx-viscosity'; + } else { + $conf_dir = 'windows'; + } + $rootPath = realpath("./client-conf/$conf_dir"); + + // Initialize archive object + $archive_base_name = "openvpn-$conf_dir"; + $archive_name = "$archive_base_name.zip"; + $archive_path = "./client-conf/$archive_name"; + $zip = new ZipArchive(); + $zip->open($archive_path, ZipArchive::CREATE | ZipArchive::OVERWRITE); + + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($rootPath), + RecursiveIteratorIterator::LEAVES_ONLY + ); + + foreach ($files as $name => $file) { + // Skip directories (they would be added automatically) + if (!$file->isDir()) { + // Get real and relative path for current file + $filePath = $file->getRealPath(); + $relativePath = substr($filePath, strlen($rootPath) + 1); + + // Add current file to archive + $zip->addFile($filePath, "$archive_base_name/$relativePath"); + } } - } - - // Zip archive will be created only after closing object - $zip->close(); - //then send the headers to foce download the zip file - header("Content-type: application/zip"); - header("Content-Disposition: attachment; filename=$archive_name"); - header("Pragma: no-cache"); - header("Expires: 0"); - readfile($archive_path); - } - else { - $error = true; + // Zip archive will be created only after closing object + $zip->close(); + + //then send the headers to foce download the zip file + header("Content-type: application/zip"); + header("Content-Disposition: attachment; filename=$archive_name"); + header("Pragma: no-cache"); + header("Expires: 0"); + readfile($archive_path); + } else { + $error = true; } - } - - // Admin login attempt ? - else if(isset($_POST['admin_login'], $_POST['admin_username'], $_POST['admin_pass']) && !empty($_POST['admin_pass'])){ +} // Admin login attempt ? +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->execute(array($_POST['admin_username'])); $data = $req->fetch(); // Error ? - if($data && passEqual($_POST['admin_pass'], $data['admin_pass'])) { - $_SESSION['admin_id'] = $data['admin_id']; - header("Location: index.php?admin"); - exit(-1); - } - else { - $error = true; + if ($data && passEqual($_POST['admin_pass'], $data['admin_pass'])) { + $_SESSION['admin_id'] = $data['admin_id']; + header("Location: index.php?admin"); + exit(-1); + } else { + $error = true; } - } +} ?> - - + +