Advertisement
trupsalms

with android folder

Oct 7th, 2019
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. require(dirname(__FILE__) . '/include/functions.php');
  5. require(dirname(__FILE__) . '/include/connect.php');
  6.  
  7. // Disconnecting ?
  8. if(isset($_GET['logout'])){
  9. session_destroy();
  10. header("Location: .");
  11. exit(-1);
  12. }
  13.  
  14. // Get the configuration files ?
  15. if(isset($_POST['configuration_get'], $_POST['configuration_username'], $_POST['configuration_pass'], $_POST['configuration_os'])
  16. && !empty($_POST['configuration_pass'])) {
  17. $req = $bdd->prepare('SELECT * FROM user WHERE user_id = ?');
  18. $req->execute(array($_POST['configuration_username']));
  19. $data = $req->fetch();
  20.  
  21. // Error ?
  22. if($data && passEqual($_POST['configuration_pass'], $data['user_pass'])) {
  23. // Thanks http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php
  24. if($_POST['configuration_os'] == "android") {
  25. $conf_dir = 'android';
  26. } if($_POST['configuration_os'] == "gnu_linux") {
  27. $conf_dir = 'gnu-linux';
  28. } elseif($_POST['configuration_os'] == "osx_viscosity") {
  29. $conf_dir = 'osx-viscosity';
  30. } else {
  31. $conf_dir = 'windows';
  32. }
  33. $rootPath = realpath("./client-conf/$conf_dir");
  34.  
  35. // Initialize archive object ;;;; why doing this every time the user logs in, when the cert is static?
  36. $archive_base_name = "openvpn-$conf_dir";
  37. $archive_name = "$archive_base_name.zip";
  38. $archive_path = "./client-conf/$archive_name";
  39. $zip = new ZipArchive();
  40. $zip->open($archive_path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
  41.  
  42. $files = new RecursiveIteratorIterator(
  43. new RecursiveDirectoryIterator($rootPath),
  44. RecursiveIteratorIterator::LEAVES_ONLY
  45. );
  46.  
  47. foreach ($files as $name => $file) {
  48. // Skip directories (they would be added automatically)
  49. if (!$file->isDir()) {
  50. // Get real and relative path for current file
  51. $filePath = $file->getRealPath();
  52. $relativePath = substr($filePath, strlen($rootPath) + 1);
  53.  
  54. // Add current file to archive
  55. $zip->addFile($filePath, "$archive_base_name/$relativePath");
  56. }
  57. }
  58.  
  59. // Zip archive will be created only after closing object
  60. $zip->close();
  61.  
  62. //then send the headers to foce download the zip file
  63. header("Content-type: application/zip");
  64. header("Content-Disposition: attachment; filename=$archive_name");
  65. header("Pragma: no-cache");
  66. header("Expires: 0");
  67. readfile($archive_path);
  68. }
  69. else {
  70. $error = true;
  71. }
  72. }
  73.  
  74. // Admin login attempt ?
  75. else if(isset($_POST['admin_login'], $_POST['admin_username'], $_POST['admin_pass']) && !empty($_POST['admin_pass'])){
  76.  
  77. $req = $bdd->prepare('SELECT * FROM admin WHERE admin_id = ?');
  78. $req->execute(array($_POST['admin_username']));
  79. $data = $req->fetch();
  80.  
  81. // Error ?
  82. if($data && passEqual($_POST['admin_pass'], $data['admin_pass'])) {
  83. $_SESSION['admin_id'] = $data['admin_id'];
  84. header("Location: index.php?admin");
  85. exit(-1);
  86. }
  87. else {
  88. $error = true;
  89. }
  90. }
  91. ?>
  92.  
  93. <!DOCTYPE html>
  94. <html>
  95. <head>
  96. <meta charset="utf-8" />
  97.  
  98. <title>OpenVPN-Admin</title>
  99.  
  100. <link rel="stylesheet" href="vendor/bootstrap/dist/css/bootstrap.min.css" type="text/css" />
  101. <link rel="stylesheet" href="vendor/x-editable/dist/bootstrap3-editable/css/bootstrap-editable.css" type="text/css" />
  102. <link rel="stylesheet" href="vendor/bootstrap-table/dist/bootstrap-table.min.css" type="text/css" />
  103. <link rel="stylesheet" href="vendor/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css" type="text/css" />
  104. <link rel="stylesheet" href="vendor/bootstrap-table/dist/extensions/filter-control/bootstrap-table-filter-control.css" type="text/css" />
  105. <link rel="stylesheet" href="css/index.css" type="text/css" />
  106.  
  107. <link rel="icon" type="image/png" href="css/icon.png">
  108. </head>
  109. <body class='container-fluid'>
  110. <?php
  111.  
  112. // --------------- INSTALLATION ---------------
  113. if(isset($_GET['installation'])) {
  114. if(isInstalled($bdd) == true) {
  115. printError('OpenVPN-admin is already installed. Redirection.');
  116. header( "refresh:3;url=index.php?admin" );
  117. exit(-1);
  118. }
  119.  
  120. // If the user sent the installation form
  121. if(isset($_POST['admin_username'])) {
  122. $admin_username = $_POST['admin_username'];
  123. $admin_pass = $_POST['admin_pass'];
  124. $admin_repeat_pass = $_POST['repeat_admin_pass'];
  125.  
  126. if($admin_pass != $admin_repeat_pass) {
  127. printError('The passwords do not correspond. Redirection.');
  128. header( "refresh:3;url=index.php?installation" );
  129. exit(-1);
  130. }
  131.  
  132. // Create the initial tables
  133. $migrations = getMigrationSchemas();
  134. foreach ($migrations as $migration_value) {
  135. $sql_file = dirname(__FILE__) . "/sql/schema-$migration_value.sql";
  136. try {
  137. $sql = file_get_contents($sql_file);
  138. $bdd->exec($sql);
  139. }
  140. catch (PDOException $e) {
  141. printError($e->getMessage());
  142. exit(1);
  143. }
  144.  
  145. unlink($sql_file);
  146.  
  147. // Update schema to the new value
  148. updateSchema($bdd, $migration_value);
  149. }
  150.  
  151. // Generate the hash
  152. $hash_pass = hashPass($admin_pass);
  153.  
  154. // Insert the new admin
  155. $req = $bdd->prepare('INSERT INTO admin (admin_id, admin_pass) VALUES (?, ?)');
  156. $req->execute(array($admin_username, $hash_pass));
  157.  
  158. rmdir(dirname(__FILE__) . '/sql');
  159. printSuccess('Well done, OpenVPN-Admin is installed. Redirection.');
  160. header( "refresh:3;url=index.php?admin" );
  161. }
  162. // Print the installation form
  163. else {
  164. require(dirname(__FILE__) . '/include/html/menu.php');
  165. require(dirname(__FILE__) . '/include/html/form/installation.php');
  166. }
  167.  
  168. exit(-1);
  169. }
  170.  
  171. // --------------- CONFIGURATION ---------------
  172. if(!isset($_GET['admin'])) {
  173. if(isset($error) && $error == true)
  174. printError('Login error');
  175.  
  176. require(dirname(__FILE__) . '/include/html/menu.php');
  177. require(dirname(__FILE__) . '/include/html/form/configuration.php');
  178. }
  179.  
  180.  
  181. // --------------- LOGIN ---------------
  182. else if(!isset($_SESSION['admin_id'])){
  183. if(isset($error) && $error == true)
  184. printError('Login error');
  185.  
  186. require(dirname(__FILE__) . '/include/html/menu.php');
  187. require(dirname(__FILE__) . '/include/html/form/login.php');
  188. }
  189.  
  190. // --------------- GRIDS ---------------
  191. else{
  192. ?>
  193. <nav class="navbar navbar-default">
  194. <div class="row col-md-12">
  195. <div class="col-md-6">
  196. <p class="navbar-text signed">Signed in as <?php echo $_SESSION['admin_id']; ?>
  197. </div>
  198. <div class="col-md-6">
  199. <a class="navbar-text navbar-right" href="index.php?logout" title="Logout"><button class="btn btn-danger">Logout <span class="glyphicon glyphicon-off" aria-hidden="true"></span></button></a>
  200. <a class="navbar-text navbar-right" href="index.php" title="Configuration"><button class="btn btn-default">Configurations</button></a>
  201. </p>
  202. </div>
  203. </div>
  204. </nav>
  205.  
  206. <?php
  207. require(dirname(__FILE__) . '/include/html/grids.php');
  208. }
  209. ?>
  210. <div id="message-stage">
  211. <!-- used to display application messages (failures / status-notes) to the user -->
  212. </div>
  213. </body>
  214. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement