summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Mazoyer <respawneral@gmail.com>2014-06-04 11:04:21 +0200
committerGuillaume Mazoyer <respawneral@gmail.com>2014-06-04 11:04:21 +0200
commit0269dccacb67f25beb39dac8f16fb3d5538c7782 (patch)
treea257d5ef3d49883ca9dd819622521ae43f491bee
parent3b65c83a5e2ce34a27d104fdb3761cbea18cda90 (diff)
Little improvement for the logging function.
Log spamers into the logs file.
-rw-r--r--execute.php1
-rw-r--r--router.php11
-rw-r--r--utils.php8
3 files changed, 11 insertions, 9 deletions
diff --git a/execute.php b/execute.php
index d927141..9761c57 100644
--- a/execute.php
+++ b/execute.php
@@ -25,6 +25,7 @@ require_once 'utils.php';
// Obvious spam
if (!isset($_POST['dontlook']) || !empty($_POST['dontlook'])) {
+ log_to_file('Spam detected from '.$_SERVER['REMOTE_ADDR'].'.');
die('Spam detected');
}
diff --git a/router.php b/router.php
index ee90947..b5112e1 100644
--- a/router.php
+++ b/router.php
@@ -46,13 +46,6 @@ class Router {
}
}
- protected function log_command($command) {
- global $config;
-
- file_put_contents($config['misc']['logs'], $command,
- FILE_APPEND | LOCK_EX);
- }
-
public function send_command($command, $parameters) {
global $config;
@@ -110,8 +103,8 @@ class Router {
$data = $auth->send_command($complete_command);
$auth->disconnect();
- $this->log_command('['.date("Y-m-d H:i:s").'] [client: '.
- $this->requester.'] '.$this->host.'> '.$complete_command."\n");
+ log_to_file('[client: '.$this->requester.'] '.$this->host.'> '.
+ $complete_command);
return $data;
}
diff --git a/utils.php b/utils.php
index e622642..20a8088 100644
--- a/utils.php
+++ b/utils.php
@@ -19,6 +19,8 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+require_once 'config.php';
+
function match_ipv4($ip) {
return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
@@ -59,4 +61,10 @@ function match_aspath_regex($aspath_regex) {
return true;
}
+function log_to_file($log) {
+ $log = '['.date("Y-m-d H:i:s").'] '.$log."\n";
+ file_put_contents($config['misc']['logs'], $log, FILE_APPEND | LOCK_EX);
+}
+
+
// End of utils.php