-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSystemadmin.class.php
More file actions
1261 lines (1228 loc) · 51.4 KB
/
Systemadmin.class.php
File metadata and controls
1261 lines (1228 loc) · 51.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace FreePBX\modules;
use splitbrain\PHPArchive\Tar;
/*
* Class stub for BMO Module class
* In _Construct you may remove the database line if you don't use it
* In getActionbar change extdisplay to align with whatever variable you use to decide if the page is in edit mode.
*
*/
class Systemadmin extends \FreePBX_Helpers implements \BMO {
public function __construct($freepbx = null) {
if ($freepbx == null) {
throw new Exception("Not given a FreePBX Object");
}
$this->FreePBX = $freepbx;
$this->db = $freepbx->Database;
}
public function install() {
$spooldir = $this->FreePBX->Config->get('ASTSPOOLDIR');
$dir = is_dir("$spooldir/packetcapture") || mkdir("$spooldir/packetcapture", 0755, true);
$this->addCronJob();
}
public function uninstall() {
$sql = "DROP TABLE IF EXISTS `systemadmin_settings`, `systemadmin_logs`, `systemadmin_packetcapture`";
try {
$sth = $this->db->prepare($sql);
return $sth->execute();
} catch(PDOException $e) {
return $e->getMessage();
}
$spooldir = $this->FreePBX->Config->get('ASTSPOOLDIR');
$this->deleteDirectory("$spooldir/packetcapture");
}
public function doConfigPageInit($page) {}
public function chownFreepbx () {
$files = array(
array('type' => 'rdir',
'path' => '/var/spool/asterisk/packetcapture',
'perms' => 0755)
);
return $files;
}
public function deleteDirectory($str) {
if (is_file($str)) {
return unlink($str);
}
elseif (is_dir($str)) {
$scan = glob(rtrim($str, '/').'/*');
foreach($scan as $index=>$path) {
deleteAll($path);
}
return @rmdir($str);
}
}
public function addCronJob() {
$this->removeCronJob();
$this->FreePBX->Job()->addCommand("systemadmin", "updateCaptureTable", "[ -e /usr/local/freepbx/php/updateCaptureTable.php ] && /usr/local/freepbx/php/updateCaptureTable.php", "0 6 * * *");
$this->FreePBX->Job()->addCommand("systemadmin", "sendCaptureWaring", "[ -e /usr/local/freepbx/php/sendCaptureWaring.php ] && /usr/local/freepbx/php/sendCaptureWaring.php", "0 7 * * *");
$this->FreePBX->Job()->addCommand("systemadmin", "sendStorageNotifications", "[ -e /usr/local/freepbx/php/sendStorageNotifications.php ] && /usr/local/freepbx/php/sendStorageNotifications.php", "@hourly");
}
public function removeCronJob() {
$this->FreePBX->Job()->remove("systemadmin", "updateCaptureTable");
$this->FreePBX->Job()->remove("systemadmin", "sendCaptureWaring");
$this->FreePBX->Job()->remove("systemadmin", "sendStorageNotifications");
}
/*
* Write log-entry to systemadmin_logs and return mysql_insert_id
* Needed to prevent unprivileged users with shell access to call our setuid-binaries directly
* @param module-name
* @return id of the inserted entry
*/
public function write_log($module = '') {
if ($module == '') {
//module should not be empty
return -1;
}
$id = 0;
$module = preg_replace('/[^a-z]*/', '', $module);
$username = (isset($_SESSION['AMP_user']->username) ? $_SESSION['AMP_user']->username : 'unknown');
$timestamp = time();
$sql = "INSERT INTO systemadmin_logs(username, module, timestamp) VALUES('$username', '$module', '$timestamp')";
$stmt = $this->db->prepare($sql);
$stmt->execute();
$id = $this->db->lastInsertId();
return $id;
}
public function delete_log($id = 0) {
if ($id == 0) {
return false;
}
$id = preg_replace('/[^0-9]*/', '', $id);
$sql = "DELETE FROM systemadmin_logs WHERE id='$id'";
$stmt = $this->db->prepare($sql);
$stmt->execute();
return true;
}
//get all network interfaces
public function getInterfaces() {
$interfaces = array();
if ($handle = opendir('/sys/class/net/')) {
while (false !== ($file = readdir($handle))) {
if ($file == '.' || $file == '..' || $file == 'lo' || $file == 'bonding_masters') {
continue;
}
$interfaces[$file]['name'] = $file;
$interfaces[$file]['unconfigured'] = true;
$interfaces[$file]['ipv4_assignment'] = '';
$interfaces[$file]['ipv4_address'] = '';
$interfaces[$file]['ipv4_gateway'] = '';
$interfaces[$file]['ipv6_assignment'] = '';
$interfaces[$file]['ipv6_address'] = array();
$interfaces[$file]['ipv6_gateway'] = '';
$interfaces[$file]['ipv6_accept_ra'] = '1'; //0 = off, 1 = on, 2 = on + forwarding
$interfaces[$file]['ipv6_autoconf'] = '0'; //0 = off, 1 = on
$interfaces[$file]['dyn_ipv4_address'] = "";
$interfaces[$file]['dyn_ipv6_address'] = "";
$interfaces[$file]['bonding_status'] = 'none';
$interfaces[$file]['bonding_master'] = '';
$interfaces[$file]['bond_member'] = array();
$interfaces[$file]['bond_parameter'] = array();
if (is_dir('/proc/net/bonding')) {
exec("/usr/bin/grep -rl $file /proc/net/bonding", $output_is_bonding_slave, $rc_is_bonding_slave);
if($rc_is_bonding_slave == 0) {
$interfaces[$file]['bonding_status'] = 'slave';
$interfaces[$file]['bonding_master'] = basename($output_is_bonding_slave[0]);
}
}
if (file_exists('/sys/class/net/bonding_masters')) {
exec("/usr/bin/grep -q $file /sys/class/net/bonding_masters", $output_is_bonding_master, $rc_is_bonding_master);
if ($rc_is_bonding_master == 0) {
$interfaces[$file]['bonding_status'] = 'master';
}
}
}
return $interfaces;
}
}
public function get_ifupdown_config ($interface) {
exec("/usr/bin/grep -rl $interface[name] /etc/network/interfaces.d", $output, $rc);
$i = 0;
$last_i = 0;
$last_inserted = ""; //if the adddress is not in cidr format (--> address and netmask are configured in different lines) we need to know what the last entry was (ipv4 or ipv6?)
if ($rc == 0) { //file for this interface exists in /etc/network/interfaces.d
$file = fopen("$output[0]", "r") or die("Unable to open file!");
while(!feof($file)) {
$line = trim(fgets($file), " \t\x00\v");
if (str_contains($line, "iface $interface[name] inet static") || str_contains($line, "iface $interface[name] inet manual") || str_contains($line, "iface $interface[name] inet dhcp") || str_contains($line, "iface $interface[name] inet6 static") || str_contains($line, "iface $interface[name] inet6 manual") || str_contains($line, "iface $interface[name] inet6 dhcp") || str_contains($line, "iface $interface[name] inet6 auto")) {
$interface['unconfigured'] = false;
if (preg_match("/iface $interface[name] inet\s(.*)/i", $line, $matches)) {
$interface['ipv4_assignment'] = $matches[1];
}
else if (preg_match("/iface $interface[name] inet6\s(.*)/i", $line, $matches)) {
$interface['ipv6_assignment'] = $matches[1];
}
}
else if (preg_match("/address\s(.*)/i", $line, $matches)) {
if (str_contains($matches[1], '/')) { //address is configured in CIDR notation
$temp = explode("/", $matches[1]);
if (filter_var($temp[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_address'] = "$temp[0]/$temp[1]";
}
else if (filter_var($temp[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_address'][$i] = "$temp[0]/$temp[1]";
$last_i = $i;
$i++;
}
}
else {
if (filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_address'] = $matches[1];
$last_inserted = "ipv4";
}
else if (filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_address'][$i] = $matches[1];
$last_inserted = "ipv6";
$last_i = $i;
$i++;
}
}
}
else if (preg_match("/netmask\s(.*)/i", $line, $matches)) {
if ($last_inserted == ipv4) {
if (is_numeric($matches[1]) && $matches[1] <= 32) { //netmask is not in dotted-decimal
$interface['ipv4_address'] .= "/$matches[1]";
}
else { //netmask is in dotted-decimal-format so we need to convert it
$long = ip2long($matches[1]);
$base = ip2long('255.255.255.255');
$temp_netmask = 32-log(($long ^ $base)+1,2);
$interface['ipv4_address'] .= "/$temp_netmask";
}
}
else {
$interface['ipv6_address'][$last_i] .= "/$matches[1]";
}
}
else if (preg_match("/gateway\s(.*)/i", $line, $matches)) {
if (filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_gateway'] = $matches[1];
}
else if (filter_var($temp[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_gateway'] = $matches[1];
}
}
else if (preg_match("/autoconf\s(.*)/i", $line, $matches)) {
$interface['ipv6_autoconf'] = $matches[1];
}
else if (preg_match("/accept_ra\s(.*)/i", $line, $matches)) {
$interface['ipv6_accept_ra'] = $matches[1];
}
else if (preg_match("/bond-slaves\s(.*)/i", $line, $matches)) {
$interface['bond_member'] = explode(' ', $matches[1]);
}
else if (preg_match("/bond-mode\s(.*)/i", $line, $matches)) {
if ($matches[1] == "balance-rr" || $matches[1] == "0") {
$interface['bond_parameter']['mode'] = 'balance-rr';
}
else if ($matches[1] == "active-backup" || $matches[1] == "1") {
$interface['bond_parameter']['mode'] = 'active-backup';
}
else if ($matches[1] == "balance-xor" || $matches[1] == "2") {
$interface['bond_parameter']['mode'] = 'balance-xor';
}
else if ($matches[1] == "broadcast" || $matches[1] == "3") {
$interface['bond_parameter']['mode'] = 'broadcast';
}
else if ($matches[1] == "802.3ad" || $matches[1] == "4") {
$interface['bond_parameter']['mode'] = '802.3ad';
}
else if ($matches[1] == "balance-tlbr" || $matches[1] == "5") {
$interface['bond_parameter']['mode'] = 'balance-tlb';
}
else if ($matches[1] == "balance-alb" || $matches[1] == "6") {
$interface['bond_parameter']['mode'] = 'balance-alb';
}
}
else if (preg_match("/bond-lacp-rate\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['lacp_rate'] = $matches[1];
}
elseif (preg_match("/bond-miimon\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['mii_monitor_interval'] = $matches[1];
}
elseif (preg_match("/bond-min-links\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['min_links'] = $matches[1];
}
elseif (preg_match("/bond-xmit-hash-policy\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['transmit_hash_policy'] = $matches[1];
}
elseif (preg_match("/bond-ad-select\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['ad_select'] = $matches[1];
}
elseif (preg_match("/bond-all-slaves-active\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['all_members_active'] = $matches[1];
}
elseif (preg_match("/bond-arp-interval\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['arp_interval'] = $matches[1];
}
elseif (preg_match("/bond-arp-ip-target\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['arp_ip_targets'] = $matches[1];
}
elseif (preg_match("/bond-arp-validate\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['arp_validate'] = $matches[1];
}
elseif (preg_match("/bond-arp-all-targets\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['arp_all_targets'] = $matches[1];
}
elseif (preg_match("/bond-updelay\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['up_delay'] = $matches[1];
}
elseif (preg_match("/bond-downdelay\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['down_delay'] = $matches[1];
}
elseif (preg_match("/fail-over-mac-policy\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['fail_over_mac_policy'] = $matches[1];
}
elseif (preg_match("/bond-num-grat-arp\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['gratuitous_arp'] = $matches[1];
}
elseif (preg_match("/bond-packets-per-slave\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['packets_per_member'] = $matches[1];
}
elseif (preg_match("/bond-primary-reselect\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['primary_reselect_policy'] = $matches[1];
}
elseif (preg_match("/bond-resend-igmp\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['resend_igmp'] = $matches[1];
}
elseif (preg_match("/bond-lp-interval\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['learn_packet_interval'] = $matches[1];
}
elseif (preg_match("/bond-primary\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['primary'] = $matches[1];
}
}
fclose($file);
}
else { //no file for this interface exists in /etc/network/interfaces.d
exec("/usr/bin/grep $interface[name] /etc/network/interfaces", $output, $rc);
if ($rc == 0) { //interface is configured in /etc/network/interfaces
$ouputLines = false;
$file = fopen("/etc/network/interfaces", "r") or die("Unable to open file!");
while(!feof($file)) {
$line = trim(fgets($file), " \t\x00\v");
if (str_contains($line, "allow-hotplug $interface[name]") || str_contains($line, "iface $interface[name]")) {
$ouputLines = true;
}
else if (str_contains($line, "allow-hotplug") || str_contains($line, "iface")) {
$ouputLines = false;
}
if ($ouputLines) {
if (str_contains($line, "iface $interface[name] inet static") || str_contains($line, "iface $interface[name] inet manual") || str_contains($line, "iface $interface[name] inet dhcp") || str_contains($line, "iface $interface[name] inet6 static") || str_contains($line, "iface $interface[name] inet6 manual") || str_contains($line, "iface $interface[name] inet6 dhcp") || str_contains($line, "iface $interface[name] inet6 auto")) {
$interface['unconfigured'] = false;
if (preg_match("/iface $interface[name] inet\s(.*)/i", $line, $matches)) {
$interface['ipv4_assignment'] = $matches[1];
}
else if (preg_match("/iface $interface[name] inet6\s(.*)/i", $line, $matches)) {
$interface['ipv6_assignment'] = $matches[1];
}
}
else if (preg_match("/address\s(.*)/i", $line, $matches)) {
if (str_contains($matches[1], '/')) { //address is configured in CIDR notation
$temp = explode("/", $matches[1]);
if (filter_var($temp[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_address'] = "$temp[0]/$temp[1]";
}
else if (filter_var($temp[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_address'][$i] = "$temp[0]/$temp[1]";
$last_i = $i;
$i++;
}
}
else {
if (filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_address'] = $matches[1];
}
else if (filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_address'][$i] = $matches[1];
$last_i = $i;
$i++;
}
}
}
else if (preg_match("/netmask\s(.*)/i", $line, $matches)) {
if (str_contains($matches[1], ".") || (is_numeric($matches[1]) && $matches[1] <= 32)) {
$interface['ipv4_address'] .= "/$matches[1]";
}
else {
$interface['ipv6_address'][$last_i] .= "/$matches[1]";
}
}
else if (preg_match("/gateway\s(.*)/i", $line, $matches)) {
if (filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_gateway'] = $matches[1];
}
else if (filter_var($temp[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_gateway'] = $matches[1];
}
}
else if (preg_match("/autoconf\s(.*)/i", $line, $matches)) {
$interface['ipv6_autoconf'] = $matches[1];
}
else if (preg_match("/accept_ra\s(.*)/i", $line, $matches)) {
$interface['ipv6_accept_ra'] = $matches[1];
}
else if (preg_match("/bond-slaves\s(.*)/i", $line, $matches)) {
$interface['bond_member'] = explode(' ', $matches[1]);
}
else if (preg_match("/bond-mode\s(.*)/i", $line, $matches)) {
if ($matches[1] == "balance-rr" || $matches[1] == "0") {
$interface['bond_parameter']['mode'] = 'balance-rr';
}
else if ($matches[1] == "active-backup" || $matches[1] == "1") {
$interface['bond_parameter']['mode'] = 'active-backup';
}
else if ($matches[1] == "balance-xor" || $matches[1] == "2") {
$interface['bond_parameter']['mode'] = 'balance-xor';
}
else if ($matches[1] == "broadcast" || $matches[1] == "3") {
$interface['bond_parameter']['mode'] = 'broadcast';
}
else if ($matches[1] == "802.3ad" || $matches[1] == "4") {
$interface['bond_parameter']['mode'] = '802.3ad';
}
else if ($matches[1] == "balance-tlbr" || $matches[1] == "5") {
$interface['bond_parameter']['mode'] = 'balance-tlb';
}
else if ($matches[1] == "balance-alb" || $matches[1] == "6") {
$interface['bond_parameter']['mode'] = 'balance-alb';
}
}
else if (preg_match("/bond-lacp-rate\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['lacp_rate'] = $matches[1];
}
elseif (preg_match("/bond-miimon\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['mii_monitor_interval'] = $matches[1];
}
elseif (preg_match("/bond-min-links\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['min_links'] = $matches[1];
}
elseif (preg_match("/bond-xmit-hash-policy\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['transmit_hash_policy'] = $matches[1];
}
elseif (preg_match("/bond-ad-select\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['ad_select'] = $matches[1];
}
elseif (preg_match("/bond-all-slaves-active\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['all_members_active'] = $matches[1];
}
elseif (preg_match("/bond-arp-interval\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['arp_interval'] = $matches[1];
}
elseif (preg_match("/bond-arp-ip-target\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['arp_ip_targets'] = $matches[1];
}
elseif (preg_match("/bond-arp-validate\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['arp_validate'] = $matches[1];
}
elseif (preg_match("/bond-arp-all-targets\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['arp_all_targets'] = $matches[1];
}
elseif (preg_match("/bond-updelay\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['up_delay'] = $matches[1];
}
elseif (preg_match("/bond-downdelay\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['down_delay'] = $matches[1];
}
elseif (preg_match("/fail-over-mac-policy\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['fail_over_mac_policy'] = $matches[1];
}
elseif (preg_match("/bond-num-grat-arp\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['gratuitous_arp'] = $matches[1];
}
elseif (preg_match("/bond-packets-per-slave\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['packets_per_member'] = $matches[1];
}
elseif (preg_match("/bond-primary-reselect\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['primary_reselect_policy'] = $matches[1];
}
elseif (preg_match("/bond-resend-igmp\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['resend_igmp'] = $matches[1];
}
elseif (preg_match("/bond-lp-interval\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['learn_packet_interval'] = $matches[1];
}
elseif (preg_match("/bond-primary\s(.*)/i", $line, $matches)) {
$interface['bond_parameter']['primary'] = $matches[1];
}
}
}
fclose($file);
}
}
exec("/usr/sbin/ip -4 address show dev $interface[name] | grep inet | grep dynamic", $output_dyn_4, $rc_ipv4);
if ($rc_ipv4 == 0) {
$interface['dyn_ipv4_address'] = '';
foreach($output_dyn_4 AS $temp) {
$temp = explode(" ", $temp);
$interface['dyn_ipv4_address'] .= $temp[5];
}
}
exec("/usr/sbin/ip -6 address show dev $interface[name] | grep inet | grep dynamic", $output_dyn_6, $rc_ipv6);
if ($rc_ipv6 == 0) {
$interface['dyn_ipv6_address'] = '';
foreach($output_dyn_6 AS $temp) {
$temp = explode(" ", $temp);
$interface['dyn_ipv6_address'] .= "$temp[5], ";
}
}
return $interface;
}
public function get_systemd_networkd_config ($interface) {
$i = 0;
exec("/usr/bin/grep -l Name=$interface[name] /etc/systemd/network/*.network", $output, $rc);
if ($rc == 0) {
$interface['unconfigured'] = false;
$file = fopen("$output[0]", "r") or die("Unable to open file!");
while(!feof($file)) {
$line = trim(fgets($file), " \t\x00\v");
if (preg_match("/DHCP=(.*)/i", $line, $matches)) {
if ($matches[1] == "yes") {
$interface['ipv4_assignment'] = 'dhcp';
$interface['ipv6_assignment'] = 'dhcp';
}
else if ($matches[1] == "ipv4") {
$interface['ipv4_assignment'] = 'dhcp';
}
else if ($matches[1] == "ipv6") {
$interface['ipv6_assignment'] = 'dhcp';
}
}
else if (preg_match("/Address=(.*)/i", $line, $matches)) {
$temp = explode("/", $matches[1]);
if (filter_var($temp[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_address'] = "$temp[0]/$temp[1]";
$interface['ipv4_assignment'] = 'static';
}
else if (filter_var($temp[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_address'][$i] = "$temp[0]/$temp[1]";
$interface['ipv6_assignment'] = 'static';
$i++;
}
}
else if (preg_match("/Gateway=(.*)/i", $line, $matches)) {
if (filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_gateway'] = $matches[1];
}
else if (filter_var($temp[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_gateway'] = $matches[1];
}
}
else if (preg_match("/IPv6AcceptRA=(.*)/i", $line, $matches)) {
if ($matches[1] == "true") {
$interface['ipv6_accept_ra'] = "1";
}
else {
$interface['ipv6_accept_ra'] = "0";
}
}
}
fclose($file);
if ($interface['bonding_status'] == "master") {
exec("/usr/bin/grep -l Bond=$interface[name] /etc/systemd/network/*.network", $output_bond_member, $rc_bond_member);
if ($rc_bond_member == 0) {
foreach($output_bond_member AS $member_file) {
$output_member_name = "";
$rc_bond_parameter = 0;
//get interface name of the bond slaves
exec("/usr/bin/grep Name $member_file | awk -F'=' {'print $2'}", $output_member_name, $rc_member_name);
if ($rc_member_name == 0) {
$temp_member[] = $output_member_name[0];
}
//networkd configures the Primary interface not in the parameter-file (see below), but in the .network file of the interface
exec("/usr/bin/grep PrimarySlave $member_file", $output_bond_primary, $rc_bond_primary);
if ($rc_bond_primary == 0) {
$bond_primary = explode('=', $output_bond_primary[0]);
if ($bond_primary[1] == "true") {
exec("/usr/bin/grep Name $member_file | awk -F'=' {'print $2'}", $output_primary_name, $rc_primary_name);
if($rc_primary_name == 0) {
$interface['bond_parameter']['primary'] = $output_primary_name[0];
}
}
}
}
$interface['bond_member'] = $temp_member;
}
//Get Bond parameter
exec("/usr/bin/grep -l Name=$interface[name] /etc/systemd/network/*.netdev", $output_bond_parameter, $rc_bond_parameter);
if($rc_bond_parameter == 0) {
$parameter_file = fopen("$output_bond_parameter[0]", "r") or die("Unable to open file!");
while(!feof($parameter_file)) {
$parameter_line = trim(fgets($parameter_file), " \t\x00\v");
if (preg_match("/Mode=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['mode'] = $matches[1];
}
else if (preg_match("/LACPTransmitRate=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['lacp_rate'] = $matches[1];
}
elseif (preg_match("/MIIMonitorSec=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['mii_monitor_interval'] = $matches[1];
//this parameter is configured in seconds by networkd and a 's' is added to the value, so we have to remove the 's' and we need to convert the value to milliseconds
rtrim($interface['bond_parameter']['mii_monitor_interval'], 's');
$interface['bond_parameter']['mii_monitor_interval'] = (int)$interface['bond_parameter']['mii_monitor_interval'] *1000;
}
elseif (preg_match("/MinLinks=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['min_links'] = $matches[1];
}
elseif (preg_match("/TransmitHashPolicy=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['transmit_hash_policy'] = $matches[1];
}
elseif (preg_match("/AdSelect=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['ad_select'] = $matches[1];
}
elseif (preg_match("/AllSlavesActive=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['all_members_active'] = $matches[1];
}
elseif (preg_match("/ARPIntervalSec=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['arp_interval'] = $matches[1];
//this parameter is configured in seconds by networkd and a 's' is added to the value, so we have to remove the 's' and we need to convert the value to milliseconds
rtrim($interface['bond_parameter']['arp_interval'], 's');
$interface['bond_parameter']['arp_interval'] = (int)$interface['bond_parameter']['arp_interval'] *1000;
}
elseif (preg_match("/ARPIPTargets=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['arp_ip_targets'] = str_replace(' ', ',', $matches[1]);
}
elseif (preg_match("/ARPValidate=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['arp_validate'] = $matches[1];
}
elseif (preg_match("/ARPAllTargets=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['arp_all_targets'] = $matches[1];
}
elseif (preg_match("/UpDelaySec=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['up_delay'] = $matches[1];
//this parameter is configured in seconds by networkd and a 's' is added to the value, so we have to remove the 's' and we need to convert the value to milliseconds
rtrim($interface['bond_parameter']['up_delay'], 's');
$interface['bond_parameter']['up_delay'] = (int)$interface['bond_parameter']['up_delay'] *1000;
}
elseif (preg_match("/DownDelaySec=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['down_delay'] = $matches[1];
//this parameter is configured in seconds by networkd and a 's' is added to the value, so we have to remove the 's' and we need to convert the value to milliseconds
rtrim($interface['bond_parameter']['down_delay'], 's');
$interface['bond_parameter']['down_delay'] = (int)$interface['bond_parameter']['down_delay'] *1000;
}
elseif (preg_match("/FailOverMACPolicy=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['fail_over_mac_policy'] = $matches[1];
}
elseif (preg_match("/GratuitousARP=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['gratuitous_arp'] = $matches[1];
}
elseif (preg_match("/PacketsPerSlave=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['packets_per_member'] = $matches[1];
}
elseif (preg_match("/PrimaryReselectPolicy=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['primary_reselect_policy'] = $matches[1];
}
elseif (preg_match("/ResendIGMP=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['resend_igmp'] = $matches[1];
}
elseif (preg_match("/LearnPacketIntervalSec=(.*)/i", $parameter_line, $matches)) {
$interface['bond_parameter']['learn_packet_interval'] = $matches[1];
//this parameter is configured in seconds by networkd and a 's' is added to the value, so we have to remove the 's' and we need to convert the value to milliseconds
rtrim($interface['bond_parameter']['learn_packet_interval'], 's');
$interface['bond_parameter']['learn_packet_interval'] = (int)$interface['bond_parameter']['learn_packet_interval'] *1000;
}
}
fclose($parameter_file);
}
}
}
exec("/usr/sbin/ip -4 address show dev $interface[name] | grep inet | grep dynamic", $output_dyn_4, $rc_ipv4);
if ($rc_ipv4 == 0) {
$interface['dyn_ipv4_address'] = '';
foreach($output_dyn_4 AS $temp) {
$temp = explode(" ", $temp);
$ip = explode("/", $temp[5]);
$interface['dyn_ipv4_address'] .= $ip[0];
}
}
exec("/usr/sbin/ip -6 address show dev $interface[name] | grep inet | grep dynamic", $output_dyn_6, $rc_ipv6);
if ($rc_ipv6 == 0) {
$interface['dyn_ipv6_address'] = '';
foreach($output_dyn_6 AS $temp) {
$temp = explode(" ", $temp);
$ip = explode("/", $temp[5]);
$interface['dyn_ipv6_address'] .= "$ip[0]<br>\n";
}
}
return $interface;
}
public function get_nm_config ($interface) {
if (is_dir("/proc/sys/net/ipv6/conf/$interface[name]")) {
$interface['ipv6_accept_ra'] = trim(file_get_contents("/proc/sys/net/ipv6/conf/$interface[name]/accept_ra"));
}
exec("/usr/bin/nmcli -t -f all device show $interface[name]", $output, $rc);
if ($rc == 0) {
$interface['unconfigured'] = false;
foreach($output AS $line) {
if (preg_match("/BOND.SLAVES:(.*)/i", $line, $matches)) {
$interface['bond_member'] = explode(' ', $matches[1]);
}
if (preg_match("/GENERAL.CONNECTION:(.*)/i", $line, $matches)) {
$interface['nm_connection'] = $matches[1];
exec("/usr/bin/nmcli -t connection show $matches[1]", $connection, $rc_connection);
if ($rc_connection == 0) {
foreach($connection AS $con) {
if (preg_match("/ipv4.method:(.*)/i", $con, $ipv4_method)) {
$ipv4_method = explode(":", $ipv4_method[0]);
if ($ipv4_method[1] == "auto") {
$interface['ipv4_assignment'] = "dhcp";
}
else if ($ipv4_method[1] == "manual") {
$interface['ipv4_assignment'] = "static";
}
else {
$interface['ipv4_assignment'] = "unconfigured";
}
}
else if (preg_match("/ipv6.method:(.*)/i", $con, $ipv6_method)) {
$ipv6_method = explode(":", $ipv6_method[0]);
if ($ipv6_method[1] == "dhcp") {
$interface['ipv6_assignment'] = "dhcp";
$interface['ipv6_autoconf'] = '0';
}
else if ($ipv6_method[1] == "auto") {
$interface['ipv6_assignment'] = "dhcp";
$interface['ipv6_autoconf'] = '1';
}
else if ($ipv6_method[1] == "manual") {
$interface['ipv6_assignment'] = "static";
}
else {
$interface['ipv6_assignment'] = "unconfigured";
}
}
else if (preg_match("/ipv4.addresses:(.*)/i", $con, $ipv4_address)) {
$ipv4_address = explode(":", $ipv4_address[0]);
$ipv4_address = explode("/", $ipv4_address[1]);
if (filter_var($ipv4_address[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_address'] = "$ipv4_address[0]/$ipv4_address[1]";
}
}
else if (preg_match("/ipv6.addresses:(.*)/i", $con, $ipv6_address)) {
$ipv6_address = explode(":", $ipv6_address[0], 2);
$ipv6_address = explode(", ", $ipv6_address[1]);
$i = 0;
foreach($ipv6_address AS $entry) {
$entry = explode("/", $entry);
if (filter_var($entry[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_address'][$i] = "$entry[0]/$entry[1]";
$i++;
}
}
}
else if (preg_match("/ipv4.gateway:(.*)/i", $con, $ipv4_gateway)) {
$temp = explode(":", $ipv4_gateway[0]);
if (filter_var($temp[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_gateway'] = $temp[1];
}
}
else if (preg_match("/ipv6.gateway:(.*)/i", $con, $ipv6_gateway)) {
$temp = explode(":", $ipv6_gateway[0], 2);
if (filter_var($temp[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_gateway'] = $temp[1];
}
}
else if (preg_match("/bond.options:(.*)/i", $con, $bond_options)) {
$temp_options = explode(":", $bond_options[0]);
foreach($temp_options AS $b_option) {
$options = explode(',', $b_option);
foreach($options AS $option) {
if (preg_match("/mode=(.*)/i", $option, $matches_option)) {
if ($matches_option[1] == "balance-rr" || $matches_option[1] == "0") {
$interface['bond_parameter']['mode'] = 'balance-rr';
}
else if ($matches_option[1] == "active-backup" || $matches_option[1] == "1") {
$interface['bond_parameter']['mode'] = 'active-backup';
}
else if ($matches_option[1] == "balance-xor" || $matches_option[1] == "2") {
$interface['bond_parameter']['mode'] = 'balance-xor';
}
else if ($matches_option[1] == "broadcast" || $matches_option[1] == "3") {
$interface['bond_parameter']['mode'] = 'broadcast';
}
else if ($matches_option[1] == "802.3ad" || $matches_option[1] == "4") {
$interface['bond_parameter']['mode'] = '802.3ad';
}
else if ($matches_option[1] == "balance-tlb" || $matches_option[1] == "5") {
$interface['bond_parameter']['mode'] = 'balance-tlb';
}
else if ($matches_option[1] == "balance-alb" || $matches_option[1] == "6") {
$interface['bond_parameter']['mode'] = 'balance-alb';
}
}
else if (preg_match("/lacp_rate=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['lacp_rate'] = $matches_option[1];
}
elseif (preg_match("/miimon=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['mii_monitor_interval'] = $matches_option[1];
}
elseif (preg_match("/min_links=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['min_links'] = $matches_option[1];
}
elseif (preg_match("/xmit_hash_policy=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['transmit_hash_policy'] = $matches_option[1];
}
elseif (preg_match("/ad_select=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['ad_select'] = $matches_option[1];
}
elseif (preg_match("/all_slaves_active=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['all_members_active'] = $matches_option[1];
}
elseif (preg_match("/arp_interval=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['arp_interval'] = $matches_option[1];
}
elseif (preg_match("/arp_ip_target=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['arp_ip_targets'] = $matches_option[1];
}
elseif (preg_match("/arp_validate=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['arp_validate'] = $matches_option[1];
}
elseif (preg_match("/arp_all_targets=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['arp_all_targets'] = $matches_option[1];
}
elseif (preg_match("/updelay=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['up_delay'] = $matches_option[1];
}
elseif (preg_match("/downdelay=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['down_delay'] = $matches_option[1];
}
elseif (preg_match("/fail_over_mac=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['fail_over_mac_policy'] = $matches_option[1];
}
elseif (preg_match("/num_grat_arp=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['gratuitous_arp'] = $matches_option[1];
}
elseif (preg_match("/packets_per_slave=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['packets_per_member'] = $matches_option[1];
}
elseif (preg_match("/primary_reselect=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['primary_reselect_policy'] = $matches_option[1];
}
elseif (preg_match("/resend_igmp=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['resend_igmp'] = $matches_option[1];
}
elseif (preg_match("/lp_interval=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['learn_packet_interval'] = $matches_option[1];
}
elseif (preg_match("/primary=(.*)/i", $option, $matches_option)) {
$interface['bond_parameter']['primary'] = $matches_option[1];
}
}
}
}
}
}
}
}
if ($interface['bonding_status'] == "master" && $interface['bond_member'][0] == "") {
$name = array();
//This interface is a bond but we were unable to fetch the slaves. So we need to loop through each connection to find the bond-member and update the bonding-status of the meber (this happens in balance-alb)
exec("/usr/bin/nmcli -t connection show", $output_loop_connections, $rc_loop_connections);
if ($rc_loop_connections == 0) {
foreach($output_loop_connections AS $loop) {
$output_lcon = "";
$output_lname = "";
$rc_lcon = -1;
$rc_lname = -1;
$lcon = explode(':', $loop);
exec("/usr/bin/nmcli -t connection show $lcon[0] | /usr/bin/grep connection.master:$interface[name]", $output_lcon, $rc_lcon);
if ($rc_lcon == 0) {
exec("/usr/bin/nmcli -t connection show $lcon[0] | /usr/bin/grep connection.interface-name", $output_lname, $rc_lname);
if($rc_lname == 0) {
$temp_name = explode(':', $output_lname[0]);
$name[] = $temp_name[1];
}
}
}
}
$interface['bond_member'] = $name;
}
}
exec("/usr/sbin/ip -4 address show dev $interface[name] | grep inet | grep dynamic", $output_dyn_4, $rc_ipv4);
if ($rc_ipv4 == 0) {
$interface['dyn_ipv4_address'] = '';
foreach($output_dyn_4 AS $temp) {
$temp = explode(" ", $temp);
$ip = explode("/", $temp[5]);
$interface['dyn_ipv4_address'] .= $ip[0];
}
}
exec("/usr/sbin/ip -6 address show dev $interface[name] | grep inet | grep dynamic", $output_dyn_6, $rc_ipv6);
if ($rc_ipv6 == 0) {
$interface['dyn_ipv6_address'] = '';
foreach($output_dyn_6 AS $temp) {
$temp = explode(" ", $temp);
$ip = explode("/", $temp[5]);
$interface['dyn_ipv6_address'] .= "$ip[0]<br>\n";
}
}
return $interface;
}
public function get_netplan_config ($interface) {
/*if ($interface['bonding_status'] == "slave") {
return;
}*/
//Netplan configuration files are only accessible by root. We need to fetch them by a program which has setuid-bit enabled
// the 2>&1 at the end of the next line is required to catch any error messages
if ($interface['bonding_status'] == "none") {
$type = "ethernets";
}
else {
$type = "bonds";
}
exec("/usr/local/freepbx/bin/get_netplan_config --interface $interface[name] --type $type 2>&1", $temp_interface, $rc);
if ($rc != 0) {
$err_msg = "";
foreach($temp_interface AS $line) {
$err_msg .= "$line\n";
}
throw new \Exception("Can't get neplan config for interface $interface[name]: $err_msg");
}
else {
//Check if interface is unconfigured
exec("/usr/local/freepbx/bin/get_netplan_config --interface $interface[name] --type $type --check_configured 2>&1", $output, $rc_check);
if ($rc_check != 0) {
$err_msg = "";
foreach($temp_interface AS $line) {
$err_msg .= "$line\n";
}
throw new \Exception("Can't get neplan config for interface $interface[name]: $err_msg");
}
if ($output == "0") {
$interface['unconfigured'] = false;
}
$i = 0;
$interface['ipv6_autoconf'] = "1"; //Netplan has no option to configure autoconf;
foreach($temp_interface AS $line) {
if (preg_match("/dhcp4:\s(.*)/i", $line, $matches)) {
if ($matches[1] == "true") {
$interface['ipv4_assignment'] = "dhcp";
}
}
else if (preg_match("/dhcp6:\s(.*)/i", $line, $matches)) {
if ($matches[1] == "true") {
$interface['ipv6_assignment'] = "dhcp";
}
}
else if (preg_match("/ip_address:\s(.*)/i", $line, $matches)) {
$temp = explode(", ", $matches[1]);
foreach($temp AS $temp1) {
$ip_addr = explode("/", $temp1);
if (filter_var($ip_addr[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_address'] = "$ip_addr[0]/$ip_addr[1]";
$interface['ipv4_assignment'] = "static";
}
else if (filter_var($ip_addr[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_address'][$i] = "$ip_addr[0]/$ip_addr[1]";
$interface['ipv6_assignment'] = "static";
$i++;
}
}
}
else if (preg_match("/routes:\s(.*)/i", $line, $matches)) {
if (preg_match("/to:default,\svia:(.*)|to:0.0.0.0,\svia:(.*)|to:::\/0,\svia(.*)/i", $matches[1], $gateway_addr)) {
$gateway_addr = explode(", ", $gateway_addr[1]);
if (filter_var($gateway_addr[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$interface['ipv4_gateway'] = $gateway_addr[0];
}
else if (filter_var($gateway_addr[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$interface['ipv6_gateway'] = $gateway_addr[0];
}
}
}
else if (preg_match("/accept_ra:\s(.*)/i", $line, $matches)) {
if ($matches[1] == "false") {
$interface['ipv6_accept_ra'] = 0;
}
else {
$interface['ipv6_accept_ra'] = 1;
}
}
else if (preg_match("/interfaces:\s(.*)/i", $line, $matches)) {
$interface['bond_member'] = explode(', ', $matches[1]);
}
else if (preg_match("/parameters:\s(.*)/i", $line, $matches)) {
$parameters = explode('; ', $matches[1]);
foreach($parameters AS $parameter) {
$param = explode(':', $parameter);
if ($param[0] == 'mode') {
$interface['bond_parameter']['mode'] = $param[1];
}
elseif ($param[0] == 'lacp-rate') {
$interface['bond_parameter']['lacp_rate'] = $param[1];
}
elseif ($param[0] == 'mii-monitor-interval') {
$interface['bond_parameter']['mii_monitor_interval'] = $param[1];
}
elseif ($param[0] == 'min-links') {
$interface['bond_parameter']['min_links'] = $param[1];
}
elseif ($param[0] == 'transmit-hash-policy') {
$interface['bond_parameter']['transmit_hash_policy'] = $param[1];
}
elseif ($param[0] == 'ad-select') {
$interface['bond_parameter']['ad_select'] = $param[1];
}
elseif ($param[0] == 'all-members-active') {
$interface['bond_parameter']['all_members_active'] = $param[1];
}
elseif ($param[0] == 'arp-interval') {
$interface['bond_parameter']['arp_interval'] = $param[1];
}
elseif ($param[0] == 'arp-ip-targets') {
$interface['bond_parameter']['arp_ip_targets'] = str_replace(' -', '', $param[1]);
}
elseif ($param[0] == 'arp-validate') {
$interface['bond_parameter']['arp_validate'] = $param[1];
}
elseif ($param[0] == 'arp-all-targets') {
$interface['bond_parameter']['arp_all_targets'] = $param[1];
}
elseif ($param[0] == 'up-delay') {