setup.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. error_reporting (E_ALL ^ E_NOTICE);
  3. $configfile = 'settings.ini.php';
  4. $examplefile = 'example.ini.php';
  5. if(isset($_GET["action"])){$action = $_GET["action"];}
  6. if(!file_exists($configfile) && !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 example.ini.php?</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. if(($action == "write" && password_verify($pass, $hash_pass))){
  34. setcookie("logged", $hash_pass, time() + (86400 * 7), "/");
  35. $error = "You got it dude!";
  36. echo "<!DOCTYPE html>";
  37. echo "<head>";
  38. echo "<title>Form submitted</title>";
  39. echo "<script type='text/javascript'>window.parent.location.reload()</script>";
  40. echo "</head>";
  41. echo "<body></body></html>";
  42. }
  43. if(isset( $_POST["pass"] ) && (!password_verify($pass, $hash_pass))){
  44. $error = "Wrong Password!";
  45. }
  46. if($_COOKIE["logged"] == $hash_pass){
  47. echo "<!DOCTYPE html>";
  48. echo "<head>";
  49. echo "<title>Form submitted</title>";
  50. echo "<script type='text/javascript'>window.location.replace('settings.php');</script>";
  51. echo "</head>";
  52. echo "<body></body></html>";
  53. }
  54. if(!password_verify($pass, $hash_pass)){
  55. echo "<link rel='stylesheet prefetch' href='css/bootstrap.min.css'>";
  56. echo "<center><B>Please Login to Continue<br/><br/>";
  57. echo $error . "<br/>";
  58. echo "<form action=\"?action=write\" method='POST'>";
  59. echo "<div class=\"form-group clearfix well well-sm\" style=\"width: 300px; padding-bottom: 0px; padding-top: 10px; margin-bottom: 5px;\">";
  60. echo "<div style=\"margin-bottom: 8px\" class=\"input-group\"><div class=\"input-group-addon\">Password</div>";
  61. echo "<input style=\"margin-bottom: 0px\" type=\"password\" name=\"pass\" class=\"form-control\">";
  62. echo "<span class=\"input-group-btn\"><button name=\"submit\" class=\"btn btn-success\" type=\"submit\">Go!</button></span></div></div>";
  63. echo "</form></center>";
  64. }
  65. ?>