22
33namespace BNETDocs \Libraries ;
44
5- use \CarlBennett \MVC \Libraries \Common as CommonMVCLib ;
5+ use \CarlBennett \MVC \Libraries \Common ;
66use \CarlBennett \MVC \Libraries \IP ;
77
8+ use \BNETDocs \Libraries \Authentication ;
9+ use \BNETDocs \Libraries \EventTypes ;
10+ use \BNETDocs \Libraries \Logger ;
11+
812class BlizzardChecker {
913
1014 /**
@@ -13,12 +17,29 @@ class BlizzardChecker {
1317 private function __construct () {}
1418
1519 public static function checkIfBlizzard () {
16- $ IP = getenv (" REMOTE_ADDR " );
17- $ CIDRs = file_get_contents (getcwd () . " /static/a/Blizzard-CIDRs.txt " );
18- $ CIDRs = preg_replace ("/^#.*? \n/sm " , "" , $ CIDRs );
19- $ CIDRs = CommonMVCLib ::stripLinesWith ($ CIDRs , "\n" );
20+ $ IP = getenv (' REMOTE_ADDR ' );
21+ $ CIDRs = file_get_contents (getcwd () . ' /static/a/Blizzard-CIDRs.txt ' );
22+ $ CIDRs = preg_replace ("/^#.*? \n/sm " , '' , $ CIDRs );
23+ $ CIDRs = Common ::stripLinesWith ($ CIDRs , "\n" );
2024 $ CIDRs = explode ("\n" , $ CIDRs );
2125 return IP ::checkCIDRArray ($ IP , $ CIDRs );
2226 }
2327
28+ public static function logIfBlizzard () {
29+ $ user_id = (isset (Authentication::$ user ) ? Authentication::$ user : null );
30+ if (BlizzardChecker::checkIfBlizzard ()) {
31+ Logger::logEvent (
32+ EventTypes::BLIZZARD_VISIT ,
33+ $ user_id ,
34+ getenv ('REMOTE_ADDR ' ),
35+ json_encode ([
36+ 'method ' => getenv ('REQUEST_METHOD ' ),
37+ 'referer ' => getenv ('HTTP_REFERER ' ),
38+ 'uri ' => getenv ('REQUEST_URI ' ),
39+ 'version ' => VersionInfo::get (),
40+ ])
41+ );
42+ }
43+ }
44+
2445}
0 commit comments