Diff
8 years ago
dashboard
7 years ago
rest-api
7 years ago
.htaccess
7 years ago
Diff.php
14 years ago
GeoLite2-Country.mmdb
7 years ago
IPTraf.php
8 years ago
IPTrafList.php
7 years ago
compat.php
8 years ago
conntest.php
7 years ago
cronview.php
8 years ago
dbview.php
8 years ago
diffResult.php
8 years ago
email_genericAlert.php
7 years ago
email_newIssues.php
7 years ago
email_unlockRequest.php
8 years ago
email_unsubscribeRequest.php
7 years ago
flags.php
7 years ago
live_activity.php
8 years ago
menu_dashboard.php
7 years ago
menu_dashboard_options.php
7 years ago
menu_firewall.php
7 years ago
menu_firewall_blocking.php
7 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
7 years ago
menu_firewall_waf_options.php
7 years ago
menu_options.php
7 years ago
menu_scanner.php
7 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
8 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
7 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
7 years ago
menu_tools_twoFactor.php
8 years ago
menu_tools_whois.php
8 years ago
menu_wordfence_central.php
7 years ago
sysinfo.php
8 years ago
unknownFiles.php
8 years ago
viewFullActivityLog.php
8 years ago
wf503.php
7 years ago
wfAPI.php
7 years ago
wfActivityReport.php
7 years ago
wfAdminNoticeQueue.php
8 years ago
wfArray.php
7 years ago
wfBrowscap.php
8 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
9 years ago
wfCentralAPI.php
7 years ago
wfConfig.php
7 years ago
wfCrawl.php
8 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
8 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
7 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
7 years ago
wfImportExportController.php
7 years ago
wfIssues.php
7 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
7 years ago
wfMD5BloomFilter.php
8 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
7 years ago
wfScan.php
7 years ago
wfScanEngine.php
7 years ago
wfSchema.php
7 years ago
wfStyle.php
8 years ago
wfSupportController.php
7 years ago
wfUnlockMsg.php
7 years ago
wfUpdateCheck.php
8 years ago
wfUtils.php
7 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
7 years ago
wordfenceConstants.php
7 years ago
wordfenceHash.php
7 years ago
wordfenceScanner.php
7 years ago
wordfenceURLHoover.php
7 years ago
wfBrowscap.php
129 lines
| 1 | <?php |
| 2 | class wfBrowscap { |
| 3 | protected $_cacheLoaded = false; |
| 4 | protected $_userAgents = array(); |
| 5 | protected $_browsers = array(); |
| 6 | protected $_patterns = array(); |
| 7 | protected $_properties = array(); |
| 8 | protected $resultCache = array(); |
| 9 | const COMPRESSION_PATTERN_START = '@'; |
| 10 | const COMPRESSION_PATTERN_DELIMITER = '|'; |
| 11 | const REGEX_DELIMITER = '@'; |
| 12 | |
| 13 | public static function shared() { |
| 14 | static $_browscap = null; |
| 15 | if ($_browscap === null) { |
| 16 | $_browscap = new wfBrowscap(); |
| 17 | } |
| 18 | return $_browscap; |
| 19 | } |
| 20 | |
| 21 | public function getBrowser($user_agent){ |
| 22 | if (!$this->_cacheLoaded) { |
| 23 | if (!$this->_loadCache('wfBrowscapCache.php')) { |
| 24 | throw new Exception('Cannot load this cache version - the cache format is not compatible.'); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | $browser = array(); |
| 29 | foreach ($this->_patterns as $pattern => $pattern_data) { |
| 30 | if (preg_match($pattern . 'i', $user_agent, $matches)) { |
| 31 | if (1 == count($matches)) { |
| 32 | $key = $pattern_data; |
| 33 | |
| 34 | $simple_match = true; |
| 35 | } else { |
| 36 | $pattern_data = unserialize($pattern_data); |
| 37 | |
| 38 | array_shift($matches); |
| 39 | |
| 40 | $match_string = self::COMPRESSION_PATTERN_START |
| 41 | . implode(self::COMPRESSION_PATTERN_DELIMITER, $matches); |
| 42 | |
| 43 | if (!isset($pattern_data[$match_string])) { |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | $key = $pattern_data[$match_string]; |
| 48 | |
| 49 | $simple_match = false; |
| 50 | } |
| 51 | |
| 52 | $browser = array( |
| 53 | $user_agent, |
| 54 | trim(strtolower($pattern), self::REGEX_DELIMITER), |
| 55 | $this->_pregUnQuote($pattern, $simple_match ? false : $matches) |
| 56 | ); |
| 57 | |
| 58 | $browser = $value = $browser + unserialize($this->_browsers[$key]); |
| 59 | |
| 60 | while (array_key_exists(3, $value)) { |
| 61 | $value = unserialize($this->_browsers[$value[3]]); |
| 62 | $browser += $value; |
| 63 | } |
| 64 | |
| 65 | if (!empty($browser[3])) { |
| 66 | $browser[3] = $this->_userAgents[$browser[3]]; |
| 67 | } |
| 68 | |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | $array = array(); |
| 74 | foreach ($browser as $key => $value) { |
| 75 | if ($value === 'true') { |
| 76 | $value = true; |
| 77 | } elseif ($value === 'false') { |
| 78 | $value = false; |
| 79 | } |
| 80 | $array[$this->_properties[$key]] = $value; |
| 81 | } |
| 82 | |
| 83 | return $array; |
| 84 | } |
| 85 | protected function _loadCache($cache_file){ |
| 86 | $cache_version = null; |
| 87 | $source_version = null; |
| 88 | $browsers = array(); |
| 89 | $userAgents = array(); |
| 90 | $patterns = array(); |
| 91 | $properties = array(); |
| 92 | |
| 93 | $this->_cacheLoaded = false; |
| 94 | |
| 95 | require $cache_file; |
| 96 | |
| 97 | $this->_source_version = $source_version; |
| 98 | $this->_browsers = $browsers; |
| 99 | $this->_userAgents = $userAgents; |
| 100 | $this->_patterns = $patterns; |
| 101 | $this->_properties = $properties; |
| 102 | |
| 103 | $this->_cacheLoaded = true; |
| 104 | |
| 105 | return true; |
| 106 | } |
| 107 | protected function _pregUnQuote($pattern, $matches){ |
| 108 | $search = array( |
| 109 | '\\' . self::REGEX_DELIMITER, '\\.', '\\\\', '\\+', '\\[', '\\^', '\\]', '\\$', '\\(', '\\)', '\\{', '\\}', |
| 110 | '\\=', '\\!', '\\<', '\\>', '\\|', '\\:', '\\-', '.*', '.', '\\?' |
| 111 | ); |
| 112 | $replace = array( |
| 113 | self::REGEX_DELIMITER, '\\?', '\\', '+', '[', '^', ']', '$', '(', ')', '{', '}', '=', '!', '<', '>', '|', |
| 114 | ':', '-', '*', '?', '.' |
| 115 | ); |
| 116 | |
| 117 | $result = substr(str_replace($search, $replace, $pattern), 2, -2); |
| 118 | |
| 119 | if ($matches) { |
| 120 | foreach ($matches as $one_match) { |
| 121 | $num_pos = strpos($result, '(\d)'); |
| 122 | $result = substr_replace($result, $one_match, $num_pos, 4); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | return $result; |
| 127 | } |
| 128 | } |
| 129 |