Advertisement
trupsalms

no android folder

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