forked from causefx/iDashboard-PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.php
101 lines (65 loc) · 2.92 KB
/
setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
error_reporting (E_ALL ^ E_NOTICE);
$configfile = 'settings.ini.php';
$examplefile = 'example.ini.php';
if(isset($_GET["action"])){$action = $_GET["action"];}
if(!file_exists($configfile) && !file_exists($examplefile)){
die('You are missing the ini configuration file, please download and refresh this page');
}
if(!file_exists($configfile)){
echo "The file $configfile does not exist, we will make a copy now...<br/><br/>";
if (!is_writable(dirname($examplefile)))
die('We don\'t have access to write to the current directory, please change the permissions to this directory.');
else {
copy($examplefile, $configfile);
sleep(2);
echo "<!DOCTYPE html>";
echo "<head>";
echo "<title>Form submitted</title>";
echo "<script type='text/javascript'>window.parent.location.reload()</script>";
echo "</head>";
echo "<body></body></html>";
}
}
try {
$config = parse_ini_file('settings.ini.php', true);
} catch(Exception $e) {
die('<b>Unable to read settings.ini.php. Did you rename it from example.ini.php?</b><br><br>Error message: ' .$e->getMessage());
}
foreach ($config as $keyname => $section) {
if(($keyname == "general")) { $hash_pass = $section["password"]; }
}
$pass = isset( $_POST["pass"] ) ? $_POST["pass"] : "none" ;
if(($action == "write" && password_verify($pass, $hash_pass))){
setcookie("logged", $hash_pass, time() + (86400 * 7), "/");
$error = "You got it dude!";
echo "<!DOCTYPE html>";
echo "<head>";
echo "<title>Form submitted</title>";
echo "<script type='text/javascript'>window.parent.location.reload()</script>";
echo "</head>";
echo "<body></body></html>";
}
if(isset( $_POST["pass"] ) && (!password_verify($pass, $hash_pass))){
$error = "Wrong Password!";
}
if($_COOKIE["logged"] == $hash_pass){
echo "<!DOCTYPE html>";
echo "<head>";
echo "<title>Form submitted</title>";
echo "<script type='text/javascript'>window.location.replace('settings.php');</script>";
echo "</head>";
echo "<body></body></html>";
}
if(!password_verify($pass, $hash_pass)){
echo "<link rel='stylesheet prefetch' href='css/bootstrap.min.css'>";
echo "<center><B>Please Login to Continue<br/><br/>";
echo $error . "<br/>";
echo "<form action=\"?action=write\" method='POST'>";
echo "<div class=\"form-group clearfix well well-sm\" style=\"width: 300px; padding-bottom: 0px; padding-top: 10px; margin-bottom: 5px;\">";
echo "<div style=\"margin-bottom: 8px\" class=\"input-group\"><div class=\"input-group-addon\">Password</div>";
echo "<input style=\"margin-bottom: 0px\" type=\"password\" name=\"pass\" class=\"form-control\">";
echo "<span class=\"input-group-btn\"><button name=\"submit\" class=\"btn btn-success\" type=\"submit\">Go!</button></span></div></div>";
echo "</form></center>";
}
?>