PageRenderTime 59ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/web/root/config.php

https://gitlab.com/OOTTEE/OARF
PHP | 147 lines | 139 code | 8 blank | 0 comment | 28 complexity | 16bd980a18e06015732d8bcccdff4b77 MD5 | raw file
  1. <?php
  2. function write_ini_file($assoc_arr, $path, $has_sections=FALSE) {
  3. $content = "";
  4. if ($has_sections) {
  5. foreach ($assoc_arr as $key=>$elem) {
  6. $content .= "[".$key."]\n";
  7. foreach ($elem as $key2=>$elem2) {
  8. if(is_array($elem2))
  9. {
  10. for($i=0;$i<count($elem2);$i++)
  11. {
  12. $content .= $key2."[] = ".$elem2[$i]."\n";
  13. }
  14. }
  15. else if($elem2=="") $content .= $key2." = \n";
  16. else $content .= $key2." = ".$elem2."\n";
  17. }
  18. }
  19. }
  20. else {
  21. foreach ($assoc_arr as $key=>$elem) {
  22. if(is_array($elem))
  23. {
  24. for($i=0;$i<count($elem);$i++)
  25. {
  26. $content .= $key."[] = ".$elem[$i]."\n";
  27. }
  28. }
  29. else if($elem=="") $content .= $key." = \n";
  30. else $content .= $key." = ".$elem."\n";
  31. }
  32. }
  33. if (!$handle = fopen($path, 'w')) {
  34. return false;
  35. }
  36. $success = fwrite($handle, $content);
  37. fclose($handle);
  38. return $success;
  39. }
  40. $ERROR = 'NO';
  41. if( !file_exists('../server/config.ini')){
  42. if(isset($_POST['config'])) {
  43. if (isset($_POST['DB']) AND $_POST['DB'] != '' AND
  44. isset($_POST['pass']) AND $_POST['pass'] != '' AND
  45. isset($_POST['User']) AND $_POST['User'] != '' AND
  46. isset($_POST['channel'])
  47. ) {
  48. $dsn = 'mysql:dbname=' . $_POST['DB'] . ';host=127.0.0.1';
  49. try {
  50. $DB = new PDO($dsn, $_POST['User'], $_POST['pass']);
  51. $DB_CONNECTION = true;
  52. } catch (PDOException $e) {
  53. echo 'Falló la conexión: ' . $e->getMessage();
  54. }
  55. if ($DB_CONNECTION) {
  56. $CONFIG = array(
  57. 'DataBase' => array(
  58. 'address' => '127.0.0.1',
  59. 'port' => '3306',
  60. 'user' => $_POST['User'],
  61. 'name' => $_POST['DB'],
  62. 'password' => $_POST['pass'],
  63. ),
  64. 'Radio' => array(
  65. 'channel' => $_POST['channel'],
  66. 'power' => 'MAX',
  67. ));
  68. write_ini_file($CONFIG, '../server/config.ini', true);
  69. header('Location: /');
  70. } else {
  71. $ERROR = 'DB';
  72. }
  73. } else {
  74. $ERROR = 'FIELDS';
  75. }
  76. }
  77. }else{
  78. header('Location: /');
  79. }
  80. ?>
  81. <!DOCTYPE html>
  82. <html lang="en">
  83. <head>
  84. <meta charset="utf-8">
  85. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  86. <meta name="viewport" content="width=device-width, initial-scale=1">
  87. <title>Instalador GAHF</title>
  88. <!-- Bootstrap core CSS -->
  89. <link href="/public/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  90. <link href="/public/lib/bootstrap/css/bootstrap-switch.min.css" rel="stylesheet">
  91. </head>
  92. <body>
  93. <div class="container">
  94. <?php if($ERROR == 'FIELDS'): ?>
  95. <div class="alert alert-warning" >
  96. Complete todos los campos.
  97. </div>
  98. <?php endif; ?>
  99. <?php if($ERROR == 'DB'): ?>
  100. <div class="alert alert-warning" >
  101. Los datos de conexion a la base de datos son incorrectos.
  102. </div>
  103. <?php endif; ?>
  104. <div class="jumbotron">
  105. <form action="config.php" method="post" >
  106. <div class="well">
  107. Bienvenido al instalador de GAHF, a continuación se le solicitarán datos de conexión a la base de datos.
  108. <div class="form-group">
  109. <label for="BD">Nombre de la base de datos</label>
  110. <input type="text" class="form-control" id="DB" name="DB" placeholder="Base de datos" <?= (isset($_POST['DB']))? 'value="'.$_POST['DB'].'"' : '' ?>>
  111. </div>
  112. <div class="form-group">
  113. <label for="usuario">Usuario</label>
  114. <input type="text" class="form-control" id="usuario" name="User" placeholder="User" <?= (isset($_POST['User']))? 'value="'.$_POST['User'].'"' : '' ?>>
  115. </div>
  116. <div class="form-group">
  117. <label for="pass">Contraseña</label>
  118. <input type="password" class="form-control" id="pass" name="pass" placeholder="Password">
  119. </div>
  120. </div>
  121. <div class="well">
  122. A continuación se solicita la banda de funcionamiento del sistema de comunicaciones inalambricas.
  123. <div class="form-group">
  124. <label for="channel">Canal</label>
  125. <select class="form-control" name="channel" id="channel">
  126. <?php $i = 50; while ($i<= 150):?>
  127. <option <?= (isset($_POST['channel']) AND $_POST['channel'] == $i )? 'selected' : '' ?> ><?= $i ?></option>
  128. <?php $i++; endwhile; ?>
  129. </select>
  130. </div>
  131. </div>
  132. <button type="submit" class="btn btn-default" name="config" value="1">Continuar</button>
  133. </form>
  134. </div>
  135. </div>
  136. <script src="/public/lib/js/jquery.min.js"></script>
  137. <script src="/public/lib/bootstrap/js/bootstrap.min.js"></script>
  138. </body>
  139. </html>