PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/0xSentinel/install.php

https://github.com/KinG-InFeT/0xSentinel
PHP | 186 lines | 168 code | 7 blank | 11 comment | 14 complexity | 4d05d25a6c599888255083909579a62b MD5 | raw file
  1. <?php
  2. /*
  3. *
  4. * @project 0xSentinel
  5. * @author KinG-InFeT
  6. * @licence GNU/GPL
  7. *
  8. * @file install.php
  9. *
  10. * @link http://0xproject.netsons.org#0xSentinel
  11. *
  12. */
  13. if(!(phpversion() >= '5.2.0')) {
  14. die('<h2 align="center">In questo server è installata una versione di PHP invferiore alla 5.2.0, quindi 0xSentinel non potrà essere installato causa futuri maltunzionamenti!<br />
  15. Si contatti l\'amministratore del server per aggiornare la versione di PHP installata sul server almeno alla 5.2.0</h2>');
  16. }
  17. if(!(is_writable('./config.php')))
  18. die("Il file config.php non ha i permessi di scrittura, impostarli a 777 per i server UNIX-Like");
  19. if( isset($_GET['delete']) && $_GET['delete'] == 1 ) {
  20. if( (unlink("install.php") == FALSE) || (unlink("rules.sql") == FALSE) ) {
  21. die("<p align='center'><b>Unable to delete installation file</b><br>Please delete install.php and rules.sql manually for security reasons !</p>");
  22. }else{
  23. header("location: login.php");
  24. }
  25. }
  26. ?>
  27. <html>
  28. <head>
  29. <title>0xSentinel Installation</title>
  30. <link href="style.css" rel="stylesheet" type="text/css" />
  31. <body>
  32. <br />
  33. <h1 align="center">0xSentinel Installation</h1><br />
  34. <table width="100%" border="0" align="center">
  35. <?php
  36. if( isset($_POST['install']) == FALSE ){
  37. ?>
  38. <form method="POST">
  39. <table align="center" border="0" width="35%">
  40. <tbody><tr>
  41. <td width="100%"><div>Database Settings</div></td>
  42. </tr>
  43. </tbody></table> <table align="center" border="0" width="35%">
  44. <tbody><tr>
  45. <td><div align="left"><b>Host</b></div></td>
  46. <td><div align="right"><input name="host" type="text" width="150"></div></td>
  47. </tr>
  48. <tr>
  49. <td><div align="left"><b>Username</b></div></td>
  50. <td><div align="right"><input name="user" type="text" width="150"></div></td>
  51. </tr>
  52. <tr>
  53. <td><div align="left"><b>Password</b></div></td>
  54. <td><div align="right"><input name="pass" type="text" width="150"></div></td>
  55. </tr>
  56. <tr>
  57. <td><div align="left"><b>Database name</b></div></td>
  58. <td><div align="right"><input name="name" type="text" width="150"></div></td>
  59. </tr>
  60. </table>
  61. <br>
  62. <table align="center" border="0" width="35%">
  63. <tbody><tr>
  64. <td width="100%"><div>General Settings</div></td>
  65. </tr>
  66. </tbody></table>
  67. <table align="center" border="0" width="35%">
  68. <tbody><tr>
  69. <td><div align="left"><b>Admin username</b></div></td>
  70. <td><div align="right"><input name="admin_user" type="text" width="150"></div></td>
  71. </tr>
  72. <tr>
  73. <td><div align="left"><b>Admin password</b></div></td>
  74. <td><div align="right"><input name="admin_pass" type="password" width="150"></div></td>
  75. </tr>
  76. <tr>
  77. <td><div align="left"><b>Admin email</b></div><br></td>
  78. <td><div align="right"><input name="email" type="text" width="150"></div><br></td>
  79. </tr>
  80. <tr>
  81. <td></td>
  82. <td><div align="right"><input name="install" value="Install" type="submit"></div></td>
  83. </tr>
  84. </form>
  85. <?php
  86. }else{
  87. $db_connect = @mysql_connect( $_POST['host'], $_POST['user'], $_POST['pass'] );
  88. $db_select = @mysql_select_db( $_POST['name'] );
  89. if(!$db_connect) {
  90. die("<b>Errore durante la connessione al database MySQL</b><br>".mysql_errno()." : ".mysql_error());
  91. }
  92. elseif(!$db_select) {
  93. die("<b>Errore durante la selezione del database MySQL</b><br>".mysql_errno()." : ".mysql_error());
  94. }
  95. if(!($fd = fopen( "config.php", "w+t" )))
  96. die("Errore durante l'apertura sul file config.php<br /> Prego di controllare i permessi sul file!");
  97. if( !fwrite( $fd, "<?php\n"
  98. ."\t\$db_host = \"".trim($_POST['host'])."\";\n"
  99. ."\t\$db_user = \"".trim($_POST['user'])."\";\n"
  100. ."\t\$db_pass = \"".trim($_POST['pass'])."\";\n"
  101. ."\t\$db_name = \"".trim($_POST['name'])."\";\n"
  102. ."?>" ) ) {
  103. die("Errore durante la scrittura del file config.php<br /> Prego di controllare i permessi sul file!");
  104. }
  105. fclose($fd);
  106. $query_create = "CREATE TABLE `0xSentinel_rules` (
  107. `id` int(11) NOT NULL auto_increment,
  108. `type` TEXT NOT NULL,
  109. `regola` TEXT NOT NULL,
  110. `descrizione` TEXT NOT NULL,
  111. PRIMARY KEY (`id`)
  112. );";
  113. $read_file = fopen("rules.sql","r");
  114. $dim_file = filesize("rules.sql");
  115. $content = fread($read_file,$dim_file);//contenuto
  116. fclose($read_file);
  117. mysql_query($query_create) or die(mysql_error());
  118. mysql_query($content) or die(mysql_error());
  119. $query_settings = "CREATE TABLE `0xSentinel_settings` (
  120. `active` smallint(5) unsigned NOT NULL default 1,
  121. `admin_user` TEXT NOT NULL,
  122. `admin_pass` TEXT NOT NULL,
  123. `email` TEXT NOT NULL,
  124. `filter_get` smallint(5) unsigned NOT NULL default 1,
  125. `filter_post` smallint(5) unsigned NOT NULL default 1,
  126. `filter_cookie` smallint(5) unsigned NOT NULL default 1,
  127. `filter_session` smallint(5) unsigned NOT NULL default 1,
  128. `filter_ip` smallint(5) unsigned NOT NULL default 1,
  129. `filter_csrf` smallint(5) unsigned NOT NULL default 1,
  130. `filter_fpd` smallint(5) unsigned NOT NULL default 1,
  131. `filter_scanner` smallint(5) unsigned NOT NULL default 1,
  132. `email_notify` smallint(5) unsigned NOT NULL default 1
  133. );";
  134. $query_settings_insert = "INSERT INTO `0xSentinel_settings`
  135. (`admin_user`, `admin_pass`, `email`)
  136. VALUES
  137. ('".mysql_real_escape_string(trim($_POST['admin_user']))."', '".md5(trim($_POST['admin_pass']))."', '".mysql_real_escape_string(trim($_POST['email']))."');";
  138. mysql_query($query_settings) or die(mysql_error());
  139. mysql_query($query_settings_insert) or die(mysql_error());
  140. $query_logs = "CREATE TABLE `0xSentinel_logs` (
  141. `id` INT NOT NULL AUTO_INCREMENT ,
  142. `pagina` TEXT NOT NULL ,
  143. `query_string` TEXT NOT NULL ,
  144. `type_attack` TEXT NOT NULL ,
  145. `referer` TEXT NOT NULL ,
  146. `ip` TEXT NOT NULL ,
  147. `data` TEXT NOT NULL,
  148. PRIMARY KEY (`id`)
  149. );";
  150. mysql_query($query_logs) or die(mysql_error());
  151. $query_ban_ip = "CREATE TABLE `0xSentinel_ban_ip` (
  152. `id` INT NOT NULL AUTO_INCREMENT ,
  153. `ip` TEXT NOT NULL ,
  154. `motivazione` TEXT NOT NULL ,
  155. `data` TEXT NOT NULL ,
  156. PRIMARY KEY (`id`)
  157. );";
  158. mysql_query($query_ban_ip) or die(mysql_error());
  159. print "\n<h3 align='center'><b><font color='green'>Installation succesfully completed</font></b>"
  160. . "\n<br />Click <a href='?delete=1'>here</a> to delete installation file .</h3>";
  161. }
  162. ?>
  163. </table>
  164. </body>
  165. </html>