forked from MineAndCraft12/AaronOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesavernew.php
177 lines (166 loc) · 8.17 KB
/
filesavernew.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
<?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", "./");
if((isset($_POST['c']) || isset($_POST['mkdir'])) && (strpos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME']) !== FALSE || explode(':', $_SERVER['HTTP_HOST'])[0] === "localhost" || $_SERVER['SERVER_NAME'] === '0.0.0.0')){ //aaron-os-mineandcraft12.c9.io'){
function error($errno, $errstr){
echo "Error - [".$errno.'] '.$errstr;
}
set_error_handler("error");
//if(strlen($_POST['c']) !== 0){
if(strlen($_POST['k']) == 21 && $_COOKIE['keyword'] === $_POST['k']){
if(!is_dir('USERFILES/'.$_POST['k'])){
mkdir('USERFILES/'.$_POST['k']);
}
if(file_exists('USERFILES/'.$_POST['k'].'/aOSpassword.txt')){
if(isset($_COOKIE['logintoken'])){
if((require 'checkToken.php') === 0){
echo 'Error - Not logged in.';
die();
}
}else{
echo 'Error - Not logged in.';
die();
}
/*
if(strlen(file_get_contents('USERFILES/'.$_POST['k'].'/aOSpassword.txt')) === 64){
unlink('USERFILES/'.$_POST['k'].'/aOSpassword.txt');
}else{
if(strlen(file_get_contents('USERFILES/'.$_POST['k'].'/aOSpassword.txt')) !== 60){
$passbc = password_hash(file_get_contents('USERFILES/'.$_POST['k'].'/aOSpassword.txt'), PASSWORD_BCRYPT);
$passfile = fopen('USERFILES/'.$_POST['k'].'/aOSpassword.txt', 'w');
fwrite($passfile, $passbc);
fclose($passfile);
//$currPassword = $passbc;
}
}
if(isset($_COOKIE['password'])){
if(!password_verify($_COOKIE['password'], file_get_contents('USERFILES/'.$_POST['k'].'/aOSpassword.txt'))){
echo 'Error - Password incorrect.';
die();
}
}else{
echo 'Error - Password not provided.';
die();
}
*/
}
if(strpos($_POST['f'], '..') != FALSE){
echo 'Error - Keyword ".." not allowed.';
die();
}
if(isset($_POST['mkdir'])){
$filepath = 'USERFILES/'.$_POST['k'].'/'.$_POST['f'];
}else{
$filepath = 'USERFILES/'.$_POST['k'].'/'.$_POST['f'];
}
$newUsers = fopen('USERFILES/newUsers.txt', 'r');
if(filesize('USERFILES/newUsers.txt') === 0){
$newUsersList = array();
}else{
$newUsersList = explode("\n", fread($newUsers, filesize('USERFILES/newUsers.txt')));
}
fclose($newUsers);
$newList = array();
$userFound = 0;
$user = 'none';
foreach($newUsersList as $user){
if((int)substr($user, strpos($user, '=') + 1, strlen($user)) >= round(microtime(true) * 1000) - 120000){
array_push($newList, $user);
//if(strpos($user, $_COOKIE['keyword']) === 0){
// echo 'Error - Your account is too new to save files, please wait a total of 30 seconds before creating your first file. This is to prevent a flood on the server.';
// $userFound = 1;
//}
}
}
unset($user);
$newUsers = fopen('USERFILES/newUsers.txt', 'w');
fwrite($newUsers, join("\n", $newList));
fclose($newUsers);
if($userFound){
die();
}
ini_set("open_basedir", "./USERFILES/".$_COOKIE['keyword']."/");
if(isset($_POST['mkdir'])){
if(file_exists($filepath.'.txt')){
echo 'Error - Cannot save directory with same name as a file.';
die();
}
if(!is_dir($filepath)){
mkdir($filepath, 0777, true);
}
echo 'Success!';
}else{
$allowedToModifyPassword = 0;
if(isset($_POST['setpass'])){
$allowedToModifyPassword = 1;
}
if(strpos($filepath, '/aosPassword.txt') != FALSE){
if(!$allowedToModifyPassword){
echo 'Error - Not allowed to modify password file.';
die();
}
}
if(is_dir(substr($filepath, 0, strrpos($filepath, '.txt')))){
echo 'Error - Cannot save file with same name as directory.';
die();
}
if(!is_dir(substr($filepath, 0, strrpos($filepath, '/')))){
mkdir(substr($filepath, 0, strrpos($filepath, '/')), 0777, true);
}
$file = fopen($filepath.'.txt', 'w');
if(!$file){
echo 'Error - could not open file.';
die();
}
fwrite($file, $_POST['c']);
echo("Success!");
fclose($file);
if(isset($_GET['mUname'])){
if(strpos(strtolower($_POST['c']), '{admin}') !== false){
echo 'Admin username check: ';
/*
if(isset($_GET['pass'])){
if($_GET['pass'] === 'L33t_H4x0r_Sk1llz'){
$mNamefile = fopen('messageUsernames/n_'.$_POST['k'].'.txt', 'w');
fwrite($mNamefile, $_POST['c']);
fclose($mNamefile);
echo 'Pass ';
}else{
echo 'Bad password ';
}
}else{
echo 'No password ';
}
*/
echo 'Not allowed (have an administrator manually set your admin tag) ';
}else{
echo 'Admin username not discovered ';
$mNamefile = fopen('messageUsernames/n_'.$_POST['k'].'.txt', 'w');
fwrite($mNamefile, join('>', explode('>', join('<', explode('<', join('&', explode('&', $_POST['c'])))))));
fclose($mNamefile);
if($_POST['c'] === "" || $_POST['c'] === "Anonymous"){
unlink('messageUsernames/n_'.$_POST['k'].'.txt');
}
}
}
}
}else{
echo "Error - User ID malformed, or your user ID is incorrect. ".$_POST['k'].', '.$_COOKIE['keyword'];
die();
}
//}else{
// echo 'Error - Content blank.';
// die();
//}
}else{
echo 'Error - No content provided, or forbidden request from cross-origin domain.';
die();
}
?>