-
Notifications
You must be signed in to change notification settings - Fork 24
/
messager.php
77 lines (69 loc) · 3.46 KB
/
messager.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
<?php
echo 'Error - Messaging is disabled.';
die();
// recieve message from client
if(isset($_COOKIE['keyword']) && isset($_POST['c']) && (strpos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME']) !== FALSE || explode(':', $_SERVER['HTTP_HOST'])[0] === "localhost" || $_SERVER['SERVER_NAME'] === '0.0.0.0')){
if(file_exists('USERFILES/'.$_COOKIE['keyword'].'/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();
}
*/
}
// old message writer, insecure
//fwrite($file, '{n:"'.$_GET['n'].'",c:"'.join('>', explode('>', join('<', explode('<',$_GET['c'])))).'",l:"'.$filenumber.'"}');
$messageUsername = 'Anonymous '.substr($_COOKIE['keyword'], 0, 4);
//if(is_dir('USERFILES/'.$_COOKIE['keyword'])){
// if(file_exists('USERFILES/'.$_COOKIE['keyword'].'/APP_MSG_CHATNAME.txt')){
if(file_exists('messageUsernames/n_'.$_COOKIE['keyword'].'.txt')){
$usernamefile = fopen('messageUsernames/n_'.$_COOKIE['keyword'].'.txt', 'r');
$messageUsername = fread($usernamefile, filesize('messageUsernames/n_'.$_COOKIE['keyword'].'.txt'));
fclose($usernamefile);
}
$outUsername = join('\'\'', explode('"', join('\\\\', explode('\\', join('>', explode('>', join('<', explode('<', $messageUsername))))))));
$outMessage = join('"', explode('"', join('\\\\', explode('\\', join('>', explode('>', join('<', explode('<', $_POST['c']))))))));
$outTime = round(microtime(true) * 1000);
$files = scandir('USERFILES/!MESSAGE');
usort($files, 'strnatcmp');
$newest_file = $files[count($files) - 1];
$lastJSON = file_get_contents('USERFILES/!MESSAGE/'.$newest_file);
$lastMessage = json_decode($lastJSON);
if($lastMessage->n == $outUsername && $lastMessage->c == $outMessage){
echo 'Error - Message identical to previous message.';
die();
}
$filenumber = intval($lastMessage->l) + 1;
$file = fopen('USERFILES/!MESSAGE/m'.$filenumber.'.txt', 'w');
//$file = fopen('USERFILES/!MESSAGE/m'.date('d_m_Y_H_i_s_').$_GET['n'].'.txt', 'w');
fwrite($file, '{"n":"'.$outUsername.'","c":"'.$outMessage.'","t":"'.$outTime.'","l":"'.$filenumber.'"}');
fclose($file);
}else{
echo 'Error - No user specified, or you are not allowed to send messages from your domain.';
}
?>