Skip to content

Commit 163dbb9

Browse files
authored
Merge pull request #626 from Aldione/patch-15
Add per-user expiration with date & time for PlaylistAuth and PlaylistAlias
2 parents f12a4f4 + 9ca72e2 commit 163dbb9

File tree

8 files changed

+95
-0
lines changed

8 files changed

+95
-0
lines changed

app/Filament/Resources/PlaylistAliases/PlaylistAliasResource.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,13 @@ public static function getForm(): array
468468
->columnSpan(1)
469469
->password()
470470
->revealable(),
471+
Forms\Components\DateTimePicker::make('expires_at')
472+
->label('Expiration (date & time)')
473+
->seconds(false)
474+
->native(false)
475+
->helperText('If set, this alias credentials will stop working at that exact time.')
476+
->nullable()
477+
->columnSpan(2),
471478
]),
472479
];
473480
}

app/Filament/Resources/PlaylistAuths/PlaylistAuthResource.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Filament\Actions\DeleteBulkAction;
1717
use Filament\Actions\EditAction;
1818
use Filament\Forms;
19+
use Filament\Forms\Components\DateTimePicker;
1920
use Filament\Forms\Components\Select;
2021
use Filament\Forms\Components\TextInput;
2122
use Filament\Forms\Components\Toggle;
@@ -145,6 +146,13 @@ public static function getForm(): array
145146
->required()
146147
->revealable()
147148
->columnSpan(1),
149+
DateTimePicker::make('expires_at')
150+
->label('Expiration (date & time)')
151+
->seconds(false)
152+
->native(false)
153+
->helperText('If set, this account will stop working at that exact time.')
154+
->nullable()
155+
->columnSpan(2),
148156
];
149157

150158
return [

app/Http/Controllers/XtreamStreamController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ private function findAuthenticatedPlaylistAndStreamModel(string $username, strin
3333
->where('enabled', true)
3434
->first();
3535

36+
if ($playlistAuth && $playlistAuth->isExpired()) {
37+
$playlistAuth = null;
38+
}
39+
3640
if ($playlistAuth) {
3741
$playlist = $playlistAuth->getAssignedModel();
3842
if ($playlist) {

app/Models/PlaylistAlias.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class PlaylistAlias extends Model
2525
'enabled' => 'boolean',
2626
'enable_proxy' => 'boolean',
2727
'priority' => 'integer',
28+
'expires_at' => 'datetime',
2829
'custom_headers' => 'array',
2930
'strict_live_ts' => 'boolean',
3031
];
@@ -113,6 +114,18 @@ public function customPlaylist(): BelongsTo
113114
return $this->belongsTo(CustomPlaylist::class);
114115
}
115116

117+
/**
118+
* Determine whether this alias auth credential is expired.
119+
*/
120+
public function isExpired(): bool
121+
{
122+
if ($this->expires_at === null) {
123+
return false;
124+
}
125+
126+
return now()->greaterThanOrEqualTo($this->expires_at);
127+
}
128+
116129
/**
117130
* Get the effective playlist (either the main playlist or custom playlist)
118131
* This method returns the playlist that should be used for configuration

app/Models/PlaylistAuth.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,26 @@ class PlaylistAuth extends Model
2424
'id' => 'integer',
2525
'enabled' => 'boolean',
2626
'user_id' => 'integer',
27+
'expires_at' => 'datetime',
2728
];
2829

2930
public function user(): BelongsTo
3031
{
3132
return $this->belongsTo(User::class);
3233
}
3334

35+
/**
36+
* Determine whether this auth credential is expired.
37+
*/
38+
public function isExpired(): bool
39+
{
40+
if ($this->expires_at === null) {
41+
return false;
42+
}
43+
44+
return now()->greaterThanOrEqualTo($this->expires_at);
45+
}
46+
3447
public function playlists(): HasMany
3548
{
3649
return $this->hasMany(PlaylistAuthPivot::class, 'playlist_auth_id')

app/Services/PlaylistService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ public function authenticate($username, $password): array|bool
384384
->where('enabled', true)
385385
->first();
386386

387+
if ($playlistAuth && $playlistAuth->isExpired()) {
388+
$playlistAuth = null;
389+
}
390+
387391
if ($playlistAuth) {
388392
$playlist = $playlistAuth->getAssignedModel();
389393
if ($playlist) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::table('playlist_auths', function (Blueprint $table) {
12+
$table->dateTime('expires_at')->nullable()->after('password')->index();
13+
});
14+
}
15+
16+
public function down(): void
17+
{
18+
Schema::table('playlist_auths', function (Blueprint $table) {
19+
$table->dropIndex(['expires_at']);
20+
$table->dropColumn('expires_at');
21+
});
22+
}
23+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::table('playlist_aliases', function (Blueprint $table) {
12+
$table->dateTime('expires_at')->nullable()->after('password')->index();
13+
});
14+
}
15+
16+
public function down(): void
17+
{
18+
Schema::table('playlist_aliases', function (Blueprint $table) {
19+
$table->dropIndex(['expires_at']);
20+
$table->dropColumn('expires_at');
21+
});
22+
}
23+
};

0 commit comments

Comments
 (0)