1 | <?php |
||||
2 | /** |
||||
3 | * InstallController.php |
||||
4 | * Copyright (c) 2018 [email protected] |
||||
5 | * |
||||
6 | * This file is part of Firefly III. |
||||
7 | * |
||||
8 | * Firefly III is free software: you can redistribute it and/or modify |
||||
9 | * it under the terms of the GNU General Public License as published by |
||||
10 | * the Free Software Foundation, either version 3 of the License, or |
||||
11 | * (at your option) any later version. |
||||
12 | * |
||||
13 | * Firefly III 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 General Public License for more details. |
||||
17 | * |
||||
18 | * You should have received a copy of the GNU General Public License |
||||
19 | * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. |
||||
20 | */ |
||||
21 | |||||
22 | declare(strict_types=1); |
||||
23 | |||||
24 | namespace FireflyIII\Http\Controllers\System; |
||||
25 | |||||
26 | |||||
27 | use Artisan; |
||||
28 | use Exception; |
||||
29 | use FireflyIII\Http\Controllers\Controller; |
||||
30 | use FireflyIII\Support\Http\Controllers\GetConfigurationData; |
||||
31 | use Illuminate\Http\JsonResponse; |
||||
32 | use Laravel\Passport\Passport; |
||||
33 | use Log; |
||||
34 | use phpseclib\Crypt\RSA; |
||||
35 | |||||
36 | /** |
||||
37 | * Class InstallController |
||||
38 | * |
||||
39 | * @codeCoverageIgnore |
||||
40 | */ |
||||
41 | class InstallController extends Controller |
||||
42 | { |
||||
43 | use GetConfigurationData; |
||||
44 | /** @var string Forbidden error */ |
||||
45 | public const FORBIDDEN_ERROR = 'Internal PHP function "proc_close" is disabled for your installation. Auto-migration is not possible.'; |
||||
46 | /** @var string Basedir error */ |
||||
47 | public const BASEDIR_ERROR = 'Firefly III cannot execute the upgrade commands. It is not allowed to because of an open_basedir restriction.'; |
||||
48 | /** @var string Other errors */ |
||||
49 | public const OTHER_ERROR = 'An unknown error prevented Firefly III from executing the upgrade commands. Sorry.'; |
||||
50 | /** @noinspection MagicMethodsValidityInspection */ |
||||
51 | /** @noinspection PhpMissingParentConstructorInspection */ |
||||
52 | /** |
||||
53 | * InstallController constructor. |
||||
54 | */ |
||||
55 | public function __construct() |
||||
56 | { |
||||
57 | // empty on purpose. |
||||
58 | } |
||||
59 | |||||
60 | /** |
||||
61 | * Do database decrypt. |
||||
62 | * |
||||
63 | * @return \Illuminate\Http\JsonResponse |
||||
64 | */ |
||||
65 | public function decrypt(): JsonResponse |
||||
66 | { |
||||
67 | if ($this->hasForbiddenFunctions()) { |
||||
68 | return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]); |
||||
69 | } |
||||
70 | try { |
||||
71 | Log::debug('Am now calling decrypt database routine...'); |
||||
72 | Artisan::call('firefly:decrypt-all'); |
||||
73 | Log::debug(Artisan::output()); |
||||
74 | } catch (Exception $e) { |
||||
75 | Log::error($e->getMessage()); |
||||
76 | Log::error($e->getTraceAsString()); |
||||
77 | if (strpos($e->getMessage(), 'open_basedir restriction in effect')) { |
||||
78 | return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]); |
||||
79 | } |
||||
80 | |||||
81 | return response()->json(['error' => true, 'message' => self::OTHER_ERROR . ' ' . $e->getMessage()]); |
||||
82 | } |
||||
83 | |||||
84 | return response()->json(['error' => false, 'message' => 'OK']); |
||||
85 | } |
||||
86 | |||||
87 | /** |
||||
88 | * Show index. |
||||
89 | * |
||||
90 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
||||
91 | */ |
||||
92 | public function index() |
||||
93 | { |
||||
94 | return view('install.index'); |
||||
95 | } |
||||
96 | |||||
97 | /** |
||||
98 | * Create specific RSA keys. |
||||
99 | * |
||||
100 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
||||
101 | */ |
||||
102 | public function keys() |
||||
103 | { |
||||
104 | if ($this->hasForbiddenFunctions()) { |
||||
105 | return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]); |
||||
106 | } |
||||
107 | // create keys manually because for some reason the passport namespace |
||||
108 | // does not exist |
||||
109 | $rsa = new RSA(); |
||||
110 | $keys = $rsa->createKey(4096); |
||||
111 | |||||
112 | [$publicKey, $privateKey] = [ |
||||
113 | Passport::keyPath('oauth-public.key'), |
||||
114 | Passport::keyPath('oauth-private.key'), |
||||
115 | ]; |
||||
116 | |||||
117 | if (file_exists($publicKey) || file_exists($privateKey)) { |
||||
118 | return response()->json(['error' => false, 'message' => 'OK']); |
||||
119 | } |
||||
120 | |||||
121 | file_put_contents($publicKey, array_get($keys, 'publickey')); |
||||
0 ignored issues
–
show
|
|||||
122 | file_put_contents($privateKey, array_get($keys, 'privatekey')); |
||||
0 ignored issues
–
show
The function
array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 5.9.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||
123 | |||||
124 | return response()->json(['error' => false, 'message' => 'OK']); |
||||
125 | } |
||||
126 | |||||
127 | /** |
||||
128 | * Run migration commands. |
||||
129 | * |
||||
130 | * @return JsonResponse |
||||
131 | */ |
||||
132 | public function migrate(): JsonResponse |
||||
133 | { |
||||
134 | if ($this->hasForbiddenFunctions()) { |
||||
135 | return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]); |
||||
136 | } |
||||
137 | |||||
138 | try { |
||||
139 | Log::debug('Am now calling migrate routine...'); |
||||
140 | Artisan::call('migrate', ['--seed' => true, '--force' => true]); |
||||
141 | Log::debug(Artisan::output()); |
||||
142 | } catch (Exception $e) { |
||||
143 | Log::error($e->getMessage()); |
||||
144 | Log::error($e->getTraceAsString()); |
||||
145 | if (strpos($e->getMessage(), 'open_basedir restriction in effect')) { |
||||
146 | return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]); |
||||
147 | } |
||||
148 | |||||
149 | return response()->json(['error' => true, 'message' => self::OTHER_ERROR]); |
||||
150 | } |
||||
151 | |||||
152 | |||||
153 | return response()->json(['error' => false, 'message' => 'OK']); |
||||
154 | } |
||||
155 | |||||
156 | /** |
||||
157 | * Do database upgrade. |
||||
158 | * |
||||
159 | * @return \Illuminate\Http\JsonResponse |
||||
160 | */ |
||||
161 | public function upgrade(): JsonResponse |
||||
162 | { |
||||
163 | if ($this->hasForbiddenFunctions()) { |
||||
164 | return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]); |
||||
165 | } |
||||
166 | try { |
||||
167 | Log::debug('Am now calling upgrade database routine...'); |
||||
168 | Artisan::call('firefly:upgrade-database'); |
||||
169 | Log::debug(Artisan::output()); |
||||
170 | } catch (Exception $e) { |
||||
171 | Log::error($e->getMessage()); |
||||
172 | Log::error($e->getTraceAsString()); |
||||
173 | if (strpos($e->getMessage(), 'open_basedir restriction in effect')) { |
||||
174 | return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]); |
||||
175 | } |
||||
176 | |||||
177 | return response()->json(['error' => true, 'message' => self::OTHER_ERROR . ' ' . $e->getMessage()]); |
||||
178 | } |
||||
179 | |||||
180 | return response()->json(['error' => false, 'message' => 'OK']); |
||||
181 | } |
||||
182 | |||||
183 | /** |
||||
184 | * Do database verification. |
||||
185 | * |
||||
186 | * @return \Illuminate\Http\JsonResponse |
||||
187 | */ |
||||
188 | public function verify(): JsonResponse |
||||
189 | { |
||||
190 | if ($this->hasForbiddenFunctions()) { |
||||
191 | return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]); |
||||
192 | } |
||||
193 | try { |
||||
194 | Log::debug('Am now calling verify database routine...'); |
||||
195 | Artisan::call('firefly:verify'); |
||||
196 | Log::debug(Artisan::output()); |
||||
197 | } catch (Exception $e) { |
||||
198 | Log::error($e->getMessage()); |
||||
199 | Log::error($e->getTraceAsString()); |
||||
200 | if (strpos($e->getMessage(), 'open_basedir restriction in effect')) { |
||||
201 | return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]); |
||||
202 | } |
||||
203 | |||||
204 | return response()->json(['error' => true, 'message' => self::OTHER_ERROR . ' ' . $e->getMessage()]); |
||||
205 | } |
||||
206 | |||||
207 | return response()->json(['error' => false, 'message' => 'OK']); |
||||
208 | } |
||||
209 | |||||
210 | |||||
211 | } |
||||
212 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.