Last active
October 14, 2016 15:36
-
-
Save shulard/1fc5735332c40a33682e0ac170d28667 to your computer and use it in GitHub Desktop.
Melody script which help to identify who is current UserAgent in a webserver visit : http://melody.sensiolabs.org/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/vendor/ | |
/ua-detector.phar | |
composer.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"directories": ["vendor"], | |
"chmod": "0755", | |
"main": "ua-detector.php", | |
"output": "ua-detector.phar", | |
"stub": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "bee4/ua-detector", | |
"type": "script", | |
"require": { | |
"bee4/useragent-classifier": "^1.0" | |
}, | |
"authors": [ | |
{ | |
"name": "Stéphane HULARD", | |
"email": "[email protected]" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
require_once 'vendor/autoload.php'; | |
use Bee4\UserAgent\Classifier\Detector; | |
$regex = '/^(?P<ip>\S+) (?P<domain>\S+) (.+) \[(?P<date>[^\[]+)\] "(((?P<method>\S+) (?P<parent>.*?) (?P<version>\S+))|[^"]+)" (?P<status>\S+) (?P<size>\S+) "(?P<referer>((?:[^\\\\]*?(?:(\\x+|\\\\+|\\\"|\\\'))?)*?))" "(?P<useragent>.*)"/'; | |
if ($argc === 2) { | |
$regex = $argv[1]; | |
} | |
try { | |
$input = fgets(STDIN); | |
if (1 !== preg_match($regex, $input, $infos)) { | |
throw new Exception('Regex doesn\'t match the given line !'); | |
} | |
$bot = Detector::whoIs($infos['useragent']); | |
echo $bot->getBot().'::'.$bot->getName(); | |
} catch(\Exception $error) { | |
exit(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment