-
Notifications
You must be signed in to change notification settings - Fork 24
/
messageAdminAction.php
106 lines (95 loc) · 4.19 KB
/
messageAdminAction.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
<?php
if(isset($_COOKIE['keyword'])){
if($_COOKIE['keyword']){
if(strpos($_COOKIE['keyword'], '.') !== false || strpos($_COOKIE['keyword'], '/') !== false){
// bad cookie. ignore it
unset($_COOKIE['keyword']);
}
}
}
ini_set("open_basedir", "./");
function error($errno, $errstr){
echo "Error - [" + $errno + '] ' + $errstr;
}
set_error_handler("error");
if(strlen($_COOKIE['keyword']) == 21){
if(!is_dir('USERFILES/'.$_COOKIE['keyword'])){
mkdir('USERFILES/'.$_COOKIE['keyword']);
}
if(file_exists('messageUsernames/n_'.$_COOKIE['keyword'].'.txt')){
if(strpos(file_get_contents('messageUsernames/n_'.$_COOKIE['keyword'].'.txt'), '{ADMIN}') !== 0){
echo 'Error - You are not an admin.';
die();
}
}else{
echo 'Error - You are not an admin.';
die();
}
if(file_exists('USERFILES/'.$_COOKIE['keyword'].'/aOSpassword.txt')){
if(strlen(file_get_contents('USERFILES/'.$_COOKIE['keyword'].'/aOSpassword.txt')) === 64){
unlink('USERFILES/'.$_COOKIE['keyword'].'/aOSpassword.txt');
}else{
if(strlen(file_get_contents('USERFILES/'.$_COOKIE['keyword'].'/aOSpassword.txt')) !== 60){
$passbc = password_hash(file_get_contents('USERFILES/'.$_COOKIE['keyword'].'/aOSpassword.txt'), PASSWORD_BCRYPT);
$passfile = fopen('USERFILES/'.$_COOKIE['keyword'].'/aOSpassword.txt', 'w');
fwrite($passfile, $passbc);
fclose($passfile);
}
}
if(isset($_COOKIE['password'])){
if(!password_verify($_COOKIE['password'], file_get_contents('USERFILES/'.$_COOKIE['keyword'].'/aOSpassword.txt'))){
echo 'Error - Password incorrect.';
die();
}
}else{
echo 'Error - Password not provided.';
die();
}
}
}else{
echo "Error - User ID malformed, or your user ID is incorrect. ".$_COOKIE['keyword'];
die();
}
if($_POST['action'] === 'getMessages'){
$allMessages = scandir('USERFILES/!MESSAGE');
$allMessages = array_filter($allMessages, function($item){
return strpos($item, '.') !== 0;
});
usort($allMessages, 'strnatcmp');
$messages = array();
foreach($allMessages as $msg){
$messages[$msg] = file_get_contents('USERFILES/!MESSAGE/'.$msg);
}
echo json_encode($messages);
}else if($_POST['action'] === 'setContent'){
if(strpos($_POST['target'], '/') !== FALSE || strpos($_POST['target'], '.') !== FALSE){
echo 'Error: Invalid message name: '.$_POST['target'];
die();
}
if(file_exists('USERFILES/!MESSAGE/'.$_POST['target'].'.txt')){
$message = json_decode(file_get_contents('USERFILES/!MESSAGE/'.$_POST['target'].'.txt'));
$message->c = $_POST['content'];
file_put_contents('USERFILES/!MESSAGE/'.$_POST['target'].'.txt', json_encode($message));
echo 'Success: '.($message->c);
}else{
echo 'Error: Message not found: '.$_POST['target'];
die();
}
}else if($_POST['action'] === 'setAuthor'){
if(strpos($_POST['target'], '/') !== FALSE || strpos($_POST['target'], '.') !== FALSE){
echo 'Error: Invalid message name: '.$_POST['target'];
die();
}
if(file_exists('USERFILES/!MESSAGE/'.$_POST['target'].'.txt')){
$message = json_decode(file_get_contents('USERFILES/!MESSAGE/'.$_POST['target'].'.txt'));
$message->n = $_POST['content'];
file_put_contents('USERFILES/!MESSAGE/'.$_POST['target'].'.txt', json_encode($message));
echo 'Success: '.($message->n);
}else{
echo 'Error: Message not found: '.$_POST['target'];
die();
}
}else{
echo 'Error: Invalid action: '.$_POST['action'];
}
?>