Skip to content

Commit 5bc9870

Browse files
committed
Refactoring
1 parent a2ebdaf commit 5bc9870

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+585
-556
lines changed

bin/deploy

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
PROJECT_NAME="bnetdocs-web"
55
VERSION="$(git symbolic-ref HEAD | sed -e 's/^refs\/heads\/*//g')"
66
SOURCE_DIRECTORY="$(git rev-parse --show-toplevel)"
7-
TARGET_DIRECTORY="/opt/carlbennett/nginx-www/www.bnetdocs.org"
7+
TARGET_DIRECTORY="/var/www/github-deploy.bnetdocs.org"
88
TARGET_FILE="${SOURCE_DIRECTORY}/etc/deploy-targets.csv"
99
TARGET_ENV=""
1010
SKIP_COMPOSER=0

etc/config.sample.json

+7-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"asset_versioning": true,
77
"blizzard_greeting_html": "<div class=\"alert alert-secondary p-2\">Hey there, Blizzard! We hope you find our info useful with your work, come ask us in the Discord any questions. <a href=\"https://discord.gg/u87WVeu\">discord.gg/u87WVeu</a> 😊</div>",
88
"campaigns": {
9-
"battleforthenet": "",
109
"vultr": ""
1110
},
1211
"donations": {
@@ -15,10 +14,10 @@
1514
"paypal_url": null,
1615
"user_id": null
1716
},
18-
"maintenance": [
19-
false,
20-
"BNETDocs has to take a brief moment to do some system maintenance. We'll be back shortly."
21-
],
17+
"maintenance": {
18+
"enabled": false,
19+
"message": "BNETDocs has to take a brief moment to do some system maintenance. We'll be back shortly."
20+
},
2221
"navigation": {
2322
"front_page": "/welcome"
2423
},
@@ -98,15 +97,11 @@
9897
"enabled": true
9998
},
10099
"mysql": {
101-
"character_set": "utf8",
100+
"character_set": "utf8mb4",
102101
"database": "bnetdocs_phoenix",
102+
"hostname": "localhost",
103103
"password": "",
104-
"servers": [
105-
{
106-
"hostname": "localhost",
107-
"port": 3306
108-
}
109-
],
104+
"port": 3306,
110105
"timeout": 3,
111106
"timezone": "+00:00",
112107
"username": "bnetdocs"

src/Controllers/Community/Donate.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace BNETDocs\Controllers\Community;
44

5+
use \BNETDocs\Libraries\Core\Config;
6+
57
class Donate extends \BNETDocs\Controllers\Base
68
{
79
/**
@@ -20,7 +22,21 @@ public function __construct()
2022
*/
2123
public function invoke(?array $args): bool
2224
{
23-
$this->model->donations = \BNETDocs\Libraries\Core\Config::get('bnetdocs.donations');
25+
$this->model->donations_btc_address = Config::get('bnetdocs.donations.btc_address');
26+
$this->model->donations_email_address = Config::get('bnetdocs.donations.email_address');
27+
$this->model->donations_paypal_url = Config::get('bnetdocs.donations.paypal_url');
28+
$this->model->donations_user_id = Config::get('bnetdocs.donations.user_id');
29+
if (is_int($this->model->donations_user_id))
30+
{
31+
try
32+
{
33+
$this->model->donations_user = new \BNETDocs\Libraries\User\User($this->model->donations_user_id);
34+
}
35+
catch (\BNETDocs\Exceptions\UserNotFoundException)
36+
{
37+
$this->model->donations_user = null;
38+
}
39+
}
2440
$this->model->_responseCode = \BNETDocs\Libraries\Core\HttpCode::HTTP_OK;
2541
return true;
2642
}

src/Controllers/Core/Legacy.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use \BNETDocs\Libraries\Core\HttpCode;
66
use \BNETDocs\Libraries\Core\Router;
7-
use \CarlBennett\MVC\Libraries\Common;
87

98
class Legacy extends \BNETDocs\Controllers\Base
109
{

src/Controllers/Core/RedirectSoft.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct()
2020
*/
2121
public function invoke(?array $args): bool
2222
{
23-
$this->model->location = \CarlBennett\MVC\Libraries\Common::relativeUrlToAbsolute(\array_shift($args));
23+
$this->model->location = \BNETDocs\Libraries\Core\UrlFormatter::format(\array_shift($args));
2424
$this->model->_responseCode = \BNETDocs\Libraries\Core\HttpCode::HTTP_FOUND;
2525
$this->model->_responseHeaders['Location'] = $this->model->location;
2626
return true;

src/Controllers/Core/Robotstxt.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct()
2020
*/
2121
public function invoke(?array $args): bool
2222
{
23-
$this->model->rules = \CarlBennett\MVC\Libraries\Common::$config->bnetdocs->robotstxt;
23+
$this->model->rules = \BNETDocs\Libraries\Core\Config::get('bnetdocs.robotstxt');
2424
$this->model->_responseCode = \BNETDocs\Libraries\Core\HttpCode::HTTP_OK;
2525
return true;
2626
}

src/Controllers/Core/Status.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace BNETDocs\Controllers\Core;
44

5+
use \BNETDocs\Libraries\Core\Config;
56
use \BNETDocs\Libraries\Core\HttpCode;
67
use \BNETDocs\Models\Core\Status as StatusModel;
7-
use \CarlBennett\MVC\Libraries\Common;
88

99
class Status extends \BNETDocs\Controllers\Base
1010
{
@@ -42,15 +42,16 @@ protected static function getStatus(StatusModel $model) : bool
4242
$ua = substr(getenv('HTTP_USER_AGENT') ?? '', 0, self::MAX_USER_AGENT);
4343
$utc = new \DateTimeZone('Etc/UTC');
4444

45+
$geoip_enabled = Config::get('geoip.enabled');
4546
$model->status = [
4647
'healthcheck' => [
4748
'database' => (!is_null(\BNETDocs\Libraries\Db\MariaDb::instance())),
48-
'geoip' => Common::$config->geoip->enabled && file_exists(Common::$config->geoip->database_file),
49+
'geoip' => $geoip_enabled && file_exists(Config::get('geoip.database_file')),
4950
],
5051
'remote_address' => $remote_address,
51-
'remote_geoinfo' => Common::$config->geoip->enabled ? \BNETDocs\Libraries\Core\GeoIP::getRecord($remote_address) : null,
52+
'remote_geoinfo' => $geoip_enabled ? \BNETDocs\Libraries\Core\GeoIP::getRecord($remote_address) : null,
5253
'remote_is_blizzard' => \BNETDocs\Libraries\Core\BlizzardCheck::is_blizzard(),
53-
'remote_is_browser' => Common::isBrowser($ua),
54+
'remote_is_browser' => \BNETDocs\Libraries\Core\StringProcessor::isBrowser($ua),
5455
'remote_is_slack' => \BNETDocs\Libraries\Core\SlackCheck::is_slack(),
5556
'remote_user_agent' => $ua,
5657
'timestamp' => new \BNETDocs\Libraries\Core\DateTimeImmutable('now', $utc),

src/Controllers/Server/UpdateJob.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ public function invoke(?array $args): bool
3131
return true;
3232
}
3333

34-
$c = &\CarlBennett\MVC\Libraries\Common::$config;
3534
$q = Router::query();
3635
$server_id = isset($q['id']) ? (int) $q['id'] : null;
3736
$job_token = isset($q['job_token']) ? $q['job_token'] : null;
3837
$status = isset($q['status']) ? (int) $q['status'] : null;
3938

40-
if ($job_token !== $c->bnetdocs->server_update_job_token)
39+
if ($job_token !== \BNETDocs\Libraries\Core\Config::get('bnetdocs.server_update_job_token'))
4140
{
4241
$this->model->_responseCode = HttpCode::HTTP_FORBIDDEN;
4342
return true;

src/Controllers/User/ChangePassword.php

+21-17
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
namespace BNETDocs\Controllers\User;
44

5+
use \BNETDocs\Libraries\Core\Config;
56
use \BNETDocs\Libraries\Core\Router;
67
use \BNETDocs\Libraries\EventLog\Logger;
7-
use \CarlBennett\MVC\Libraries\Common;
8+
use \BNETDocs\Libraries\User\User;
9+
use \BNETDocs\Models\User\ChangePassword as ChangePasswordModel;
810

911
class ChangePassword extends \BNETDocs\Controllers\Base
1012
{
1113
public function __construct()
1214
{
13-
$this->model = new \BNETDocs\Models\User\ChangePassword();
15+
$this->model = new ChangePasswordModel();
1416
}
1517

1618
public function invoke(?array $args): bool
@@ -33,53 +35,55 @@ protected function tryChangePassword(): void
3335

3436
if ($pw2 !== $pw3)
3537
{
36-
$this->model->error = 'NONMATCHING_PASSWORD';
38+
$this->model->error = ChangePasswordModel::ERROR_NONMATCHING_PASSWORD;
3739
return;
3840
}
3941

4042
if (!$this->model->active_user->checkPassword($pw1))
4143
{
42-
$this->model->error = 'PASSWORD_INCORRECT';
44+
$this->model->error = ChangePasswordModel::ERROR_PASSWORD_INCORRECT;
4345
return;
4446
}
4547

4648
$pwlen = strlen($pw2);
47-
$req = &Common::$config->bnetdocs->user_register_requirements;
49+
$req = Config::get('bnetdocs.user_register_requirements') ?? [];
4850
$email = $this->model->active_user->getEmail();
4951
$username = $this->model->active_user->getUsername();
5052

51-
if (!$req->password_allow_email && stripos($pw2, $email))
53+
if (!($req['password_allow_email'] ?? false) && stripos($pw2, $email))
5254
{
53-
$this->model->error = 'PASSWORD_CONTAINS_EMAIL';
55+
$this->model->error = ChangePasswordModel::ERROR_PASSWORD_CONTAINS_EMAIL;
5456
return;
5557
}
5658

57-
if (!$req->password_allow_username && stripos($pw2, $username))
59+
if (!($req['password_allow_username'] ?? false) && stripos($pw2, $username))
5860
{
59-
$this->model->error = 'PASSWORD_CONTAINS_USERNAME';
61+
$this->model->error = ChangePasswordModel::ERROR_PASSWORD_CONTAINS_USERNAME;
6062
return;
6163
}
6264

63-
if (is_numeric($req->password_length_max) && $pwlen > $req->password_length_max)
65+
if (is_numeric($req['password_length_max'] ?? User::MAX_PASSWORD_HASH)
66+
&& $pwlen > ($req['password_length_max'] ?? User::MAX_PASSWORD_HASH))
6467
{
65-
$this->model->error = 'PASSWORD_TOO_LONG';
68+
$this->model->error = ChangePasswordModel::ERROR_PASSWORD_TOO_LONG;
6669
return;
6770
}
6871

69-
if (is_numeric($req->password_length_min) && $pwlen < $req->password_length_min)
72+
if (is_numeric($req['password_length_min'] ?? 4)
73+
&& $pwlen < ($req['password_length_min'] ?? 4))
7074
{
71-
$this->model->error = 'PASSWORD_TOO_SHORT';
75+
$this->model->error = ChangePasswordModel::ERROR_PASSWORD_TOO_SHORT;
7276
return;
7377
}
7478

75-
$denylist = Common::$config->bnetdocs->user_password_denylist_map;
79+
$denylist = Config::get('bnetdocs.user_password_denylist_map') ?? '../etc/password_denylist.json';
7680
$denylist = json_decode(file_get_contents('./' . $denylist));
7781
foreach ($denylist as $denylist_pw)
7882
{
7983
if (strtolower($denylist_pw->password) == strtolower($pw2))
8084
{
81-
$this->model->error = 'PASSWORD_BLACKLIST';
82-
$this->model->error_extra = $denylist_pw->reason;
85+
$this->model->error = ChangePasswordModel::ERROR_PASSWORD_DENYLIST;
86+
$this->model->denylist_reason = $denylist_pw->reason;
8387
return;
8488
}
8589
}
@@ -88,7 +92,7 @@ protected function tryChangePassword(): void
8892
$old_password_salt = $this->model->active_user->getPasswordSalt();
8993

9094
$this->model->active_user->setPassword($pw2);
91-
$this->model->error = $this->model->active_user->commit() ? false : 'INTERNAL_ERROR';
95+
$this->model->error = $this->model->active_user->commit() ? false : ChangePasswordModel::ERROR_INTERNAL;
9296

9397
$event = Logger::initEvent(
9498
\BNETDocs\Libraries\EventLog\EventTypes::USER_PASSWORD_CHANGE,

src/Controllers/User/Login.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use \BNETDocs\Libraries\EventLog\Logger;
88
use \BNETDocs\Libraries\User\User;
99
use \BNETDocs\Models\User\Login as LoginModel;
10-
use \CarlBennett\MVC\Libraries\Common;
1110

1211
class Login extends \BNETDocs\Controllers\Base
1312
{
@@ -38,7 +37,7 @@ public function invoke(?array $args): bool
3837
$this->model->error = LoginModel::ERROR_EMPTY_EMAIL;
3938
else if (empty($this->model->password))
4039
$this->model->error = LoginModel::ERROR_EMPTY_PASSWORD;
41-
else if (Common::$config->bnetdocs->user_login_disabled)
40+
else if (\BNETDocs\Libraries\Core\Config::get('bnetdocs.user_login_disabled'))
4241
$this->model->error = LoginModel::ERROR_SYSTEM_DISABLED;
4342

4443
if ($this->model->error) return true;

0 commit comments

Comments
 (0)