PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/install/install.php

https://github.com/ivansoriasolis/Vidali
PHP | 88 lines | 49 code | 1 blank | 38 comment | 11 complexity | df4c164c8594bfc0f0302807fdc5d4ee MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. /* Vidali, Social Network Open Source.
  3. This file is part of Vidali.
  4. Vidali is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Vidali is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Foobar. If not, see <http://www.gnu.org/licenses/>.*/
  14. //Comprobar la integridad de los datos
  15. $error= false;
  16. $aux = 0;
  17. $empty = "";
  18. foreach ($_POST as $id => $data){
  19. if(empty($_POST[$id])){
  20. $aux++;
  21. $empty = $empty . "&emp$aux=$id";
  22. $error = true;
  23. }
  24. }
  25. if($error == true){
  26. //header('Location:' . getenv('HTTP_REFERER') . "?empty=$aux"."$empty");
  27. //TODO: Si no es un lio, devolver esto en JSON
  28. echo $empty;
  29. }else{
  30. //crear el db.ini
  31. $con = new mysqli($_POST["DB_DIR"], $_POST["DB_USER"], $_POST["DB_PASS"],$_POST["DB_NAME"]);
  32. if (mysqli_connect_errno()) {
  33. printf("Connect failed: %s\n", mysqli_connect_error());
  34. exit();
  35. }
  36. else{
  37. include "../vdl-include/vdl-core/core_db.class.php";
  38. define ("DBDIR","NULL");
  39. $core= new CORE_DB();
  40. $config = $core->set($_POST["DB_DIR"], $_POST["DB_USER"], $_POST["DB_PASS"],$_POST["DB_NAME"]);
  41. $nombre_archivo = 'vidali.sql';
  42. $sql = explode(";",file_get_contents($nombre_archivo));
  43. $con->autocommit(FALSE);
  44. foreach($sql as $query){
  45. // echo " Linea de la BD: $query<br>";
  46. if (!empty($query)){
  47. if(!$con->query($query))
  48. printf("Error: %s<br>", mysqli_error($con));
  49. }
  50. }
  51. $con->autocommit(TRUE);
  52. }
  53. if(!$con->query("INSERT INTO `vdl_config` (`config_id`, `config_name`, `config_value`) VALUES (4, 'ADMIN', '1')"))
  54. printf("Error: %s<br>", mysqli_error($con));
  55. if(!$con->query("INSERT INTO `vdl_config` (`config_id`, `config_name`, `config_value`) VALUES (5, 'REGISTER', '".$_POST["optionsRadios"]."')"))
  56. printf("Error: %s<br>", mysqli_error($con));
  57. if(!$con->query("INSERT INTO `vdl_config` (`config_id`, `config_name`, `config_value`) VALUES (6, 'PRIVACY', '".$_POST["optionsRadios2"]."')"))
  58. printf("Error: %s<br>", mysqli_error($con));
  59. /* TODO: Si index_bots o central_sync no estan marcados, no se envia el valor "yes" por POST y por lo tanto deja $_POST["index_bots"] sin definir. Codigo comentado hasta que se solucione el bug para que el resto funcione.
  60. if(!$con->query("INSERT INTO `vdl_config` (`config_id`, `config_name`, `config_value`) VALUES (7, 'INDEX', '".$_POST["index_bots"]."')"))
  61. printf("Error: %s<br>", mysqli_error($con));
  62. if(!$con->query("INSERT INTO `vdl_config` (`config_id`, `config_name`, `config_value`) VALUES (8, 'SYNC', '".$_POST["central_sync"]."')"))
  63. printf("Error: %s<br>", mysqli_error($con));
  64. */
  65. if(!$con->query("INSERT INTO `vdl_config` (`config_id`, `config_name`, `config_value`) VALUES (9, 'STORAGE', 'SERVER')"))
  66. printf("Error: %s<br>", mysqli_error($con));
  67. if(!$con->query("INSERT INTO `vdl_config` (`config_id`, `config_name`, `config_value`) VALUES (10, 'BASEDIR', '/Vidali')"))
  68. printf("Error: %s<br>", mysqli_error($con));
  69. //Crear usuario
  70. /* $admin = $_POST["nickname"];
  71. $password = mysql_real_escape_string(sha1(md5(trim($_POST["password"]))));
  72. date_default_timezone_set("Europe/London");
  73. $date = date($_POST["birthdate"]);
  74. $query = ("INSERT INTO vdl_users (user_id,passwd,nickname,name,location,genre,bday,email,bio,img_prof,prof_nets) VALUES
  75. ('$admin','$password','".$_POST["nickname"]."','".$_POST["name"]."','".$_POST["location"]."','".$_POST["sex"]."','$date','".$_POST["email"]."','".$_POST["bio"]."','prof_def',1)");
  76. $result = mysql_query($query,$connection);
  77. $result = mysql_query("INSERT INTO `vdl_config` (`config_id`, `config_name`, `config_value`) VALUES (4, 'ADMIN', '$admin')",$connection);
  78. */
  79. //header("Location:../index.php?action=register");
  80. echo "1";
  81. }
  82. mysqli_close($con);
  83. ?>