1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* MikoPBX - free phone system for small business |
4
|
|
|
* Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
17
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace MikoPBX\Modules\Config; |
21
|
|
|
|
22
|
|
|
use MikoPBX\Common\Providers\ConfigProvider; |
23
|
|
|
use MikoPBX\Core\System\MikoPBXConfig; |
24
|
|
|
use MikoPBX\PBXCoreREST\Lib\PBXApiResult; |
25
|
|
|
use Phalcon\Acl\Adapter\Memory as AclList; |
26
|
|
|
use Phalcon\Config; |
27
|
|
|
use Phalcon\Di\Injectable; |
28
|
|
|
use Phalcon\Mvc\Router; |
29
|
|
|
use ReflectionClass as ReflectionClassAlias; |
30
|
|
|
|
31
|
|
|
class ConfigClass extends Injectable implements SystemConfigInterface, |
32
|
|
|
RestAPIConfigInterface, |
33
|
|
|
WebUIConfigInterface |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Config file name i.e. extensions.conf |
38
|
|
|
*/ |
39
|
|
|
protected string $description; |
40
|
|
|
private string $stageMessage = ''; |
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Easy way to get or set the PbxSettings values |
44
|
|
|
* |
45
|
|
|
* @var \MikoPBX\Core\System\MikoPBXConfig |
46
|
|
|
*/ |
47
|
|
|
protected MikoPBXConfig $mikoPBXConfig; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Access to the /etc/inc/mikopbx-settings.json values |
51
|
|
|
* |
52
|
|
|
* @var \Phalcon\Config |
53
|
|
|
*/ |
54
|
|
|
protected Config $config; |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Error and notice messages |
59
|
|
|
* |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
protected array $messages; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Array of PbxSettings values |
66
|
|
|
*/ |
67
|
|
|
protected array $generalSettings; |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* External module UniqueID |
72
|
|
|
*/ |
73
|
|
|
public string $moduleUniqueId; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Additional module directory |
77
|
|
|
*/ |
78
|
|
|
protected string $moduleDir; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* ConfigClass constructor. |
82
|
|
|
* |
83
|
|
|
*/ |
84
|
|
|
public function __construct() |
85
|
|
|
{ |
86
|
|
|
$this->config = $this->di->getShared(ConfigProvider::SERVICE_NAME); |
87
|
|
|
$this->mikoPBXConfig = new MikoPBXConfig(); |
88
|
|
|
$this->generalSettings = $this->mikoPBXConfig->getGeneralSettings(); |
89
|
|
|
$this->messages = []; |
90
|
|
|
|
91
|
|
|
// Get child class parameters and define module Dir and UniqueID |
92
|
|
|
$reflector = new ReflectionClassAlias(static::class); |
93
|
|
|
$partsOfNameSpace = explode('\\', $reflector->getNamespaceName()); |
94
|
|
|
if (count($partsOfNameSpace) === 3 && $partsOfNameSpace[0] === 'Modules') { |
95
|
|
|
$modulesDir = $this->config->path('core.modulesDir'); |
96
|
|
|
$this->moduleUniqueId = $partsOfNameSpace[1]; |
97
|
|
|
$this->moduleDir = $modulesDir . '/' . $this->moduleUniqueId; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$this->messages = []; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Returns array of additional routes for the PBXCoreREST interface from module |
105
|
|
|
* |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function getPBXCoreRESTAdditionalRoutes(): array |
109
|
|
|
{ |
110
|
|
|
return []; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Process PBXCoreREST requests under root rights |
115
|
|
|
* |
116
|
|
|
* @param array $request GET/POST parameters |
117
|
|
|
* |
118
|
|
|
* @return \MikoPBX\PBXCoreREST\Lib\PBXApiResult |
119
|
|
|
*/ |
120
|
|
|
public function moduleRestAPICallback(array $request): PBXApiResult |
121
|
|
|
{ |
122
|
|
|
$res = new PBXApiResult(); |
123
|
|
|
$res->processor = __METHOD__; |
124
|
|
|
$action = strtoupper($request['action']); |
125
|
|
|
switch ($action) { |
126
|
|
|
case 'CHECK': |
127
|
|
|
$res->success = true; |
128
|
|
|
break; |
129
|
|
|
default: |
130
|
|
|
$res->success = false; |
131
|
|
|
$res->messages[] = 'API action not found in moduleRestAPICallback'; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $res; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* This method calls in the WorkerModelsEvents after receive each models change |
139
|
|
|
* |
140
|
|
|
* @param $data |
141
|
|
|
*/ |
142
|
|
|
public function modelsEventChangeData($data): void |
143
|
|
|
{ |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* This method calls in the WorkerModelsEvents after finished process models changing |
148
|
|
|
* |
149
|
|
|
* @param array $modified_tables list of modified models |
150
|
|
|
*/ |
151
|
|
|
public function modelsEventNeedReload(array $modified_tables): void |
152
|
|
|
{ |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Returns array of workers classes for WorkerSafeScripts |
157
|
|
|
* |
158
|
|
|
* @return array |
159
|
|
|
*/ |
160
|
|
|
public function getModuleWorkers(): array |
161
|
|
|
{ |
162
|
|
|
return []; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Returns array of additional firewall rules for module |
167
|
|
|
* |
168
|
|
|
* @return array |
169
|
|
|
*/ |
170
|
|
|
public function getDefaultFirewallRules(): array |
171
|
|
|
{ |
172
|
|
|
return []; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Process module enable request |
177
|
|
|
* |
178
|
|
|
* @return bool |
179
|
|
|
*/ |
180
|
|
|
public function onBeforeModuleEnable(): bool |
181
|
|
|
{ |
182
|
|
|
return true; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Process some actions after module enable |
187
|
|
|
* |
188
|
|
|
* @return void |
189
|
|
|
*/ |
190
|
|
|
public function onAfterModuleEnable(): void |
191
|
|
|
{ |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Process module disable request |
196
|
|
|
* |
197
|
|
|
* @return bool |
198
|
|
|
*/ |
199
|
|
|
public function onBeforeModuleDisable(): bool |
200
|
|
|
{ |
201
|
|
|
return true; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Process some actions after module disable |
206
|
|
|
* |
207
|
|
|
* @return void |
208
|
|
|
*/ |
209
|
|
|
public function onAfterModuleDisable(): void |
210
|
|
|
{ |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Create additional Nginx locations from modules |
215
|
|
|
* |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
|
|
public function createNginxLocations(): string |
219
|
|
|
{ |
220
|
|
|
return ''; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Generates additional fail2ban jail conf rules from modules |
225
|
|
|
* |
226
|
|
|
* @return string |
227
|
|
|
*/ |
228
|
|
|
public function generateFail2BanJails(): string |
229
|
|
|
{ |
230
|
|
|
return ''; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Generates the modules.conf file |
235
|
|
|
* |
236
|
|
|
* @return string |
237
|
|
|
*/ |
238
|
|
|
public function generateModulesConf(): string |
239
|
|
|
{ |
240
|
|
|
return ''; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Prepares crontab rules strings |
245
|
|
|
* |
246
|
|
|
* @param array $tasks |
247
|
|
|
*/ |
248
|
|
|
public function createCronTasks(&$tasks): void |
249
|
|
|
{ |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* This module's method calls after the asterisk service started |
254
|
|
|
*/ |
255
|
|
|
public function onAfterPbxStarted(): void |
256
|
|
|
{ |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Makes pretty module text block into config file |
261
|
|
|
* |
262
|
|
|
* @param string $addition |
263
|
|
|
* |
264
|
|
|
* @return string |
265
|
|
|
*/ |
266
|
|
|
protected function confBlockWithComments(string $addition): string |
267
|
|
|
{ |
268
|
|
|
$result = ''; |
269
|
|
|
if (empty($addition)) { |
270
|
|
|
return $result; |
271
|
|
|
} |
272
|
|
|
$result = PHP_EOL . '; ***** BEGIN BY ' . $this->moduleUniqueId . PHP_EOL; |
273
|
|
|
$result .= rtrim($addition); |
274
|
|
|
$result .= PHP_EOL . '; ***** END BY ' . $this->moduleUniqueId . PHP_EOL; |
275
|
|
|
|
276
|
|
|
return $result; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Authenticates user over external module |
282
|
|
|
* |
283
|
|
|
* @param string $login |
284
|
|
|
* @param string $password |
285
|
|
|
* @return array session data |
286
|
|
|
*/ |
287
|
|
|
public function authenticateUser(string $login, string $password): array |
288
|
|
|
{ |
289
|
|
|
return []; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Prepares list of additional ACL roles and rules |
294
|
|
|
* |
295
|
|
|
* @param AclList $aclList |
296
|
|
|
* @return void |
297
|
|
|
*/ |
298
|
|
|
public function onAfterACLPrepared(AclList $aclList): void |
299
|
|
|
{ |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Modifies system menu |
304
|
|
|
* |
305
|
|
|
* @param array $menuItems |
306
|
|
|
* @return void |
307
|
|
|
*/ |
308
|
|
|
public function onBeforeHeaderMenuShow(array &$menuItems):void |
309
|
|
|
{ |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Modifies system routes |
314
|
|
|
* |
315
|
|
|
* @param Router $router |
316
|
|
|
* @return void |
317
|
|
|
*/ |
318
|
|
|
public function onAfterRoutesPrepared(Router $router):void |
319
|
|
|
{ |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
} |