File tree Expand file tree Collapse file tree 5 files changed +112
-1
lines changed Expand file tree Collapse file tree 5 files changed +112
-1
lines changed Original file line number Diff line number Diff line change 17
17
use Flarum \Api \Serializer \CurrentUserSerializer ;
18
18
use Flarum \Api \Serializer \ForumSerializer ;
19
19
use Flarum \Api \Serializer \GroupSerializer ;
20
+ use Flarum \Console \Schedule ;
20
21
use Flarum \Extend ;
21
22
use Flarum \Group \Event \Saving as GroupSaving ;
22
23
use Flarum \Group \Group ;
23
24
use Flarum \User \User ;
24
25
use IanM \TwoFactor \Api \Serializer \TwoFactorSerializer ;
25
26
use IanM \TwoFactor \Model \TwoFactor ;
26
27
use IanM \TwoFactor \OAuth \TwoFactorOAuthCheck ;
28
+ use Illuminate \Console \Scheduling \Event ;
27
29
28
30
return [
29
31
(new Extend \Frontend ('forum ' ))
92
94
93
95
(new Extend \Settings ())
94
96
->default ('ianm-twofactor.admin.settings.forum_logo_qr ' , true )
95
- ->default ('ianm-twofactor.admin.settings.forum_logo_qr_width ' , 100 ),
97
+ ->default ('ianm-twofactor.admin.settings.forum_logo_qr_width ' , 100 )
98
+ ->default ('ianm-twofactor.kill_inactive_tokens ' , true )
99
+ ->default ('ianm-twofactor.kill_inactive_tokens_age_days ' , 30 )
100
+ ->default ('ianm-twofactor.also_kill_developer_tokens ' , false ),
101
+
102
+ (new Extend \Console ())
103
+ ->command (Console \KillInactiveTokensCommand::class)
104
+ ->schedule (Console \KillInactiveTokensCommand::class, Console \InactiveTokensSchedule::class),
96
105
97
106
(new Extend \Conditional ())
98
107
->whenExtensionEnabled ('fof-oauth ' , fn () => [
Original file line number Diff line number Diff line change @@ -32,6 +32,27 @@ export default class SettingsPage extends ExtensionPage {
32
32
help : app . translator . trans ( 'ianm-twofactor.admin.settings.forum_logo_qr_width_help' ) ,
33
33
max : 200 ,
34
34
} ) }
35
+ < h3 > { app . translator . trans ( 'ianm-twofactor.admin.settings.tokens.heading' ) } </ h3 >
36
+ < p className = "helpText" > { app . translator . trans ( 'ianm-twofactor.admin.settings.tokens.help' ) } </ p >
37
+ { this . buildSettingComponent ( {
38
+ setting : 'ianm-twofactor.kill_inactive_tokens' ,
39
+ type : 'boolean' ,
40
+ label : app . translator . trans ( 'ianm-twofactor.admin.settings.tokens.kill_inactive_tokens' ) ,
41
+ help : app . translator . trans ( 'ianm-twofactor.admin.settings.tokens.kill_inactive_tokens_help' ) ,
42
+ } ) }
43
+ { this . buildSettingComponent ( {
44
+ setting : 'ianm-twofactor.kill_inactive_tokens_age_days' ,
45
+ type : 'number' ,
46
+ min : 1 ,
47
+ label : app . translator . trans ( 'ianm-twofactor.admin.settings.tokens.kill_inactive_tokens_age_days' ) ,
48
+ help : app . translator . trans ( 'ianm-twofactor.admin.settings.tokens.kill_inactive_tokens_age_days_help' ) ,
49
+ } ) }
50
+ { this . buildSettingComponent ( {
51
+ setting : 'ianm-twofactor.also_kill_developer_tokens' ,
52
+ type : 'boolean' ,
53
+ label : app . translator . trans ( 'ianm-twofactor.admin.settings.tokens.also_kill_developer_tokens' ) ,
54
+ help : app . translator . trans ( 'ianm-twofactor.admin.settings.tokens.also_kill_developer_tokens_help' ) ,
55
+ } ) }
35
56
{ this . submitButton ( ) }
36
57
</ div >
37
58
</ div >
Original file line number Diff line number Diff line change @@ -17,6 +17,16 @@ ianm-twofactor:
17
17
forum_logo_qr_width_help : The width of the forum logo embedded on the QR code displayed when enabling 2FA. Max 200.
18
18
logo_qr : Logo on QR Code
19
19
logo_qr_help : If logo has been uploaded, this logo will be embedded on the QR code. Leave blank to use the forum logo.
20
+ tokens :
21
+ heading : Access Tokens
22
+ help : For extended security, you can manage additional behaviour here related to access tokens.
23
+ kill_inactive_tokens : Kill Inactive Tokens
24
+ kill_inactive_tokens_help : Automatically kill access tokens that have been inactive for a specified period of time.
25
+ kill_inactive_tokens_age_days : Kill Inactive Tokens After (Days)
26
+ kill_inactive_tokens_age_days_help : The number of days of inactivity after which access tokens will be deleted.
27
+ also_kill_developer_tokens : Also Kill Developer Tokens
28
+ also_kill_developer_tokens_help : Also kill developer access tokens that have been inactive for the specified period of time.
29
+
20
30
21
31
forum :
22
32
user_2fa.alert_message : You must enable 2FA to continue accessing your account.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace IanM \TwoFactor \Console ;
4
+
5
+ use Flarum \Settings \SettingsRepositoryInterface ;
6
+ use Illuminate \Console \Scheduling \Event ;
7
+
8
+ class InactiveTokensSchedule
9
+ {
10
+ public function __construct (
11
+ protected SettingsRepositoryInterface $ settings
12
+ ) { }
13
+
14
+ public function __invoke (Event $ event )
15
+ {
16
+ if (! (bool ) $ this ->settings ->get ('ianm-twofactor.kill_inactive_tokens ' )) {
17
+ return ;
18
+ }
19
+
20
+ $ event ->twiceDaily ();
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace IanM \TwoFactor \Console ;
4
+
5
+ use Carbon \Carbon ;
6
+ use Flarum \Http \AccessToken ;
7
+ use Flarum \Settings \SettingsRepositoryInterface ;
8
+ use Illuminate \Console \Command ;
9
+
10
+ class KillInactiveTokensCommand extends Command
11
+ {
12
+ protected $ signature = 'twofactor:kill-inactive-tokens ' ;
13
+ protected $ description = 'Kill all inactive tokens ' ;
14
+
15
+ public function __construct (
16
+ protected SettingsRepositoryInterface $ settings
17
+ ) {
18
+ parent ::__construct ();
19
+ }
20
+
21
+ public function handle (): void
22
+ {
23
+ $ age = (int ) $ this ->settings ->get ('ianm-twofactor.kill_inactive_tokens_age_days ' );
24
+ $ maxAge = Carbon::now ()->subdays ($ age );
25
+
26
+ $ query = AccessToken::query ()
27
+ ->where ('last_activity_at ' , '< ' , $ maxAge );
28
+
29
+ if (! (bool ) $ this ->settings ->get ('ianm-twofactor.also_kill_developer_tokens ' )) {
30
+ $ this ->info ('Not deleting any developer tokens. ' );
31
+ $ query ->where ('type ' , '!= ' , 'developer ' );
32
+ }
33
+
34
+ $ count = $ query ->count ();
35
+
36
+ if ($ count === 0 ) {
37
+ $ this ->info ("No tokens found which have not been used in $ age+ days. " );
38
+ return ;
39
+ }
40
+
41
+ $ this ->info ("Found $ count tokens which have not been used in $ age+ days. Deleting... " );
42
+
43
+ $ this ->output ->progressStart ($ count );
44
+
45
+ $ query ->delete ();
46
+
47
+ $ this ->output ->progressFinish ();
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments