-
Notifications
You must be signed in to change notification settings - Fork 5
/
OLSendLog.php
171 lines (140 loc) · 3.33 KB
/
OLSendLog.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
<?php
// OLSendLog v1.34
//
// OverloadUT's OLSendLog for OLStats 3.01 modified by Panther for UTStatsDB 3.03
/*
Possible return codes:
R1 OK
R2 Bad Password
R3 No filename specified
R4 No data sent
R5 Could not create logfile
R6 Error saving data
R7 Configuration error
R8 Invalid Prefix
*/
echo "OLStatsSendLogTarget\n";
error_reporting(0);
require("includes/statsdb.inc.php");
require("includes/logsql.php");
function check_post($val)
{
$magic = get_magic_quotes_gpc();
if (isset($_POST["$val"])) {
if ($magic)
$store = stripslashes($_POST["$val"]);
else
$store = $_POST["$val"];
if ($store)
return $store;
return 1;
}
return 0;
}
function loadstatconfig()
{
global $dbpre, $UpdatePass, $conflogs, $AutoParse;
$magicrt = get_magic_quotes_runtime();
$link = sql_connect();
$result = sql_querynb($link, "SELECT conf,value FROM {$dbpre}config WHERE conf='UpdatePass' OR conf='AutoParse'");
if ($result && sql_num_rows($result) >= 2) {
while ($row = sql_fetch_row($result)) {
${$row[0]} = $magicrt ? stripslashes($row[1]) : $row[1];
}
sql_free_result($result);
}
else {
send_result("7");
exit;
}
$conflogs = array(array());
$result = sql_querynb($link, "SELECT logpath,prefix FROM {$dbpre}configlogs ORDER BY num");
if ($result && sql_num_rows($result)) {
$num = 0;
while ($row = sql_fetch_row($result)) {
$conflogs["logpath"][$num] = $magicrt ? stripslashes($row[0]) : $row[0];
$conflogs["logprefix"][$num++] = $magicrt ? stripslashes($row[1]) : $row[1];
}
sql_free_result($result);
}
else {
send_result("7");
exit;
}
sql_close($link);
}
function checkprefix($fn)
{
global $conflogs;
$logpath = "";
$num = 0;
while (isset($conflogs["logpath"][$num]) && $logpath == "") {
$len = strlen($conflogs["logprefix"][$num]);
if (!strncasecmp($fn, $conflogs["logprefix"][$num], $len))
$logpath = $conflogs["logpath"][$num];
$num++;
}
return $logpath;
}
function send_result($rc)
{
// There is a bug in LibHTTP2 that makes it so the last couple lines sometimes
// do not come through, so I add buffer to the end of the output to fix that.
echo "$rc\nBuffer\nBuffer\nBuffer";
}
function logparse() {
global $dbpre;
$result = sql_query("SELECT value FROM {$dbpre}config WHERE conf='UpdatePass' LIMIT 1");
if ($result) {
$row = sql_fetch_row($result);
sql_free_result($result);
$UpdatePass = $row[0];
}
else
return;
require("logs.php");
}
loadstatconfig();
$okay = false;
$password = check_post("pass");
$filename = check_post("filename");
$data = check_post("data");
if ($password == "" || $UpdatePass == "" || $password != $UpdatePass) {
send_result("2");
exit;
}
if ($filename === 0)
{
send_result("3");
exit;
}
if ($data === 0)
{
send_result("4");
exit;
}
$logpath = checkprefix($filename);
if ($logpath == "") {
send_result("8");
exit;
}
$ext = strtolower(substr($filename, -4));
if ($ext == ".log" || $ext == ".txt")
$filename = $logpath.$filename;
else
$filename = $logpath.$filename.".log";
if (($f = @fopen($filename, "w")) === FALSE)
{
send_result("5");
exit;
}
if ((fwrite($f, $data, strlen($data))) === FALSE)
send_result("6");
else {
send_result("1");
$okay = true;
}
fclose($f);
if ($okay && $AutoParse)
logparse();
?>