Skip to content

Commit 35ef866

Browse files
committed
Re-add missing check for Blizzard visits
1 parent ec34ccd commit 35ef866

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/libraries/BlizzardChecker.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace BNETDocs\Libraries;
44

5-
use \CarlBennett\MVC\Libraries\Common as CommonMVCLib;
5+
use \CarlBennett\MVC\Libraries\Common;
66
use \CarlBennett\MVC\Libraries\IP;
77

8+
use \BNETDocs\Libraries\Authentication;
9+
use \BNETDocs\Libraries\EventTypes;
10+
use \BNETDocs\Libraries\Logger;
11+
812
class 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
}

src/main.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace BNETDocs;
2222

2323
use \BNETDocs\Libraries\Authentication;
24+
use \BNETDocs\Libraries\BlizzardChecker;
2425
use \BNETDocs\Libraries\Logger;
2526
use \BNETDocs\Libraries\VersionInfo;
2627
use \CarlBennett\MVC\Libraries\Cache;
@@ -70,6 +71,8 @@ function main() {
7071

7172
Authentication::verify();
7273

74+
BlizzardChecker::logIfBlizzard();
75+
7376
$router = new Router(
7477
"BNETDocs\\Controllers\\",
7578
"BNETDocs\\Views\\"

0 commit comments

Comments
 (0)