-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffline.php
78 lines (59 loc) · 2.25 KB
/
offline.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
<?php
if (!defined('ENV_READ_CONFIG')) require_once(realpath(dirname(__FILE__).'/../include/config.php'));
if (!defined('ENV_READ_DEFINE')) require_once(realpath(ENV_HELPER_PATH.'/../include/env_define.php'));
require_once(realpath(ENV_HELPER_PATH.'/../include/opensim.mysql.php'));
if (!isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = file_get_contents('php://input');
//$request_xml = $HTTP_RAW_POST_DATA;
//error_log('offline.php: '.$request_xml);
//
if (!opensim_is_access_from_region_server()) {
$remote_addr = $_SERVER['REMOTE_ADDR'];
error_log('offline.php: Illegal access from '.$remote_addr);
exit;
}
$DbLink = new DB($MESSAGE_DB_HOST, $MESSAGE_DB_NAME, $MESSAGE_DB_USER, $MESSAGE_DB_PASS, $MESSAGE_DB_MYSQLI);
$method = $_SERVER['PATH_INFO'];
if ($method=='/SaveMessage/') {
$msg = $HTTP_RAW_POST_DATA;
$start = strpos($msg, "?>");
if ($start!=-1) {
$start+=2;
$msg = substr($msg, $start);
$parts = preg_split("/[<>]/", $msg);
$from_agent = $parts[4];
$to_agent = $parts[12];
if (isGUID($from_agent) and isGUID($to_agent)) {
$esc_msg = $DbLink->escape($msg);
$query_str = "INSERT INTO ".OFFLINE_MESSAGE_TBL." (to_uuid,from_uuid,message) VALUES ('".$to_agent."','".$from_agent."','".$esc_msg."')";
$DbLink->query($query_str);
if ($DbLink->Errno==0) {
echo '<?xml version="1.0" encoding="utf-8"?><boolean>true</boolean>';
exit;
}
}
}
echo '<?xml version="1.0" encoding="utf-8"?><boolean>false</boolean>';
exit;
}
if ($method == '/RetrieveMessages/') {
$parms = $HTTP_RAW_POST_DATA;
$parts = preg_split("/[<>]/", $parms);
$agent_id = $parts[6];
$errno = -1;
if (isGUID($agent_id)) {
$DbLink->query("SELECT message FROM ".OFFLINE_MESSAGE_TBL." WHERE to_uuid='".$agent_id."'");
$errno = $DbLink->Errno;
}
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<ArrayOfGridInstantMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">';
if ($errno==0) {
while(list($message) = $DbLink->next_record()) {
echo $message;
}
}
echo '</ArrayOfGridInstantMessage>';
if ($errno==0) {
$DbLink->query("DELETE FROM ".OFFLINE_MESSAGE_TBL." WHERE to_uuid='".$agent_id."'");
}
exit;
}