Passed
Push — develop ( c1cb26...7b17c4 )
by Nikolay
04:47 queued 10s
created
src/Core/System/Network.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
         }
30 30
 
31 31
         Processes::killByName('pcapsipdump');
32
-        $log_dir = System::getLogDir() . '/pcapsipdump';
32
+        $log_dir = System::getLogDir().'/pcapsipdump';
33 33
         Util::mwMkdir($log_dir);
34 34
 
35 35
         $network         = new Network();
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
         foreach ($arr_eth as $eth) {
39 39
             $pid_file = "/var/run/pcapsipdump_{$eth}.pid";
40 40
             Processes::mwExecBg(
41
-                $pcapsipdumpPath . ' -T 120 -P ' . $pid_file . ' -i ' . $eth . ' -m \'^(INVITE|REGISTER)$\' -L ' . $log_dir . '/dump.db'
41
+                $pcapsipdumpPath.' -T 120 -P '.$pid_file.' -i '.$eth.' -m \'^(INVITE|REGISTER)$\' -L '.$log_dir.'/dump.db'
42 42
             );
43 43
         }
44 44
     }
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
         /** @var \MikoPBX\Common\Models\LanInterfaces $res */
147 147
         $res = LanInterfaces::findFirst("internet = '1'");
148 148
         if (null !== $res) {
149
-            if ( ! empty($res->primarydns) && '127.0.0.1' != $res->primarydns) {
149
+            if (!empty($res->primarydns) && '127.0.0.1' != $res->primarydns) {
150 150
                 $dns[] = $res->primarydns;
151 151
             }
152
-            if ( ! empty($res->secondarydns) && '127.0.0.1' != $res->secondarydns) {
152
+            if (!empty($res->secondarydns) && '127.0.0.1' != $res->secondarydns) {
153 153
                 $dns[] = $res->secondarydns;
154 154
             }
155 155
         }
@@ -165,39 +165,39 @@  discard block
 block discarded – undo
165 165
     public function generatePdnsdConfig($named_dns): void
166 166
     {
167 167
         $tempDir   = $this->di->getShared('config')->path('core.tempDir');
168
-        $cache_dir = $tempDir . '/pdnsd/cache';
168
+        $cache_dir = $tempDir.'/pdnsd/cache';
169 169
         Util::mwMkdir($cache_dir);
170 170
 
171
-        $conf = 'global {' . "\n" .
172
-            '	perm_cache=10240;' . "\n" .
173
-            '	cache_dir="' . $cache_dir . '";' . "\n" .
174
-            '	pid_file = /var/run/pdnsd.pid;' . "\n" .
175
-            '	run_as="nobody";' . "\n" .
176
-            '	server_ip = 127.0.0.1;' . "\n" .
177
-            '	status_ctl = on;' . "\n" .
178
-            '	query_method=udp_tcp;' . "\n" .
179
-            '	min_ttl=15m;' . "\n" .
180
-            '	max_ttl=1w;' . "\n" .
181
-            '	timeout=10;' . "\n" .
182
-            '	neg_domain_pol=on;' . "\n" .
183
-            '	run_as=root;' . "\n" .
184
-            '	daemon=on;' . "\n" .
185
-            '}' . "\n" .
186
-            'server {' . "\n" .
187
-            '	label = "main";' . "\n" .
188
-            '	ip = ' . implode(', ', $named_dns) . ';' . "\n" .
189
-            '	interface=lo;' . "\n" .
190
-            '	uptest=if;' . "\n" .
191
-            '	interval=10m;' . "\n" .
192
-            '	purge_cache=off;' . "\n" .
171
+        $conf = 'global {'."\n".
172
+            '	perm_cache=10240;'."\n".
173
+            '	cache_dir="'.$cache_dir.'";'."\n".
174
+            '	pid_file = /var/run/pdnsd.pid;'."\n".
175
+            '	run_as="nobody";'."\n".
176
+            '	server_ip = 127.0.0.1;'."\n".
177
+            '	status_ctl = on;'."\n".
178
+            '	query_method=udp_tcp;'."\n".
179
+            '	min_ttl=15m;'."\n".
180
+            '	max_ttl=1w;'."\n".
181
+            '	timeout=10;'."\n".
182
+            '	neg_domain_pol=on;'."\n".
183
+            '	run_as=root;'."\n".
184
+            '	daemon=on;'."\n".
185
+            '}'."\n".
186
+            'server {'."\n".
187
+            '	label = "main";'."\n".
188
+            '	ip = '.implode(', ', $named_dns).';'."\n".
189
+            '	interface=lo;'."\n".
190
+            '	uptest=if;'."\n".
191
+            '	interval=10m;'."\n".
192
+            '	purge_cache=off;'."\n".
193 193
             '}';
194 194
 
195
-        $pdnsdConfFile  = '/etc/pdnsd.conf';
195
+        $pdnsdConfFile = '/etc/pdnsd.conf';
196 196
         $savedConf = '';
197
-        if(file_exists($pdnsdConfFile)){
197
+        if (file_exists($pdnsdConfFile)) {
198 198
             $savedConf = file_get_contents($pdnsdConfFile);
199 199
         }
200
-        if($savedConf !== $conf){
200
+        if ($savedConf !== $conf) {
201 201
             file_put_contents($pdnsdConfFile, $conf);
202 202
         }
203 203
         $pdnsdPath = Util::which('pdnsd');
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         if (!empty($pid) && $savedConf === $conf) {
206 206
             // Выполним дополнительную проверку, работает ли сервер.
207 207
             $resultResolve = gethostbynamel('lic.miko.ru');
208
-            if($resultResolve !== false){
208
+            if ($resultResolve !== false) {
209 209
                 // Ничего делать не нужно. Конфиг не изменился. Рестарт не требуется.
210 210
                 return;
211 211
             }
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                  */
284 284
                 $pid_file = "/var/run/udhcpc_{$if_name}";
285 285
                 $pid_pcc  = Processes::getPidOfProcess($pid_file);
286
-                if ( ! empty($pid_pcc) && file_exists($pid_file)) {
286
+                if (!empty($pid_pcc) && file_exists($pid_file)) {
287 287
                     // Завершаем старый процесс.
288 288
                     $killPath = Util::which('kill');
289 289
                     $catPath  = Util::which('cat');
@@ -412,10 +412,10 @@  discard block
 block discarded – undo
412 412
 
413 413
             $result = [''];
414 414
             if (file_exists('/etc/static-routes')) {
415
-                $command = "{$catPath} /etc/static-routes " .
416
-                    "| {$grepPath} '^rout' " .
417
-                    "| {$busyboxPath} awk -F ';' '{print $1}' " .
418
-                    "| {$grepPath} '{$if_name}\$' " .
415
+                $command = "{$catPath} /etc/static-routes ".
416
+                    "| {$grepPath} '^rout' ".
417
+                    "| {$busyboxPath} awk -F ';' '{print $1}' ".
418
+                    "| {$grepPath} '{$if_name}\$' ".
419 419
                     "| {$awkPath} -F 'dev {$if_name}' '{ print $1 }'";
420 420
                 Processes::mwExec($command, $result);
421 421
             }
@@ -425,19 +425,19 @@  discard block
 block discarded – undo
425 425
 
426 426
             if ($if_data['vlanid'] > 0) {
427 427
                 // Пока только статика.
428
-                $lan_config = "auto {$if_data['interface_orign']}.{$if_data['vlanid']}\n" .
429
-                    "iface {$if_data['interface_orign']}.{$if_data['vlanid']} inet static \n" .
430
-                    "address {$ipaddr}\n" .
431
-                    "netmask {$subnet}\n" .
432
-                    "gateway {$gateway}\n" .
433
-                    "dns-nameservers 127.0.0.1\n" .
434
-                    "vlan_raw_device {$if_data['interface_orign']}\n" .
435
-                    "{$routs_add}\n" .
428
+                $lan_config = "auto {$if_data['interface_orign']}.{$if_data['vlanid']}\n".
429
+                    "iface {$if_data['interface_orign']}.{$if_data['vlanid']} inet static \n".
430
+                    "address {$ipaddr}\n".
431
+                    "netmask {$subnet}\n".
432
+                    "gateway {$gateway}\n".
433
+                    "dns-nameservers 127.0.0.1\n".
434
+                    "vlan_raw_device {$if_data['interface_orign']}\n".
435
+                    "{$routs_add}\n".
436 436
                     "{$routs_rem}\n";
437 437
             } elseif (trim($if_data['dhcp']) === '1') {
438
-                $lan_config = "auto {$if_name}\n" .
439
-                    "iface {$if_name} inet dhcp\n" .
440
-                    "{$routs_add}\n" .
438
+                $lan_config = "auto {$if_name}\n".
439
+                    "iface {$if_name} inet dhcp\n".
440
+                    "{$routs_add}\n".
441 441
                     "{$routs_rem}\n";
442 442
             } else {
443 443
                 if (empty($ipaddr)) {
@@ -450,13 +450,13 @@  discard block
 block discarded – undo
450 450
                     echo "Caught exception: $ipaddr $subnet", $e->getMessage(), "\n";
451 451
                     continue;
452 452
                 }
453
-                $lan_config = "auto {$if_name}\n" .
454
-                    "iface {$if_name} inet static\n" .
455
-                    "address {$ipaddr}\n" .
456
-                    "netmask {$subnet}\n" .
457
-                    "gateway {$gateway}\n" .
458
-                    "dns-nameservers 127.0.0.1\n" .
459
-                    "{$routs_add}\n" .
453
+                $lan_config = "auto {$if_name}\n".
454
+                    "iface {$if_name} inet static\n".
455
+                    "address {$ipaddr}\n".
456
+                    "netmask {$subnet}\n".
457
+                    "gateway {$gateway}\n".
458
+                    "dns-nameservers 127.0.0.1\n".
459
+                    "{$routs_add}\n".
460 460
                     "{$routs_rem}\n";
461 461
             }
462 462
             file_put_contents("/etc/network/interfaces.d/{$if_name}", $lan_config);
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
         $net_mask = explode(".", $net_mask);
548 548
 
549 549
         foreach ($net_mask as $oct_ect) {
550
-            $bits += strlen(str_replace("0", "", decbin((int)$oct_ect)));
550
+            $bits += strlen(str_replace("0", "", decbin((int) $oct_ect)));
551 551
         }
552 552
 
553 553
         return $bits;
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
         $data->hostname  = 'mikopbx';
611 611
         $data->domain    = '';
612 612
         $data->topology  = 'private';
613
-        $data->primarydns= '';
613
+        $data->primarydns = '';
614 614
         $data->save();
615 615
 
616 616
         return $data->toArray();
@@ -631,15 +631,15 @@  discard block
 block discarded – undo
631 631
     public function hostnameConfigure(): void
632 632
     {
633 633
         $data       = Network::getHostName();
634
-        $hosts_conf = "127.0.0.1 localhost\n" .
634
+        $hosts_conf = "127.0.0.1 localhost\n".
635 635
             "127.0.0.1 {$data['hostname']}\n";
636
-        if ( ! empty($data['domain'])) {
636
+        if (!empty($data['domain'])) {
637 637
             $hosts_conf .= "127.0.0.1 {$data['hostname']}.{$data['domain']}\n";
638 638
         }
639 639
         Util::fileWriteContent('/etc/hosts', $hosts_conf);
640 640
 
641 641
         $hostnamePath = Util::which('hostname');
642
-        Processes::mwExec($hostnamePath . ' ' . escapeshellarg("{$data['hostname']}"));
642
+        Processes::mwExec($hostnamePath.' '.escapeshellarg("{$data['hostname']}"));
643 643
     }
644 644
 
645 645
     /**
@@ -653,12 +653,12 @@  discard block
 block discarded – undo
653 653
 
654 654
         $pidFile = '/var/run/openvpn.pid';
655 655
         $pid     = Processes::getPidOfProcess('openvpn');
656
-        if ( ! empty($pid)) {
656
+        if (!empty($pid)) {
657 657
             // Завершаем процесс.
658 658
             $busyboxPath = Util::which('busybox');
659 659
             Processes::mwExec("{$busyboxPath} kill '$pid'");
660 660
         }
661
-        if ( ! empty($data)) {
661
+        if (!empty($data)) {
662 662
             $openvpnPath = Util::which('openvpn');
663 663
             Processes::mwExecBg("{$openvpnPath} --config /etc/openvpn.ovpn --writepid {$pidFile}", '/dev/null', 5);
664 664
         }
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
     {
847 847
         /** @var LanInterfaces $res */
848 848
         $res = LanInterfaces::findFirst("interface = '$name' AND vlanid=0");
849
-        if ($res === null || !$this->settingsIsChange($data, $res->toArray()) ) {
849
+        if ($res === null || !$this->settingsIsChange($data, $res->toArray())) {
850 850
             return;
851 851
         }
852 852
         foreach ($data as $key => $value) {
@@ -886,8 +886,8 @@  discard block
 block discarded – undo
886 886
      */
887 887
     private function settingsIsChange(array $data, array $dbData):bool{
888 888
         $isChange = false;
889
-        foreach ($data as $key => $value){
890
-            if(!isset($dbData[$key]) || $value === $dbData[$key]){
889
+        foreach ($data as $key => $value) {
890
+            if (!isset($dbData[$key]) || $value === $dbData[$key]) {
891 891
                 continue;
892 892
             }
893 893
             $isChange = true;
@@ -932,7 +932,7 @@  discard block
 block discarded – undo
932 932
     {
933 933
         // Настройка по умолчанию.
934 934
         $interface = trim(getenv('interface'));
935
-        if ( ! Util::isSystemctl()) {
935
+        if (!Util::isSystemctl()) {
936 936
             // Для MIKO LFS Edition.
937 937
             $busyboxPath = Util::which('busybox');
938 938
             Processes::mwExec("{$busyboxPath} ifconfig $interface 192.168.2.1 netmask 255.255.255.0");
Please login to merge, or discard this patch.