setup.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. $configfile = 'settings.ini.php';
  3. $examplefile = 'example.ini.php';
  4. if(isset($_GET["action"])){$action = $_GET["action"];}
  5. if(!file_exists($filename) && !file_exists($examplefile)){
  6. die('You are missing the ini configuration file, please download and refresh this page');
  7. }
  8. if(!file_exists($configfile)){
  9. echo "The file $configfile does not exist, we will make a copy now...<br/><br/>";
  10. if (!is_writable(dirname($examplefile)))
  11. die('We don\'t have access to write to the current directory, please change the permissions to this directory.');
  12. else {
  13. copy($examplefile, $configfile);
  14. sleep(2);
  15. echo "<!DOCTYPE html>";
  16. echo "<head>";
  17. echo "<title>Form submitted</title>";
  18. echo "<script type='text/javascript'>window.parent.location.reload()</script>";
  19. echo "</head>";
  20. echo "<body></body></html>";
  21. }
  22. }
  23. try {
  24. $config = parse_ini_file('settings.ini.php', true);
  25. } catch(Exception $e) {
  26. die('<b>Unable to read config.ini.php. Did you rename it from settings.ini.php-example?</b><br><br>Error message: ' .$e->getMessage());
  27. }
  28. foreach ($config as $keyname => $section) {
  29. if(($keyname == "general")) { $hash_pass = $section["password"]; }
  30. }
  31. $pass = isset( $_POST["pass"] ) ? $_POST["pass"] : "none" ;
  32. if(($action == "write" && password_verify($pass, $hash_pass))){
  33. setcookie("logged", $hash_pass, time() + (86400 * 7), "/");
  34. $error = "You got it dude!";
  35. echo "<!DOCTYPE html>";
  36. echo "<head>";
  37. echo "<title>Form submitted</title>";
  38. echo "<script type='text/javascript'>window.parent.location.reload()</script>";
  39. echo "</head>";
  40. echo "<body></body></html>";
  41. }
  42. if(isset( $_POST["pass"] ) && (!password_verify($pass, $hash_pass))){
  43. $error = "Wrong Password!";
  44. }
  45. if($_COOKIE["logged"] == $hash_pass){
  46. echo "<!DOCTYPE html>";
  47. echo "<head>";
  48. echo "<title>Form submitted</title>";
  49. echo "<script type='text/javascript'>window.location.replace('settings.php');</script>";
  50. echo "</head>";
  51. echo "<body></body></html>";
  52. }
  53. if(!password_verify($pass, $hash_pass)){
  54. echo "<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css'>";
  55. echo "<center><B>Please Login to Contiune<br/><br/>";
  56. echo $error . "<br/>";
  57. echo "<form action=\"?action=write\" method='POST'>";
  58. echo "<div class=\"form-group clearfix well well-sm\" style=\"width: 300px; padding-bottom: 0px; padding-top: 10px; margin-bottom: 5px;\">";
  59. echo "<div style=\"margin-bottom: 8px\" class=\"input-group\"><div class=\"input-group-addon\">Password</div>";
  60. echo "<input style=\"margin-bottom: 0px\" type=\"password\" name=\"pass\" class=\"form-control\">";
  61. echo "<span class=\"input-group-btn\"><button name=\"submit\" class=\"btn btn-success\" type=\"submit\">Go!</button></span></div></div>";
  62. echo "</form></center>";
  63. }
  64. ?>