-
Notifications
You must be signed in to change notification settings - Fork 2
/
receive.php
52 lines (40 loc) · 1.01 KB
/
receive.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
<?php
include("config.php");
if (!isset($_POST['secret']) || $_POST['secret'] != SECRET)
{
exit('403');
}
$server_name = isset($_POST['name']) ? trim($_POST['name']) : '';
$data = trim($_POST['data']);
if (empty($server_name) || empty($data))
{
exit('fail');
}
$data = explode(';', $data);
$wmon_log = array();
$wmon_log['server_name'] = $server_name;
$wmon_log['ip'] = $_SERVER['REMOTE_ADDR'];
foreach($data as $log)
{
$log = explode(':', $log, 2);
$wmon_log[$log[0]] = $log[0] == 'time' ? intval($log[1]) : trim($log[1]);
}
$log = array();
foreach($wmon_log as $name=>$value)
{
$log[] = "`$name`='$value'";
}
$log = implode(',', $log);
$sql = "INSERT INTO wmon_log SET ".$log;
$link = mysql_connect(MYSQL_HOST.':'.MYSQL_PORT, MYSQL_USER, MYSQL_PASS);
if (!$link)
{
die('Could not connect db: ' . mysql_error());
}
$db_selected = mysql_select_db(MYSQL_DB, $link);
if (!$db_selected) {
die ('Can not select db:' . mysql_error());
}
mysql_query($sql, $link);
mysql_close($link);
echo "ok";