diff --git a/ykval-common.php b/ykval-common.php index f7f28ee..7200f3c 100644 --- a/ykval-common.php +++ b/ykval-common.php @@ -81,7 +81,7 @@ function sign($a, $apiKey, $logger) $qs = utf8_encode($qs); // base64 encoded binary digest - $hmac = hash_hmac('sha1', $qs, $apiKey, TRUE); + $hmac = hash_hmac('sha1', $qs, $apiKey, true); $hmac = base64_encode($hmac); $logger->log(LOG_DEBUG, "SIGN: $qs H=$hmac"); @@ -96,17 +96,17 @@ function curl_settings($logger, $ident, $ch, $url, $timeout, $opts) curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_USERAGENT, 'YK-VAL'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_FAILONERROR, true); - if (is_array($opts) === FALSE) + if (is_array($opts) === false) { $logger->log(LOG_WARN, $ident . 'curl options must be an array'); return; } foreach ($opts as $key => $val) - if (curl_setopt($ch, $key, $val) === FALSE) + if (curl_setopt($ch, $key, $val) === false) $logger->log(LOG_WARN, "$ident failed to set " . curl_opt_name($key)); } @@ -120,10 +120,10 @@ function curl_opt_name($opt) $consts = get_defined_constants(true); $consts = $consts['curl']; - $name = array_search($opt, $consts, TRUE); + $name = array_search($opt, $consts, true); // array_search may return either on failure... - if ($name === FALSE || $name === NULL) + if ($name === false || $name === null) return 'curl option'; return $name; @@ -136,7 +136,7 @@ function curl_opt_name($opt) // long as one of the URLs given work, data will be returned. If all // URLs fail, data from some URL that did not match parameter $match // (defaults to ^OK) is returned, or if all URLs failed, false. -function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $returl=False, $timeout=10, $curlopts) +function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $returl=false, $timeout=10, $curlopts) { $mh = curl_multi_init(); $ch = array(); @@ -216,9 +216,9 @@ function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $ret function KSMdecryptOTP($urls, $logger, $curlopts) { - $response = retrieveURLasync('YK-KSM', $urls, $logger, $ans_req=1, $match='^OK', $returl=False, $timeout=10, $curlopts); + $response = retrieveURLasync('YK-KSM', $urls, $logger, $ans_req=1, $match='^OK', $returl=false, $timeout=10, $curlopts); - if ($response === FALSE) + if ($response === false) return false; $response = array_shift($response); @@ -242,7 +242,7 @@ function KSMdecryptOTP($urls, $logger, $curlopts) function sendResp($status, $logger, $apiKey = '', $extra = null) { - if ($logger->request !== NULL) + if ($logger->request !== null) $logger->request->set('status', $status); $a['status'] = $status; @@ -272,7 +272,7 @@ function sendResp($status, $logger, $apiKey = '', $extra = null) $logger->log(LOG_INFO, "Response: " . $str . " (at " . gmdate("c") . " " . microtime() . ")"); - if ($logger->request !== NULL) + if ($logger->request !== null) $logger->request->write(); echo $str; @@ -280,7 +280,7 @@ function sendResp($status, $logger, $apiKey = '', $extra = null) } // backport from PHP 5.6 -if (function_exists('hash_equals') === FALSE) +if (function_exists('hash_equals') === false) { function hash_equals($a, $b) { @@ -309,27 +309,27 @@ function total_time ($url) $opts = array( CURLOPT_URL => $url, CURLOPT_TIMEOUT => 3, - CURLOPT_FORBID_REUSE => TRUE, - CURLOPT_FRESH_CONNECT => TRUE, - CURLOPT_RETURNTRANSFER => TRUE, + CURLOPT_FORBID_REUSE => true, + CURLOPT_FRESH_CONNECT => true, + CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => 'ykval-munin-vallatency/1.0', ); - if (($ch = curl_init()) === FALSE) + if (($ch = curl_init()) === false) return false; - if (curl_setopt_array($ch, $opts) === FALSE) + if (curl_setopt_array($ch, $opts) === false) return false; // we don't care about the actual response - if (curl_exec($ch) === FALSE) + if (curl_exec($ch) === false) return false; $total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME); curl_close($ch); - if (is_float($total_time) === FALSE) + if (is_float($total_time) === false) return false; return $total_time; @@ -355,7 +355,7 @@ function endpoints ($urls) $internal = substr(sha1($url), 0, 20); // actual label name shown for graph values - if (($label = hostport($url)) === FALSE) + if (($label = hostport($url)) === false) { return false; } @@ -387,20 +387,20 @@ function endpoints ($urls) */ function hostport ($url) { - if (($url = parse_url($url)) === FALSE) + if (($url = parse_url($url)) === false) return false; - if (array_key_exists('host', $url) === FALSE || $url['host'] === NULL) + if (array_key_exists('host', $url) === false || $url['host'] === null) return false; - if (array_key_exists('port', $url) === TRUE && $url['port'] !== NULL) + if (array_key_exists('port', $url) === true && $url['port'] !== null) return $url['host'].':'.$url['port']; - if (array_key_exists('scheme', $url) === TRUE + if (array_key_exists('scheme', $url) === true && strtolower($url['scheme']) === 'http') return $url['host'].':80'; - if (array_key_exists('scheme', $url) === TRUE + if (array_key_exists('scheme', $url) === true && strtolower($url['scheme']) === 'https') return $url['host'].':443'; diff --git a/ykval-db-oci.php b/ykval-db-oci.php index 834a09d..bbbfece 100644 --- a/ykval-db-oci.php +++ b/ykval-db-oci.php @@ -72,7 +72,7 @@ public function connect(){ if (!$this->dbh) { $error = oci_error(); $this->myLog->log(LOG_CRIT, "Database connection error: " . $error["message"]); - $this->dbh=Null; + $this->dbh=null; return false; } return true; @@ -88,7 +88,7 @@ protected function query($query, $returnresult=false) { $result = oci_parse($this->dbh, $query); if(!oci_execute($result)) { $this->myLog->log(LOG_INFO, 'Database query error: ' . preg_replace('/\n/',' ',print_r(oci_error($result), true))); - $this->dbh = Null; + $this->dbh = null; return false; } $this->result = $result; diff --git a/ykval-db-pdo.php b/ykval-db-pdo.php index a3a7014..b11b8b6 100644 --- a/ykval-db-pdo.php +++ b/ykval-db-pdo.php @@ -71,7 +71,7 @@ public function connect(){ $this->dbh = new PDO($this->db_dsn, $this->db_username, $this->db_password, $this->db_options); } catch (PDOException $e) { $this->myLog->log(LOG_CRIT, "Database connection error: " . $e->getMessage()); - $this->dbh=Null; + $this->dbh=null; return false; } return true; @@ -88,7 +88,7 @@ protected function query($query, $returnresult=false) { $this->result = $this->dbh->query($query); } catch (PDOException $e) { $this->myLog->log(LOG_INFO, 'Database query error: ' . preg_replace('/\n/',' ',print_r($this->dbh->errorInfo(), true))); - $this->dbh = Null; + $this->dbh = null; return false; } if ($returnresult) return $this->result; @@ -137,33 +137,33 @@ public function closeCursor($result=null){ * * @return mixed Array with values from Db row or 2d-array with multiple rows */ - public function findByMultiple($table, $where, $nr=NULL, $rev=NULL, $distinct=NULL) + public function findByMultiple($table, $where, $nr=null, $rev=null, $distinct=null) { $value = ''; - $match = NULL; + $match = null; $query = 'SELECT'; - if ($distinct != NULL) + if ($distinct != null) $query.= " DISTINCT " . $distinct; else $query.= " *"; $query.= " FROM " . $table; - if ($where != NULL) + if ($where != null) { foreach ($where as $key => $value) { - if ($key != NULL) + if ($key != null) { - if ($value != NULL) + if ($value != null) $match .= " ". $key . " = '" . $value . "' and"; else $match .= " ". $key . " is NULL and"; } } - if ($match != NULL) + if ($match != null) $query .= " WHERE" . $match; $query = rtrim($query, "and"); @@ -173,7 +173,7 @@ public function findByMultiple($table, $where, $nr=NULL, $rev=NULL, $distinct=NU if ($rev == 1) $query.= " ORDER BY id DESC"; - if ($nr != NULL) + if ($nr != null) $query.= " LIMIT " . $nr; $result = $this->query($query, true); diff --git a/ykval-db.php b/ykval-db.php index d22551e..d836995 100644 --- a/ykval-db.php +++ b/ykval-db.php @@ -93,7 +93,7 @@ public function timestampDeltaTime($first, $second) */ public function disconnect() { - $this->dbh=NULL; + $this->dbh=null; } /** @@ -104,8 +104,8 @@ public function disconnect() */ public function isConnected() { - if ($this->dbh!=NULL) return True; - else return False; + if ($this->dbh!=null) return true; + else return false; } /** diff --git a/ykval-log-verify.php b/ykval-log-verify.php index 927bc4d..5725580 100644 --- a/ykval-log-verify.php +++ b/ykval-log-verify.php @@ -31,27 +31,27 @@ class LogVerify { - public $format = NULL; + public $format = null; private $fields = array( - 'time_start' => NULL, - 'time_end' => NULL, - 'time_taken' => NULL, - 'ip' => NULL, - 'client' => NULL, - 'public_id' => NULL, - 'otp' => NULL, - 'status' => NULL, - 'nonce' => NULL, - 'signed' => NULL, - 'counter' => NULL, - 'low' => NULL, - 'high' => NULL, - 'use' => NULL, - 'tls' => NULL, - 'protocol' => NULL, - 'sl' => NULL, - 'timeout' => NULL, + 'time_start' => null, + 'time_end' => null, + 'time_taken' => null, + 'ip' => null, + 'client' => null, + 'public_id' => null, + 'otp' => null, + 'status' => null, + 'nonce' => null, + 'signed' => null, + 'counter' => null, + 'low' => null, + 'high' => null, + 'use' => null, + 'tls' => null, + 'protocol' => null, + 'sl' => null, + 'timeout' => null, ); /** @@ -67,7 +67,7 @@ public function set($name, $value) if ($name === 'time_end' || $name === 'time_taken') return false; - if (array_key_exists($name, $this->fields) === FALSE) + if (array_key_exists($name, $this->fields) === false) return false; $this->fields[$name] = $value; @@ -81,7 +81,7 @@ public function set($name, $value) */ public function write() { - if ($this->format === NULL) + if ($this->format === null) return false; $values = array(); @@ -127,25 +127,25 @@ private function sanitized() if (preg_match('/^[0-9]+$/', $a['client']) !== 1) $a['client'] = '-'; - if (filter_var($a['ip'], FILTER_VALIDATE_IP) === FALSE) + if (filter_var($a['ip'], FILTER_VALIDATE_IP) === false) $a['ip'] = '-'; - if (is_int($a['counter']) === FALSE) + if (is_int($a['counter']) === false) $a['counter'] = '-'; - if (is_int($a['low']) === FALSE) + if (is_int($a['low']) === false) $a['low'] = '-'; - if (is_int($a['high']) === FALSE) + if (is_int($a['high']) === false) $a['high'] = '-'; - if (is_int($a['use']) === FALSE) + if (is_int($a['use']) === false) $a['use'] = '-'; if (preg_match('/^[a-zA-Z0-9]{16,40}$/', $a['nonce']) !== 1) $a['nonce'] = '-'; - if (is_float($a['protocol']) === TRUE) + if (is_float($a['protocol']) === true) $a['protocol'] = sprintf('%.1f', $a['protocol']); else $a['protocol'] = '-'; diff --git a/ykval-log.php b/ykval-log.php index 20502f3..4c46f8d 100644 --- a/ykval-log.php +++ b/ykval-log.php @@ -30,7 +30,7 @@ class Log { // request logger object - public $request = NULL; + public $request = null; private $log_levels = array( LOG_EMERG => 'LOG_EMERG', @@ -57,7 +57,7 @@ public function addField ($name, $value) $this->fields[$name] = $value; } - public function log ($priority, $message, $extra = NULL) + public function log ($priority, $message, $extra = null) { $prefix = ''; foreach ($this->fields as $val) diff --git a/ykval-munin-ksmlatency.php b/ykval-munin-ksmlatency.php index 450121c..6cc1ce1 100755 --- a/ykval-munin-ksmlatency.php +++ b/ykval-munin-ksmlatency.php @@ -41,7 +41,7 @@ # otp and client ID should be moved to a munin environment variable $urls = otp2ksmurls('ccccccccfnkjtvvijktfrvvginedlbvudjhjnggndtck', 16); -if (($endpoints = endpoints($urls)) === FALSE) +if (($endpoints = endpoints($urls)) === false) { echo "Cannot parse URLs from ksm url list\n"; exit(1); @@ -81,7 +81,7 @@ { list ($internal, $label, $url) = $endpoint; - if (($total_time = total_time($url)) === FALSE) + if (($total_time = total_time($url)) === false) $total_time = 'error'; echo "${internal}_avgwait.value ${total_time}\n"; diff --git a/ykval-munin-queuelength.php b/ykval-munin-queuelength.php index e7ce582..79baa67 100755 --- a/ykval-munin-queuelength.php +++ b/ykval-munin-queuelength.php @@ -53,7 +53,7 @@ exit(0); } -if (($endpoints = endpoints($urls)) === FALSE) +if (($endpoints = endpoints($urls)) === false) { echo "Cannot parse URLs from sync pool list\n"; exit(1); diff --git a/ykval-munin-vallatency.php b/ykval-munin-vallatency.php index 7de0abe..1273082 100755 --- a/ykval-munin-vallatency.php +++ b/ykval-munin-vallatency.php @@ -52,7 +52,7 @@ exit(0); } -if (($endpoints = endpoints($urls)) === FALSE) +if (($endpoints = endpoints($urls)) === false) { echo "Cannot parse URLs from sync pool list\n"; exit(1); @@ -86,7 +86,7 @@ { list ($internal, $label, $url) = $endpoint; - if (($total_time = total_time($url)) === FALSE) + if (($total_time = total_time($url)) === false) $total_time = 'error'; echo "${internal}_avgwait.value ${total_time}\n"; diff --git a/ykval-munin-yubikeystats.php b/ykval-munin-yubikeystats.php index 0d0a76a..ee25995 100755 --- a/ykval-munin-yubikeystats.php +++ b/ykval-munin-yubikeystats.php @@ -81,7 +81,7 @@ function get_count($db, $table, $conditions) return $r['count']; } - return Null; + return null; } if ($count = get_count($db, 'yubikeys', 'active=true')) diff --git a/ykval-resync.php b/ykval-resync.php index 9913d7f..7ccab46 100644 --- a/ykval-resync.php +++ b/ykval-resync.php @@ -84,7 +84,7 @@ } foreach($yubikeys as $key) { - if (($localParams = $sync->getLocalParams($key)) === FALSE) { + if (($localParams = $sync->getLocalParams($key)) === false) { logdie($myLog, 'ERROR Invalid Yubikey ' . $key); } diff --git a/ykval-sync.php b/ykval-sync.php index b9520a4..bc42b92 100644 --- a/ykval-sync.php +++ b/ykval-sync.php @@ -47,7 +47,7 @@ } // verify request sent by whitelisted address -if (in_array($ipaddr, $allowed, TRUE) === FALSE) +if (in_array($ipaddr, $allowed, true) === false) { $myLog->log(LOG_NOTICE, "Operation not allowed from IP $ipaddr"); $myLog->log(LOG_DEBUG, "Remote IP $ipaddr not listed in allowed sync pool : " . implode(', ', $allowed)); @@ -56,23 +56,23 @@ // define requirements on protocol $syncParams = array( - 'modified' => NULL, - 'otp' => NULL, - 'nonce' => NULL, - 'yk_publicname' => NULL, - 'yk_counter' => NULL, - 'yk_use' => NULL, - 'yk_high' => NULL, - 'yk_low' => NULL + 'modified' => null, + 'otp' => null, + 'nonce' => null, + 'yk_publicname' => null, + 'yk_counter' => null, + 'yk_use' => null, + 'yk_high' => null, + 'yk_low' => null ); // extract values from HTTP request $tmp_log = 'Received '; foreach ($syncParams as $param => $value) { - $value = getHttpVal($param, NULL, $_GET); + $value = getHttpVal($param, null, $_GET); - if ($value == NULL) + if ($value == null) { $myLog->log(LOG_NOTICE, "Received request with parameter[s] ($param) missing value"); sendResp(S_MISSING_PARAMETER, $myLog); @@ -114,7 +114,7 @@ // get local counter data $yk_publicname = $syncParams['yk_publicname']; -if (($localParams = $sync->getLocalParams($yk_publicname)) === FALSE) +if (($localParams = $sync->getLocalParams($yk_publicname)) === false) { $myLog->log(LOG_NOTICE, "Invalid Yubikey $yk_publicname"); sendResp(S_BACKEND_ERROR, $myLog); diff --git a/ykval-synclib.php b/ykval-synclib.php index 2963ccb..db05e2d 100644 --- a/ykval-synclib.php +++ b/ykval-synclib.php @@ -150,7 +150,7 @@ public function queue($otpParams, $localParams) return $result; } - public function log($priority, $msg, $params=NULL) + public function log($priority, $msg, $params=null) { if ($params) $msg .= ' modified=' . $params['modified'] . @@ -466,9 +466,9 @@ public function sync($ans_req, $timeout=1) } // send out requests - $ans_arr = retrieveURLasync('YK-VAL sync', $urls, $this->myLog, $ans_req, $match='status=OK', $returl=True, $timeout, $this->curlopts); + $ans_arr = retrieveURLasync('YK-VAL sync', $urls, $this->myLog, $ans_req, $match='status=OK', $returl=true, $timeout, $this->curlopts); - if ($ans_arr === FALSE) + if ($ans_arr === false) { $this->log(LOG_WARNING, 'No responses from validation server pool'); $ans_arr = array(); @@ -542,7 +542,7 @@ public function sync($ans_req, $timeout=1) * NULL queued_time for remaining entries in queue, to allow * daemon to take care of them as soon as possible. */ - $this->db->updateBy('queue', 'server_nonce', $this->server_nonce, array('queued'=>NULL)); + $this->db->updateBy('queue', 'server_nonce', $this->server_nonce, array('queued'=>null)); /** * Return true if valid answers equals required answers. diff --git a/ykval-verify.php b/ykval-verify.php index bd15013..156d324 100644 --- a/ykval-verify.php +++ b/ykval-verify.php @@ -38,8 +38,8 @@ $ipaddr = $_SERVER['REMOTE_ADDR']; -$https = (array_key_exists('HTTPS', $_SERVER) === TRUE - && strtolower($_SERVER['HTTPS']) !== 'off' ? TRUE : FALSE); +$https = (array_key_exists('HTTPS', $_SERVER) === true + && strtolower($_SERVER['HTTPS']) !== 'off' ? true : false); $myLog = new Log('ykval-verify'); $myLog->addField('ip', $ipaddr); @@ -255,7 +255,7 @@ sendResp(S_BACKEND_ERROR, $myLog); } -if (($cd = $sync->getClientData($client)) === FALSE) +if (($cd = $sync->getClientData($client)) === false) { $myLog->log(LOG_NOTICE, "Invalid client id $client"); sendResp(S_NO_SUCH_CLIENT, $myLog); @@ -277,7 +277,7 @@ $hmac = sign($request, $apiKey, $myLog); - if (hash_equals($hmac, $h) === FALSE) + if (hash_equals($hmac, $h) === false) { $myLog->log(LOG_DEBUG, "client hmac=$h, server hmac=$hmac"); sendResp(S_BAD_SIGNATURE, $myLog, $apiKey); @@ -308,7 +308,7 @@ { $curlopts = $baseParams['__YKVAL_KSM_CURL_OPTS__']; } -if (($otpinfo = KSMdecryptOTP($urls, $myLog, $curlopts)) === FALSE) +if (($otpinfo = KSMdecryptOTP($urls, $myLog, $curlopts)) === false) { /** * FIXME @@ -327,7 +327,7 @@ // get Yubikey from DB $public_id = substr($otp, 0, strlen ($otp) - TOKEN_LEN); $myLog->request->set('public_id', $public_id); -if (($localParams = $sync->getLocalParams($public_id)) === FALSE) +if (($localParams = $sync->getLocalParams($public_id)) === false) { $myLog->log(LOG_NOTICE, "Invalid Yubikey $public_id"); sendResp(S_BACKEND_ERROR, $myLog, $apiKey); @@ -414,7 +414,7 @@ 'timeout' => $timeout, )); -if ($syncres == False) +if ($syncres == false) { /* sync returned false, indicating that either at least 1 answer marked OTP as invalid or