@@ -79,22 +79,22 @@ |
||
79 | 79 | return $res; |
80 | 80 | } |
81 | 81 | |
82 | - public static function getDbConnection(){ |
|
83 | - if(!file_exists(Fail2BanConf::FAIL2BAN_DB_PATH)){ |
|
84 | - return null; |
|
85 | - } |
|
86 | - try { |
|
87 | - $db = new SQLite3(Fail2BanConf::FAIL2BAN_DB_PATH); |
|
88 | - }catch (\Exception $e){ |
|
89 | - return null; |
|
90 | - } |
|
91 | - $db->busyTimeout(5000); |
|
92 | - $fail2ban = new Fail2BanConf(); |
|
93 | - if (false === $fail2ban->tableBanExists($db)) { |
|
94 | - return null; |
|
95 | - } |
|
82 | + public static function getDbConnection(){ |
|
83 | + if(!file_exists(Fail2BanConf::FAIL2BAN_DB_PATH)){ |
|
84 | + return null; |
|
85 | + } |
|
86 | + try { |
|
87 | + $db = new SQLite3(Fail2BanConf::FAIL2BAN_DB_PATH); |
|
88 | + }catch (\Exception $e){ |
|
89 | + return null; |
|
90 | + } |
|
91 | + $db->busyTimeout(5000); |
|
92 | + $fail2ban = new Fail2BanConf(); |
|
93 | + if (false === $fail2ban->tableBanExists($db)) { |
|
94 | + return null; |
|
95 | + } |
|
96 | 96 | |
97 | - return $db; |
|
97 | + return $db; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public static function fail2banUnbanAll(string $ip): PBXApiResult |
30 | 30 | { |
31 | - $ip = trim($ip); |
|
31 | + $ip = trim($ip); |
|
32 | 32 | $res = new PBXApiResult(); |
33 | 33 | $res->processor = __METHOD__; |
34 | 34 | $res->success = true; |
35 | - if ( ! Verify::isIpAddress($ip)) { |
|
35 | + if (!Verify::isIpAddress($ip)) { |
|
36 | 36 | $res->success = false; |
37 | - $res->messages[]="Not valid ip '{$ip}'."; |
|
37 | + $res->messages[] = "Not valid ip '{$ip}'."; |
|
38 | 38 | } |
39 | - $fail2ban = new Fail2BanConf(); |
|
39 | + $fail2ban = new Fail2BanConf(); |
|
40 | 40 | if ($fail2ban->fail2ban_enable) { |
41 | 41 | $fail2ban = Util::which('fail2ban-client'); |
42 | - $res->success = (Util::mwExec("{$fail2ban} unban {$ip}") === 0); |
|
42 | + $res->success = (Util::mwExec("{$fail2ban} unban {$ip}") === 0); |
|
43 | 43 | } else { |
44 | 44 | $res = self::fail2banUnbanDb($ip); |
45 | 45 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $res->processor = __METHOD__; |
61 | 61 | |
62 | 62 | $db = self::getDbConnection(); |
63 | - if(!$db){ |
|
63 | + if (!$db) { |
|
64 | 64 | // Таблица не существует. Бана нет. |
65 | 65 | $res->success = false; |
66 | 66 | $res->messages[] = 'DB '.Fail2BanConf::FAIL2BAN_DB_PATH.' not found'; |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | return $res; |
80 | 80 | } |
81 | 81 | |
82 | - public static function getDbConnection(){ |
|
83 | - if(!file_exists(Fail2BanConf::FAIL2BAN_DB_PATH)){ |
|
82 | + public static function getDbConnection() { |
|
83 | + if (!file_exists(Fail2BanConf::FAIL2BAN_DB_PATH)) { |
|
84 | 84 | return null; |
85 | 85 | } |
86 | 86 | try { |
87 | - $db = new SQLite3(Fail2BanConf::FAIL2BAN_DB_PATH); |
|
88 | - }catch (\Exception $e){ |
|
87 | + $db = new SQLite3(Fail2BanConf::FAIL2BAN_DB_PATH); |
|
88 | + } catch (\Exception $e) { |
|
89 | 89 | return null; |
90 | 90 | } |
91 | 91 | $db->busyTimeout(5000); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $ban_time = '43800'; |
111 | 111 | } |
112 | 112 | // Добавленн фильтр по времени бана. возвращаем только адреса, которые еще НЕ разбанены. |
113 | - $q = 'SELECT' . ' DISTINCT jail,ip,MAX(timeofban) AS timeofban, MAX(timeofban+' . $ban_time . ') AS timeunban FROM bans where (timeofban+' . $ban_time . ')>' . time(); |
|
113 | + $q = 'SELECT'.' DISTINCT jail,ip,MAX(timeofban) AS timeofban, MAX(timeofban+'.$ban_time.') AS timeunban FROM bans where (timeofban+'.$ban_time.')>'.time(); |
|
114 | 114 | if ($ip !== null) { |
115 | 115 | $q .= " AND ip='{$ip}'"; |
116 | 116 | } |
@@ -133,13 +133,13 @@ discard block |
||
133 | 133 | |
134 | 134 | $jail_q = ($jail === '') ? '' : "AND jail = '{$jail}'"; |
135 | 135 | $path_db = Fail2BanConf::FAIL2BAN_DB_PATH; |
136 | - if(!file_exists($path_db)){ |
|
136 | + if (!file_exists($path_db)) { |
|
137 | 137 | // Таблица не существует. Бана нет. |
138 | 138 | $res->success = false; |
139 | 139 | $res->messages[] = "DB {$path_db} not found"; |
140 | 140 | return $res; |
141 | 141 | } |
142 | - $db = new SQLite3($path_db); |
|
142 | + $db = new SQLite3($path_db); |
|
143 | 143 | $db->busyTimeout(3000); |
144 | 144 | $fail2ban = new Fail2BanConf(); |
145 | 145 | if (false === $fail2ban->tableBanExists($db)) { |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $res->success = true; |
148 | 148 | return $res; |
149 | 149 | } |
150 | - $q = 'DELETE' . " FROM bans WHERE ip = '{$ip}' {$jail_q}"; |
|
150 | + $q = 'DELETE'." FROM bans WHERE ip = '{$ip}' {$jail_q}"; |
|
151 | 151 | $db->query($q); |
152 | 152 | |
153 | 153 | $err = $db->lastErrorMsg(); |
@@ -79,13 +79,14 @@ |
||
79 | 79 | return $res; |
80 | 80 | } |
81 | 81 | |
82 | - public static function getDbConnection(){ |
|
82 | + public static function getDbConnection() |
|
83 | + { |
|
83 | 84 | if(!file_exists(Fail2BanConf::FAIL2BAN_DB_PATH)){ |
84 | 85 | return null; |
85 | 86 | } |
86 | 87 | try { |
87 | 88 | $db = new SQLite3(Fail2BanConf::FAIL2BAN_DB_PATH); |
88 | - }catch (\Exception $e){ |
|
89 | + } catch (\Exception $e){ |
|
89 | 90 | return null; |
90 | 91 | } |
91 | 92 | $db->busyTimeout(5000); |
@@ -136,7 +136,7 @@ |
||
136 | 136 | if(!file_exists($path_db)){ |
137 | 137 | // Таблица не существует. Бана нет. |
138 | 138 | $res->success = false; |
139 | - $res->messages[] = "DB {$path_db} not found"; |
|
139 | + $res->messages[] = "db {$path_db} not found"; |
|
140 | 140 | return $res; |
141 | 141 | } |
142 | 142 | $db = new SQLite3($path_db); |
@@ -162,14 +162,14 @@ discard block |
||
162 | 162 | $res->data['message'] = 'In progress...'; |
163 | 163 | |
164 | 164 | |
165 | - if ( ! file_exists($tempFilename)) { |
|
165 | + if (!file_exists($tempFilename)) { |
|
166 | 166 | $res->success = false; |
167 | 167 | $res->messages[] = "Update file '{$tempFilename}' not found."; |
168 | 168 | |
169 | 169 | return $res; |
170 | 170 | } |
171 | 171 | |
172 | - if ( ! file_exists('/var/etc/cfdevice')) { |
|
172 | + if (!file_exists('/var/etc/cfdevice')) { |
|
173 | 173 | $res->success = false; |
174 | 174 | $res->messages[] = "The system is not installed"; |
175 | 175 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $res = new PBXApiResult(); |
199 | 199 | $res->processor = __METHOD__; |
200 | 200 | $moduleMetadata = FilesManagementProcessor::getMetadataFromModuleFile($filePath); |
201 | - if ( ! $moduleMetadata->success) { |
|
201 | + if (!$moduleMetadata->success) { |
|
202 | 202 | return $moduleMetadata; |
203 | 203 | } else { |
204 | 204 | $moduleUniqueID = $moduleMetadata->data['uniqid']; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | if (class_exists($pbxExtensionSetupClass) |
238 | 238 | && method_exists($pbxExtensionSetupClass, 'installModule')) { |
239 | 239 | $setup = new $pbxExtensionSetupClass($moduleUniqueID); |
240 | - if ( ! $setup->installModule()) { |
|
240 | + if (!$setup->installModule()) { |
|
241 | 241 | $res->success = false; |
242 | 242 | $res->messages[] = $setup->getMessages(); |
243 | 243 | } |
@@ -384,15 +384,15 @@ discard block |
||
384 | 384 | [IncomingRoutingTable::class => ''], |
385 | 385 | [OutWorkTimes::class => ''], |
386 | 386 | [AsteriskManagerUsers::class => ''], |
387 | - [Extensions::class => 'type="' . Extensions::TYPE_IVR_MENU . '"'], // IVR Menu |
|
388 | - [Extensions::class => 'type="' . Extensions::TYPE_CONFERENCE . '"'], // CONFERENCE |
|
389 | - [Extensions::class => 'type="' . Extensions::TYPE_QUEUE . '"'], // QUEUE |
|
387 | + [Extensions::class => 'type="'.Extensions::TYPE_IVR_MENU.'"'], // IVR Menu |
|
388 | + [Extensions::class => 'type="'.Extensions::TYPE_CONFERENCE.'"'], // CONFERENCE |
|
389 | + [Extensions::class => 'type="'.Extensions::TYPE_QUEUE.'"'], // QUEUE |
|
390 | 390 | ]; |
391 | 391 | |
392 | 392 | foreach ($clearThisModels as $modelParams) { |
393 | 393 | foreach ($modelParams as $key => $value) { |
394 | 394 | $records = call_user_func([$key, 'find'], $value); |
395 | - if ( ! $records->delete()) { |
|
395 | + if (!$records->delete()) { |
|
396 | 396 | $res->messages[] = $records->getMessages(); |
397 | 397 | $res->success = false; |
398 | 398 | } |
@@ -400,13 +400,13 @@ discard block |
||
400 | 400 | } |
401 | 401 | |
402 | 402 | // Other extensions |
403 | - $parameters = [ |
|
403 | + $parameters = [ |
|
404 | 404 | 'conditions' => 'not number IN ({ids:array})', |
405 | 405 | 'bind' => [ |
406 | 406 | 'ids' => [ |
407 | 407 | '000063', // Reads back the extension |
408 | 408 | '000064', // 0000MILLI |
409 | - '10003246',// Echo test |
|
409 | + '10003246', // Echo test |
|
410 | 410 | '10000100' // Voicemail |
411 | 411 | ], |
412 | 412 | ], |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | $stopDeleting = true; |
421 | 421 | continue; |
422 | 422 | } |
423 | - if ( ! $record->delete()) { |
|
423 | + if (!$record->delete()) { |
|
424 | 424 | $deleteAttempts += 1; |
425 | 425 | } |
426 | 426 | if ($deleteAttempts > $countRecords * 10) { |
@@ -436,12 +436,12 @@ discard block |
||
436 | 436 | 'custom' => SoundFiles::CATEGORY_CUSTOM, |
437 | 437 | ], |
438 | 438 | ]; |
439 | - $records = SoundFiles::find($parameters); |
|
439 | + $records = SoundFiles::find($parameters); |
|
440 | 440 | |
441 | 441 | foreach ($records as $record) { |
442 | 442 | if (stripos($record->path, '/storage/usbdisk1/mikopbx') !== false) { |
443 | 443 | Util::mwExec("{$rm} -rf {$record->path}"); |
444 | - if ( ! $record->delete()) { |
|
444 | + if (!$record->delete()) { |
|
445 | 445 | $res->messages[] = $record->getMessages(); |
446 | 446 | $res->success = false; |
447 | 447 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | foreach ($records as $record) { |
454 | 454 | $moduleDir = PbxExtensionUtils::getModuleDir($record->uniqid); |
455 | 455 | Util::mwExec("{$rm} -rf {$moduleDir}"); |
456 | - if ( ! $record->delete()) { |
|
456 | + if (!$record->delete()) { |
|
457 | 457 | $res->messages[] = $record->getMessages(); |
458 | 458 | $res->success = false; |
459 | 459 | } |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | |
462 | 462 | // Delete CallRecords |
463 | 463 | $records = CallDetailRecords::find(); |
464 | - if ( ! $records->delete()) { |
|
464 | + if (!$records->delete()) { |
|
465 | 465 | $res->messages[] = $records->getMessages(); |
466 | 466 | $res->success = false; |
467 | 467 | } |
@@ -486,14 +486,14 @@ discard block |
||
486 | 486 | { |
487 | 487 | $res = new PBXApiResult(); |
488 | 488 | $res->processor = __METHOD__; |
489 | - if ( ! file_exists($filename)) { |
|
489 | + if (!file_exists($filename)) { |
|
490 | 490 | $res->success = false; |
491 | 491 | $res->messages[] = "File '{$filename}' not found."; |
492 | 492 | |
493 | 493 | return $res; |
494 | 494 | } |
495 | 495 | $out = []; |
496 | - $tmp_filename = '/tmp/' . time() . "_" . basename($filename); |
|
496 | + $tmp_filename = '/tmp/'.time()."_".basename($filename); |
|
497 | 497 | if (false === copy($filename, $tmp_filename)) { |
498 | 498 | $res->success = false; |
499 | 499 | $res->messages[] = "Unable to create temporary file '{$tmp_filename}'."; |
@@ -502,8 +502,8 @@ discard block |
||
502 | 502 | } |
503 | 503 | |
504 | 504 | // Принудительно устанавливаем расширение файла в wav. |
505 | - $n_filename = Util::trimExtensionForFile($filename) . ".wav"; |
|
506 | - $n_filename_mp3 = Util::trimExtensionForFile($filename) . ".mp3"; |
|
505 | + $n_filename = Util::trimExtensionForFile($filename).".wav"; |
|
506 | + $n_filename_mp3 = Util::trimExtensionForFile($filename).".mp3"; |
|
507 | 507 | // Конвертируем файл. |
508 | 508 | $tmp_filename = escapeshellcmd($tmp_filename); |
509 | 509 | $n_filename = escapeshellcmd($n_filename); |
@@ -49,10 +49,10 @@ |
||
49 | 49 | { |
50 | 50 | $di->setShared( |
51 | 51 | self::SERVICE_NAME, |
52 | - function () { |
|
52 | + function() { |
|
53 | 53 | try { |
54 | 54 | return new License('http://127.0.0.1:8223'); |
55 | - } catch (Error $exception){ |
|
55 | + } catch (Error $exception) { |
|
56 | 56 | Util::sysLogMsg(__CLASS__, $exception); |
57 | 57 | } |
58 | 58 | return null; |
@@ -49,7 +49,8 @@ |
||
49 | 49 | { |
50 | 50 | $di->setShared( |
51 | 51 | self::SERVICE_NAME, |
52 | - function () { |
|
52 | + function () |
|
53 | + { |
|
53 | 54 | try { |
54 | 55 | return new License('http://127.0.0.1:8223'); |
55 | 56 | } catch (Error $exception){ |