diff --git a/ykval-log.php b/ykval-log.php index c8a500e..53d29dd 100644 --- a/ykval-log.php +++ b/ykval-log.php @@ -6,14 +6,26 @@ class Log function __construct($name='ykval') { $this->name=$name; + $this->fields=array(); } + + function addField($name, $value) + { + $this->fields[$name]=$value; + } + function log($priority, $message, $arr=null){ if (is_array($arr)) { foreach($arr as $key=>$value){ $message.=" $key=$value "; } } - syslog($priority, $this->name . ':' . $message); + # Add fields + $msg_fields = ""; + foreach ($this->fields as $field=>$value) { + $mes_fields .= "[" . $value . "] "; + } + syslog($priority, $this->name . ':' . $msg_fields . $message); } } diff --git a/ykval-sync.php b/ykval-sync.php index 32086a0..b03562c 100644 --- a/ykval-sync.php +++ b/ykval-sync.php @@ -8,9 +8,12 @@ $apiKey = ''; header("content-type: text/plain"); $myLog = new Log('ykval-sync'); +$myLog->addField('ip', $_SERVER['REMOTE_ADDR']); + $myLog->log(LOG_INFO, "Request: " . $_SERVER['QUERY_STRING']); $sync = new SyncLib('ykval-sync:synclib'); +$sync->myLog->addField('ip', $_SERVER['REMOTE_ADDR']); if (! $sync->isConnected()) { sendResp(S_BACKEND_ERROR, $apiKey); @@ -67,6 +70,12 @@ foreach ($syncParams as $param=>$value) { } $myLog->log(LOG_INFO, $tmp_log); +# +# At this point we should have to otp so let's add it to the logging module +# +$myLog->addField('otp', $syncParams['otp']); +$sync->myLog->addField('otp', $syncParams['otp']); + # # Verify correctness of input parameters # diff --git a/ykval-verify.php b/ykval-verify.php index 09e417c..f0c53ff 100644 --- a/ykval-verify.php +++ b/ykval-verify.php @@ -8,6 +8,7 @@ $apiKey = ''; header("content-type: text/plain"); $myLog = new Log('ykval-verify'); +$myLog->addField('ip', $_SERVER['REMOTE_ADDR']); $myLog->log(LOG_INFO, "Request: " . $_SERVER['QUERY_STRING']); /* Detect protocol version */ @@ -20,7 +21,9 @@ $myLog->log(LOG_INFO, "found protocol version " . $protocol_version); /* Initialize the sync library. Strive to use this instead of custom DB requests, custom comparisons etc */ -$sync = new SyncLib(); +$sync = new SyncLib('ykval-verify:synclib'); +$sync->myLog->addField('ip', $_SERVER['REMOTE_ADDR']); + if (! $sync->isConnected()) { sendResp(S_BACKEND_ERROR, $apiKey); exit; @@ -34,6 +37,11 @@ $client = getHttpVal('id', 0); $otp = getHttpVal('otp', ''); $otp = strtolower($otp); $timestamp = getHttpVal('timestamp', 0); + +/* We have the OTP now, so let's add it to the logging */ +$myLog->addField('otp', $otp); +$sync->myLog->addField('otp', $otp); + if ($protocol_version>=2.0) { $sl = getHttpVal('sl', '');