1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © MIKO LLC - All Rights Reserved |
4
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited |
5
|
|
|
* Proprietary and confidential |
6
|
|
|
* Written by Alexey Portnov, 12 2019 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace MikoPBX\Common\Models; |
10
|
|
|
|
11
|
|
|
use Phalcon\Validation; |
12
|
|
|
use Phalcon\Validation\Validator\Uniqueness as UniquenessValidator; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class PbxSettings |
16
|
|
|
* |
17
|
|
|
* @method static mixed findFirstByKey(string $string) |
18
|
|
|
* |
19
|
|
|
* @package MikoPBX\Common\Models |
20
|
|
|
*/ |
21
|
|
|
class PbxSettings extends ModelsBase |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @Primary |
26
|
|
|
* @Column(type="string", nullable=false) |
27
|
|
|
*/ |
28
|
|
|
public string $key; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @Column(type="string", nullable=true) |
32
|
|
|
*/ |
33
|
|
|
public ?string $value; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Prepares default values for PbxSettings keys |
38
|
|
|
* |
39
|
|
|
* @return array default values |
40
|
|
|
*/ |
41
|
|
|
public static function getDefaultArrayValues(): array |
42
|
|
|
{ |
43
|
|
|
return [ |
44
|
|
|
'Name' => 'PBX system', |
45
|
|
|
'VirtualHardwareType' => 'REAL',//VMWARE,HYPERV,AWS,AZURE |
46
|
|
|
'Description' => '', |
47
|
|
|
'RestartEveryNight' => '0', |
48
|
|
|
'SIPPort' => '5060', |
49
|
|
|
'SIPDefaultExpiry' => '120', |
50
|
|
|
'SIPMinExpiry' => '60', |
51
|
|
|
'SIPMaxExpiry' => '3600', |
52
|
|
|
'RTPPortFrom' => '10000', |
53
|
|
|
'RTPPortTo' => '10200', |
54
|
|
|
'IAXPort' => '4569', |
55
|
|
|
'AMIEnabled' => '1', |
56
|
|
|
'AMIPort' => '5038', |
57
|
|
|
'AJAMEnabled' => '1', |
58
|
|
|
'AJAMPort' => '8088', |
59
|
|
|
'AJAMPortTLS' => '8089', |
60
|
|
|
'SSHPort' => '22', |
61
|
|
|
'SSHPassword' => 'admin', |
62
|
|
|
'SSHRsaKey' => '', |
63
|
|
|
'SSHDssKey' => '', |
64
|
|
|
'SSHAuthorizedKeys' => '', |
65
|
|
|
'SSHecdsaKey' => '', |
66
|
|
|
'SSHLanguage' => 'en', |
67
|
|
|
'WEBPort' => '80', |
68
|
|
|
'WEBHTTPSPort' => '443', |
69
|
|
|
'WEBHTTPSPublicKey' => '', |
70
|
|
|
'WEBHTTPSPrivateKey' => '', |
71
|
|
|
'RedirectToHttps' => '0', |
72
|
|
|
'MailSMTPUseTLS' => '0', |
73
|
|
|
'MailSMTPCertCheck' => '0', |
74
|
|
|
'MailSMTPHost' => '', |
75
|
|
|
'MailSMTPPort' => '25', |
76
|
|
|
'MailSMTPUsername' => '', |
77
|
|
|
'MailSMTPPassword' => '', |
78
|
|
|
'MailSMTPFromUsername' => 'PBX', |
79
|
|
|
'MailSMTPSenderAddress' => '', |
80
|
|
|
'MailEnableNotifications' => '0', |
81
|
|
|
'MailTplMissedCallSubject' => 'You have missing call from <MailSMTPSenderAddress>', |
82
|
|
|
'MailTplMissedCallBody' => 'You have missed calls (NOTIFICATION_MISSEDCAUSE) from <NOTIFICATION_CALLERID> at <NOTIFICATION_DATE>', |
83
|
|
|
'MailTplMissedCallFooter' => '', |
84
|
|
|
'MailTplVoicemailSubject' => 'VoiceMail from PBX', |
85
|
|
|
'MailTplVoicemailBody' => 'See attach', |
86
|
|
|
'MailTplVoicemailFooter' => '', |
87
|
|
|
'NTPServer' => '0.pool.ntp.org'.PHP_EOL.'1.pool.ntp.org'.PHP_EOL, |
88
|
|
|
'VoicemailNotificationsEmail' => '[email protected]', |
89
|
|
|
'VoicemailExten' => '*001', |
90
|
|
|
'PBXLanguage' => 'en-en', |
91
|
|
|
'PBXInternalExtensionLength' => '3',// Длина внутреннего номера |
92
|
|
|
'PBXRecordCalls' => '1', |
93
|
|
|
'PBXSplitAudioThread' => '0', |
94
|
|
|
'PBXCallParkingExt' => '800', |
95
|
|
|
'PBXCallParkingStartSlot' => '801', |
96
|
|
|
'PBXCallParkingEndSlot' => '820', |
97
|
|
|
'PBXFeatureAttendedTransfer' => '##', |
98
|
|
|
'PBXFeatureBlindTransfer' => '**', |
99
|
|
|
'PBXFeatureDigitTimeout' => '2500', |
100
|
|
|
'PBXFeatureAtxferNoAnswerTimeout' => '45', |
101
|
|
|
'PBXFirewallEnabled' => '0', |
102
|
|
|
'PBXFail2BanEnabled' => '0', |
103
|
|
|
'PBXTimezone' => 'Europe/Moscow', |
104
|
|
|
'PBXVersion' => '1', |
105
|
|
|
'PickupExten' => '*8', |
106
|
|
|
'WebAdminLogin' => 'admin', |
107
|
|
|
'WebAdminPassword' => 'admin', |
108
|
|
|
'WebAdminLanguage' => 'en', |
109
|
|
|
'SystemNotificationsEmail' => '[email protected]', |
110
|
|
|
'SendMetrics' => '1', |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
]; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Returns default or saved values for all predefined keys if it exists on DB |
118
|
|
|
* |
119
|
|
|
* @return array |
120
|
|
|
*/ |
121
|
|
|
public static function getAllPbxSettings(): array |
122
|
|
|
{ |
123
|
|
|
$arrOfDefaultValues = self::getDefaultArrayValues(); |
124
|
|
|
foreach ($arrOfDefaultValues as $key => $record) { |
125
|
|
|
$arrOfDefaultValues[$key] = self::getValueByKey($key); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $arrOfDefaultValues; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns default or saved value for key if it exists on DB |
133
|
|
|
* |
134
|
|
|
* @param $key string value key |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
public static function getValueByKey(string $key): string |
139
|
|
|
{ |
140
|
|
|
|
141
|
|
|
$result = parent::findFirstByKey($key); |
142
|
|
|
if ($result === null || $result->value === null) { |
143
|
|
|
$arrOfDefaultValues = self::getDefaultArrayValues(); |
144
|
|
|
if ( ! array_key_exists($key, $arrOfDefaultValues)) { |
145
|
|
|
return ''; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return $arrOfDefaultValues[$key]; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $result->value; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function initialize(): void |
155
|
|
|
{ |
156
|
|
|
$this->setSource('m_PbxSettings'); |
157
|
|
|
parent::initialize(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Before PbxSettings entity save callback |
162
|
|
|
* @return bool |
163
|
|
|
*/ |
164
|
|
|
public function validation(): bool |
165
|
|
|
{ |
166
|
|
|
$validation = new Validation(); |
167
|
|
|
$validation->add( |
168
|
|
|
'key', |
169
|
|
|
new UniquenessValidator( |
170
|
|
|
[ |
171
|
|
|
'message' => $this->t('mo_ThisKeyMustBeUniqueForPbxSettingsModels'), |
172
|
|
|
] |
173
|
|
|
) |
174
|
|
|
); |
175
|
|
|
|
176
|
|
|
return $this->validate($validation); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* After PbxSettings entity save callback |
181
|
|
|
*/ |
182
|
|
|
public function afterSave(): void |
183
|
|
|
{ |
184
|
|
|
parent::afterSave(); |
185
|
|
|
if ($this->itHasFirewallParametersChanges()) { |
186
|
|
|
FirewallRules::updatePorts($this); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Check if this changes influence to the iptables daemon |
192
|
|
|
* |
193
|
|
|
* @return bool |
194
|
|
|
*/ |
195
|
|
|
public function itHasFirewallParametersChanges(): bool |
196
|
|
|
{ |
197
|
|
|
switch ($this->key) { |
198
|
|
|
case 'SIPPort': |
199
|
|
|
case 'RTPPortFrom': |
200
|
|
|
case 'RTPPortTo': |
201
|
|
|
case 'IAXPort': |
202
|
|
|
case 'AMIPort': |
203
|
|
|
case 'AJAMPort': |
204
|
|
|
case 'AJAMPortTLS': |
205
|
|
|
case 'WEBPort': |
206
|
|
|
case 'WEBHTTPSPort': |
207
|
|
|
case 'SSHPort': |
208
|
|
|
case 'PBXFirewallEnabled': |
209
|
|
|
case 'PBXFail2BanEnabled': |
210
|
|
|
return true; |
211
|
|
|
default: |
212
|
|
|
if (strpos($this->key, 'FirewallSettings') !== false) { |
213
|
|
|
return true; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
return false; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Check if this changes influence to the pjsip.conf |
222
|
|
|
* |
223
|
|
|
* @return bool |
224
|
|
|
*/ |
225
|
|
|
public function itHasSipParametersChanges(): bool |
226
|
|
|
{ |
227
|
|
|
switch ($this->key) { |
228
|
|
|
case 'SIPPort': |
229
|
|
|
case 'RTPPortFrom': |
230
|
|
|
case 'RTPPortTo': |
231
|
|
|
case 'SIPDefaultExpiry': |
232
|
|
|
case 'SIPMinExpiry': |
233
|
|
|
case 'SIPMaxExpiry': |
234
|
|
|
case 'PBXLanguage': |
235
|
|
|
return true; |
236
|
|
|
default: |
237
|
|
|
return false; |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Check if this changes influence to the iax2.conf |
243
|
|
|
* |
244
|
|
|
* @return bool |
245
|
|
|
*/ |
246
|
|
|
public function itHasIaxParametersChanges(): bool |
247
|
|
|
{ |
248
|
|
|
switch ($this->key) { |
249
|
|
|
case 'IAXPort': |
250
|
|
|
return true; |
251
|
|
|
default: |
252
|
|
|
return false; |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Check if this changes influence to the manager.conf |
258
|
|
|
* |
259
|
|
|
* @return bool |
260
|
|
|
*/ |
261
|
|
|
public function itHasAMIParametersChanges(): bool |
262
|
|
|
{ |
263
|
|
|
switch ($this->key) { |
264
|
|
|
case 'AMIPort': |
265
|
|
|
case 'AJAMPort': |
266
|
|
|
case 'AJAMPortTLS': |
267
|
|
|
return true; |
268
|
|
|
default: |
269
|
|
|
return false; |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Check if this changes influence to the features.conf |
275
|
|
|
* |
276
|
|
|
* @return bool |
277
|
|
|
*/ |
278
|
|
|
public function itHasFeaturesSettingsChanges(): bool |
279
|
|
|
{ |
280
|
|
|
switch ($this->key) { |
281
|
|
|
case 'PBXLanguage': |
282
|
|
|
case 'PBXInternalExtensionLength': |
283
|
|
|
case 'PBXRecordCalls': |
284
|
|
|
case 'PBXCallParkingExt': |
285
|
|
|
case 'PBXCallParkingStartSlot': |
286
|
|
|
case 'PBXCallParkingEndSlot': |
287
|
|
|
case 'PBXFeatureAttendedTransfer': |
288
|
|
|
case 'PBXFeatureBlindTransfer': |
289
|
|
|
case 'PBXFeatureDigitTimeout': |
290
|
|
|
case 'PBXFeatureAtxferNoAnswerTimeout': |
291
|
|
|
return true; |
292
|
|
|
default: |
293
|
|
|
return false; |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Check if this changes influence to the SSHd daemon |
299
|
|
|
* |
300
|
|
|
* @return bool |
301
|
|
|
*/ |
302
|
|
|
public function itHasSSHParametersChanges(): bool |
303
|
|
|
{ |
304
|
|
|
switch ($this->key) { |
305
|
|
|
case 'SSHPort': |
306
|
|
|
case 'SSHPassword': |
307
|
|
|
case 'SSHAuthorizedKeys': |
308
|
|
|
case 'SSHRsaKey': |
309
|
|
|
case 'SSHDssKey': |
310
|
|
|
case 'SSHecdsaKey': |
311
|
|
|
return true; |
312
|
|
|
default: |
313
|
|
|
return false; |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Check if this changes influence to the Nginx daemon |
319
|
|
|
* |
320
|
|
|
* @return bool |
321
|
|
|
*/ |
322
|
|
|
public function itHasWebParametersChanges(): bool |
323
|
|
|
{ |
324
|
|
|
switch ($this->key) { |
325
|
|
|
case 'WEBPort': |
326
|
|
|
case 'WEBHTTPSPort': |
327
|
|
|
case 'WEBHTTPSPublicKey': |
328
|
|
|
case 'WEBHTTPSPrivateKey': |
329
|
|
|
case 'RedirectToHttps': |
330
|
|
|
return true; |
331
|
|
|
default: |
332
|
|
|
return false; |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Check if this changes influence to the Crond daemon |
338
|
|
|
* |
339
|
|
|
* @return bool |
340
|
|
|
*/ |
341
|
|
|
public function itHasCronParametersChanges(): bool |
342
|
|
|
{ |
343
|
|
|
switch ($this->key) { |
344
|
|
|
case 'RestartEveryNight': |
345
|
|
|
return true; |
346
|
|
|
default: |
347
|
|
|
return false; |
348
|
|
|
} |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* Check if this changes influence to the extensions.conf |
353
|
|
|
* |
354
|
|
|
* @return bool |
355
|
|
|
*/ |
356
|
|
|
public function itHasDialplanParametersChanges(): bool |
357
|
|
|
{ |
358
|
|
|
switch ($this->key) { |
359
|
|
|
case 'PBXLanguage': |
360
|
|
|
return true; |
361
|
|
|
default: |
362
|
|
|
return false; |
363
|
|
|
} |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* Check if this changes influence to the voicemail.conf |
368
|
|
|
* |
369
|
|
|
* @return bool |
370
|
|
|
*/ |
371
|
|
|
public function itHasVoiceMailParametersChanges(): bool |
372
|
|
|
{ |
373
|
|
|
switch ($this->key) { |
374
|
|
|
case 'MailTplVoicemailSubject': |
375
|
|
|
case 'MailTplVoicemailBody': |
376
|
|
|
case 'MailSMTPSenderAddress': |
377
|
|
|
case 'MailSMTPUsername': |
378
|
|
|
case 'PBXTimezone': |
379
|
|
|
case 'VoicemailNotificationsEmail': |
380
|
|
|
case 'SystemNotificationsEmail': |
381
|
|
|
return true; |
382
|
|
|
default: |
383
|
|
|
return false; |
384
|
|
|
} |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* Check if this changes influence to translations |
389
|
|
|
* |
390
|
|
|
* @return bool |
391
|
|
|
*/ |
392
|
|
|
public function itHasVisualLanguageSettings(): bool |
393
|
|
|
{ |
394
|
|
|
switch ($this->key) { |
395
|
|
|
case 'SSHLanguage': |
396
|
|
|
case 'WebAdminLanguage': |
397
|
|
|
return true; |
398
|
|
|
default: |
399
|
|
|
return false; |
400
|
|
|
} |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Check if this changes influence to timezone and logs |
405
|
|
|
* |
406
|
|
|
* @return bool |
407
|
|
|
*/ |
408
|
|
|
public function itHasTimeZoneSettings(): bool |
409
|
|
|
{ |
410
|
|
|
switch ($this->key) { |
411
|
|
|
case 'PBXTimezone': |
412
|
|
|
return true; |
413
|
|
|
default: |
414
|
|
|
return false; |
415
|
|
|
} |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Check if this changes influence to NTP daemon settings |
420
|
|
|
* |
421
|
|
|
* @return bool |
422
|
|
|
*/ |
423
|
|
|
public function itHasNTPSettings(): bool |
424
|
|
|
{ |
425
|
|
|
switch ($this->key) { |
426
|
|
|
case 'PBXManualTimeSettings': |
427
|
|
|
case 'NTPServer': |
428
|
|
|
return true; |
429
|
|
|
default: |
430
|
|
|
return false; |
431
|
|
|
} |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Check if this changes influence to licensing |
436
|
|
|
* |
437
|
|
|
* @return bool |
438
|
|
|
*/ |
439
|
|
|
public function itHasLicenseSettings(): bool |
440
|
|
|
{ |
441
|
|
|
switch ($this->key) { |
442
|
|
|
case 'PBXLicense': |
443
|
|
|
return true; |
444
|
|
|
default: |
445
|
|
|
return false; |
446
|
|
|
} |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* Check if this changes influence to call recording |
451
|
|
|
* |
452
|
|
|
* @return bool |
453
|
|
|
*/ |
454
|
|
|
public function itHasCallRecordSettings(): bool |
455
|
|
|
{ |
456
|
|
|
switch ($this->key) { |
457
|
|
|
case 'PBXRecordCalls': |
458
|
|
|
case 'PBXSplitAudioThread': |
459
|
|
|
return true; |
460
|
|
|
default: |
461
|
|
|
return false; |
462
|
|
|
} |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
|
466
|
|
|
|
467
|
|
|
} |