Improved UserAgent analyze.

This commit is contained in:
Christian P. MOMON 2022-01-06 10:24:55 +01:00
parent 07de9414b9
commit fd19427700
2 changed files with 70 additions and 13 deletions

View file

@ -47,6 +47,8 @@ public class UserAgent
/** /**
* Gets the browser. * Gets the browser.
*
* WARNING: MUST BE GREATLY IMPROVED
* *
* @return the browser * @return the browser
*/ */
@ -54,18 +56,34 @@ public class UserAgent
{ {
UserAgentBrowser result; UserAgentBrowser result;
if (StringUtils.containsIgnoreCase(this.source, "Firefox")) if (StringUtils.containsIgnoreCase(this.source, "Chrome/"))
{
result = UserAgentBrowser.FIREFOX;
}
else if (StringUtils.containsIgnoreCase(this.source, "Chrome"))
{ {
result = UserAgentBrowser.CHROME; result = UserAgentBrowser.CHROME;
} }
else if (StringUtils.containsIgnoreCase(this.source, "Chromium/"))
{
result = UserAgentBrowser.CHROMIUM;
}
else if (StringUtils.containsIgnoreCase(this.source, "Firefox/"))
{
result = UserAgentBrowser.FIREFOX;
}
else if (StringUtils.containsIgnoreCase(this.source, "Lynx")) else if (StringUtils.containsIgnoreCase(this.source, "Lynx"))
{ {
result = UserAgentBrowser.LYNX; result = UserAgentBrowser.LYNX;
} }
else if (StringUtils.containsIgnoreCase(this.source, "MSIE "))
{
result = UserAgentBrowser.MSIE;
}
else if (StringsUtils.containsAnyIgnoreCase(this.source, "Opera", "OPR/"))
{
result = UserAgentBrowser.OPERA;
}
else if (StringUtils.containsIgnoreCase(this.source, "Safari/"))
{
result = UserAgentBrowser.SAFARI;
}
else else
{ {
result = UserAgentBrowser.OTHER; result = UserAgentBrowser.OTHER;
@ -77,6 +95,8 @@ public class UserAgent
/** /**
* Gets the device. * Gets the device.
*
* WARNING: MUST BE GREATLY IMPROVED
* *
* @return the device * @return the device
*/ */
@ -84,13 +104,21 @@ public class UserAgent
{ {
UserAgentDevice result; UserAgentDevice result;
if (StringsUtils.containsAnyIgnoreCase(this.source, "iOS", "Android")) if (StringsUtils.containsAnyIgnoreCase(this.source, "Playstation"))
{
result = UserAgentDevice.CONSOLE;
}
else if (StringsUtils.containsAnyIgnoreCase(this.source, "Desktop"))
{
result = UserAgentDevice.PC;
}
else if (StringsUtils.containsAnyIgnoreCase(this.source, "Android", "iPhone"))
{ {
result = UserAgentDevice.PHONE; result = UserAgentDevice.PHONE;
} }
else if (StringsUtils.containsAnyIgnoreCase(this.source, "Playstation")) else if (StringsUtils.containsAnyIgnoreCase(this.source, "iPad"))
{ {
result = UserAgentDevice.CONSOLE; result = UserAgentDevice.TABLET;
} }
else else
{ {
@ -110,18 +138,42 @@ public class UserAgent
{ {
UserAgentOS result; UserAgentOS result;
if (StringUtils.containsIgnoreCase(this.source, "Firefox")) if (StringUtils.containsIgnoreCase(this.source, "Android"))
{ {
result = UserAgentOS.ANDROID; result = UserAgentOS.ANDROID;
} }
else if (StringUtils.containsIgnoreCase(this.source, "Chrome")) else if (StringUtils.containsIgnoreCase(this.source, "FreeBSD"))
{ {
result = UserAgentOS.FREEBSD; result = UserAgentOS.FREEBSD;
} }
else if (StringUtils.containsIgnoreCase(this.source, "Lynx")) else if (StringsUtils.containsAnyIgnoreCase(this.source, "Debian", "Gentoo", "Linux aarch", "Linux arm", "Linux i586", "Linux i686", "Linux x64", "Linux x86_64"))
{ {
result = UserAgentOS.GNULINUX; result = UserAgentOS.GNULINUX;
} }
else if (StringsUtils.containsAnyIgnoreCase(this.source, "Debian", "Gentoo", "Linux aarch", "Linux arm", "Linux i586", "Linux i686", "Linux x64", "Linux x86_64"))
{
result = UserAgentOS.GNULINUX;
}
else if (StringsUtils.containsAnyIgnoreCase(this.source, "iPhone"))
{
result = UserAgentOS.IOS;
}
else if (StringsUtils.containsAnyIgnoreCase(this.source, "Macintosh", "Mac OS X", "Mac OS Desktop"))
{
result = UserAgentOS.MACOS;
}
else if (StringUtils.containsIgnoreCase(this.source, "windows"))
{
result = UserAgentOS.MSWINDOWS;
}
else if (StringUtils.containsIgnoreCase(this.source, "NetBSD"))
{
result = UserAgentOS.NETBSD;
}
else if (StringUtils.containsIgnoreCase(this.source, "OpenBSD"))
{
result = UserAgentOS.OPENBSD;
}
else else
{ {
result = UserAgentOS.OTHER; result = UserAgentOS.OTHER;
@ -134,6 +186,8 @@ public class UserAgent
/** /**
* Gets the type. * Gets the type.
* *
* WARNING: MUST BE GREATLY IMPROVED
*
* @return the type * @return the type
*/ */
public UserAgentType getType() public UserAgentType getType()

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org> * Copyright (C) 2021-2022 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of StatoolInfos, simple service statistics tool. * This file is part of StatoolInfos, simple service statistics tool.
* *
@ -18,6 +18,9 @@
*/ */
package fr.devinsy.statoolinfos.metrics.http; package fr.devinsy.statoolinfos.metrics.http;
/**
* The Enum UserAgentOS.
*/
public enum UserAgentOS public enum UserAgentOS
{ {
ANDROID, ANDROID,
@ -28,5 +31,5 @@ public enum UserAgentOS
MACOS, MACOS,
NETBSD, NETBSD,
OPENBSD, OPENBSD,
OTHER OTHER,
} }