@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | } |
296 | 296 | // Connect to the SMTP server |
297 | 297 | $this->edebug( |
298 | - "Connection: opening to $host:$port, timeout=$timeout, options=" . |
|
298 | + "Connection: opening to $host:$port, timeout=$timeout, options=". |
|
299 | 299 | (count($options) > 0 ? var_export($options, true) : 'array()'), |
300 | 300 | self::DEBUG_CONNECTION |
301 | 301 | ); |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | $socket_context = stream_context_create($options); |
306 | 306 | set_error_handler([$this, 'errorHandler']); |
307 | 307 | $this->smtp_conn = stream_socket_client( |
308 | - $host . ':' . $port, |
|
308 | + $host.':'.$port, |
|
309 | 309 | $errno, |
310 | 310 | $errstr, |
311 | 311 | $timeout, |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | (string) $errstr |
339 | 339 | ); |
340 | 340 | $this->edebug( |
341 | - 'SMTP ERROR: ' . $this->error['error'] |
|
341 | + 'SMTP ERROR: '.$this->error['error'] |
|
342 | 342 | . ": $errstr ($errno)", |
343 | 343 | self::DEBUG_CLIENT |
344 | 344 | ); |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | } |
359 | 359 | // Get any announcement |
360 | 360 | $announce = $this->get_lines(); |
361 | - $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER); |
|
361 | + $this->edebug('SERVER -> CLIENT: '.$announce, self::DEBUG_SERVER); |
|
362 | 362 | |
363 | 363 | return true; |
364 | 364 | } |
@@ -431,15 +431,15 @@ discard block |
||
431 | 431 | return false; |
432 | 432 | } |
433 | 433 | |
434 | - $this->edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
434 | + $this->edebug('Auth method requested: '.($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
435 | 435 | $this->edebug( |
436 | - 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), |
|
436 | + 'Auth methods available on the server: '.implode(',', $this->server_caps['AUTH']), |
|
437 | 437 | self::DEBUG_LOWLEVEL |
438 | 438 | ); |
439 | 439 | |
440 | 440 | //If we have requested a specific auth type, check the server supports it before trying others |
441 | 441 | if (!in_array($authtype, $this->server_caps['AUTH'])) { |
442 | - $this->edebug('Requested auth method not available: ' . $authtype, self::DEBUG_LOWLEVEL); |
|
442 | + $this->edebug('Requested auth method not available: '.$authtype, self::DEBUG_LOWLEVEL); |
|
443 | 443 | $authtype = null; |
444 | 444 | } |
445 | 445 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | |
458 | 458 | return false; |
459 | 459 | } |
460 | - self::edebug('Auth method selected: ' . $authtype, self::DEBUG_LOWLEVEL); |
|
460 | + self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | if (!in_array($authtype, $this->server_caps['AUTH'])) { |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | // Send encoded username and password |
478 | 478 | if (!$this->sendCommand( |
479 | 479 | 'User & Password', |
480 | - base64_encode("\0" . $username . "\0" . $password), |
|
480 | + base64_encode("\0".$username."\0".$password), |
|
481 | 481 | 235 |
482 | 482 | ) |
483 | 483 | ) { |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | $challenge = base64_decode(substr($this->last_reply, 4)); |
506 | 506 | |
507 | 507 | // Build the response |
508 | - $response = $username . ' ' . $this->hmac($challenge, $password); |
|
508 | + $response = $username.' '.$this->hmac($challenge, $password); |
|
509 | 509 | |
510 | 510 | // send encoded credentials |
511 | 511 | return $this->sendCommand('Username', base64_encode($response), 235); |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | $oauth = $OAuth->getOauth64(); |
518 | 518 | |
519 | 519 | // Start authentication |
520 | - if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) { |
|
520 | + if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 '.$oauth, 235)) { |
|
521 | 521 | return false; |
522 | 522 | } |
523 | 523 | break; |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | $k_ipad = $key ^ $ipad; |
565 | 565 | $k_opad = $key ^ $opad; |
566 | 566 | |
567 | - return md5($k_opad . pack('H*', md5($k_ipad . $data))); |
|
567 | + return md5($k_opad.pack('H*', md5($k_ipad.$data))); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | } |
680 | 680 | //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1 |
681 | 681 | if ($in_headers) { |
682 | - $line = "\t" . $line; |
|
682 | + $line = "\t".$line; |
|
683 | 683 | } |
684 | 684 | } |
685 | 685 | $lines_out[] = $line; |
@@ -688,9 +688,9 @@ discard block |
||
688 | 688 | foreach ($lines_out as $line_out) { |
689 | 689 | //RFC2821 section 4.5.2 |
690 | 690 | if (!empty($line_out) and $line_out[0] == '.') { |
691 | - $line_out = '.' . $line_out; |
|
691 | + $line_out = '.'.$line_out; |
|
692 | 692 | } |
693 | - $this->client_send($line_out . static::LE, 'DATA'); |
|
693 | + $this->client_send($line_out.static::LE, 'DATA'); |
|
694 | 694 | } |
695 | 695 | } |
696 | 696 | |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | */ |
737 | 737 | protected function sendHello($hello, $host) |
738 | 738 | { |
739 | - $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250); |
|
739 | + $noerror = $this->sendCommand($hello, $hello.' '.$host, 250); |
|
740 | 740 | $this->helo_rply = $this->last_reply; |
741 | 741 | if ($noerror) { |
742 | 742 | $this->parseHelloFields($hello); |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | |
808 | 808 | return $this->sendCommand( |
809 | 809 | 'MAIL FROM', |
810 | - 'MAIL FROM:<' . $from . '>' . $useVerp, |
|
810 | + 'MAIL FROM:<'.$from.'>'.$useVerp, |
|
811 | 811 | 250 |
812 | 812 | ); |
813 | 813 | } |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | { |
848 | 848 | return $this->sendCommand( |
849 | 849 | 'RCPT TO', |
850 | - 'RCPT TO:<' . $address . '>', |
|
850 | + 'RCPT TO:<'.$address.'>', |
|
851 | 851 | [250, 251] |
852 | 852 | ); |
853 | 853 | } |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | |
887 | 887 | return false; |
888 | 888 | } |
889 | - $this->client_send($commandstring . static::LE, $command); |
|
889 | + $this->client_send($commandstring.static::LE, $command); |
|
890 | 890 | |
891 | 891 | $this->last_reply = $this->get_lines(); |
892 | 892 | // Fetch SMTP code and possible error code explanation |
@@ -896,8 +896,8 @@ discard block |
||
896 | 896 | $code_ex = (count($matches) > 2 ? $matches[2] : null); |
897 | 897 | // Cut off error code from each response line |
898 | 898 | $detail = preg_replace( |
899 | - "/{$code}[ -]" . |
|
900 | - ($code_ex ? str_replace('.', '\\.', $code_ex) . ' ' : '') . '/m', |
|
899 | + "/{$code}[ -]". |
|
900 | + ($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '').'/m', |
|
901 | 901 | '', |
902 | 902 | $this->last_reply |
903 | 903 | ); |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | $detail = substr($this->last_reply, 4); |
909 | 909 | } |
910 | 910 | |
911 | - $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER); |
|
911 | + $this->edebug('SERVER -> CLIENT: '.$this->last_reply, self::DEBUG_SERVER); |
|
912 | 912 | |
913 | 913 | if (!in_array($code, (array) $expect)) { |
914 | 914 | $this->setError( |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | $code_ex |
919 | 919 | ); |
920 | 920 | $this->edebug( |
921 | - 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply, |
|
921 | + 'SMTP ERROR: '.$this->error['error'].': '.$this->last_reply, |
|
922 | 922 | self::DEBUG_CLIENT |
923 | 923 | ); |
924 | 924 | |
@@ -984,7 +984,7 @@ discard block |
||
984 | 984 | public function turn() |
985 | 985 | { |
986 | 986 | $this->setError('The SMTP TURN command is not implemented'); |
987 | - $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT); |
|
987 | + $this->edebug('SMTP NOTICE: '.$this->error['error'], self::DEBUG_CLIENT); |
|
988 | 988 | |
989 | 989 | return false; |
990 | 990 | } |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | in_array($command, ['User & Password', 'Username', 'Password'], true)) { |
1006 | 1006 | $this->edebug('CLIENT -> SERVER: <credentials hidden>', self::DEBUG_CLIENT); |
1007 | 1007 | } else { |
1008 | - $this->edebug('CLIENT -> SERVER: ' . $data, self::DEBUG_CLIENT); |
|
1008 | + $this->edebug('CLIENT -> SERVER: '.$data, self::DEBUG_CLIENT); |
|
1009 | 1009 | } |
1010 | 1010 | set_error_handler([$this, 'errorHandler']); |
1011 | 1011 | $result = fwrite($this->smtp_conn, $data); |
@@ -1111,14 +1111,14 @@ discard block |
||
1111 | 1111 | //Must pass vars in here as params are by reference |
1112 | 1112 | if (!stream_select($selR, $selW, $selW, $this->Timelimit)) { |
1113 | 1113 | $this->edebug( |
1114 | - 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', |
|
1114 | + 'SMTP -> get_lines(): timed-out ('.$this->Timeout.' sec)', |
|
1115 | 1115 | self::DEBUG_LOWLEVEL |
1116 | 1116 | ); |
1117 | 1117 | break; |
1118 | 1118 | } |
1119 | 1119 | //Deliberate noise suppression - errors are handled afterwards |
1120 | 1120 | $str = @fgets($this->smtp_conn, 515); |
1121 | - $this->edebug('SMTP INBOUND: "' . trim($str) . '"', self::DEBUG_LOWLEVEL); |
|
1121 | + $this->edebug('SMTP INBOUND: "'.trim($str).'"', self::DEBUG_LOWLEVEL); |
|
1122 | 1122 | $data .= $str; |
1123 | 1123 | // If response is only 3 chars (not valid, but RFC5321 S4.2 says it must be handled), |
1124 | 1124 | // or 4th character is a space, we are done reading, break the loop, |
@@ -1130,7 +1130,7 @@ discard block |
||
1130 | 1130 | $info = stream_get_meta_data($this->smtp_conn); |
1131 | 1131 | if ($info['timed_out']) { |
1132 | 1132 | $this->edebug( |
1133 | - 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', |
|
1133 | + 'SMTP -> get_lines(): timed-out ('.$this->Timeout.' sec)', |
|
1134 | 1134 | self::DEBUG_LOWLEVEL |
1135 | 1135 | ); |
1136 | 1136 | break; |
@@ -1138,8 +1138,8 @@ discard block |
||
1138 | 1138 | // Now check if reads took too long |
1139 | 1139 | if ($endtime and time() > $endtime) { |
1140 | 1140 | $this->edebug( |
1141 | - 'SMTP -> get_lines(): timelimit reached (' . |
|
1142 | - $this->Timelimit . ' sec)', |
|
1141 | + 'SMTP -> get_lines(): timelimit reached ('. |
|
1142 | + $this->Timelimit.' sec)', |
|
1143 | 1143 | self::DEBUG_LOWLEVEL |
1144 | 1144 | ); |
1145 | 1145 | break; |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | protected function sendCommand($command, $commandstring, $expect) |
877 | 877 | { |
878 | 878 | if (!$this->connected()) { |
879 | - $this->setError("Called $command without being connected"); |
|
879 | + $this->setError("called $command without being connected"); |
|
880 | 880 | |
881 | 881 | return false; |
882 | 882 | } |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | */ |
959 | 959 | public function verify($name) |
960 | 960 | { |
961 | - return $this->sendCommand('VRFY', "VRFY $name", [250, 251]); |
|
961 | + return $this->sendCommand('VRFY', "vrfy $name", [250, 251]); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | /** |
@@ -22,6 +22,6 @@ |
||
22 | 22 | */ |
23 | 23 | public function errorMessage() |
24 | 24 | { |
25 | - return '<strong>' . htmlspecialchars($this->getMessage()) . "</strong><br />\n"; |
|
25 | + return '<strong>'.htmlspecialchars($this->getMessage())."</strong><br />\n"; |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | } |
277 | 277 | |
278 | 278 | // Send the Username |
279 | - $this->sendString("USER $username" . static::LE); |
|
279 | + $this->sendString("USER $username".static::LE); |
|
280 | 280 | $pop3_response = $this->getResponse(); |
281 | 281 | if ($this->checkResponse($pop3_response)) { |
282 | 282 | // Send the Password |
283 | - $this->sendString("PASS $password" . static::LE); |
|
283 | + $this->sendString("PASS $password".static::LE); |
|
284 | 284 | $pop3_response = $this->getResponse(); |
285 | 285 | if ($this->checkResponse($pop3_response)) { |
286 | 286 | return true; |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | protected function catchWarning($errno, $errstr, $errfile, $errline) |
401 | 401 | { |
402 | 402 | $this->setError( |
403 | - 'Connecting to the POP3 server raised a PHP warning:' . |
|
403 | + 'Connecting to the POP3 server raised a PHP warning:'. |
|
404 | 404 | "errno: $errno errstr: $errstr; errfile: $errfile; errline: $errline" |
405 | 405 | ); |
406 | 406 | } |
@@ -276,11 +276,11 @@ |
||
276 | 276 | } |
277 | 277 | |
278 | 278 | // Send the Username |
279 | - $this->sendString("USER $username" . static::LE); |
|
279 | + $this->sendString("user $username" . static::LE); |
|
280 | 280 | $pop3_response = $this->getResponse(); |
281 | 281 | if ($this->checkResponse($pop3_response)) { |
282 | 282 | // Send the Password |
283 | - $this->sendString("PASS $password" . static::LE); |
|
283 | + $this->sendString("pass $password" . static::LE); |
|
284 | 284 | $pop3_response = $this->getResponse(); |
285 | 285 | if ($this->checkResponse($pop3_response)) { |
286 | 286 | return true; |
@@ -10,23 +10,23 @@ discard block |
||
10 | 10 | ini_set('display_errors', 1); |
11 | 11 | ini_set('display_startup_errors', 1); |
12 | 12 | require_once 'globals.php'; |
13 | -$g['booting'] = true; |
|
13 | +$g['booting'] = true; |
|
14 | 14 | |
15 | -unset($errorLogger,$g['error_logger']); |
|
15 | +unset($errorLogger, $g['error_logger']); |
|
16 | 16 | Util::get_pid_process('udhcp', ''); |
17 | 17 | |
18 | 18 | $if_name = 'eth1'; |
19 | -$pid_file= "/var/run/udhcpc_{$if_name}"; |
|
19 | +$pid_file = "/var/run/udhcpc_{$if_name}"; |
|
20 | 20 | $pid_pcc = Util::get_pid_process($pid_file); |
21 | -if(!empty($pid_pcc)){ |
|
21 | +if (!empty($pid_pcc)) { |
|
22 | 22 | // Завершаем старый процесс. |
23 | 23 | system("kill `cat {$pid_file}` {$pid_pcc}"); |
24 | 24 | } |
25 | 25 | |
26 | 26 | exit(0); |
27 | 27 | |
28 | -if(count($argv)===1){ |
|
29 | - $g['booting'] = false; |
|
28 | +if (count($argv) === 1) { |
|
29 | + $g['booting'] = false; |
|
30 | 30 | Cdr::create_db(); |
31 | 31 | Util::CreateLogDB(); |
32 | 32 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | Firewall::reload_firewall(); |
38 | 38 | |
39 | -}elseif (count($argv)===3){ |
|
39 | +}elseif (count($argv) === 3) { |
|
40 | 40 | // php -f /etc/inc/test.php ModuleSmartIVR InstallDB |
41 | 41 | // php -f /etc/inc/test.php ModuleSmartIVR unInstallDB |
42 | 42 | // php -f /etc/inc/test.php ModuleCTIClient unInstallDB |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $module = $argv[1] ?? ''; |
59 | 59 | $action = $argv[2] ?? ''; |
60 | 60 | $path_class = "\\Modules\\{$module}\\setup\\PbxExtensionSetup"; |
61 | - if(!class_exists($path_class)){ |
|
61 | + if (!class_exists($path_class)) { |
|
62 | 62 | $path_class = false; |
63 | 63 | echo "Класс не существует.. $path_class"; |
64 | 64 | exit(1); |
@@ -36,7 +36,7 @@ |
||
36 | 36 | |
37 | 37 | Firewall::reload_firewall(); |
38 | 38 | |
39 | -}elseif (count($argv)===3){ |
|
39 | +} elseif (count($argv)===3){ |
|
40 | 40 | // php -f /etc/inc/test.php ModuleSmartIVR InstallDB |
41 | 41 | // php -f /etc/inc/test.php ModuleSmartIVR unInstallDB |
42 | 42 | // php -f /etc/inc/test.php ModuleCTIClient unInstallDB |
@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * Удаление всех правил Firewall. |
33 | 33 | */ |
34 | - private function drop_all_rules():void { |
|
35 | - Util::mwexec('iptables -F'); |
|
36 | - Util::mwexec('iptables -X'); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Установка правил Firewall. |
|
41 | - **/ |
|
34 | + private function drop_all_rules():void { |
|
35 | + Util::mwexec('iptables -F'); |
|
36 | + Util::mwexec('iptables -X'); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Установка правил Firewall. |
|
41 | + **/ |
|
42 | 42 | public function apply_config():void { |
43 | 43 | self::fail2ban_stop(); |
44 | 44 | $this->drop_all_rules(); |
45 | - self::fail2ban_make_dirs(); |
|
45 | + self::fail2ban_make_dirs(); |
|
46 | 46 | |
47 | 47 | if($this->firewall_enable){ |
48 | 48 | $arr_command = array(); |
@@ -167,13 +167,13 @@ discard block |
||
167 | 167 | * @return string |
168 | 168 | */ |
169 | 169 | private function get_iptables_input_rule($dport='', $other_data='', $action='ACCEPT'){ |
170 | - $data_port = ''; |
|
171 | - if(trim($dport) !== ''){ |
|
172 | - $data_port= '--dport '.$dport; |
|
170 | + $data_port = ''; |
|
171 | + if(trim($dport) !== ''){ |
|
172 | + $data_port= '--dport '.$dport; |
|
173 | 173 | } |
174 | - $other_data = trim($other_data); |
|
175 | - return "iptables -A INPUT $other_data $data_port -j $action"; |
|
176 | - } |
|
174 | + $other_data = trim($other_data); |
|
175 | + return "iptables -A INPUT $other_data $data_port -j $action"; |
|
176 | + } |
|
177 | 177 | |
178 | 178 | /** |
179 | 179 | * Записываем конфиг для fail2ban. Описываем правила блокировок. |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | 'mikopbx-www' => 'iptables-allports[name=HTTP, protocol=all]' |
213 | 213 | ); |
214 | 214 | $config = "[DEFAULT]\n". |
215 | - "ignoreip = 127.0.0.1 {$user_whitelist}\n\n"; |
|
215 | + "ignoreip = 127.0.0.1 {$user_whitelist}\n\n"; |
|
216 | 216 | |
217 | 217 | $syslog_file = System::get_syslog_file(); |
218 | 218 | |
@@ -231,34 +231,34 @@ discard block |
||
231 | 231 | |
232 | 232 | $log_dir = System::get_log_dir().'/asterisk/'; |
233 | 233 | $config.= "[asterisk_security_log]\n". |
234 | - "enabled = true\n". |
|
235 | - "filter = asterisk\n". |
|
236 | - "action = iptables-allports[name=ASTERISK, protocol=all]\n". |
|
237 | - "logencoding = utf-8\n". |
|
238 | - "maxretry = {$max_retry}\n". |
|
239 | - "findtime = {$find_time}\n". |
|
240 | - "bantime = {$ban_time}\n". |
|
241 | - "logpath = {$log_dir}security_log\n\n"; |
|
234 | + "enabled = true\n". |
|
235 | + "filter = asterisk\n". |
|
236 | + "action = iptables-allports[name=ASTERISK, protocol=all]\n". |
|
237 | + "logencoding = utf-8\n". |
|
238 | + "maxretry = {$max_retry}\n". |
|
239 | + "findtime = {$find_time}\n". |
|
240 | + "bantime = {$ban_time}\n". |
|
241 | + "logpath = {$log_dir}security_log\n\n"; |
|
242 | 242 | |
243 | 243 | $config.= "[asterisk_error]\n". |
244 | - "enabled = true\n". |
|
245 | - "filter = asterisk\n". |
|
246 | - "action = iptables-allports[name=ASTERISK_ERROR, protocol=all]\n". |
|
247 | - "maxretry = {$max_retry}\n". |
|
248 | - "findtime = {$find_time}\n". |
|
249 | - "bantime = {$ban_time}\n". |
|
250 | - "logencoding = utf-8\n". |
|
251 | - "logpath = {$log_dir}error\n\n"; |
|
244 | + "enabled = true\n". |
|
245 | + "filter = asterisk\n". |
|
246 | + "action = iptables-allports[name=ASTERISK_ERROR, protocol=all]\n". |
|
247 | + "maxretry = {$max_retry}\n". |
|
248 | + "findtime = {$find_time}\n". |
|
249 | + "bantime = {$ban_time}\n". |
|
250 | + "logencoding = utf-8\n". |
|
251 | + "logpath = {$log_dir}error\n\n"; |
|
252 | 252 | |
253 | 253 | $config.= "[asterisk_public]\n". |
254 | - "enabled = true\n". |
|
255 | - "filter = asterisk\n". |
|
256 | - "action = iptables-allports[name=ASTERISK_PUBLIC, protocol=all]\n". |
|
257 | - "maxretry = {$max_retry}\n". |
|
258 | - "findtime = {$find_time}\n". |
|
259 | - "bantime = {$ban_time}\n". |
|
260 | - "logencoding = utf-8\n". |
|
261 | - "logpath = {$log_dir}messages\n\n"; |
|
254 | + "enabled = true\n". |
|
255 | + "filter = asterisk\n". |
|
256 | + "action = iptables-allports[name=ASTERISK_PUBLIC, protocol=all]\n". |
|
257 | + "maxretry = {$max_retry}\n". |
|
258 | + "findtime = {$find_time}\n". |
|
259 | + "bantime = {$ban_time}\n". |
|
260 | + "logencoding = utf-8\n". |
|
261 | + "logpath = {$log_dir}messages\n\n"; |
|
262 | 262 | |
263 | 263 | Util::file_write_content('/etc/fail2ban/jail.local',$config); |
264 | 264 | } |
@@ -8,14 +8,14 @@ discard block |
||
8 | 8 | |
9 | 9 | require_once('globals.php'); |
10 | 10 | |
11 | -class Firewall{ |
|
11 | +class Firewall { |
|
12 | 12 | private $firewall_enable; |
13 | 13 | private $fail2ban_enable; |
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Firewall constructor. |
17 | 17 | */ |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | $this->firewall_enable = false; |
20 | 20 | $this->fail2ban_enable = false; |
21 | 21 | // Получение настроек. |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $this->drop_all_rules(); |
45 | 45 | self::fail2ban_make_dirs(); |
46 | 46 | |
47 | - if($this->firewall_enable){ |
|
47 | + if ($this->firewall_enable) { |
|
48 | 48 | $arr_command = array(); |
49 | 49 | $arr_command[] = $this->get_iptables_input_rule('', '-m conntrack --ctstate ESTABLISHED,RELATED'); |
50 | 50 | // Добавляем разрешения на сервисы. |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | // Кастомизация правил firewall. |
58 | 58 | $arr_commands = []; $out = []; |
59 | 59 | Util::file_write_content('/etc/firewall_additional', ''); |
60 | - Util::mwexec("/bin/cat /etc/firewall_additional | grep -v '|' | grep -v '&'| /bin/grep '^iptables' | /bin/busybox awk -F ';' '{print $1}'",$arr_commands); |
|
61 | - Util::mwexec_commands($arr_commands,$out, 'firewall_additional'); |
|
60 | + Util::mwexec("/bin/cat /etc/firewall_additional | grep -v '|' | grep -v '&'| /bin/grep '^iptables' | /bin/busybox awk -F ';' '{print $1}'", $arr_commands); |
|
61 | + Util::mwexec_commands($arr_commands, $out, 'firewall_additional'); |
|
62 | 62 | } |
63 | - if($this->fail2ban_enable){ |
|
63 | + if ($this->fail2ban_enable) { |
|
64 | 64 | // Настройка правил бана. |
65 | 65 | $this->write_config(); |
66 | 66 | self::fail2ban_start(); |
67 | - }else{ |
|
67 | + } else { |
|
68 | 68 | self::fail2ban_stop(); |
69 | 69 | } |
70 | 70 | } |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | * Рестарт firewall. |
74 | 74 | * @return array |
75 | 75 | */ |
76 | - static function reload_firewall(){ |
|
76 | + static function reload_firewall() { |
|
77 | 77 | $result = []; |
78 | 78 | |
79 | 79 | $pid_file = '/var/run/service_reload_firewall.pid'; |
80 | - if(file_exists($pid_file)){ |
|
80 | + if (file_exists($pid_file)) { |
|
81 | 81 | $old_pid = file_get_contents($pid_file); |
82 | 82 | $process = Util::get_pid_process("^{$old_pid}"); |
83 | - if($process !== ''){ |
|
83 | + if ($process !== '') { |
|
84 | 84 | $result['result'] = 'ERROR'; |
85 | 85 | $result['data'] = 'Another restart process has not yet completed'; |
86 | 86 | return $result; |
@@ -100,12 +100,12 @@ discard block |
||
100 | 100 | * Проверка статуса fail2ban |
101 | 101 | * @return bool |
102 | 102 | */ |
103 | - private function fail2ban_is_runing(){ |
|
103 | + private function fail2ban_is_runing() { |
|
104 | 104 | $res_ping = Util::mwexec('fail2ban-client ping'); |
105 | 105 | $res_stat = Util::mwexec('fail2ban-client status'); |
106 | 106 | |
107 | 107 | $result = false; |
108 | - if($res_ping === 0 && $res_stat === 0){ |
|
108 | + if ($res_ping === 0 && $res_stat === 0) { |
|
109 | 109 | $result = true; |
110 | 110 | } |
111 | 111 | return $result; |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | /** |
115 | 115 | * Проверка запущен ли fail2ban. |
116 | 116 | */ |
117 | - static function check_fail2ban(){ |
|
117 | + static function check_fail2ban() { |
|
118 | 118 | $firewall = new Firewall(); |
119 | - if($firewall->fail2ban_enable && !$firewall->fail2ban_is_runing()){ |
|
119 | + if ($firewall->fail2ban_enable && !$firewall->fail2ban_is_runing()) { |
|
120 | 120 | self::fail2ban_start(); |
121 | 121 | } |
122 | 122 | } |
@@ -125,34 +125,34 @@ discard block |
||
125 | 125 | * Генератор правил iptables. |
126 | 126 | * @param $arr_command |
127 | 127 | */ |
128 | - private function AddFirewallRules(&$arr_command){ |
|
128 | + private function AddFirewallRules(&$arr_command) { |
|
129 | 129 | /** @var Models\FirewallRules $result */ |
130 | 130 | /** @var Models\FirewallRules $rule */ |
131 | 131 | /** @var Models\FirewallRules $rule */ |
132 | 132 | $result = Models\FirewallRules::find(); |
133 | - foreach ($result as $rule){ |
|
134 | - if($rule->portfrom !== $rule->portto && trim($rule->portto) !== ''){ |
|
135 | - $port ="{$rule->portfrom}:{$rule->portto}"; |
|
136 | - }else{ |
|
133 | + foreach ($result as $rule) { |
|
134 | + if ($rule->portfrom !== $rule->portto && trim($rule->portto) !== '') { |
|
135 | + $port = "{$rule->portfrom}:{$rule->portto}"; |
|
136 | + } else { |
|
137 | 137 | $port = $rule->portfrom; |
138 | 138 | } |
139 | 139 | /** @var Models\NetworkFilters $network_filter */ |
140 | 140 | $network_filter = Models\NetworkFilters::findFirst($rule->networkfilterid); |
141 | - if(!$network_filter){ |
|
141 | + if (!$network_filter) { |
|
142 | 142 | Util::sys_log_msg('Firewall', "network_filter_id not found {$rule->networkfilterid}"); |
143 | 143 | continue; |
144 | 144 | } |
145 | - if('0.0.0.0/0' === $network_filter->permit && $rule->action !== 'allow'){ |
|
145 | + if ('0.0.0.0/0' === $network_filter->permit && $rule->action !== 'allow') { |
|
146 | 146 | continue; |
147 | 147 | } |
148 | 148 | $other_data = "-p {$rule->protocol}"; |
149 | - $other_data .= ($network_filter===null)?'':' -s '.$network_filter->permit; |
|
150 | - if($rule->protocol === 'icmp'){ |
|
149 | + $other_data .= ($network_filter === null) ? '' : ' -s '.$network_filter->permit; |
|
150 | + if ($rule->protocol === 'icmp') { |
|
151 | 151 | $port = ''; |
152 | 152 | $other_data .= ' --icmp-type echo-request'; |
153 | 153 | } |
154 | 154 | |
155 | - $action = ($rule->action === 'allow')?'ACCEPT':'DROP'; |
|
155 | + $action = ($rule->action === 'allow') ? 'ACCEPT' : 'DROP'; |
|
156 | 156 | $arr_command[] = $this->get_iptables_input_rule($port, $other_data, $action); |
157 | 157 | } |
158 | 158 | // Разрешим все локальные подключения. |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | * @param string $action |
167 | 167 | * @return string |
168 | 168 | */ |
169 | - private function get_iptables_input_rule($dport='', $other_data='', $action='ACCEPT'){ |
|
169 | + private function get_iptables_input_rule($dport = '', $other_data = '', $action = 'ACCEPT') { |
|
170 | 170 | $data_port = ''; |
171 | - if(trim($dport) !== ''){ |
|
172 | - $data_port= '--dport '.$dport; |
|
171 | + if (trim($dport) !== '') { |
|
172 | + $data_port = '--dport '.$dport; |
|
173 | 173 | } |
174 | 174 | $other_data = trim($other_data); |
175 | 175 | return "iptables -A INPUT $other_data $data_port -j $action"; |
@@ -183,24 +183,24 @@ discard block |
||
183 | 183 | $user_whitelist = ''; |
184 | 184 | /** @var Models\Fail2BanRules $res */ |
185 | 185 | $res = Models\Fail2BanRules::findFirst("id = '1'"); |
186 | - if($res!==null){ |
|
186 | + if ($res !== null) { |
|
187 | 187 | $max_retry = $res->maxretry; |
188 | 188 | $find_time = $res->findtime; |
189 | 189 | $ban_time = $res->bantime; |
190 | 190 | $whitelist = $res->whitelist; |
191 | 191 | $arr_whitelist = explode(' ', $whitelist); |
192 | - foreach ($arr_whitelist as $ip_string){ |
|
193 | - if(Verify::is_ipaddress($ip_string)){ |
|
194 | - $user_whitelist.="$ip_string "; |
|
192 | + foreach ($arr_whitelist as $ip_string) { |
|
193 | + if (Verify::is_ipaddress($ip_string)) { |
|
194 | + $user_whitelist .= "$ip_string "; |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 | $net_filters = Models\NetworkFilters::find("newer_block_ip = '1'"); |
198 | - foreach ($net_filters as $filter){ |
|
199 | - $user_whitelist.="{$filter->permit} "; |
|
198 | + foreach ($net_filters as $filter) { |
|
199 | + $user_whitelist .= "{$filter->permit} "; |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | $user_whitelist = trim($user_whitelist); |
203 | - }else{ |
|
203 | + } else { |
|
204 | 204 | $max_retry = '10'; |
205 | 205 | $find_time = '1800'; |
206 | 206 | $ban_time = '43200'; |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | |
217 | 217 | $syslog_file = System::get_syslog_file(); |
218 | 218 | |
219 | - foreach ($jails as $jail => $action){ |
|
220 | - $config.= "[{$jail}]\n". |
|
219 | + foreach ($jails as $jail => $action) { |
|
220 | + $config .= "[{$jail}]\n". |
|
221 | 221 | "enabled = true\n". |
222 | 222 | "backend = process\n". |
223 | 223 | "logpath = {$syslog_file}\n". |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | } |
231 | 231 | |
232 | 232 | $log_dir = System::get_log_dir().'/asterisk/'; |
233 | - $config.= "[asterisk_security_log]\n". |
|
233 | + $config .= "[asterisk_security_log]\n". |
|
234 | 234 | "enabled = true\n". |
235 | 235 | "filter = asterisk\n". |
236 | 236 | "action = iptables-allports[name=ASTERISK, protocol=all]\n". |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | "bantime = {$ban_time}\n". |
241 | 241 | "logpath = {$log_dir}security_log\n\n"; |
242 | 242 | |
243 | - $config.= "[asterisk_error]\n". |
|
243 | + $config .= "[asterisk_error]\n". |
|
244 | 244 | "enabled = true\n". |
245 | 245 | "filter = asterisk\n". |
246 | 246 | "action = iptables-allports[name=ASTERISK_ERROR, protocol=all]\n". |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | "logencoding = utf-8\n". |
251 | 251 | "logpath = {$log_dir}error\n\n"; |
252 | 252 | |
253 | - $config.= "[asterisk_public]\n". |
|
253 | + $config .= "[asterisk_public]\n". |
|
254 | 254 | "enabled = true\n". |
255 | 255 | "filter = asterisk\n". |
256 | 256 | "action = iptables-allports[name=ASTERISK_PUBLIC, protocol=all]\n". |
@@ -260,13 +260,13 @@ discard block |
||
260 | 260 | "logencoding = utf-8\n". |
261 | 261 | "logpath = {$log_dir}messages\n\n"; |
262 | 262 | |
263 | - Util::file_write_content('/etc/fail2ban/jail.local',$config); |
|
263 | + Util::file_write_content('/etc/fail2ban/jail.local', $config); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | 267 | * Создаем дополнительные правила. |
268 | 268 | */ |
269 | - private function generate_jails(){ |
|
269 | + private function generate_jails() { |
|
270 | 270 | |
271 | 271 | $conf = "[INCLUDES]\n". |
272 | 272 | "before = common.conf\n". |
@@ -302,14 +302,14 @@ discard block |
||
302 | 302 | /** |
303 | 303 | * Завершение работы fail2ban; |
304 | 304 | */ |
305 | - static function fail2ban_stop(){ |
|
305 | + static function fail2ban_stop() { |
|
306 | 306 | Util::mwexec('fail2ban-client -x stop'); |
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | 310 | * Старт firewall. |
311 | 311 | */ |
312 | - static function fail2ban_start(){ |
|
312 | + static function fail2ban_start() { |
|
313 | 313 | |
314 | 314 | // Чистим битые строки, не улдаленные после отмены бана. |
315 | 315 | self::clean_fail2ban_db(); |
@@ -320,18 +320,18 @@ discard block |
||
320 | 320 | Util::mwexec($command); |
321 | 321 | } |
322 | 322 | |
323 | - static function clean_fail2ban_db(){ |
|
323 | + static function clean_fail2ban_db() { |
|
324 | 324 | /** @var Models\Fail2BanRules $res */ |
325 | 325 | $res = Models\Fail2BanRules::findFirst("id = '1'"); |
326 | - if($res!==null) { |
|
326 | + if ($res !== null) { |
|
327 | 327 | $ban_time = $res->bantime; |
328 | - }else{ |
|
328 | + } else { |
|
329 | 329 | $ban_time = '43800'; |
330 | 330 | } |
331 | 331 | $path_db = self::fail2ban_get_db_path(); |
332 | 332 | $db = new SQLite3($path_db); |
333 | 333 | $db->busyTimeout(3000); |
334 | - if(FALSE === self::table_ban_exists($db)){ |
|
334 | + if (FALSE === self::table_ban_exists($db)) { |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | $q = 'DELETE'.' from bans WHERE (timeofban+'.$ban_time.')<'.time(); |
@@ -343,28 +343,28 @@ discard block |
||
343 | 343 | * @param $ip |
344 | 344 | * @return array |
345 | 345 | */ |
346 | - static function fail2ban_unban_all($ip){ |
|
346 | + static function fail2ban_unban_all($ip) { |
|
347 | 347 | $ip = trim($ip); |
348 | 348 | $result = array('result'=>'Success'); |
349 | - if(!Verify::is_ipaddress($ip)){ |
|
349 | + if (!Verify::is_ipaddress($ip)) { |
|
350 | 350 | $result['message'] = "Not valid ip '{$ip}'."; |
351 | 351 | return $result; |
352 | 352 | } |
353 | 353 | $config = new Config(); |
354 | 354 | $fail2ban_enable = $config->get_general_settings('PBXFail2BanEnabled'); |
355 | 355 | $enable = ($fail2ban_enable == '1'); |
356 | - if($enable){ |
|
356 | + if ($enable) { |
|
357 | 357 | // Попробуем найти jail по данным DB. |
358 | 358 | // fail2ban-client unban 172.16.156.1 |
359 | 359 | // TODO Util::mwexec("fail2ban-client unban {$ip}}"); |
360 | 360 | $data = self::get_ban_ip($ip); |
361 | - foreach ($data as $row){ |
|
361 | + foreach ($data as $row) { |
|
362 | 362 | $res = self::fail2ban_unban($ip, $row['jail']); |
363 | - if($res['result']==='ERROR'){ |
|
363 | + if ($res['result'] === 'ERROR') { |
|
364 | 364 | $result = $res; |
365 | 365 | } |
366 | 366 | } |
367 | - }else{ |
|
367 | + } else { |
|
368 | 368 | $result = self::fail2ban_unban_db($ip); |
369 | 369 | } |
370 | 370 | |
@@ -377,27 +377,27 @@ discard block |
||
377 | 377 | * @param $jail |
378 | 378 | * @return array |
379 | 379 | */ |
380 | - static function fail2ban_unban($ip, $jail){ |
|
380 | + static function fail2ban_unban($ip, $jail) { |
|
381 | 381 | $res = array('result' => 'ERROR'); |
382 | 382 | $ip = trim($ip); |
383 | 383 | // Валидация... |
384 | 384 | $matches = array(); |
385 | 385 | // preg_match_all('/^[a-z-]+$/', $jail, $matches, PREG_SET_ORDER); |
386 | - if(!Verify::is_ipaddress($ip)){ |
|
386 | + if (!Verify::is_ipaddress($ip)) { |
|
387 | 387 | // это НЕ IP адрес, или не корректно указан jail. |
388 | 388 | $res['message'] = 'Not valid ip or jail.'; |
389 | 389 | return $res; |
390 | 390 | } |
391 | 391 | $path_sock = '/var/run/fail2ban/fail2ban.sock'; |
392 | - if(file_exists($path_sock) && filetype($path_sock) === 'socket'){ |
|
392 | + if (file_exists($path_sock) && filetype($path_sock) === 'socket') { |
|
393 | 393 | $out = array(); |
394 | 394 | Util::mwexec("fail2ban-client set {$jail} unbanip {$ip} 2>&1", $out); |
395 | 395 | $res_data = trim(implode('', $out)); |
396 | - if($res_data !== $ip && $res_data !== "IP $ip is not banned"){ |
|
396 | + if ($res_data !== $ip && $res_data !== "IP $ip is not banned") { |
|
397 | 397 | $res['message'] = 'Error fail2ban-client. '.$res_data; |
398 | 398 | return $res; |
399 | 399 | } |
400 | - }else{ |
|
400 | + } else { |
|
401 | 401 | $res['message'] = 'Fail2ban not run.'; |
402 | 402 | return $res; |
403 | 403 | } |
@@ -412,12 +412,12 @@ discard block |
||
412 | 412 | * @param string $jail |
413 | 413 | * @return array |
414 | 414 | */ |
415 | - static function fail2ban_unban_db($ip, $jail=''){ |
|
416 | - $jail_q = ($jail==='')?'':"AND jail = '{$jail}'"; |
|
415 | + static function fail2ban_unban_db($ip, $jail = '') { |
|
416 | + $jail_q = ($jail === '') ? '' : "AND jail = '{$jail}'"; |
|
417 | 417 | $path_db = self::fail2ban_get_db_path(); |
418 | 418 | $db = new SQLite3($path_db); |
419 | 419 | $db->busyTimeout(3000); |
420 | - if(FALSE === self::table_ban_exists($db)){ |
|
420 | + if (FALSE === self::table_ban_exists($db)) { |
|
421 | 421 | // Таблица не существует. Бана нет. |
422 | 422 | $res = [ |
423 | 423 | 'result' => 'Success', |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | |
431 | 431 | $err = $db->lastErrorMsg(); |
432 | 432 | $res = [ |
433 | - 'result' => ($err === 'not an error')?'Success':'ERROR', |
|
433 | + 'result' => ($err === 'not an error') ? 'Success' : 'ERROR', |
|
434 | 434 | 'message' => $err |
435 | 435 | ]; |
436 | 436 | |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | * Возвращает путь к файлу базы данных fail2ban. |
442 | 442 | * @return string |
443 | 443 | */ |
444 | - static function fail2ban_get_db_path(){ |
|
444 | + static function fail2ban_get_db_path() { |
|
445 | 445 | return '/var/lib/fail2ban/fail2ban.sqlite3'; |
446 | 446 | } |
447 | 447 | |
@@ -449,55 +449,55 @@ discard block |
||
449 | 449 | * Создает служебные директории и ссылки на файлы fail2ban |
450 | 450 | * @return string |
451 | 451 | */ |
452 | - static function fail2ban_make_dirs(){ |
|
452 | + static function fail2ban_make_dirs() { |
|
453 | 453 | global $g; |
454 | 454 | $res_file = self::fail2ban_get_db_path(); |
455 | 455 | $filename = basename($res_file); |
456 | 456 | |
457 | - $old_dir_db = $g['cf_path'].'/fail2ban'; |
|
457 | + $old_dir_db = $g['cf_path'].'/fail2ban'; |
|
458 | 458 | $dir_db = self::get_fail2ban_db_dir(); |
459 | 459 | |
460 | 460 | // Создаем рабочие каталоги. |
461 | 461 | $db_bd_dir = dirname($res_file); |
462 | - if(!is_dir($db_bd_dir) && !mkdir($db_bd_dir,0755, true) && !is_dir($db_bd_dir)){ |
|
462 | + if (!is_dir($db_bd_dir) && !mkdir($db_bd_dir, 0755, true) && !is_dir($db_bd_dir)) { |
|
463 | 463 | Util::log_msg_db('Fail2ban', 'Error create dir '.$db_bd_dir); |
464 | 464 | } |
465 | - if(!is_dir($dir_db) && !mkdir($dir_db,0755, true) && !is_dir($dir_db)){ |
|
465 | + if (!is_dir($dir_db) && !mkdir($dir_db, 0755, true) && !is_dir($dir_db)) { |
|
466 | 466 | Util::log_msg_db('Fail2ban', 'Error create dir '.$dir_db); |
467 | 467 | } |
468 | 468 | |
469 | 469 | $create_link = false; |
470 | 470 | |
471 | 471 | // Символическая ссылка на базу данных. |
472 | - if(@filetype($res_file) !== 'link'){ |
|
472 | + if (@filetype($res_file) !== 'link') { |
|
473 | 473 | @unlink($res_file); |
474 | 474 | $create_link = true; |
475 | - }elseif(readlink($res_file) === "$old_dir_db/$filename"){ |
|
475 | + }elseif (readlink($res_file) === "$old_dir_db/$filename") { |
|
476 | 476 | @unlink($res_file); |
477 | 477 | $create_link = true; |
478 | - if(file_exists("$old_dir_db/$filename")){ |
|
478 | + if (file_exists("$old_dir_db/$filename")) { |
|
479 | 479 | // Перемещаем файл в новое местоположение. |
480 | 480 | Util::mwexec("mv '$old_dir_db/$filename' '$dir_db/$filename'"); |
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
484 | - if($create_link === true){ |
|
484 | + if ($create_link === true) { |
|
485 | 485 | @symlink("$dir_db/$filename", $res_file); |
486 | 486 | } |
487 | 487 | return $res_file; |
488 | 488 | } |
489 | 489 | |
490 | - static function get_fail2ban_db_dir(){ |
|
491 | - if( Storage::is_storage_disk_mounted() ){ |
|
490 | + static function get_fail2ban_db_dir() { |
|
491 | + if (Storage::is_storage_disk_mounted()) { |
|
492 | 492 | $mount_point = Storage::get_media_dir(); |
493 | 493 | $db_dir = "$mount_point/fail2ban"; |
494 | - }else{ |
|
494 | + } else { |
|
495 | 495 | $db_dir = "/var/spool/fail2ban"; |
496 | 496 | } |
497 | - if(!is_dir($db_dir) && !mkdir($db_dir,0755, true) && !is_dir($db_dir)){ |
|
497 | + if (!is_dir($db_dir) && !mkdir($db_dir, 0755, true) && !is_dir($db_dir)) { |
|
498 | 498 | Util::log_msg_db('Fail2ban', 'Error create dir '.$db_dir); |
499 | 499 | } |
500 | - if(!file_exists($db_dir)){ |
|
500 | + if (!file_exists($db_dir)) { |
|
501 | 501 | $db_dir = '/tmp'; |
502 | 502 | } |
503 | 503 | return $db_dir; |
@@ -508,36 +508,36 @@ discard block |
||
508 | 508 | * @param null $ip |
509 | 509 | * @return array |
510 | 510 | */ |
511 | - static function get_ban_ip($ip = null){ |
|
511 | + static function get_ban_ip($ip = null) { |
|
512 | 512 | $result = []; |
513 | 513 | |
514 | 514 | /** @var Models\Fail2BanRules $res */ |
515 | 515 | $res = Models\Fail2BanRules::findFirst("id = '1'"); |
516 | - if($res!==null) { |
|
516 | + if ($res !== null) { |
|
517 | 517 | $ban_time = $res->bantime; |
518 | - }else{ |
|
518 | + } else { |
|
519 | 519 | $ban_time = '43800'; |
520 | 520 | } |
521 | 521 | |
522 | 522 | // Добавленн фильтр по времени бана. возвращаем только адреса, которые еще НЕ разбанены. |
523 | 523 | $q = 'SELECT'.' DISTINCT jail,ip,MAX(timeofban) AS timeofban, MAX(timeofban+'.$ban_time.') AS timeunban FROM bans where (timeofban+'.$ban_time.')>'.time(); |
524 | - if($ip !== null){ |
|
524 | + if ($ip !== null) { |
|
525 | 525 | $q .= " AND ip='{$ip}'"; |
526 | 526 | } |
527 | - $q.=' GROUP BY jail,ip'; |
|
527 | + $q .= ' GROUP BY jail,ip'; |
|
528 | 528 | |
529 | 529 | $path_db = self::fail2ban_get_db_path(); |
530 | 530 | $db = new SQLite3($path_db); |
531 | 531 | $db->busyTimeout(5000); |
532 | 532 | |
533 | - if(FALSE === self::table_ban_exists($db)){ |
|
533 | + if (FALSE === self::table_ban_exists($db)) { |
|
534 | 534 | // Таблица не существует. Бана нет. |
535 | 535 | return $result; |
536 | 536 | } |
537 | 537 | |
538 | - $results = $db->query($q); |
|
539 | - if(FALSE !== $results && $results->numColumns()>0){ |
|
540 | - while($res = $results->fetchArray(SQLITE3_ASSOC)){ |
|
538 | + $results = $db->query($q); |
|
539 | + if (FALSE !== $results && $results->numColumns() > 0) { |
|
540 | + while ($res = $results->fetchArray(SQLITE3_ASSOC)) { |
|
541 | 541 | $result[] = $res; |
542 | 542 | } |
543 | 543 | } |
@@ -550,9 +550,9 @@ discard block |
||
550 | 550 | * @param SQLite3 $db |
551 | 551 | * @return bool |
552 | 552 | */ |
553 | - static function table_ban_exists($db){ |
|
553 | + static function table_ban_exists($db) { |
|
554 | 554 | $q_check = 'SELECT'.' name FROM sqlite_master WHERE type = "table" AND name="bans"'; |
555 | - $result_check = $db->query($q_check); |
|
555 | + $result_check = $db->query($q_check); |
|
556 | 556 | $result = (FALSE !== $result_check && $result_check->fetchArray(SQLITE3_ASSOC) !== FALSE); |
557 | 557 | return $result; |
558 | 558 | } |
@@ -8,14 +8,16 @@ discard block |
||
8 | 8 | |
9 | 9 | require_once('globals.php'); |
10 | 10 | |
11 | -class Firewall{ |
|
11 | +class Firewall |
|
12 | +{ |
|
12 | 13 | private $firewall_enable; |
13 | 14 | private $fail2ban_enable; |
14 | 15 | |
15 | 16 | /** |
16 | 17 | * Firewall constructor. |
17 | 18 | */ |
18 | - public function __construct(){ |
|
19 | + public function __construct() |
|
20 | + { |
|
19 | 21 | $this->firewall_enable = false; |
20 | 22 | $this->fail2ban_enable = false; |
21 | 23 | // Получение настроек. |
@@ -64,7 +66,7 @@ discard block |
||
64 | 66 | // Настройка правил бана. |
65 | 67 | $this->write_config(); |
66 | 68 | self::fail2ban_start(); |
67 | - }else{ |
|
69 | + } else{ |
|
68 | 70 | self::fail2ban_stop(); |
69 | 71 | } |
70 | 72 | } |
@@ -73,7 +75,8 @@ discard block |
||
73 | 75 | * Рестарт firewall. |
74 | 76 | * @return array |
75 | 77 | */ |
76 | - static function reload_firewall(){ |
|
78 | + static function reload_firewall() |
|
79 | + { |
|
77 | 80 | $result = []; |
78 | 81 | |
79 | 82 | $pid_file = '/var/run/service_reload_firewall.pid'; |
@@ -100,7 +103,8 @@ discard block |
||
100 | 103 | * Проверка статуса fail2ban |
101 | 104 | * @return bool |
102 | 105 | */ |
103 | - private function fail2ban_is_runing(){ |
|
106 | + private function fail2ban_is_runing() |
|
107 | + { |
|
104 | 108 | $res_ping = Util::mwexec('fail2ban-client ping'); |
105 | 109 | $res_stat = Util::mwexec('fail2ban-client status'); |
106 | 110 | |
@@ -114,7 +118,8 @@ discard block |
||
114 | 118 | /** |
115 | 119 | * Проверка запущен ли fail2ban. |
116 | 120 | */ |
117 | - static function check_fail2ban(){ |
|
121 | + static function check_fail2ban() |
|
122 | + { |
|
118 | 123 | $firewall = new Firewall(); |
119 | 124 | if($firewall->fail2ban_enable && !$firewall->fail2ban_is_runing()){ |
120 | 125 | self::fail2ban_start(); |
@@ -125,7 +130,8 @@ discard block |
||
125 | 130 | * Генератор правил iptables. |
126 | 131 | * @param $arr_command |
127 | 132 | */ |
128 | - private function AddFirewallRules(&$arr_command){ |
|
133 | + private function AddFirewallRules(&$arr_command) |
|
134 | + { |
|
129 | 135 | /** @var Models\FirewallRules $result */ |
130 | 136 | /** @var Models\FirewallRules $rule */ |
131 | 137 | /** @var Models\FirewallRules $rule */ |
@@ -133,7 +139,7 @@ discard block |
||
133 | 139 | foreach ($result as $rule){ |
134 | 140 | if($rule->portfrom !== $rule->portto && trim($rule->portto) !== ''){ |
135 | 141 | $port ="{$rule->portfrom}:{$rule->portto}"; |
136 | - }else{ |
|
142 | + } else{ |
|
137 | 143 | $port = $rule->portfrom; |
138 | 144 | } |
139 | 145 | /** @var Models\NetworkFilters $network_filter */ |
@@ -166,7 +172,8 @@ discard block |
||
166 | 172 | * @param string $action |
167 | 173 | * @return string |
168 | 174 | */ |
169 | - private function get_iptables_input_rule($dport='', $other_data='', $action='ACCEPT'){ |
|
175 | + private function get_iptables_input_rule($dport='', $other_data='', $action='ACCEPT') |
|
176 | + { |
|
170 | 177 | $data_port = ''; |
171 | 178 | if(trim($dport) !== ''){ |
172 | 179 | $data_port= '--dport '.$dport; |
@@ -200,7 +207,7 @@ discard block |
||
200 | 207 | } |
201 | 208 | |
202 | 209 | $user_whitelist = trim($user_whitelist); |
203 | - }else{ |
|
210 | + } else{ |
|
204 | 211 | $max_retry = '10'; |
205 | 212 | $find_time = '1800'; |
206 | 213 | $ban_time = '43200'; |
@@ -266,7 +273,8 @@ discard block |
||
266 | 273 | /** |
267 | 274 | * Создаем дополнительные правила. |
268 | 275 | */ |
269 | - private function generate_jails(){ |
|
276 | + private function generate_jails() |
|
277 | + { |
|
270 | 278 | |
271 | 279 | $conf = "[INCLUDES]\n". |
272 | 280 | "before = common.conf\n". |
@@ -302,14 +310,16 @@ discard block |
||
302 | 310 | /** |
303 | 311 | * Завершение работы fail2ban; |
304 | 312 | */ |
305 | - static function fail2ban_stop(){ |
|
313 | + static function fail2ban_stop() |
|
314 | + { |
|
306 | 315 | Util::mwexec('fail2ban-client -x stop'); |
307 | 316 | } |
308 | 317 | |
309 | 318 | /** |
310 | 319 | * Старт firewall. |
311 | 320 | */ |
312 | - static function fail2ban_start(){ |
|
321 | + static function fail2ban_start() |
|
322 | + { |
|
313 | 323 | |
314 | 324 | // Чистим битые строки, не улдаленные после отмены бана. |
315 | 325 | self::clean_fail2ban_db(); |
@@ -320,12 +330,13 @@ discard block |
||
320 | 330 | Util::mwexec($command); |
321 | 331 | } |
322 | 332 | |
323 | - static function clean_fail2ban_db(){ |
|
333 | + static function clean_fail2ban_db() |
|
334 | + { |
|
324 | 335 | /** @var Models\Fail2BanRules $res */ |
325 | 336 | $res = Models\Fail2BanRules::findFirst("id = '1'"); |
326 | 337 | if($res!==null) { |
327 | 338 | $ban_time = $res->bantime; |
328 | - }else{ |
|
339 | + } else{ |
|
329 | 340 | $ban_time = '43800'; |
330 | 341 | } |
331 | 342 | $path_db = self::fail2ban_get_db_path(); |
@@ -343,7 +354,8 @@ discard block |
||
343 | 354 | * @param $ip |
344 | 355 | * @return array |
345 | 356 | */ |
346 | - static function fail2ban_unban_all($ip){ |
|
357 | + static function fail2ban_unban_all($ip) |
|
358 | + { |
|
347 | 359 | $ip = trim($ip); |
348 | 360 | $result = array('result'=>'Success'); |
349 | 361 | if(!Verify::is_ipaddress($ip)){ |
@@ -364,7 +376,7 @@ discard block |
||
364 | 376 | $result = $res; |
365 | 377 | } |
366 | 378 | } |
367 | - }else{ |
|
379 | + } else{ |
|
368 | 380 | $result = self::fail2ban_unban_db($ip); |
369 | 381 | } |
370 | 382 | |
@@ -377,7 +389,8 @@ discard block |
||
377 | 389 | * @param $jail |
378 | 390 | * @return array |
379 | 391 | */ |
380 | - static function fail2ban_unban($ip, $jail){ |
|
392 | + static function fail2ban_unban($ip, $jail) |
|
393 | + { |
|
381 | 394 | $res = array('result' => 'ERROR'); |
382 | 395 | $ip = trim($ip); |
383 | 396 | // Валидация... |
@@ -397,7 +410,7 @@ discard block |
||
397 | 410 | $res['message'] = 'Error fail2ban-client. '.$res_data; |
398 | 411 | return $res; |
399 | 412 | } |
400 | - }else{ |
|
413 | + } else{ |
|
401 | 414 | $res['message'] = 'Fail2ban not run.'; |
402 | 415 | return $res; |
403 | 416 | } |
@@ -412,7 +425,8 @@ discard block |
||
412 | 425 | * @param string $jail |
413 | 426 | * @return array |
414 | 427 | */ |
415 | - static function fail2ban_unban_db($ip, $jail=''){ |
|
428 | + static function fail2ban_unban_db($ip, $jail='') |
|
429 | + { |
|
416 | 430 | $jail_q = ($jail==='')?'':"AND jail = '{$jail}'"; |
417 | 431 | $path_db = self::fail2ban_get_db_path(); |
418 | 432 | $db = new SQLite3($path_db); |
@@ -441,7 +455,8 @@ discard block |
||
441 | 455 | * Возвращает путь к файлу базы данных fail2ban. |
442 | 456 | * @return string |
443 | 457 | */ |
444 | - static function fail2ban_get_db_path(){ |
|
458 | + static function fail2ban_get_db_path() |
|
459 | + { |
|
445 | 460 | return '/var/lib/fail2ban/fail2ban.sqlite3'; |
446 | 461 | } |
447 | 462 | |
@@ -449,7 +464,8 @@ discard block |
||
449 | 464 | * Создает служебные директории и ссылки на файлы fail2ban |
450 | 465 | * @return string |
451 | 466 | */ |
452 | - static function fail2ban_make_dirs(){ |
|
467 | + static function fail2ban_make_dirs() |
|
468 | + { |
|
453 | 469 | global $g; |
454 | 470 | $res_file = self::fail2ban_get_db_path(); |
455 | 471 | $filename = basename($res_file); |
@@ -472,7 +488,7 @@ discard block |
||
472 | 488 | if(@filetype($res_file) !== 'link'){ |
473 | 489 | @unlink($res_file); |
474 | 490 | $create_link = true; |
475 | - }elseif(readlink($res_file) === "$old_dir_db/$filename"){ |
|
491 | + } elseif(readlink($res_file) === "$old_dir_db/$filename"){ |
|
476 | 492 | @unlink($res_file); |
477 | 493 | $create_link = true; |
478 | 494 | if(file_exists("$old_dir_db/$filename")){ |
@@ -487,11 +503,12 @@ discard block |
||
487 | 503 | return $res_file; |
488 | 504 | } |
489 | 505 | |
490 | - static function get_fail2ban_db_dir(){ |
|
506 | + static function get_fail2ban_db_dir() |
|
507 | + { |
|
491 | 508 | if( Storage::is_storage_disk_mounted() ){ |
492 | 509 | $mount_point = Storage::get_media_dir(); |
493 | 510 | $db_dir = "$mount_point/fail2ban"; |
494 | - }else{ |
|
511 | + } else{ |
|
495 | 512 | $db_dir = "/var/spool/fail2ban"; |
496 | 513 | } |
497 | 514 | if(!is_dir($db_dir) && !mkdir($db_dir,0755, true) && !is_dir($db_dir)){ |
@@ -508,14 +525,15 @@ discard block |
||
508 | 525 | * @param null $ip |
509 | 526 | * @return array |
510 | 527 | */ |
511 | - static function get_ban_ip($ip = null){ |
|
528 | + static function get_ban_ip($ip = null) |
|
529 | + { |
|
512 | 530 | $result = []; |
513 | 531 | |
514 | 532 | /** @var Models\Fail2BanRules $res */ |
515 | 533 | $res = Models\Fail2BanRules::findFirst("id = '1'"); |
516 | 534 | if($res!==null) { |
517 | 535 | $ban_time = $res->bantime; |
518 | - }else{ |
|
536 | + } else{ |
|
519 | 537 | $ban_time = '43800'; |
520 | 538 | } |
521 | 539 | |
@@ -550,7 +568,8 @@ discard block |
||
550 | 568 | * @param SQLite3 $db |
551 | 569 | * @return bool |
552 | 570 | */ |
553 | - static function table_ban_exists($db){ |
|
571 | + static function table_ban_exists($db) |
|
572 | + { |
|
554 | 573 | $q_check = 'SELECT'.' name FROM sqlite_master WHERE type = "table" AND name="bans"'; |
555 | 574 | $result_check = $db->query($q_check); |
556 | 575 | $result = (FALSE !== $result_check && $result_check->fetchArray(SQLITE3_ASSOC) !== FALSE); |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | $path_db = self::fail2ban_get_db_path(); |
332 | 332 | $db = new SQLite3($path_db); |
333 | 333 | $db->busyTimeout(3000); |
334 | - if(FALSE === self::table_ban_exists($db)){ |
|
334 | + if(false === self::table_ban_exists($db)){ |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | $q = 'DELETE'.' from bans WHERE (timeofban+'.$ban_time.')<'.time(); |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | $out = array(); |
394 | 394 | Util::mwexec("fail2ban-client set {$jail} unbanip {$ip} 2>&1", $out); |
395 | 395 | $res_data = trim(implode('', $out)); |
396 | - if($res_data !== $ip && $res_data !== "IP $ip is not banned"){ |
|
396 | + if($res_data !== $ip && $res_data !== "ip $ip is not banned"){ |
|
397 | 397 | $res['message'] = 'Error fail2ban-client. '.$res_data; |
398 | 398 | return $res; |
399 | 399 | } |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | $path_db = self::fail2ban_get_db_path(); |
418 | 418 | $db = new SQLite3($path_db); |
419 | 419 | $db->busyTimeout(3000); |
420 | - if(FALSE === self::table_ban_exists($db)){ |
|
420 | + if(false === self::table_ban_exists($db)){ |
|
421 | 421 | // Таблица не существует. Бана нет. |
422 | 422 | $res = [ |
423 | 423 | 'result' => 'Success', |
@@ -530,13 +530,13 @@ discard block |
||
530 | 530 | $db = new SQLite3($path_db); |
531 | 531 | $db->busyTimeout(5000); |
532 | 532 | |
533 | - if(FALSE === self::table_ban_exists($db)){ |
|
533 | + if(false === self::table_ban_exists($db)){ |
|
534 | 534 | // Таблица не существует. Бана нет. |
535 | 535 | return $result; |
536 | 536 | } |
537 | 537 | |
538 | 538 | $results = $db->query($q); |
539 | - if(FALSE !== $results && $results->numColumns()>0){ |
|
539 | + if(false !== $results && $results->numColumns()>0){ |
|
540 | 540 | while($res = $results->fetchArray(SQLITE3_ASSOC)){ |
541 | 541 | $result[] = $res; |
542 | 542 | } |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | static function table_ban_exists($db){ |
554 | 554 | $q_check = 'SELECT'.' name FROM sqlite_master WHERE type = "table" AND name="bans"'; |
555 | 555 | $result_check = $db->query($q_check); |
556 | - $result = (FALSE !== $result_check && $result_check->fetchArray(SQLITE3_ASSOC) !== FALSE); |
|
556 | + $result = (false !== $result_check && $result_check->fetchArray(SQLITE3_ASSOC) !== false); |
|
557 | 557 | return $result; |
558 | 558 | } |
559 | 559 |
@@ -94,16 +94,16 @@ discard block |
||
94 | 94 | * @var array |
95 | 95 | */ |
96 | 96 | private $configurable = [ |
97 | - 'host', |
|
98 | - 'port', |
|
99 | - 'user', |
|
100 | - 'pass', |
|
101 | - 'token', |
|
102 | - 'lang', |
|
103 | - 'version', |
|
104 | - 'verbose', |
|
105 | - 'pedantic', |
|
106 | - 'reconnect', |
|
97 | + 'host', |
|
98 | + 'port', |
|
99 | + 'user', |
|
100 | + 'pass', |
|
101 | + 'token', |
|
102 | + 'lang', |
|
103 | + 'version', |
|
104 | + 'verbose', |
|
105 | + 'pedantic', |
|
106 | + 'reconnect', |
|
107 | 107 | ]; |
108 | 108 | |
109 | 109 | |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | public function __toString() |
152 | 152 | { |
153 | 153 | $a = [ |
154 | - 'lang' => $this->lang, |
|
155 | - 'version' => $this->version, |
|
156 | - 'verbose' => $this->verbose, |
|
157 | - 'pedantic' => $this->pedantic, |
|
158 | - ]; |
|
154 | + 'lang' => $this->lang, |
|
155 | + 'version' => $this->version, |
|
156 | + 'verbose' => $this->verbose, |
|
157 | + 'pedantic' => $this->pedantic, |
|
158 | + ]; |
|
159 | 159 | if (empty($this->user) === false) { |
160 | 160 | $a['user'] = $this->user; |
161 | 161 | } |
@@ -9,12 +9,12 @@ |
||
9 | 9 | require_once 'globals.php'; |
10 | 10 | $i = 0; |
11 | 11 | while($i < 1){ |
12 | - $lines = file(__DIR__.'/nats_log'); |
|
13 | - // Осуществим проход массива и выведем номера строк и их содержимое в виде HTML-кода. |
|
14 | - foreach ($lines as $line_num => $line) { |
|
15 | - $row = trim($line); |
|
16 | - $client = new BeanstalkClient('call_events'); |
|
17 | - $client->publish($row); |
|
18 | - } |
|
19 | - $i = $i + 1; |
|
12 | + $lines = file(__DIR__.'/nats_log'); |
|
13 | + // Осуществим проход массива и выведем номера строк и их содержимое в виде HTML-кода. |
|
14 | + foreach ($lines as $line_num => $line) { |
|
15 | + $row = trim($line); |
|
16 | + $client = new BeanstalkClient('call_events'); |
|
17 | + $client->publish($row); |
|
18 | + } |
|
19 | + $i = $i + 1; |
|
20 | 20 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | |
9 | 9 | require_once 'globals.php'; |
10 | 10 | $i = 0; |
11 | -while($i < 1){ |
|
11 | +while ($i < 1) { |
|
12 | 12 | $lines = file(__DIR__.'/nats_log'); |
13 | 13 | // Осуществим проход массива и выведем номера строк и их содержимое в виде HTML-кода. |
14 | 14 | foreach ($lines as $line_num => $line) { |
@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | // Обработчик результата запроса. |
13 | 13 | $worker = function ($message) { |
14 | - echo "Получена строка в ".strlen($message)." символов\n"; |
|
14 | + echo "Получена строка в ".strlen($message)." символов\n"; |
|
15 | 15 | }; |
16 | 16 | |
17 | 17 | $start = microtime(true); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | require_once 'Nats/autoloader.php'; |
11 | 11 | |
12 | 12 | // Обработчик результата запроса. |
13 | -$worker = function ($message) { |
|
13 | +$worker = function($message) { |
|
14 | 14 | echo "Получена строка в ".strlen($message)." символов\n"; |
15 | 15 | }; |
16 | 16 | |
@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | |
22 | 22 | echo "отправляем строку в ".strlen($q)." символов\n"; |
23 | 23 | |
24 | -while ($ch < 1000){ |
|
24 | +while ($ch < 1000) { |
|
25 | 25 | $ch++; |
26 | 26 | $q = Util::generateRandomString($ch); |
27 | 27 | $client->request('echo', $q, $worker); |
28 | 28 | // echo $result."\n"; |
29 | 29 | } |
30 | 30 | |
31 | -echo "Total time: ". (microtime(true) - $start); |
|
31 | +echo "Total time: ".(microtime(true) - $start); |
|
32 | 32 | |
33 | 33 |
@@ -10,7 +10,8 @@ |
||
10 | 10 | require_once 'Nats/autoloader.php'; |
11 | 11 | |
12 | 12 | // Обработчик результата запроса. |
13 | -$worker = function ($message) { |
|
13 | +$worker = function ($message) |
|
14 | +{ |
|
14 | 15 | echo "Получена строка в ".strlen($message)." символов\n"; |
15 | 16 | }; |
16 | 17 |
@@ -12,12 +12,12 @@ |
||
12 | 12 | $client = new \Nats\Connection(); |
13 | 13 | |
14 | 14 | $echo_worker = function ($message) { |
15 | - // echo "Получена строка в ".strlen($message)." символов\n"; |
|
16 | - $message->reply($message); |
|
15 | + // echo "Получена строка в ".strlen($message)." символов\n"; |
|
16 | + $message->reply($message); |
|
17 | 17 | }; |
18 | 18 | |
19 | 19 | while (true) { |
20 | - $client->connect(); |
|
21 | - $client->subscribe('echo', $echo_worker); |
|
22 | - $client->wait(); |
|
20 | + $client->connect(); |
|
21 | + $client->subscribe('echo', $echo_worker); |
|
22 | + $client->wait(); |
|
23 | 23 | } |
@@ -11,13 +11,13 @@ |
||
11 | 11 | |
12 | 12 | $client = new \Nats\Connection(); |
13 | 13 | |
14 | -$echo_worker = function ($message) { |
|
14 | +$echo_worker = function($message) { |
|
15 | 15 | // echo "Получена строка в ".strlen($message)." символов\n"; |
16 | 16 | $message->reply($message); |
17 | 17 | }; |
18 | 18 | |
19 | 19 | while (true) { |
20 | 20 | $client->connect(); |
21 | - $client->subscribe('echo', $echo_worker); |
|
21 | + $client->subscribe('echo', $echo_worker); |
|
22 | 22 | $client->wait(); |
23 | 23 | } |
@@ -11,7 +11,8 @@ |
||
11 | 11 | |
12 | 12 | $client = new \Nats\Connection(); |
13 | 13 | |
14 | -$echo_worker = function ($message) { |
|
14 | +$echo_worker = function ($message) |
|
15 | +{ |
|
15 | 16 | // echo "Получена строка в ".strlen($message)." символов\n"; |
16 | 17 | $message->reply($message); |
17 | 18 | }; |