1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* InstallationId.php |
4
|
|
|
* Copyright (c) 2020 [email protected] |
5
|
|
|
* |
6
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii). |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
declare(strict_types=1); |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace FireflyIII\Http\Middleware; |
26
|
|
|
|
27
|
|
|
use Closure; |
28
|
|
|
use FireflyIII\Exceptions\FireflyException; |
29
|
|
|
use Log; |
30
|
|
|
use Ramsey\Uuid\Uuid; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
* Class InstallationId |
35
|
|
|
*/ |
36
|
|
|
class InstallationId |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Handle an incoming request. |
40
|
|
|
* |
41
|
|
|
* @param \Illuminate\Http\Request $request |
42
|
|
|
* @param Closure $next |
43
|
|
|
* |
44
|
|
|
* @throws FireflyException |
45
|
|
|
* |
46
|
|
|
* @return mixed |
47
|
|
|
* |
48
|
|
|
*/ |
49
|
|
|
public function handle($request, Closure $next) |
50
|
|
|
{ |
51
|
|
|
$config = app('fireflyconfig')->get('installation_id', null); |
52
|
|
|
if (null === $config) { |
53
|
|
|
$uuid5 = Uuid::uuid5(Uuid::NAMESPACE_URL, 'firefly-iii.org'); |
54
|
|
|
$uniqueId = (string) $uuid5; |
55
|
|
|
Log::info(sprintf('Created Firefly III installation ID %s', $uniqueId)); |
56
|
|
|
app('fireflyconfig')->set('installation_id', $uniqueId); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $next($request); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|