setup.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css'>";
  58. echo "<center><B>Please Login to Contiune<br/><br/>";
  59. echo $error . "<br/>";
  60. echo "<form action=\"?action=write\" method='POST'>";
  61. echo "<div class=\"form-group clearfix well well-sm\" style=\"width: 25%; padding-bottom: 0px; padding-top: 10px; margin-bottom: 5px;\">";
  62. echo "<div style=\"margin-bottom: 8px\" class=\"input-group\"><div class=\"input-group-addon\">Password</div>";
  63. echo "<input style=\"margin-bottom: 0px\" type=\"password\" name=\"pass\" class=\"form-control\">";
  64. echo "<span class=\"input-group-btn\"><button name=\"submit\" class=\"btn btn-success\" type=\"submit\">Go!</button></span></div></div>";
  65. echo "</form></center>";
  66. }
  67. ?>