From ac628ab33c0dee49194f032b6ce1c440dfbd10c7 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 17 May 2020 03:53:44 +0200 Subject: [PATCH 01/16] add some current KaiOS and Firefox UA strings --- tests/ua_list_raw.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/ua_list_raw.txt b/tests/ua_list_raw.txt index e7a69c5..03494e1 100755 --- a/tests/ua_list_raw.txt +++ b/tests/ua_list_raw.txt @@ -55,6 +55,7 @@ Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Mozilla/5.0 (X11; Linux i686 on x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Mozilla/5.0 (X11; Linux i686; rv:2.0b6pre) Gecko/20100907 Firefox/4.0b6pre Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20.0 Firefox/20.0 +Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Mozilla/5.0 (Android; Mobile; rv:12.0) Gecko/12.0 Firefox/12.0 Mozilla/5.0 (Android; Tablet; rv:14.0a1) Gecko/14 Firefox/14.0a1 Mozilla/5.0 (Android; Tablet; rv:28.0) Gecko/28.0 Firefox/28.0 @@ -83,6 +84,10 @@ Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0 Mozilla/5.0 (Mobile; LG-D300; rv:18.1) Gecko/18.1 Firefox/18.1 Mozilla/5.0 (Tablet; rv:26.0) Gecko/26.0 Firefox/26.0 Mozilla/5.0 (Tablet; Saga G1; rv:26.0) Gecko/26.0 Firefox/26.0 +Mozilla/5.0 (Mobile; ALCATEL4044V; rv:37.0) Gecko/37.0 Firefox/37.0 KaiOS/1.0 +Mozilla/5.0 (Mobile; Nokia_8110_4G; rv:48.0) Gecko/48.0 Firefox/48.0 KAIOS/2.5 +Mozilla/5.0 (Mobile; rv:68.0) Gecko/68.0 KAIOS/3.0 +Mozilla/5.0 (Mobile; rv:76.0) Gecko/20100101 Firefox/76.0 B2GOS/3.0 Mozilla/5.0 (FreeBSD; Viera; rv:34.0) Gecko/20100101 Firefox/34.0 Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.1.4pre) Gecko/20090928 Lightning/1.0pre Shredder/3.0pre Mozilla/5.0 (Windows; U; Windows NT 6.1; WOW64; en-US; rv:1.9.3a5pre) Gecko/20100514 Lanikai/3.1b1 -- 2.35.3 From 461e89f00b4707f05734dbf46fcc3c821f8f7c27 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 19 Jul 2020 02:16:02 +0200 Subject: [PATCH 02/16] create a proper error when we are unable to write the graph file --- classes/rrdstat.php-class | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/classes/rrdstat.php-class b/classes/rrdstat.php-class index 74e2012..9226d56 100644 --- a/classes/rrdstat.php-class +++ b/classes/rrdstat.php-class @@ -760,15 +760,15 @@ class rrdstat { } $graph_cmd = $this->rrdtool_bin.' graph '.str_replace('*', '\*', $fname.$gOpts.$gDefs.$gGraphs.$addSpecial); - $return = `$graph_cmd 2>&1`; - - if (strpos($return, 'ERROR') !== false) { - trigger_error($this->rrd_file.' - rrd graph error: '.$return, E_USER_WARNING); - $return = 'command:'.$graph_cmd."\n\n".$return; + if (!is_writable($fname)) { + trigger_error($this->rrd_file.' - graph file not writable: '.$fname, E_USER_WARNING); + return 'command:'.$graph_cmd."\n\n".'unwritable file: '.$fname; } - if (0) { - // debug output - $return = 'command:'.$graph_cmd."\n\n".$return; + $graph_out = `$graph_cmd 2>&1`; + + if (strpos($graph_out, 'ERROR') !== false) { + trigger_error($this->rrd_file.' - rrd graph error: '.$graph_out, E_USER_WARNING); + return 'command:'.$graph_cmd."\n\n".$graph_out; } $legendlines = ''; foreach ($graphrows as $grow) { @@ -778,7 +778,7 @@ class rrdstat { $legendline .= '|'.(isset($grow['legend_long'])?$grow['legend_long']:''); $legendlines .= 'legend:'.$legendline."\n"; } - $return = 'file:'.$fname."\n".$legendlines.$return; + $return = 'file:'.$fname."\n".$legendlines.$graph_out; return $return; } -- 2.35.3 From 5dd242eff6de2d320c75ec83e5f988cd7c769cea Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 19 Jul 2020 17:09:06 +0200 Subject: [PATCH 03/16] don't error out if the graph doesn't exist but can be created --- classes/rrdstat.php-class | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/rrdstat.php-class b/classes/rrdstat.php-class index 9226d56..0a71f13 100644 --- a/classes/rrdstat.php-class +++ b/classes/rrdstat.php-class @@ -760,7 +760,8 @@ class rrdstat { } $graph_cmd = $this->rrdtool_bin.' graph '.str_replace('*', '\*', $fname.$gOpts.$gDefs.$gGraphs.$addSpecial); - if (!is_writable($fname)) { + if ((file_exists($fname) && !is_writable($fname)) || + (!file_exists($fname) && !is_writable(dirname($fname)))) { trigger_error($this->rrd_file.' - graph file not writable: '.$fname, E_USER_WARNING); return 'command:'.$graph_cmd."\n\n".'unwritable file: '.$fname; } -- 2.35.3 From cb2420c657c2856403afada65712063542b145c0 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 21 Feb 2021 16:23:20 +0100 Subject: [PATCH 04/16] fix string array access --- classes/document.php-class | 3 +-- classes/rrdstat.php-class | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/classes/document.php-class b/classes/document.php-class index a0800f2..198296f 100755 --- a/classes/document.php-class +++ b/classes/document.php-class @@ -173,8 +173,7 @@ class ExtendedDocument extends DOMDocument { // returns an ExtendedElement that is an HTML with the given src and alt attributes (set to '' by default) // // public function createElementForm($action, $method, $name) - // returns an ExtendedElement that is an HTML
that is a child of an HTML
- // with the given action, method, and name + // returns an ExtendedElement that is an HTML with the given action, method, and name // // public function createElementInputHidden($name, $value) // returns an ExtendedElement that is an HTML of type 'hidden' with the given name and value diff --git a/classes/rrdstat.php-class b/classes/rrdstat.php-class index 0a71f13..a6b8e9c 100644 --- a/classes/rrdstat.php-class +++ b/classes/rrdstat.php-class @@ -206,11 +206,11 @@ class rrdstat { $this->status = 'graphonly'; } elseif (isset($iinfo['file'])) { - $this->rrd_file = (($iinfo['file']{0} != '/')?$this->basedir:'').$iinfo['file']; + $this->rrd_file = (($iinfo['file'][0] != '/')?$this->basedir:'').$iinfo['file']; $this->basename = basename((substr($this->rrd_file, -4) == '.rrd')?substr($this->rrd_file, 0, -4):$this->rrd_file); } elseif (!is_null($conf_id) && file_exists($conf_id.'.rrd')) { - $this->rrd_file = (($iinfo['file']{0} != '/')?$this->basedir:'').$conf_id.'.rrd'; + $this->rrd_file = (($iinfo['file'][0] != '/')?$this->basedir:'').$conf_id.'.rrd'; $this->basename = $conf_id; } else { @@ -509,8 +509,8 @@ class rrdstat { $fname = str_replace('%t', $timeframe, $fname); $fname = str_replace('%f', $fmt_ext, $fname); if (substr($fname, -strlen($fmt_ext)) != $fmt_ext) { $fname .= $fmt_ext; } - if (isset($gconf['path']) && ($fname{0} != '/')) { $fname = $gconf['path'].'/'.$fname; } - if ($fname{0} != '/') { $fname = $this->basedir.$fname; } + if (isset($gconf['path']) && ($fname[0] != '/')) { $fname = $gconf['path'].'/'.$fname; } + if ($fname[0] != '/') { $fname = $this->basedir.$fname; } $fname = str_replace('//', '/', $fname); $graphrows = array(); $specialrows = array(); $gC = 0; @@ -1178,7 +1178,7 @@ class rrdstat { $snames = array(); $s_exclude = array(); $sfiles = array(); if (isset($pconf['index_ids'])) { foreach (explode(',', $pconf['index_ids']) as $iid) { - if ($iid{0} == '-') { $s_exclude[] = substr($iid, 1); } + if ($iid[0] == '-') { $s_exclude[] = substr($iid, 1); } else { $snames[] = $iid; } } } -- 2.35.3 From 97472ddcd376ade81ef3bed3ab2ca2b0dd0b048f Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 21 Feb 2021 19:53:09 +0100 Subject: [PATCH 05/16] replace create_function with ability to just run actual anonymous functions or use an actual eval if a string is given, including backwards compat --- classes/rrdstat.php-class | 51 ++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/classes/rrdstat.php-class b/classes/rrdstat.php-class index a6b8e9c..2770af7 100644 --- a/classes/rrdstat.php-class +++ b/classes/rrdstat.php-class @@ -326,12 +326,17 @@ class rrdstat { if ($this->status != 'ok') { trigger_error('Cannot update non-writeable file', E_USER_WARNING); return false; } $upvals = array(); if (isset($this->config_raw['update'])) { - if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $this->config_raw['update'], $regs)) { - $upfunc = create_function('', $regs[1]); - $upvals = $upfunc(); + if (is_object($this->config_raw['update'])) { + // We assume it's an anonymous function + $upvals = $this->config_raw['update'](); } else { - $evalcode = $this->config_raw['update']; + if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $this->config_raw['update'], $regs)) { + $evalcode = '$upfunc = function() {'."\n".$regs[1]."\n".'};'."\n".'print(implode("\n", $upfunc()));'; + } + else { + $evalcode = $this->config_raw['update']; + } if (!is_null($evalcode)) { ob_start(); eval($evalcode); @@ -345,9 +350,13 @@ class rrdstat { foreach ($this->rrd_fields as $ds) { if (is_array($upArray) && isset($upArray[$ds['name']])) { $val = $upArray[$ds['name']]; } elseif (isset($ds['update'])) { - $val = null; $evalcode = null; - if (substr($ds['update'], 0, 4) == 'val:') { - $evalcode = 'function { return trim('.substr($ds['update'], 4).')); }'; + $val = null; + if (is_object($ds['update'])) { + // We assume it's an anonymous function + $val = $ds['update'](); + } + elseif (substr($ds['update'], 0, 4) == 'val:') { + $val = trim(substr($ds['update'], 4)); } elseif (substr($ds['update'], 0, 8) == 'snmp-if:') { if (substr_count($ds['update'], ':') >= 4) { @@ -366,19 +375,22 @@ class rrdstat { if ($valtype == 'in') { $oid = '1.3.6.1.2.1.2.2.1.10.'.$ifnr; } elseif ($valtype == 'out') { $oid = '1.3.6.1.2.1.2.2.1.16.'.$ifnr; } if (!is_null($ifnr) && !is_null($oid)) { - $evalcode = 'function { return trim(substr(strrchr(`snmpget -v2c -c '.$snmpcomm.' '.$snmphost.' '.$oid.'`,":"),1)); }'; + $val = trim(substr(strrchr(`snmpget -v2c -c $snmpcomm $snmphost $oid`,":"),1)); } } - else { $evalcode = $ds['update']; } - if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $evalcode, $regs)) { - $upfunc = create_function('', $regs[1]); - $val = $upfunc(); - } - elseif (!is_null($evalcode)) { - ob_start(); - eval($evalcode); - $val = ob_get_contents(); - ob_end_clean(); + else { + if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $ds['update'], $regs)) { + $evalcode = '$upfunc = function() {'."\n".$regs[1]."\n".'};'."\n".'print($upfunc());'; + } + else { + $evalcode = $ds['update']; + } + if (!is_null($evalcode)) { + ob_start(); + eval($evalcode); + $val = ob_get_contents(); + ob_end_clean(); + } } } else { $val = null; } @@ -396,8 +408,7 @@ class rrdstat { $upvals[$akey] = $keys_have_names?$lastvals[$akey]:$lastvals[$rowids[$akey]]; } } - $walkfunc = create_function('&$val,$key', '$val = is_numeric(trim($val))?trim($val):"U";'); - array_walk($upvals, $walkfunc); + array_walk($upvals, function(&$val, $key) { $val = is_numeric(trim($val)) ? trim($val) : "U"; }); $return = null; if (count($upvals)) { $update_cmd = $this->rrdtool_bin.' update '.$this->rrd_file -- 2.35.3 From 0ffe81c3abbc0605cf010a4872a01363a26f408f Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 9 May 2021 20:01:39 +0200 Subject: [PATCH 06/16] remove a lot of error suppression in favor of ?? in various utility classes --- classes/email.php-class | 8 ++++---- classes/rrdstat.php-class | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/classes/email.php-class b/classes/email.php-class index 3bbb5e9..7c20b5a 100644 --- a/classes/email.php-class +++ b/classes/email.php-class @@ -169,7 +169,7 @@ class email { if (in_array('to', $addrtype)) { foreach ($this->recipients as $address) { - if (strlen(@$address['mail'])) { + if (strlen($address['mail'] ?? '')) { $mailaddresses[] = array('mail'=>$address['mail'], 'name'=>strlen($address['name'])?$address['name']:'', 'addrtype'=>'to'); @@ -178,7 +178,7 @@ class email { } if (in_array('cc', $addrtype)) { foreach ($this->cc as $address) { - if (strlen(@$address['mail'])) { + if (strlen($address['mail'] ?? '')) { $mailaddresses[] = array('mail'=>$address['mail'], 'name'=>strlen($address['name'])?$address['name']:'', 'addrtype'=>'cc'); @@ -187,7 +187,7 @@ class email { } if (in_array('bcc', $addrtype)) { foreach ($this->bcc as $address) { - if (strlen(@$address['mail'])) { + if (strlen($address['mail'] ?? '')) { $mailaddresses[] = array('mail'=>$address['mail'], 'name'=>strlen($address['name'])?$address['name']:'', 'addrtype'=>'bcc'); @@ -216,7 +216,7 @@ class email { if (count($this->recipients)) { $recpt = ''; foreach ($this->recipients as $address) { - if (strlen(@$address['mail'])) { + if (strlen($address['mail'] ?? '')) { if (strlen($address['name'])) { $recpt .= $this->mimeencode($address['name'], true).' <'.$address['mail'].'>,'; } else { $recpt .= $address['mail'].','; } } diff --git a/classes/rrdstat.php-class b/classes/rrdstat.php-class index 2770af7..1ed4504 100644 --- a/classes/rrdstat.php-class +++ b/classes/rrdstat.php-class @@ -576,7 +576,7 @@ class rrdstat { } foreach (array('scale_time_src','scale_time_tgt') as $st) { if (!isset($erow[$st]) || !is_numeric($erow[$st])) { - switch (@$erow[$st]) { + switch ($erow[$st] ?? null) { case 'dyn': case 'auto': $erow[$st] = $slice; @@ -785,7 +785,7 @@ class rrdstat { $legendlines = ''; foreach ($graphrows as $grow) { $legendline = isset($grow['desc'])?$grow['desc']:(isset($grow['legend'])?$grow['legend']:$grow['name']); - $legendline .= '|'.@$grow['color']; + $legendline .= '|'.($grow['color'] ?? ''); $legendline .= '|'.(isset($grow['color_bg'])?$grow['color_bg']:''); $legendline .= '|'.(isset($grow['legend_long'])?$grow['legend_long']:''); $legendlines .= 'legend:'.$legendline."\n"; @@ -845,7 +845,7 @@ class rrdstat { $pconf = $pconf + (array)$this->config_page; $return = null; - switch (@$pconf['type']) { + switch ($pconf['type'] ?? null) { case 'index': $return = $this->page_index($pconf); break; @@ -971,9 +971,9 @@ class rrdstat { if (isset($pconf['stats_url_add'])) { $sURL_add = $pconf['stats_url_add']; } else { $sURL_add = '&sub=%s'; } - $default_num_cols = $GLOBALS['ua']->isMobile()?1:2; - $num_cols = is_numeric(@$pconf['num_rows'])?$pconf['num_rows']:$default_num_cols; - $num_rows = ceil(count($stats)/$num_cols); + $default_num_cols = $GLOBALS['ua']->isMobile() ? 1 : 2; + $num_cols = is_numeric($pconf['num_rows'] ?? null) ? $pconf['num_rows'] : $default_num_cols; + $num_rows = ceil(count($stats) / $num_cols); $out .= ''."\n"; for ($row = 0; $row < $num_rows; $row++) { @@ -984,7 +984,7 @@ class rrdstat { if ($idx < count($stats)) { @list($sname, $s_psub) = explode('|', $stats[$idx]['name'], 2); $s_psname = 'page'.(isset($s_psub)?'.'.$s_psub:''); - $g_sub = @$this->config_all[$sname][$s_psname]['graph_sub']; + $g_sub = $this->config_all[$sname][$s_psname]['graph_sub'] ?? ''; if (isset($this->config_all[$sname][$s_psname]['title_page'])) { $s_ptitle = $this->config_all[$sname][$s_psname]['title_page']; @@ -1204,7 +1204,7 @@ class rrdstat { foreach ($snames as $iname) { $newstat = array('name'=>$iname); $sfiles[] = isset($this->config_all[$iname]['file'])?$this->config_all[$iname]['file']:$iname.'.rrd'; - if (is_array(@$this->config_all[$iname])) { + if (is_array($this->config_all[$iname] ?? null)) { foreach ($this->config_all[$iname] as $key=>$val) { if (substr($key, 0, 5) == 'page.') { $newstat['sub'][] = substr($key, 5); } } -- 2.35.3 From e67037744edbb115b88b23f3ab6926f77244ca9f Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Wed, 29 Dec 2021 23:26:17 +0100 Subject: [PATCH 07/16] make sure the array key exists --- classes/rrdstat.php-class | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/rrdstat.php-class b/classes/rrdstat.php-class index 1ed4504..9743e7a 100644 --- a/classes/rrdstat.php-class +++ b/classes/rrdstat.php-class @@ -496,7 +496,7 @@ class rrdstat { // assemble configuration $gconf = (array)$extra; - if (!is_null($sub) && is_array($this->config_raw['graph.'.$sub])) { + if (!is_null($sub) && array_key_exists('graph.'.$sub, $this->config_raw) && is_array($this->config_raw['graph.'.$sub])) { $gconf = $gconf + $this->config_raw['graph.'.$sub]; } $gconf = $gconf + (array)$this->config_graph; -- 2.35.3 From 5ae00086e5e4a5ffe979d5462b388d8277417e9f Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Fri, 18 Feb 2022 23:43:09 +0100 Subject: [PATCH 08/16] fix some warnings from modern PHP versions --- classes/document.php-class | 2 +- classes/useragent.php-class | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/classes/document.php-class b/classes/document.php-class index 198296f..ed688b6 100755 --- a/classes/document.php-class +++ b/classes/document.php-class @@ -439,7 +439,7 @@ class ExtendedDocument extends DOMDocument { public function createElement($name, $value = '') { // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that. $aelem = parent::createElement($name); - if (strlen($value)) { $aelem->appendText($value); } + if (strlen($value ?? '')) { $aelem->appendText($value); } return $aelem; } diff --git a/classes/useragent.php-class b/classes/useragent.php-class index efda352..bebf553 100755 --- a/classes/useragent.php-class +++ b/classes/useragent.php-class @@ -1003,12 +1003,17 @@ class userAgent { public function getAcceptLanguages() { if (!isset($this->uadata['accept-languages'])) { $headers = getAllHeaders(); - $accLcomp = explode(',', @$headers['Accept-Language']); + $accLcomp = explode(',', ($headers['Accept-Language'] ?? '')); $accLang = array(); foreach ($accLcomp as $lcomp) { if (strlen($lcomp)) { $ldef = explode(';', $lcomp); - $accLang[$ldef[0]] = (float)((strpos(@$ldef[1],'q=')===0)?substr($ldef[1],2):1); + if (count($ldef) > 1 && strpos($ldef[1], 'q=') === 0) { + $accLang[$ldef[0]] = substr($ldef[1], 2); + } + else { + $accLang[$ldef[0]] = 1; + } } } $this->uadata['accept-languages'] = $accLang; @@ -1549,7 +1554,7 @@ class userAgent { if (strpos($this->uadata['os'], 'Windows Phone OS') !== false) { $this->mobile = true; } elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->mobile = true; } - $this->uadata['lang'] = str_replace('_', '-', @$this->uadata['lang']); + $this->uadata['lang'] = str_replace('_', '-', ($this->uadata['lang'] ?? '')); } } return $this->uadata['os']; -- 2.35.3 From e78a75387d67c9293ba7dbd7dbd846b729f1ff19 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sat, 7 Jan 2023 18:16:27 +0100 Subject: [PATCH 09/16] short array syntax, standard return indentation, fix warnings --- classes/useragent.php-class | 133 ++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 60 deletions(-) diff --git a/classes/useragent.php-class b/classes/useragent.php-class index bebf553..9c95c6d 100755 --- a/classes/useragent.php-class +++ b/classes/useragent.php-class @@ -97,7 +97,7 @@ class userAgent { private $version; private $bot = false; private $mobile = false; - private $uadata = array(); + private $uadata = []; function __construct($ua_string = '') { // *** constructor *** @@ -980,12 +980,14 @@ class userAgent { $this->bot = false; } - $botArray = array('Scooter','Spinne','Vagabondo','Firefly','Scrubby','NG','Pompos','Szukacz','Schmozilla','42_HAL', - 'NetResearchServer','LinkWalker','Zeus','W3C_Validator','ZyBorg','Ask Jeeves','ia_archiver', - 'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','search.ch', - 'appie','larbin','NutchCVS','Webchat','Mediapartners-Google','sitecheck.internetseer.com', - 'FavOrg','findlinks','DataCha0s','ichiro','Francis','CoralWebPrx','DoCoMo','Ocelli','Sogou Video', - 'Yandex','Yeti','Austronaut-URL-Checker'); + $botArray = [ + 'Scooter', 'Spinne', 'Vagabondo', 'Firefly', 'Scrubby', 'NG', 'Pompos', 'Szukacz', 'Schmozilla', '42_HAL', + 'NetResearchServer', 'LinkWalker', 'Zeus', 'W3C_Validator', 'ZyBorg', 'Ask Jeeves', 'ia_archiver', + 'PingALink Monitoring Services', 'IlTrovatore-Setaccio', 'Nutch', 'Mercator', 'search.ch', + 'appie', 'larbin', 'NutchCVS', 'Webchat', 'Mediapartners-Google', 'sitecheck.internetseer.com', + 'FavOrg', 'findlinks', 'DataCha0s', 'ichiro', 'Francis', 'CoralWebPrx', 'DoCoMo', 'Ocelli', 'Sogou Video', + 'Yandex', 'Yeti', 'Austronaut-URL-Checker' + ]; if (in_array($this->brand, $botArray)) { $this->bot = true; @@ -997,14 +999,19 @@ class userAgent { } } - public function getBrand() { return $this->brand; } - public function getVersion() { return $this->version; } + public function getBrand() { + return $this->brand; + } + + public function getVersion() { + return $this->version; + } public function getAcceptLanguages() { if (!isset($this->uadata['accept-languages'])) { $headers = getAllHeaders(); $accLcomp = explode(',', ($headers['Accept-Language'] ?? '')); - $accLang = array(); + $accLang = []; foreach ($accLcomp as $lcomp) { if (strlen($lcomp)) { $ldef = explode(';', $lcomp); @@ -1018,10 +1025,12 @@ class userAgent { } $this->uadata['accept-languages'] = $accLang; } - return $this->uadata['accept-languages']; + return $this->uadata['accept-languages']; } - public function getUAString() { return $this->uastring; } + public function getUAString() { + return $this->uastring; + } public function getEngine() { // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|netfront|unknown @@ -1106,10 +1115,12 @@ class userAgent { } } } - return $this->uadata['engine']; + return $this->uadata['engine']; } - public function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); } + public function hasEngine($rnd_engine) { + return ($this->getEngine() == $rnd_engine); + } public function getEngineVersion() { if (!isset($this->uadata['eng_version'])) { @@ -1117,7 +1128,7 @@ class userAgent { // getOS() should get the date for us $this->getOS(); } - return $this->uadata['eng_version']; + return $this->uadata['eng_version']; } public function getOS() { @@ -1507,57 +1518,57 @@ class userAgent { elseif (preg_match('/iPhone OS ([\d_]+)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'iOS '.str_replace('_', '.', $regs[1]); } elseif (preg_match('/Mac ?OS ?X/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; } elseif (preg_match('/Mac_P(ower|)PC/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; } - elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; } - elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; } - elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; } - elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; } + elseif (strpos($this->uadata['os'] ?? '', 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; } + elseif (strpos($this->uadata['os'] ?? '', 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; } + elseif (strpos($this->uadata['os'] ?? '', 'apple') !== false) { $this->uadata['os'] = 'MacOS'; } + elseif (strpos($this->uadata['os'] ?? '', 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; } elseif (preg_match('/(?:web|hpw)OS\/([0-9a-zA-Z\._+]+)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'webOS '.$regs[1]; } elseif (preg_match('/Android \(Linux (.+)\)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'Android '.$regs[1]; } - elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; } + elseif (strpos($this->uadata['os'] ?? '', 'linux') !== false) { $this->uadata['os'] = 'Linux'; } elseif (preg_match('/SymbianOS[\/ ]([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) { $this->uadata['os'] = 'SymbianOS '.$regs[1]; } elseif (preg_match('/Symbian ?OS/i', $this->uadata['os'])) { $this->uadata['os'] = 'SymbianOS'; } - if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; } - elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; } - elseif (strpos($this->uadata['os'], 'iOS') !== false) { $this->uadata['platform'] = 'Macintosh'; } - elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; } - elseif (strpos($this->uadata['os'], 'MeeGo') !== false) { $this->uadata['platform'] = 'Linux'; } - elseif (strpos($this->uadata['os'], 'webOS') !== false) { $this->uadata['platform'] = 'Linux'; } - elseif (strpos($this->uadata['os'], 'Android') !== false) { $this->uadata['platform'] = 'Android'; } - elseif (strpos($this->uadata['os'], 'Firefox OS') !== false) { $this->uadata['platform'] = 'Firefox OS'; } - elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; } - elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; } - elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; } - elseif (strpos($this->uadata['os'], 'BePC') !== false) { $this->uadata['platform'] = 'BeOS'; } - elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; } - elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; } - elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; } - elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; } - elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; } - elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; } - elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; } - elseif (strpos($this->uadata['os'], 'webOS') !== false) { $this->uadata['platform'] = 'webOS'; } - elseif (strpos($this->uadata['os'], 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; } - elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; } - elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; } - elseif (strpos($this->uadata['os'], 'OS/2') !== false) { $this->uadata['platform'] = 'OS/2'; } - elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; } - elseif (strpos($this->uadata['os'], 'BlackBerry') !== false) { $this->uadata['platform'] = 'BlackBerry'; } - elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->uadata['platform'] = 'Nintendo'; } - elseif (strpos($this->uadata['os'], 'Wii') !== false) { $this->uadata['platform'] = 'Nintendo'; } - elseif (strpos($this->uadata['os'], 'Nintendo') !== false) { $this->uadata['platform'] = 'Nintendo'; } - elseif (strpos($this->uadata['os'], 'J2ME') !== false) { $this->uadata['platform'] = 'Java'; } - elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; } - elseif (strpos($this->uadata['os'], 'mingw') !== false) { $this->uadata['platform'] = 'Windows'; } + if (strpos($this->uadata['os'] ?? '', 'Win') !== false) { $this->uadata['platform'] = 'Windows'; } + elseif (strpos($this->uadata['os'] ?? '', 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; } + elseif (strpos($this->uadata['os'] ?? '', 'iOS') !== false) { $this->uadata['platform'] = 'Macintosh'; } + elseif (strpos($this->uadata['os'] ?? '', 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; } + elseif (strpos($this->uadata['os'] ?? '', 'MeeGo') !== false) { $this->uadata['platform'] = 'Linux'; } + elseif (strpos($this->uadata['os'] ?? '', 'webOS') !== false) { $this->uadata['platform'] = 'Linux'; } + elseif (strpos($this->uadata['os'] ?? '', 'Android') !== false) { $this->uadata['platform'] = 'Android'; } + elseif (strpos($this->uadata['os'] ?? '', 'Firefox OS') !== false) { $this->uadata['platform'] = 'Firefox OS'; } + elseif (strpos($this->uadata['os'] ?? '', 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; } + elseif (strpos($this->uadata['os'] ?? '', 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; } + elseif (strpos($this->uadata['os'] ?? '', 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; } + elseif (strpos($this->uadata['os'] ?? '', 'BePC') !== false) { $this->uadata['platform'] = 'BeOS'; } + elseif (strpos($this->uadata['os'] ?? '', 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; } + elseif (strpos($this->uadata['os'] ?? '', 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; } + elseif (strpos($this->uadata['os'] ?? '', 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; } + elseif (strpos($this->uadata['os'] ?? '', 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; } + elseif (strpos($this->uadata['os'] ?? '', 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; } + elseif (strpos($this->uadata['os'] ?? '', 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; } + elseif (strpos($this->uadata['os'] ?? '', 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; } + elseif (strpos($this->uadata['os'] ?? '', 'webOS') !== false) { $this->uadata['platform'] = 'webOS'; } + elseif (strpos($this->uadata['os'] ?? '', 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; } + elseif (strpos($this->uadata['os'] ?? '', 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; } + elseif (strpos($this->uadata['os'] ?? '', 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; } + elseif (strpos($this->uadata['os'] ?? '', 'OS/2') !== false) { $this->uadata['platform'] = 'OS/2'; } + elseif (strpos($this->uadata['os'] ?? '', 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; } + elseif (strpos($this->uadata['os'] ?? '', 'BlackBerry') !== false) { $this->uadata['platform'] = 'BlackBerry'; } + elseif (strpos($this->uadata['os'] ?? '', 'Gameboy') !== false) { $this->uadata['platform'] = 'Nintendo'; } + elseif (strpos($this->uadata['os'] ?? '', 'Wii') !== false) { $this->uadata['platform'] = 'Nintendo'; } + elseif (strpos($this->uadata['os'] ?? '', 'Nintendo') !== false) { $this->uadata['platform'] = 'Nintendo'; } + elseif (strpos($this->uadata['os'] ?? '', 'J2ME') !== false) { $this->uadata['platform'] = 'Java'; } + elseif (strpos($this->uadata['os'] ?? '', 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; } + elseif (strpos($this->uadata['os'] ?? '', 'mingw') !== false) { $this->uadata['platform'] = 'Windows'; } else { $this->uadata['platform'] = $this->uadata['os']; } - if (strpos($this->uadata['os'], 'Windows Phone OS') !== false) { $this->mobile = true; } - elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->mobile = true; } + if (strpos($this->uadata['os'] ?? '', 'Windows Phone OS') !== false) { $this->mobile = true; } + elseif (strpos($this->uadata['os'] ?? '', 'Gameboy') !== false) { $this->mobile = true; } $this->uadata['lang'] = str_replace('_', '-', ($this->uadata['lang'] ?? '')); } } - return $this->uadata['os']; + return $this->uadata['os']; } public function getPlatform() { @@ -1566,7 +1577,7 @@ class userAgent { // getOS() should get the date for us $this->getOS(); } - return $this->uadata['platform']; + return $this->uadata['platform']; } public function getLanguage() { @@ -1575,7 +1586,7 @@ class userAgent { // getOS() should get the date for us $this->getOS(); } - return $this->uadata['lang']; + return $this->uadata['lang']; } public function getGeckoDate() { @@ -1584,7 +1595,7 @@ class userAgent { // getEngine() should get the date for us $this->getEngine(); } - return $this->uadata['geckodate']; + return $this->uadata['geckodate']; } public function getGeckoTime() { @@ -1602,10 +1613,12 @@ class userAgent { if ($use_time) { date_default_timezone_set($old_tz); } } } - return $this->uadata['geckotime']; + return $this->uadata['geckotime']; } - public function isBot() { return $this->bot; } + public function isBot() { + return $this->bot; + } public function isMobile() { if (!isset($this->uadata['os'])) { -- 2.35.3 From fb10d8f6bc2f713233929e8d6923155597941a84 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sat, 7 Jan 2023 18:20:01 +0100 Subject: [PATCH 10/16] fix Gecko version for Firefox 110 and later --- classes/useragent.php-class | 3 +++ 1 file changed, 3 insertions(+) diff --git a/classes/useragent.php-class b/classes/useragent.php-class index 9c95c6d..cf38a17 100755 --- a/classes/useragent.php-class +++ b/classes/useragent.php-class @@ -1229,6 +1229,9 @@ class userAgent { $this->uadata['lang'] = null; $this->uadata['eng_version'] = null; } + if (($this->brand == 'Firefox') && (intval($this->version) >= 110)) { + $this->uadata['eng_version'] = $this->version; + } } elseif ($this->hasEngine('edgehtml')) { if (preg_match('#Mozilla/5.0 \(([^;]+); (WOW64|Win64); ([^\);]+)\)#', $this->uastring, $regs)) { -- 2.35.3 From a6d14fe0a88283bd7e6a227421c4e66ba710d824 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 8 Jan 2023 16:48:18 +0100 Subject: [PATCH 11/16] update bot detection with a few more UA names --- classes/useragent.php-class | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/classes/useragent.php-class b/classes/useragent.php-class index cf38a17..6aea289 100755 --- a/classes/useragent.php-class +++ b/classes/useragent.php-class @@ -983,10 +983,11 @@ class userAgent { $botArray = [ 'Scooter', 'Spinne', 'Vagabondo', 'Firefly', 'Scrubby', 'NG', 'Pompos', 'Szukacz', 'Schmozilla', '42_HAL', 'NetResearchServer', 'LinkWalker', 'Zeus', 'W3C_Validator', 'ZyBorg', 'Ask Jeeves', 'ia_archiver', - 'PingALink Monitoring Services', 'IlTrovatore-Setaccio', 'Nutch', 'Mercator', 'search.ch', - 'appie', 'larbin', 'NutchCVS', 'Webchat', 'Mediapartners-Google', 'sitecheck.internetseer.com', - 'FavOrg', 'findlinks', 'DataCha0s', 'ichiro', 'Francis', 'CoralWebPrx', 'DoCoMo', 'Ocelli', 'Sogou Video', - 'Yandex', 'Yeti', 'Austronaut-URL-Checker' + 'PingALink Monitoring Services', 'IlTrovatore-Setaccio', 'Nutch', 'Mercator', 'search.ch', 'appie', 'larbin', + 'NutchCVS', 'Webchat', 'Mediapartners-Google', 'sitecheck.internetseer.com', 'FavOrg', 'findlinks', 'DataCha0s', + 'ichiro', 'Francis', 'CoralWebPrx', 'DoCoMo', 'Ocelli', 'Sogou Video', 'Yandex', 'Yeti', + 'Austronaut-URL-Checker', 'check_ssl_cert', 'check_http', 'vdirsyncer', 'Feedbin feed-id', + 'Cloudflare Custom Hostname Verification', 'FreshRSS', 'UniversalFeedParser', ]; if (in_array($this->brand, $botArray)) { -- 2.35.3 From 19aad8afcc770848fd356bd5f8c2d8286c6e97a3 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 8 Jan 2023 16:51:01 +0100 Subject: [PATCH 12/16] update bot detection with a few more UA names --- classes/useragent.php-class | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/useragent.php-class b/classes/useragent.php-class index 6aea289..00ceb3a 100755 --- a/classes/useragent.php-class +++ b/classes/useragent.php-class @@ -982,12 +982,12 @@ class userAgent { $botArray = [ 'Scooter', 'Spinne', 'Vagabondo', 'Firefly', 'Scrubby', 'NG', 'Pompos', 'Szukacz', 'Schmozilla', '42_HAL', - 'NetResearchServer', 'LinkWalker', 'Zeus', 'W3C_Validator', 'ZyBorg', 'Ask Jeeves', 'ia_archiver', + 'NetResearchServer', 'LinkWalker', 'Zeus', 'W3C_Validator', 'ZyBorg', 'Ask Jeeves', 'ia_archiver', 'ichiro', 'PingALink Monitoring Services', 'IlTrovatore-Setaccio', 'Nutch', 'Mercator', 'search.ch', 'appie', 'larbin', 'NutchCVS', 'Webchat', 'Mediapartners-Google', 'sitecheck.internetseer.com', 'FavOrg', 'findlinks', 'DataCha0s', - 'ichiro', 'Francis', 'CoralWebPrx', 'DoCoMo', 'Ocelli', 'Sogou Video', 'Yandex', 'Yeti', - 'Austronaut-URL-Checker', 'check_ssl_cert', 'check_http', 'vdirsyncer', 'Feedbin feed-id', - 'Cloudflare Custom Hostname Verification', 'FreshRSS', 'UniversalFeedParser', + 'Francis', 'CoralWebPrx', 'DoCoMo', 'Ocelli', 'Sogou Video', 'Yandex', 'Yeti', 'SEO Scanner', 'Feedbin feed-id', + 'Austronaut-URL-Checker', 'check_ssl_cert', 'check_http', 'vdirsyncer', 'FreshRSS', 'UniversalFeedParser', + 'Cloudflare Custom Hostname Verification', 'Scoop.it', ]; if (in_array($this->brand, $botArray)) { -- 2.35.3 From c79be4c2c1230110175194a8aee78a5eb20d6af0 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 26 Feb 2023 02:41:20 +0100 Subject: [PATCH 13/16] add support for datalist element --- classes/document.php-class | 39 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/classes/document.php-class b/classes/document.php-class index ed688b6..4490589 100755 --- a/classes/document.php-class +++ b/classes/document.php-class @@ -125,6 +125,10 @@ class ExtendedDocument extends DOMDocument { // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params) // returns the new child // + // public function appendElementDatalist([$id], [$options]) + // appends an ExtendedDocument::createElementDatalist() as a child of this document (see there for params) + // returns the new child + // // public function appendText($text) // appends a DOMDocument::createTextNode() as a child of this document (see there for params) // returns the new child @@ -250,6 +254,9 @@ class ExtendedDocument extends DOMDocument { // public function createElementLabel($for_id, $value) // returns an ExtendedElement that is an HTML