-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.php
221 lines (205 loc) · 5.88 KB
/
manager.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
<?php
global $CONFIG,$MANAGER_MODE;
require_once "config.php";
session_start();
header("Cache-Control: no-store, no-cache, must-revalidate");
$header = '<html><head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="manager.css" rel="stylesheet">
</head><body>';
$secret_cookie = md5($CONFIG['manager_password_md5'] . floor(time() / 222200) . MANAGER_FLAG); // secret cookie lasts ~60 hours
$secret_cookie2 = md5($CONFIG['manager_password_md5'] . ceil(time() / 222200) . MANAGER_FLAG); // secret cookie lasts ~60 hours
$MANAGER_MODE = @$_COOKIE[MANAGER_FLAG] == $secret_cookie || @$_COOKIE[MANAGER_FLAG] == $secret_cookie2;
$bad_password = false;
if (!$MANAGER_MODE) {
// login flow - honeypots logic
if (! empty($_POST['user']) || ! empty($_POST['pass'])) {
// honeypots logic
$bad_password = true;
} else if (! empty($_POST['po'])) {
// login flow - read password
if ($CONFIG['manager_password_md5'] == md5($_POST['po'])) {
setcookie(MANAGER_FLAG, $secret_cookie2);
header("Location: ?logged-in");
exit();
} else {
$bad_password = true;
}
}
}
if ($bad_password) {
sleep(5 * rand());
}
if (!$MANAGER_MODE) {
// login flow - display
echo $header;
?>
<div class="container">
<form method="POST" class="form-inline" action="?logging">
<?php /* START HONEYPOTS */?>
<h1>Manager Login</h1>
<label class="not-really-here">User: <input name="user" /></label> <label
class="not-really-here">Pass: <input name="pass" type="password" /></label>
<?php /* ^ when these have values - ignore everything... */?>
<?php /* END HONEYPOTS */?>
<div class="input-append form-group <?=$bad_password ? 'has-error' : ''?>">
<input placeholder="Enter your password" class="form-control <?=$bad_password ? 'has-error' : ''?>" name="po" />
<input type="submit" value="Go" class="form-control">
</div>
</form>
</div>
<script>
document.querySelector('[name="po"]').type="password";
</script>
<?php
// if manager
} else {
echo $header;
$getaction = @$_GET['f'];
$action = explode(';', $getaction);
$param = @$action[1];
$action = $action[0];
$actions = array(
'config' => 'Books Configuration',
'clearcache;list' => 'Refresh Google Drive Changes',
'testcache;list' => 'Test List Cache',
'testcache;file' => 'Test File Cache',
//'clearcache;file' => 'Clear File Cache',
'log;mylog' => 'Read Inner Log',
'log;phplog' => 'Read PHP Log',
'clearlog;mylog' => 'Clear Inner Log',
'clearlog;phplog' => 'Clear PHP Log',
'auth' => 'Validate Google Auth',
'clearauth' => 'Revoke Google Credentials',
'logout' => 'Log out',
);
if ($getaction == 'edit') {
include("manager-edit.include.php");
exit();
}
if (array_key_exists($getaction,$actions)) {
$action_name = $actions[$getaction];
if ($action == 'config') {
include("manager-config.include.php");
exit();
}
if ($action == 'logout') {
setcookie(MANAGER_FLAG, '');
header("Location: ?");
exit();
}
// /////////////////////
// Handle parameters //
// /////////////////////
if ($param == 'mylog') {
$logpath = MYLOG_PATH;
}
if ($param == 'phplog') {
$logpath = __DIR__ . '/error_log';
}
if ($param == 'list') {
$cachetype = CACHETYPE_LIST;
}
if ($param == 'file') {
$cachetype = CACHETYPE_FILE;
}
// /////////////////////////////////
// Handle actions that redirects //
// /////////////////////////////////
if ($action == 'clearauth') {
if (file_exists(REFRESH_TOKEN_PATH)) {
unlink(REFRESH_TOKEN_PATH);
}
if (file_exists(CREDENTIALS_PATH)) {
unlink(CREDENTIALS_PATH);
}
redirect('auth');
}
echo "<pre id='out'>Action: $action_name\n";
if ($action == 'auth') {
require "reader.lib.php";
$list = get_files("fullText contains 'Testing file list access'");
if ($list === null) {
echo "\nError";
} else {
echo "OK";
}
}
if ($action == 'log') {
echo "Log file path: $logpath\n";
if (file_exists($logpath)) {
readfile($logpath);
} else {
echo "No such file.";
}
}
if ($action == 'clearlog') {
if (file_exists($logpath)) {
unlink($logpath);
}
echo "\nDone.";
}
if ($action == 'clearcache') {
$path = CACHE_PATH . "/$cachetype";
echo "Removing $path\n";
rrmdir($path);
mkdir($path, 0777, true);
chmod($path, 0777);
echo "\nDone.";
}
if ($action == 'testcache') {
$id = "_test_cache";
$content = "This is a content for testing cache";
echo "Cache file = " . cache_path($id, $cachetype) . "\n";
echo "Testing basic: ";
cache_write($id, $cachetype, $content);
$read = cache_read($id, $cachetype);
if ($content != $read) {
echo "FAIL!\nContent from cache:\n" . $read;
} else {
echo "OK\n";
echo "Testing modified time up to date: ";
$read = cache_read($id, $cachetype, time() - 1000);
if ($read != $content) {
echo "FAIL";
} else {
echo "OK\n";
echo "Testing modified time expired: ";
$read = cache_read($id, $cachetype, time() + 1000);
if ($read !== false) {
echo "FAIL";
} else {
echo "OK\n";
}
}
}
}
echo "</pre>";
}
echo "<h3>Select action:</h3>";
foreach ( $actions as $act => $name ) {
echo "<a href='?f=$act' class='act btn btn-default'>$name</a><br>";
}
} // else manager
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);
}
}
function redirect($action) {
echo "<script>location.href='?f=$action&_=" . rand() . "';</script>";
exit();
}