-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchange_admin.php
More file actions
80 lines (65 loc) · 1.92 KB
/
change_admin.php
File metadata and controls
80 lines (65 loc) · 1.92 KB
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
<?php
// Change administrative flag.
error_reporting(E_ALL);
include "globals.php";
$username = $_REQUEST['username'];
$admin = $_REQUEST['admin'] == 1; // As boolean.
if ($debug[1]) {
my_error_log("[reset_password.php] username: $username, admin: $admin");
}
// Security check.
session_start();
if (! isset($_SESSION['wysiwygit_admin'])) {
$errmsg = "You are not logged in as an administrative user.";
} else {
$errmsg = "";
// Read user's file.
$userfile = "users/$username.txt";
$lines = @file($userfile);
if (! $lines) {
$errmsg = "Could not find $userfile file";
} else {
// Find info line.
$ok_f = false;
$n_lines = count($lines);
for ($i=0; $i<$n_lines; $i++) {
// Skip comments and blank lines.
$line = $lines[$i];
$line = trim($line);
if ($line{0} == '#' || $line == '') {
continue;
}
$info = json_decode($line);
if ($info->username == $username) {
// Found line for this user. Delete from array of lines.
unset($lines[$i]);
$ok_f = true;
break;
}
}
if ($ok_f) {
// Add new line with new data. Reset info.
$info->admin = $admin;
$line = json_encode($info) . "\n";
// Add line.
$lines[] = $line;
$file_string = implode('', $lines);
file_put_contents($userfile, $file_string);
if ($admin) {
$errmsg = "OK. User $username now has administrative privileges";
} else {
$errmsg = "OK. User $username now is not an administrator";
}
$errmsg .= " (" . date("g:i") . ")";
} else {
$errmsg = "Could not find info in $userfile file";
}
}
}
$return_data = $errmsg;
$json = json_encode($return_data);
print $json;
if ($debug[1]) {
my_error_log("[reset_password.php] return_data: $json");
}
?>