diff options
Diffstat (limited to 'modules-available/syslog/api.inc.php')
-rw-r--r-- | modules-available/syslog/api.inc.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/modules-available/syslog/api.inc.php b/modules-available/syslog/api.inc.php new file mode 100644 index 00000000..cebe5ef1 --- /dev/null +++ b/modules-available/syslog/api.inc.php @@ -0,0 +1,40 @@ +<?php + +if (empty($_POST['type'])) die('Missing options.'); +$type = mb_strtolower($_POST['type']); + +$ip = $_SERVER['REMOTE_ADDR']; +if (substr($ip, 0, 7) === '::ffff:') $ip = substr($ip, 7); + +// TODO: Handle UUID in appropriate modules (optional) +$uuid = Request::post('uuid', '', 'string'); +if (strlen($uuid) !== 36) { + // Probably invalid UUID. What to do? Set empty or ignore? +} + +/* + * Normal logging + */ + +if (!isset($_POST['description'])) die('Missing options..'); + +$description = $_POST['description']; +$longdesc = ''; +if (isset($_POST['longdesc'])) $longdesc = $_POST['longdesc']; + +if ($type{0} !== '.' && $type{0} !== '~') { + + // Spam from IP + $row = Database::queryFirst('SELECT Count(*) AS cnt FROM clientlog WHERE clientip = :client AND dateline + 3600 > UNIX_TIMESTAMP()', array(':client' => $ip)); + if ($row !== false && $row['cnt'] > 150) exit(0); + + Database::exec('INSERT INTO clientlog (dateline, logtypeid, clientip, description, extra) VALUES (UNIX_TIMESTAMP(), :type, :client, :description, :longdesc)', array( + 'type' => $type, + 'client' => $ip, + 'description' => $description, + 'longdesc' => $longdesc, + )); + +} + +echo "OK.\n"; |