improve user-agent formatting and use is also for accesslog

This commit is contained in:
Ralf Becker 2019-06-05 18:18:11 +02:00
parent 8f2339e67c
commit 914de29859
3 changed files with 9 additions and 6 deletions

View File

@ -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'])
{

View File

@ -41,7 +41,7 @@
<date-time id="${row}[lo]" readonly="true"/>
<date-duration id="${row}[total]" readonly="true" options=",hm,24"/>
<date-since id="${row}[session_dla]" readonly="true"/>
<description statustext="$row_cont[user_agent]" id="{$row}[user_agent]" class="admin_userAgent"/>
<description statustext="$row_cont[user_agent]" id="${row}[os_browser]" class="admin_userAgent"/>
</row>
</rows>
</grid>

View File

@ -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);
}
/**