-
Notifications
You must be signed in to change notification settings - Fork 8
/
super-powers.php
251 lines (219 loc) · 11.2 KB
/
super-powers.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php
/*
_ _ _ _
| | (_) | | | |
_ __ ___ | |__ _ _ __ ______ __| | __ _ ___| |__
| '__/ _ \| '_ \| | '_ \______/ _` |/ _` / __| '_ \
| | | (_) | |_) | | | | | | (_| | (_| \__ \ | | |
|_| \___/|_.__/|_|_| |_| \__,_|\__,_|___/_| |_|
robin-dash: Centralized Controller for Robin-Mesh networking devices
Copyright (C) 2010-2011 Cody Cooper.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if(file_exists("settings.php")) {require("settings.php");}
else {header("Location: oobe.php");}
$form = "<br /><br />
<form action=\"super-powers.php\" method=\"POST\" id=\"login-form\">
<label for=\"pass\">Password</label>
<input type=\"password\" name=\"pass\" value=\"\" />
<input type=\"submit\" name=\"submit\" value=\"Login\" class=\"btn-login\" />
</form>";
if($_COOKIE['spass']) {
if($_COOKIE['spass'] == file_get_contents("super-password.txt")) {
$status = "logged-in";
}
else {$status = "<p id=\"error\">Incorrect Password</p>";setcookie("spass");}
}
else if($_POST['submit'] == "Login" && !$_POST['pass']) {$status = "<p id=\"error\">Incorrect Password</p>";setcookie("spass");}
else if($_POST['pass']) {
if(md5($_POST['pass']) == file_get_contents("super-password.txt")) {
setcookie("spass", md5($_POST['pass']));
$status = "logged-in";
}
else {$status = "<p id=\"error\">Incorrect Password</p>";setcookie("spass");}
}
else {$status = "Please enter your Password to login.";}
if($status == "logged-in") {
if($_POST['action'] == "reset-user") {
$xmlp = simplexml_load_file($dir . "data/" . $_POST['user'] . ".xml");
function generatePassword() {
$vowels = 'aeuy';
$consonants = 'bdghjmnpqrstvz23456789';
$password = '';
$alt = time() % 2;
for ($i = 0; $i < 9; $i++) {
if ($alt == 1) {
$password .= $consonants[(rand() % strlen($consonants))];
$alt = 0;
}
else {
$password .= $vowels[(rand() % strlen($vowels))];
$alt = 1;
}
}
return $password;
}
$password = generatepassword();
mail($xmlp->robindash->notifymail, "Your " . $brand . " accounts password has been reset", "Hi there " . $_POST['user'] . ",\n\nThis is an email to let you know that your accounts password at " . $brand . " has been reset.\nYour new password will be: " . $password . "\n\nPlease login to your account at: http://" . $_SERVER['SERVER_NAME'] . str_replace("super-powers.php", "", $_SERVER['REQUEST_URI']) . " to change it to something more memorable soon.\n\nRegards,\nThe " . $brand . " Team");
$fc = file_get_contents($dir . "data/" . $_POST['user'] . ".xml");
$fc = str_replace($xmlp->robindash->password, md5($password), $fc);
$fh = fopen($dir . "data/" . $_POST['user'] . ".xml", 'w') or die("Can't write to the data file.");
fwrite($fh, $fc);
fclose($fh);
header("Location: super-powers.php");
exit;
}
else if($_POST['action'] == "remove-user") {
$xmlp = simplexml_load_file($dir . "data/" . $_POST['user'] . ".xml");
mail($xmlp->robindash->notifymail, "Your " . $brand . " account has been removed", "Hi there " . $_POST['user'] . ",\n\nThis is an email to let you know that your account at " . $brand . " has been removed.\nWe would like to thank you for taking the time to use " . $brand . " and wish you the best of luck with any other dashboard you may wish to try.\n\nRegards,\nThe " . $brand . " Team");
$xmlp = simplexml_load_file($dir . "data/" . $_POST['user'] . "_nodes.xml");
foreach($xmlp->node as $node) {
if(file_exists($dir . "data/mac2net/" . base64_encode($node->mac) . ".xml")) {
unlink($dir . "data/mac2net/" . base64_encode($node->mac) . ".xml");
}
}
unlink($dir . "data/" . $_POST['user'] . ".xml");
unlink($dir . "data/" . $_POST['user'] . "_nodes.xml");
unlink($dir . "data/" . $_POST['user'] . ".txt");
unlink($dir . "data/" . $_POST['user'] . ".csv");
unlink($dir . "data/cid/" . $_POST['user'] . ".txt");
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if(filetype($dir . "/" . $object) == "dir") {rrmdir($dir . "/" . $object);}
else {unlink($dir . "/" . $object);}
}
}
reset($objects);
rmdir($dir);
}
}
rrmdir($dir . "data/stats/" . $_POST['user']);
rrmdir($dir . "data/uploads/" . $_POST['user']);
header("Location: super-powers.php");
exit;
}
else if($_POST['action'] == "disassociate-node") {
$user = file_get_contents($dir . "data/mac2net/" . base64_encode($_POST['mac']) . ".txt");
$xmlp = simplexml_load_file($dir . "data/" . $user . ".xml");
mail($xmlp->robindash->notifymail, "A node has been removed from your " . $brand . " account", "Hi there " . $user . ",\n\nThis is an email to let you know that a node has been removed from your account at " . $brand . ".\nIt's MAC address is: " . $_POST['mac'] . ".\n\nRegards,\nThe " . $brand . " Team");
$xmlp = simplexml_load_file($dir . "data/" . $user . "_nodes.xml");
foreach($xmlp->node as $node) {
if($node->mac == $_POST['mac']) {
$data = "<node>
<name>" . $node->name . "</name>
<notes></notes>
<mac>" . $node->mac . "</mac>
<ip>" . $node->ip . "</ip>
<lat>" . $node->lat . "</lat>
<lng>" . $node->lng . "</lng>
</node>";
$fc = file_get_contents($dir . "data/" . $user . "_nodes.xml");
$fc = str_replace($data, "", $fc);
$fh = fopen($dir . "data/" . $user . "_nodes.xml", 'w') or die("Can't write to the nodes file.");
fwrite($fh, $fc);
fclose($fh);
}
}
unlink($dir . "data/mac2net/" . base64_encode($_POST['mac']) . ".txt");
unlink($dir . "data/hbc/" . base64_encode($_POST['mac']) . ".txt");
unlink($dir . "data/role/" . base64_encode($_POST['mac']) . ".txt");
unlink($dir . "data/stats/" . $networkname . "/" . base64_encode($_POST['mac']) . ".txt");
unlink($dir . "data/stats/" . $networkname . "/" . base64_encode($_POST['mac']) . ".date.txt");
unlink($dir . "data/pnc/" . base64_encode($_POST['mac']) . "/gw.defroute.txt");
unlink($dir . "data/pnc/" . base64_encode($_POST['mac']) . "/gw.ipaddr.txt");
unlink($dir . "data/pnc/" . base64_encode($_POST['mac']) . "/gw.netmask.txt");
unlink($dir . "data/pnc/" . base64_encode($_POST['mac']) . "/node.predef_role.txt");
unlink($dir . "data/pnc/" . base64_encode($_POST['mac']) . "/node.run_mode.txt");
unlink($dir . "data/pnc/" . base64_encode($_POST['mac']) . "/staticcheckbox.txt");
unlink($dir . "data/pnc/" . base64_encode($_POST['mac']) . "/");
header("Location: super-powers.php");
exit;
}
else if($_POST['action'] == "login-user") {
$xmlp = simplexml_load_file($dir . "data/" . $_POST['user'] . ".xml");
mail($xmlp->robindash->notifymail, "Your " . $brand . " account has been logged into by an administrator", "Hi there " . $_POST['user'] . ",\n\nThis is an email to let you know that your account at " . $brand . " has been logged into by an administrator. This kind of message is normally only sent to alert you to the usage of your account by an administrator in regards to a support query you may have sent us.\n\nRegards,\nThe " . $brand . " Team");
session_destroy();
session_start();
$_SESSION["user"] = $_POST['user'];
$_SESSION["pass"] = (string)$xmlp->robindash->password;
header("Location: edit.php");
exit;
}
else if(!$_GET['action']) {
$body = "Reset User Password: <a href=\"?action=reset-user\">Click Here</a><br />
Remove User Account: <a href=\"?action=remove-user\">Click Here</a><br />
Disassociate Node from Account: <a href=\"?action=disassociate-node\">Click Here</a><br />
Login to users account: <a href=\"?action=login-user\">Click Here</a><br />";
}
else if($_GET['action'] == "logout") {
setcookie("spass", 1);
$status = "<p id=\"done\">You have been logged out</p>";
}
else if($_GET['action'] == "reset-user") {
$body = "You may reset a users password here.<br /><br />
<form action=\"super-powers.php\" method=\"POST\">
<lable for=\"user\">Username</label><input type=\"text\" name=\"user\" value=\"\" /><br />
<input type=\"hidden\" name=\"action\" value=\"reset-user\" />
<input type=\"button\" name=\"cancel\" value=\"Cancel\" onclick=\"window.location = 'super-powers.php';\" /> <input type=\"submit\" name=\"sent\" value=\"Reset User\" />
</form>";
}
else if($_GET['action'] == "remove-user") {
$body = "You may remove a users account here.<br /><br />
<form action=\"super-powers.php\" method=\"POST\">
<lable for=\"user\">Username</label><input type=\"text\" name=\"user\" value=\"\" /><br />
<input type=\"hidden\" name=\"action\" value=\"remove-user\" />
<input type=\"button\" name=\"cancel\" value=\"Cancel\" onclick=\"window.location = 'super-powers.php';\" /> <input type=\"submit\" name=\"sent\" value=\"Remove User\" />
</form>";
}
else if($_GET['action'] == "disassociate-node") {
$body = "You may disassociate a node from a network here.<br /><br />
<form action=\"super-powers.php\" method=\"POST\">
<lable for=\"user\">MAC Address</label><input type=\"text\" name=\"macaddress\" value=\"\" /><br />
<input type=\"hidden\" name=\"action\" value=\"disassociate-node\" />
<input type=\"button\" name=\"cancel\" value=\"Cancel\" onclick=\"window.location = 'super-powers.php';\" /> <input type=\"submit\" name=\"sent\" value=\"Disassociate Node\" />
</form>";
}
else if($_GET['action'] == "login-user") {
$body = "You may login to a users account here.<br /><br />
<form action=\"super-powers.php\" method=\"POST\">
<lable for=\"user\">Username</label><input type=\"text\" name=\"user\" value=\"\" /><br />
<input type=\"hidden\" name=\"action\" value=\"login-user\" />
<input type=\"button\" name=\"cancel\" value=\"Cancel\" onclick=\"window.location = 'super-powers.php';\" /> <input type=\"submit\" name=\"sent\" value=\"Login as User\" />
</form>";
}
}
?>
<html>
<head>
<title><?php echo $brand; ?></title>
<link rel="stylesheet" type="text/css" href="<?php echo $wdir; ?>resources/style.css">
<link rel="shortcut icon" href="<?php echo $wdir; ?>resources/favicon.ico"/>
</head>
<body>
<div id="login-panel">
<h2 class="nospacing"><?php echo $brand; ?></h2>
<h1>with Super Powers</h1>
<div id="page-content">
<?php
if($status == "logged-in") {
echo "<b>Welcome</b> | <a href=\"" . $wdir . "super-powers.php?action=logout\">Logout</a><br />What would you like to do?<hr />";
echo $body;
}
else {echo $status . $form;}
?>
</div>
</div>
</body>
</html>