-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
36 lines (28 loc) · 1.01 KB
/
index.php
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
<?php
use \Illuminate\Encryption\Encrypter;
class PwaSecretLinks
{
public static function checkShareLink(string $hash, string $expectedSlug): bool
{
$encrypter = new Encrypter(option('secret-links.encryptionKey'), 'aes-256-gcm');
try {
$payload = $encrypter->decryptString($hash);
} catch (\Exception $x) {
return false;
}
[$timestamp, $slug] = explode('|', $payload);
if ($slug !== $expectedSlug) {
return false;
}
if ($timestamp < time()) {
return false;
}
return true;
}
public static function generateShareLink(\Kirby\Cms\Page $page, string $paramName = 's', int $expiryInSeconds = 86400): string
{
$payload = sprintf('%s|%s', time() + $expiryInSeconds, $page->id());
$encrypter = new Encrypter(option('secret-links.encryptionKey'), 'aes-256-gcm');
return sprintf('%s?%s=%s', $page->url(), $paramName, $encrypter->encryptString($payload));
}
}