Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

7.0.0 #78

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
/phpunit.xml.dist export-ignore
/README.md export-ignore
/ruleset.xml export-ignore
/scripts export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
phpunit.xml
vendor
.idea
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 7.0.0 (released 2017-xx-xx)

- ...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add changelog


## 6.1.2 (released 2016-12-28)

- Added wkhtmltopdf detection
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Contributions are welcome, and are accepted via pull requests. Please review the
* Send a coherent commit history, making sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash](http://git-scm.com/book/en/Git-Tools-Rewriting-History) them before submitting.
* You may also need to [rebase](http://git-scm.com/book/en/Git-Branching-Rebasing) to avoid merge conflicts.


## Running Tests

You will need an install of [Composer](https://getcomposer.org) before continuing.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2017 Chris Schuld <[email protected]>
Copyright (c) 2013-present Chris Schuld <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
99 changes: 92 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,13 @@ The Browser class allows you to detect a user's browser and version.
* Lynx
* Safari
* Chrome
* Navigator
* GoogleBot
* Yahoo! Slurp
* W3C Validator
* Android Navigator
* UC Browser
* BlackBerry
* IceCat
* Nokia S60 OSS Browser
* Nokia Browser
* MSN Browser
* MSN Bot
* Netscape Navigator
* Galeon
* NetPositive
Expand All @@ -69,14 +66,16 @@ The Browser class allows you to detect a user's browser and version.
* Yandex Browser
* Comodo Dragon
* Samsung Browser
* wkhtmltopdf

### Usage

```php
use Sinergi\BrowserDetector\Browser;

$browser = new Browser();
$browser = new Browser();

//You can also provide a userAgent string if you don't wish to detect the current browser
//$browser = new Browser("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0");

if ($browser->getName() === Browser::IE && $browser->getVersion() < 11) {
echo 'Please upgrade your browser.';
Expand All @@ -97,6 +96,92 @@ if ($browser->getName() === Browser::IE && $browser->isCompatibilityMode()) {
}
```

## Scripted Agent Detection

The ScriptedAgent class allows you to detect scripted agents (bots, spiders, tools)

### Scripted Agents Detected

Spiders

* GoogleBot
* Baidu
* Bing
* MSN
* Yahoo! Slurp
* W3C Spiders
* Yandex
* Apple
* Paper.li
* Majestic12
* Livelap
* Scoop.it
* Who.is
* Proximic

Web Surveys

* Ahrefs
* MetaURI
* Netcraft
* Browsershots
* MageReport
* SocialRank.io
* Gluten Free
* Ubermetrics
* Verisign IPS-Agent

Exploits

* ShellShock

Web Preview bots

* ICQ
* Google Web
* Facebook
* Bing
* Twitter
* Skype

Tools

* wkHTMLtoPDF
* W3C Validator
* WebDAV
* TLSProbe
* Wget
* Zgrab

Generic

* Google Favicon
* Curl
* Python
* GoLang
* Perl
* Java

Ad bots

* Google
* Microsoft
* AdBeat

### Usage

```php
use Sinergi\BrowserDetector\Browser;

$browser = new Browser();

$scriptedAgent = $browser->detectScriptedAgent();
if ($scriptedAgent!==false)
{
die("Detected ".$scriptedAgent->getName()." which is a ".$scriptedAgent->getType().". Info: ".$scriptedAgent->getInfoURL());
}
```

## OS Detection

The OS class allows you to detect a user's operating system and version.
Expand Down
156 changes: 156 additions & 0 deletions scripts/fetchEdgeVersions/ChangeWindows.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

/**
* Fetch versions from changewindows.org
* © 2014-present CHANGEWINDOWS
*
* Disclaimer
* All trademarks mentioned are the property of their respective owners. The content generated by this script
* comes from changewindows.org and may not be accurate.
*/
class ChangeWindows
{
private static $errors = array(
'could_not_fetch_version' => 'Could not fetch current version from ChangeWindows',
'invalid_version' => 'Windows version is invalid',
'could_not_fetch_page' => 'Could not fetch page from ChangeWindows'
);

public static function fetchVersions()
{
$windowsVersions = json_decode(file_get_contents(__DIR__ . '/windowsVersions.json'), true);
if (!count($windowsVersions)) {
$currentVersion = explode('.', self::fetchCurrentVersion(), 2);
if (!isset($currentVersion[0])) {
throw new Exception(self::$errors['invalid_version']);
}
$windowsVersions = self::fetchVersion($windowsVersions, $currentVersion[0]);
self::writeWindowsVersions($windowsVersions);
} else {
reset($windowsVersions);
$firstVersion = key($windowsVersions);
end($windowsVersions);
$lastVersion = key($windowsVersions);

try {
$result = self::fetchVersion($windowsVersions, $firstVersion);
$windowsVersions = $result;
} catch (Exception $e) {
}

$windowsVersions = self::fetchVersion($windowsVersions, $lastVersion);
self::writeWindowsVersions($windowsVersions);
}
}

private static function fetchVersion($windowsVersions, $version)
{
$siblingVersions = self::fetchPage($version);
$windowsVersions[$version] = true;
self::writeWindowsVersions($windowsVersions);

if (isset($siblingVersions[0]) && !isset($windowsVersions[$siblingVersions[0]])) {
$windowsVersions = self::fetchVersion($windowsVersions, $siblingVersions[0]);
}

if (isset($siblingVersions[1]) && !isset($windowsVersions[$siblingVersions[1]])) {
$windowsVersions = self::fetchVersion($windowsVersions, $siblingVersions[1]);
}

return $windowsVersions;
}

private static function writeWindowsVersions($windowsVersions)
{
ksort($windowsVersions);
file_put_contents(__DIR__ . '/windowsVersions.json', json_encode($windowsVersions, JSON_PRETTY_PRINT));
}

private static function fetchCurrentVersion()
{
$content = file_get_contents('https://changewindows.org/filter/pc/all/current/month/true');
if (!$content) {
throw new Exception(self::$errors['could_not_fetch_version']);
}
$content = explode('class="timeline"', $content, 2);
if (!isset($content[1])) {
throw new Exception(self::$errors['could_not_fetch_version']);
}
$content = explode('build"', $content[1], 2);
if (!isset($content[1])) {
throw new Exception(self::$errors['could_not_fetch_version']);
}
preg_match("/(\d*\.\d*)<\/div>/", $content[1], $matches);
if (!isset($matches[1])) {
throw new Exception(self::$errors['could_not_fetch_version']);
}
return $matches[1];
}

private static function fetchPage($version)
{
$url = "https://changewindows.org/build/{$version}/pc";
$content = file_get_contents($url);
$siblingVersions = self::fetchSiblingVersions($content);
self::fetchEdgeVersion($content);
return $siblingVersions;
}

private static function fetchEdgeVersion($content)
{
preg_match('/<h4[^>]*> *Edge ([\d\.]*) *<\/h4>/', $content, $edge);
preg_match('/<h4[^>]*>EdgeHTML ([\d\.]*)<\/h4>/', $content, $edgeHtml);

if (isset($edge[1]) && isset($edgeHtml[1])) {
self::writeEdgeVersion($edgeHtml[1], $edge[1]);
}
return null;
}

private static function writeEdgeVersion($edgeHtml, $edge)
{
$file = __DIR__ . '/../../src/edgeVersionMap.php';
$currentVersions = require $file;
if (!isset($currentVersions[$edgeHtml])) {
$currentVersions[$edgeHtml] = $edge;
ksort($currentVersions);
$content = '';
foreach ($currentVersions as $edgeHtml => $edge) {
$content .= " '{$edgeHtml}' => '{$edge}'," . PHP_EOL;
}
$data = <<<PHP
<?php

return array(
%s
);

PHP;
file_put_contents($file, sprintf($data, trim($content)));
}
}

private static function fetchSiblingVersions($content)
{
if (!$content) {
throw new Exception(self::$errors['could_not_fetch_page']);
}
$content = explode('build-sidebar', $content, 2);
if (!isset($content[1])) {
throw new Exception(self::$errors['could_not_fetch_page']);
}
$content = explode('fa-angle-left', $content[1]);
if (!isset($content[1])) {
throw new Exception(self::$errors['could_not_fetch_page']);
}
$content = explode('fa-angle-right', $content[1]);
if (!isset($content[0])) {
throw new Exception(self::$errors['could_not_fetch_page']);
}
preg_match_all("/> *(\d+) *</", $content[0], $matches);
if (!isset($matches[1])) {
throw new Exception(self::$errors['could_not_fetch_page']);
}
return $matches[1];
}
}
4 changes: 4 additions & 0 deletions scripts/fetchEdgeVersions/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

require_once __DIR__ . '/ChangeWindows.php';
ChangeWindows::fetchVersions();
33 changes: 33 additions & 0 deletions scripts/fetchEdgeVersions/windowsVersions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"15002": true,
"15007": true,
"15009": true,
"15014": true,
"15019": true,
"15023": true,
"15025": true,
"15026": true,
"15031": true,
"15034": true,
"15038": true,
"15039": true,
"15042": true,
"15043": true,
"15045": true,
"15046": true,
"15047": true,
"15048": true,
"15049": true,
"15051": true,
"15055": true,
"15058": true,
"15060": true,
"15061": true,
"15062": true,
"15063": true,
"15204": true,
"15205": true,
"16170": true,
"16176": true,
"16179": true
}
Loading