setup.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. //ini_set('display_errors',1); error_reporting(E_ALL);
  3. $configfile = 'settings.ini.php';
  4. $examplefile = 'example.ini.php';
  5. if(isset($_GET["action"])){$action = $_GET["action"];}
  6. if(!file_exists($filename) && !file_exists($examplefile)){
  7. die('You are missing the ini configuration file, please download and refresh this page');
  8. }
  9. if(!file_exists($configfile)){
  10. echo "The file $configfile does not exist, we will make a copy now...<br/><br/>";
  11. if (!is_writable(dirname($examplefile)))
  12. die('We don\'t have access to write to the current directory, please change the permissions to this directory.');
  13. else {
  14. copy($examplefile, $configfile);
  15. sleep(2);
  16. echo "<!DOCTYPE html>";
  17. echo "<head>";
  18. echo "<title>Form submitted</title>";
  19. echo "<script type='text/javascript'>window.parent.location.reload()</script>";
  20. echo "</head>";
  21. echo "<body></body></html>";
  22. }
  23. }
  24. try {
  25. $config = parse_ini_file('settings.ini.php', true);
  26. } catch(Exception $e) {
  27. die('<b>Unable to read config.ini.php. Did you rename it from settings.ini.php-example?</b><br><br>Error message: ' .$e->getMessage());
  28. }
  29. foreach ($config as $keyname => $section) {
  30. if(($keyname == "general")) { $hash_pass = $section["password"]; }
  31. }
  32. $pass = isset( $_POST["pass"] ) ? $_POST["pass"] : "none" ;
  33. $parts = explode('$', $hash_pass);
  34. $test_hash = crypt($pass, sprintf('$%s$%s$%s$', $parts[1], $parts[2], $parts[3]));
  35. if(($action == "write" && $hash_pass == $test_hash)){
  36. setcookie("logged", $hash_pass, time() + (86400 * 7), "/");
  37. $error = "You got it dude!";
  38. echo "<!DOCTYPE html>";
  39. echo "<head>";
  40. echo "<title>Form submitted</title>";
  41. echo "<script type='text/javascript'>window.parent.location.reload()</script>";
  42. echo "</head>";
  43. echo "<body></body></html>";
  44. }
  45. if(isset( $_POST["pass"] ) && ($hash_pass !== $test_hash)){
  46. $error = "Wrong Password!";
  47. }
  48. if($_COOKIE["logged"] == $hash_pass){
  49. echo "<!DOCTYPE html>";
  50. echo "<head>";
  51. echo "<title>Form submitted</title>";
  52. echo "<script type='text/javascript'>window.location.replace('settings.php');</script>";
  53. echo "</head>";
  54. echo "<body></body></html>";
  55. }
  56. if($hash_pass !== $test_hash){
  57. echo "<center><B>Please Login to Contiune<br/><br/>";
  58. echo $error . "<br/>";
  59. echo "<style> .css-input { padding:8px; border-radius:47px; border-width:3px; border-style:double; font-size:17px; border-color:#0a090a; box-shadow: 2px 6px 8px 0px rgba(42,42,42,.75); font-weight:bold; }
  60. .css-input:focus { outline:none; } </style>";
  61. echo "<form action=\"?action=write\" method='POST'>";
  62. echo "<b>Password: </b><input class='css-input' type='password' name='pass'></input> ";
  63. echo "<input class='css-input' type='submit' name='submit' value='Go'></input>";
  64. echo "</form></center>";
  65. }
  66. ?>