Repository navigation
Expand file tree
/
Copy pathextend.php
More file actions
110 lines (94 loc) · 6.65 KB
/
Copy pathextend.php
File metadata and controls
110 lines (94 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
require_once __DIR__ . '/autoload.php';
use Flarum\Api\Middleware\ThrottleApi;
use Flarum\Api\ForgotPasswordValidator;
use Flarum\Extend;
use Flarum\Forum\LogInValidator;
use PeopleInside\PowCaptcha\Api\RegisterUserCaptchaFields;
use PeopleInside\PowCaptcha\Controller\ClearLogsController;
use PeopleInside\PowCaptcha\Controller\ListLogsController;
use PeopleInside\PowCaptcha\Controller\PowCaptchaChallengeController;
use PeopleInside\PowCaptcha\Controller\StatsController;
use PeopleInside\PowCaptcha\Listener\AddPowValidatorRule;
use PeopleInside\PowCaptcha\Listener\RecordRegistration;
use PeopleInside\PowCaptcha\Middleware\CaptureClientContext;
use PeopleInside\PowCaptcha\Middleware\ProtectTokenEndpoint;
use PeopleInside\PowCaptcha\Middleware\RecordMissingSignupToken;
use PeopleInside\PowCaptcha\Provider\PowServiceProvider;
use PeopleInside\PowCaptcha\Service\PowSettings;
$extenders = [
// ── Frontend assets ────────────────────────────────────────────────
(new Extend\Frontend('forum'))
->js(__DIR__ . '/js/dist/forum.js')
->css(__DIR__ . '/less/forum.less'),
(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js')
->css(__DIR__ . '/less/admin.less'),
// ── Translations ───────────────────────────────────────────────────
new Extend\Locales(__DIR__ . '/locale'),
// ── Services ───────────────────────────────────────────────────────
(new Extend\ServiceProvider())
->register(PowServiceProvider::class),
// ── Settings ───────────────────────────────────────────────────────
(new Extend\Settings())
->default('peopleinside-powcaptcha.level', 3)
->default('peopleinside-powcaptcha.enabled_login', true)
->default('peopleinside-powcaptcha.enabled_signup', true)
->default('peopleinside-powcaptcha.enabled_forgot', true)
->default('peopleinside-powcaptcha.adaptive', true)
->default('peopleinside-powcaptcha.log_enabled', true)
->default('peopleinside-powcaptcha.log_ip', false)
->default('peopleinside-powcaptcha.dashboard_widget', true)
->default('peopleinside-powcaptcha.log_keep', 100)
->default('peopleinside-powcaptcha.log_prune_age', true)
->default('peopleinside-powcaptcha.log_max_age_days', 30)
->default('peopleinside-powcaptcha.privacy_notice', true)
->default('peopleinside-powcaptcha.privacy_url', '')
->default('peopleinside-powcaptcha.privacy_align', 'left')
->default('peopleinside-powcaptcha.protect_token_endpoint', false)
->default('peopleinside-powcaptcha.behavior_checks', true)
->default('peopleinside-powcaptcha.signup_limit', 2)
->default('peopleinside-powcaptcha.login_limit', 10)
->default('peopleinside-powcaptcha.forgot_limit', 3)
->serializeToForum('peopleinside-powcaptcha.enabledLogin', 'peopleinside-powcaptcha.enabled_login', 'boolval')
->serializeToForum('peopleinside-powcaptcha.enabledSignup', 'peopleinside-powcaptcha.enabled_signup', 'boolval')
->serializeToForum('peopleinside-powcaptcha.enabledForgot', 'peopleinside-powcaptcha.enabled_forgot', 'boolval')
// Privacy notice under the CAPTCHA. The forum only receives what the notice must
// disclose (what is processed), so the text can match the admin's settings.
->serializeToForum('peopleinside-powcaptcha.privacyNotice', 'peopleinside-powcaptcha.privacy_notice', 'boolval')
->serializeToForum('peopleinside-powcaptcha.privacyUrl', 'peopleinside-powcaptcha.privacy_url', fn ($value) => PowSettings::sanitizeUrl($value))
->serializeToForum('peopleinside-powcaptcha.privacyAlign', 'peopleinside-powcaptcha.privacy_align', fn ($value) => PowSettings::sanitizeAlign($value))
->serializeToForum('peopleinside-powcaptcha.privacyBehavior', 'peopleinside-powcaptcha.behavior_checks', 'boolval')
->serializeToForum('peopleinside-powcaptcha.privacyLogEnabled', 'peopleinside-powcaptcha.log_enabled', 'boolval')
->serializeToForum('peopleinside-powcaptcha.privacyLogIp', 'peopleinside-powcaptcha.log_ip', 'boolval')
->serializeToForum('peopleinside-powcaptcha.privacyLogPrune', 'peopleinside-powcaptcha.log_prune_age', 'boolval')
->serializeToForum('peopleinside-powcaptcha.privacyLogDays', 'peopleinside-powcaptcha.log_max_age_days', 'intval'),
// ── API routes: challenge issuing + admin-only event log ───────────
(new Extend\Routes('api'))
->get('/powcaptcha/challenge', 'powcaptcha.challenge', PowCaptchaChallengeController::class)
->get('/powcaptcha/logs', 'powcaptcha.logs.index', ListLogsController::class)
->get('/powcaptcha/stats', 'powcaptcha.stats', StatsController::class)
->delete('/powcaptcha/logs', 'powcaptcha.logs.clear', ClearLogsController::class),
// ── Middleware ─────────────────────────────────────────────────────
(new Extend\Middleware('forum'))
->add(CaptureClientContext::class),
(new Extend\Middleware('api'))
->add(CaptureClientContext::class)
->insertBefore(ThrottleApi::class, ProtectTokenEndpoint::class),
// ── Validator hooks: login + forgot password ───────────────────────
(new Extend\Validator(LogInValidator::class))
->configure(AddPowValidatorRule::class),
(new Extend\Validator(ForgotPasswordValidator::class))
->configure(AddPowValidatorRule::class),
// ── Daily sign-up limit per network ────────────────────────────────
(new Extend\Event())
->listen(\Flarum\User\Event\Registered::class, RecordRegistration::class),
];
// Register captchaToken on the User JSON:API resource.
$extenders[] = (new Extend\ApiResource(\Flarum\Api\Resource\UserResource::class))
->fields(RegisterUserCaptchaFields::class);
// Sign-ups that arrive WITHOUT a token (bots posting straight to the API) never
// reach the field rule above, so they were neither logged nor counted.
$extenders[] = (new Extend\Middleware('api'))
->insertBefore(ThrottleApi::class, RecordMissingSignupToken::class);
return $extenders;