Skip to content

Commit

Permalink
Updates user agent detection in client library.
Browse files Browse the repository at this point in the history
  • Loading branch information
JB Lebrun committed Oct 19, 2018
1 parent 316da90 commit 222e83a
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 37 deletions.
50 changes: 29 additions & 21 deletions engine/lib/tool/client.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @details Engine / Tool Library
* @file engine/lib/tool/client.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.39
* @version 1.0.40
* @date Creation: Jun 2007
* @date Modification: Oct 2018
* @copyright 2007 - 2018 CaMykS Team
Expand Down Expand Up @@ -188,19 +188,9 @@ function client_getUAInfos($ua=false) {
'system_title' => 'Maemo',
'system_version' => 5,
));
elseif (preg_match('/Nokia(?: |_|\-|\/|)([^ _\-\/]+)/', $ua, $matches)) {
$rep = array(
'X2DS' => array('platform_model' => 'X2 (Dual Sim)'),
);

$infos = array_merge($infos, array(
'platform_company' => 'Nokia',
'platform_model' => $matches[1],
'platform_type' => 'handheld',
'platform_format' => 'handheld',
),
isset($rep[$matches[1]])?$rep[$matches[1]]:array()
);
elseif (preg_match('/Nokia(?: |_|\-|\/|)([^_\-\/]+) Build/', $ua, $matches)) {
include_once ('clientDevices/Nokia.php.inc');
$infos = array_merge($infos, get_NokiaClientDevice(trim($matches[1])));
}
elseif (preg_match('/Lumia ([a-zA-Z0-9]*)/', $ua, $matches))
$infos = array_merge($infos, array(
Expand Down Expand Up @@ -424,7 +414,7 @@ function client_getUAInfos($ua=false) {
include_once ('clientDevices/Huawei.php.inc');
$infos = array_merge($infos, get_HuaweiClientDevice(trim($matches[2])));
}
elseif (preg_match('/(SCL\-L01) Build/', $ua, $matches)) {
elseif (preg_match('/ ([A-Z][A-Z0-9]{2,3}\-[A-Z][A-Z0-9]{2,3})( Build|\))/', $ua, $matches)) {
include_once ('clientDevices/Huawei.php.inc');
$infos = array_merge($infos, get_HuaweiClientDevice(trim($matches[1])));
}
Expand Down Expand Up @@ -1104,7 +1094,7 @@ function client_getUAInfos($ua=false) {
}

/* check Vivo mobiles */
elseif (preg_match('/ vivo ([0-9]{4}) Build/', $ua, $matches)) {
elseif (preg_match('/ vivo ([0-9A-Z]{4}) Build/', $ua, $matches)) {
include_once ('clientDevices/Vivo.php.inc');
$infos = array_merge($infos, get_VivoClientDevice($matches[1]));
}
Expand Down Expand Up @@ -1213,6 +1203,20 @@ function client_getUAInfos($ua=false) {
$infos = array_merge($infos, get_GioneeClientDevice($model));
}

/* check Konrow mobiles */
elseif (preg_match('/ (BIGCOOL) Build/i', $ua, $matches)) {
include_once ('clientDevices/Konrow.php.inc');
$model = $matches[1];
$infos = array_merge($infos, get_KonrowClientDevice($model));
}

/* check HomTom mobiles */
elseif (preg_match('/ (HT[0-9]{2}) Build/i', $ua, $matches)) {
include_once ('clientDevices/HomTom.php.inc');
$model = $matches[1];
$infos = array_merge($infos, get_HomTomClientDevice($model));
}

/*** check operating system ***/

if (!isset($infos['system_title'])) {
Expand Down Expand Up @@ -2184,6 +2188,14 @@ function client_getFakeInfosFromUserAgent($ua='') {
if (($chars = count_chars($ua, 1)) and isset($chars[ord('+')]) and $chars[ord('+')] >= 10 and (!isset($chars[ord(' ')])))
return $fake;

/* fake google bot user agent */
if (preg_match('#^Mozilla/6.0 \(compatible; Googlebot/2.1; \+http\://www.google.com/bot.html\)$#i', $ua))
return $fake;

/* badly set user agent */
if (preg_match('#Connection: closern$#i', $ua))
return $fake;

/* not a fake but Apple using a bad user agent */
if (preg_match('#Mozilla/5.0 \(Macintosh; Intel Mac OS X 10_11_1\) AppleWebKit/601.2.4 \(KHTML, like Gecko\) Version/9.0.1 Safari/601.2.4 facebookexternalhit/1.1 Facebot Twitterbot/1.0#', $ua))
return array(
Expand All @@ -2195,10 +2207,6 @@ function client_getFakeInfosFromUserAgent($ua='') {
'engine_url' => 'http://www.apple.com',
);

/* badly set user agent */
if (preg_match('#Connection: closern$#i', $ua))
return $fake;

/* default result */
return false;
}
Expand Down Expand Up @@ -2247,7 +2255,7 @@ function _client_getUAPropertiesMaxVersions() {
'Internet Explorer' => '11.0.50', // latest
'Edge' => '45', // current is 40
'Opera' => '59', // current is 56
'Safari' => '15', // current is 12
'Safari' => '15', // current is 12.0.1
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions engine/lib/tool/clientBots/Bots.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @details Engine / Bot Library
* @file engine/lib/tool/clientBots/Bots.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.17
* @version 1.0.18
* @date Creation: May 2018
* @date Modification: Oct 2018
* @copyright 2018 CaMykS Team
Expand Down Expand Up @@ -3469,7 +3469,7 @@ function _client_getKnownBots() {
'platform_type' => 'bot',
'platform_format' => 'desktop',
'bot_title' => 'Companybook-Crawler',
'bot_url' => '',
'bot_url' => 'http://support.companybooknetworking.com/knowledgebase/articles/1163176-companybook-crawler',
'engine_title' => 'Companybook',
'engine_url' => 'https://www.companybooknetworking.com',
);
Expand Down
45 changes: 45 additions & 0 deletions engine/lib/tool/clientDevices/HomTom.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* @brief HomTom client devices specific methods
* @details Engine / Tool Library
* @file engine/lib/tool/clientDevices/HomTom.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @date Creation: Oct 2018
* @date Modification: Oct 2018
* @copyright 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* @warning This library is not loaded with CaMykS initialisation.
*/

/**
* Return HomTom client device information from a known list.
* @param mixed $deviceCode
* @return array
*/
function get_HomTomClientDevice($deviceCode='') {
$deviceList = array(
'HT50' => array('platform_year' => 2017),
);

/* Check for returning list */
if ($deviceCode === false)
return $deviceList;

/* Initialise result. */
$result = array(
'platform_company' => 'HomTom',
'platform_model' => $deviceCode,
'platform_type' => 'handheld',
'platform_format' => 'handheld',
);

/* Check if device is a known device. */
if (!array_key_exists($deviceCode, $deviceList))
return $result;

/* Return result. */
return array_merge($result, $deviceList[$deviceCode]);
}
?>
8 changes: 6 additions & 2 deletions engine/lib/tool/clientDevices/Huawei.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @details Engine / Tool Library
* @file engine/lib/tool/clientDevices/Huawei.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.16
* @version 1.0.17
* @date Creation: Apr 2018
* @date Modification: Oct 2018
* @copyright 2018 CaMykS Team
Expand Down Expand Up @@ -62,6 +62,7 @@ function get_HuaweiClientDevice($deviceCode='') {
'BLA-L29S' => array('platform_model' => 'Mate 10 Pro', 'platform_year' => 2017),
'CRR-L09' => array('platform_model' => 'Mate S', 'platform_year' => 2015),
'BND-L34' => array('platform_model' => 'Mate SE', 'platform_year' => 2016),
'LYO-L21' => array('platform_model' => 'Honor 5A', 'platform_year' => 2016),
'NEM-L51' => array('platform_model' => 'Honor 5C', 'platform_year' => 2016),
'KIW-L21' => array('platform_model' => 'Honor 5X', 'platform_year' => 2015),
'JMM-L22' => array('platform_model' => 'Honor 6C Pro', 'platform_year' => 2017),
Expand All @@ -88,9 +89,12 @@ function get_HuaweiClientDevice($deviceCode='') {
'CUN-L03' => array('platform_model' => 'Y5 II', 'platform_year' => 2016),
'SCL-L01' => array('platform_model' => 'Y6', 'platform_year' => 2015),
'SCL-U31' => array('platform_model' => 'Y6', 'platform_year' => 2015),
'LYO-L01' => array('platform_model' => 'Y6 II Compact', 'platform_year' => 2016),
'MYA-L11' => array('platform_model' => 'Y6', 'platform_year' => 2017),
'MYA-L41' => array('platform_model' => 'Y6', 'platform_year' => 2017),
'LYO-L01' => array('platform_model' => 'Y6 II Compact', 'platform_year' => 2016),
'ATU-L11' => array('platform_model' => 'Y6', 'platform_year' => 2018),
'ATU-L21' => array('platform_model' => 'Y6', 'platform_year' => 2018),
'ATU-L22' => array('platform_model' => 'Y6', 'platform_year' => 2018),
'TRT-LX2' => array('platform_model' => 'Y7', 'platform_year' => 2017),
'TRT-LX3' => array('platform_model' => 'Y7', 'platform_year' => 2017),
'TRT-L53' => array('platform_model' => 'Y7\'', 'platform_year' => 2018),
Expand Down
45 changes: 45 additions & 0 deletions engine/lib/tool/clientDevices/Konrow.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* @brief Konrow client devices specific methods
* @details Engine / Tool Library
* @file engine/lib/tool/clientDevices/Konrow.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @date Creation: Oct 2018
* @date Modification: Oct 2018
* @copyright 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* @warning This library is not loaded with CaMykS initialisation.
*/

/**
* Return Konrow client device information from a known list.
* @param mixed $deviceCode
* @return array
*/
function get_KonrowClientDevice($deviceCode='') {
$deviceList = array(
'BIGCOOL' => array('platform_model' => 'BigCool', 'platform_year' => 2016),
);

/* Check for returning list */
if ($deviceCode === false)
return $deviceList;

/* Initialise result. */
$result = array(
'platform_company' => 'Konrow',
'platform_model' => $deviceCode,
'platform_type' => 'handheld',
'platform_format' => 'handheld',
);

/* Check if device is a known device. */
if (!array_key_exists($deviceCode, $deviceList))
return $result;

/* Return result. */
return array_merge($result, $deviceList[$deviceCode]);
}
?>
12 changes: 7 additions & 5 deletions engine/lib/tool/clientDevices/Nokia.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* @details Engine / Tool Library
* @file engine/lib/tool/clientDevices/Nokia.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Jun 2018
* @date Modification: Jun 2018
* @date Modification: Oct 2018
* @copyright 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* @warning This library is not loaded with CaMykS initialisation.
*/
Expand All @@ -20,7 +20,9 @@
*/
function get_NokiaClientDevice($deviceCode='') {
$deviceList = array(
'TA-1053' => array('platform_model' => '5', 'platform_year' => 2017),
'X2DS' => array('platform_model' => 'X2 (Dual Sim)', 'platform_year' => 2014),
'TA-1053' => array('platform_model' => '5', 'platform_year' => 2017),
'7 plus' => array('platform_model' => '7 Plus', 'platform_year' => 2018),
);

/* Check for returning list */
Expand All @@ -42,4 +44,4 @@ function get_NokiaClientDevice($deviceCode='') {
/* Return result. */
return array_merge($result, $deviceList[$deviceCode]);
}
?>
?>
5 changes: 3 additions & 2 deletions engine/lib/tool/clientDevices/Orange.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* @details Engine / Tool Library
* @file engine/lib/tool/clientDevices/Orange.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Sep 2018
* @date Modification: Sep 2018
* @date Modification: Oct 2018
* @copyright 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Expand All @@ -22,6 +22,7 @@ function get_OrangeClientDevice($deviceCode='') {
$deviceList = array(
'Nura' => array('platform_year' => 2015),
'Nura 2' => array('platform_year' => 2016),
'Neva 80' => array('platform_year' => 2016),
);

/* Check for returning list */
Expand Down
6 changes: 5 additions & 1 deletion engine/lib/tool/clientDevices/Samsung.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @details Engine / Tool Library
* @file engine/lib/tool/clientDevices/Samsung.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.16
* @version 1.0.17
* @date Creation: Apr 2018
* @date Modification: Oct 2018
* @copyright 2018 CaMykS Team
Expand Down Expand Up @@ -57,6 +57,7 @@ function get_SamsungClientDevice($deviceCode='') {
'GT-I9000' => array('platform_model' => 'Galaxy S', 'platform_year' => 2010),
'GT-S7562' => array('platform_model' => 'Galaxy S Duo', 'platform_year' => 2012),
'GT-I9100' => array('platform_model' => 'Galaxy S2', 'platform_year' => 2011),
'GT-I9105P' => array('platform_model' => 'Galaxy S2 Plus', 'platform_year' => 2013),
'GT-I9195' => array('platform_model' => 'Galaxy S4 Mini', 'platform_year' => 2013),
'GT-I9295' => array('platform_model' => 'Galaxy S4 Active', 'platform_year' => 2013),
'GT-I9300' => array('platform_model' => 'Galaxy S3', 'platform_year' => 2012),
Expand Down Expand Up @@ -111,6 +112,7 @@ function get_SamsungClientDevice($deviceCode='') {
'SM-A510F' => array('platform_model' => 'Galaxy A5', 'platform_year' => 2016),
'SM-A5100' => array('platform_model' => 'Galaxy A5', 'platform_year' => 2016),
'SM-A520F' => array('platform_model' => 'Galaxy A5', 'platform_year' => 2017),
'SM-A605FN' => array('platform_model' => 'Galaxy A6+', 'platform_year' => 2018),
'SM-A700F' => array('platform_model' => 'Galaxy A7', 'platform_year' => 2015),
'SM-A700L' => array('platform_model' => 'Galaxy A7', 'platform_year' => 2015),
'SM-A530F' => array('platform_model' => 'Galaxy A8', 'platform_year' => 2018),
Expand Down Expand Up @@ -180,6 +182,8 @@ function get_SamsungClientDevice($deviceCode='') {
'GT-I9082L' => array('platform_model' => 'Galaxy Grand', 'platform_year' => 2012),
'GT-I9060I' => array('platform_model' => 'Galaxy Grand Plus', 'platform_year' => 2014),
'GT-I9082' => array('platform_model' => 'Galaxy Grand Duos', 'platform_year' => 2013),
'GT-I8552' => array('platform_model' => 'Galaxy Grand Quattro', 'platform_year' => 2013),
'GT-I8552B' => array('platform_model' => 'Galaxy Grand Quattro', 'platform_year' => 2013),
'SM-G550FY' => array('platform_model' => 'Galaxy On5', 'platform_year' => 2016),
'GT-N5110' => array('platform_model' => 'Galaxy Note', 'platform_year' => 2013),
'GT-N7000' => array('platform_model' => 'Galaxy Note (3G)', 'platform_year' => 2011),
Expand Down
9 changes: 5 additions & 4 deletions engine/lib/tool/clientDevices/Vivo.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* @details Engine / Tool Library
* @file engine/lib/tool/clientDevices/Vivo.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: May 2018
* @date Modification: May 2018
* @date Modification: Oct 2018
* @copyright 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* @warning This library is not loaded with CaMykS initialisation.
*/
Expand All @@ -20,6 +20,7 @@
*/
function get_VivoClientDevice($deviceCode='') {
$deviceList = array(
'X20A' => array('platform_model' => 'X20A', 'platform_year' => 2017),
'1723' => array('platform_model' => 'V9', 'platform_year' => 2018),
);

Expand All @@ -42,4 +43,4 @@ function get_VivoClientDevice($deviceCode='') {
/* Return result. */
return array_merge($result, $deviceList[$deviceCode]);
}
?>
?>

0 comments on commit 222e83a

Please sign in to comment.