From 914de29859de04d94c8d7a105373896e04656e42 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 5 Jun 2019 18:18:11 +0200 Subject: [PATCH] improve user-agent formatting and use is also for accesslog --- admin/inc/class.admin_accesslog.inc.php | 2 ++ admin/templates/default/accesslog.xet | 2 +- api/src/Header/UserAgent.php | 11 ++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/admin/inc/class.admin_accesslog.inc.php b/admin/inc/class.admin_accesslog.inc.php index 377f929abb..7cfbbbcec8 100644 --- a/admin/inc/class.admin_accesslog.inc.php +++ b/admin/inc/class.admin_accesslog.inc.php @@ -120,6 +120,8 @@ class admin_accesslog } $row['sessionstatus'] = lang($row['sessionstatus']); unset($row['session_php']); // for security reasons, do NOT give real PHP sessionid to UI + + $row['os_browser'] = Api\Header\UserAgent::osBrowser($row['user_agent']); } if ($query['session_list']) { diff --git a/admin/templates/default/accesslog.xet b/admin/templates/default/accesslog.xet index 3a7d571428..832a8f8379 100644 --- a/admin/templates/default/accesslog.xet +++ b/admin/templates/default/accesslog.xet @@ -41,7 +41,7 @@ - + diff --git a/api/src/Header/UserAgent.php b/api/src/Header/UserAgent.php index 4682344591..49970e3e4e 100644 --- a/api/src/Header/UserAgent.php +++ b/api/src/Header/UserAgent.php @@ -59,15 +59,16 @@ class UserAgent $matches = $os_matches = null; if (preg_match_all('#([^/]+)/([0-9.]+)( \([^)]+\))? ?#i', $user_agent, $matches) && count($matches) >= 4) { - if (preg_match('/((Windows|Linux|Mac OS X)( NT)?) ([0-9._]+)/', $os=$matches[3][0], $os_matches)) + if (preg_match('/((Windows|Linux|Mac OS X|iOS|Android)( NT)?) ([0-9._]+)?/', $os=$matches[3][0], $os_matches) || + preg_match('/((Windows|Linux|Mac OS X|iOS|Android)( NT)?)\/([0-9._]+)?/', $os=$matches[0][0], $os_matches)) { $os = $os_matches[1].' '.str_replace('_', '.', $os_matches[4]); } - $browser = $matches[1][2] === 'Version' ? $matches[1][3] : $matches[1][2]; - $browser_version = $matches[2][2]; - return "$os\n$browser $browser_version"; + $browser = $matches[1][2] === 'Version' ? $matches[1][3] : (!empty($matches[1][2]) ? $matches[1][2] : $matches[1][1]); + $browser_version = !empty($matches[2][2]) ? $matches[2][2] : $matches[2][1]; + $user_agent = "$os\n$browser $browser_version"; } - return $user_agent; + return str_replace('/', ' ', $user_agent); } /**