@@ -32,34 +32,34 @@ |
||
32 | 32 | |
33 | 33 | # Update Subnet master |
34 | 34 | foreach ($rlist as $sect_id => $sect_check) { |
35 | - # Skip empty sections |
|
36 | - if (!$edata[$sect_id]) { continue; } |
|
37 | - |
|
38 | - # Grab a subnet and find its closest master |
|
39 | - foreach ($edata[$sect_id] as &$c_subnet) { |
|
40 | - if ($c_subnet['action'] == "edit") { |
|
41 | - |
|
42 | - # We only need id and new master |
|
43 | - $values = array("id"=>$c_subnet['id'], "masterSubnetId"=>$c_subnet['new_masterSubnetId']); |
|
44 | - |
|
45 | - # update |
|
46 | - $c_subnet['result'] = $Admin->object_modify("subnets", $c_subnet['action'], "id", $values); |
|
47 | - |
|
48 | - if ($c_subnet['result']) { |
|
49 | - $trc = $colors[$c_subnet['action']]; |
|
50 | - $msg = "Master ".$c_subnet['action']." successful."; |
|
51 | - } else { |
|
52 | - $trc = "danger"; |
|
53 | - $msg = "Master ".$c_subnet['action']." failed."; |
|
54 | - } |
|
55 | - |
|
56 | - $rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$c_subnet['action']]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>"; |
|
57 | - $rows.="<td>".$sect_names[$sect_id]."</td><td>".$c_subnet['ip']."/".$c_subnet['mask']."</td>"; |
|
58 | - $rows.="<td>".$c_subnet['description']."</td><td>".$vrf_name[$c_subnet['vrfId']]."</td><td>"; |
|
59 | - $rows.=$c_subnet['new_master']."</td><td>"._($msg)."</td></tr>\n"; |
|
60 | - |
|
61 | - } |
|
62 | - } |
|
35 | + # Skip empty sections |
|
36 | + if (!$edata[$sect_id]) { continue; } |
|
37 | + |
|
38 | + # Grab a subnet and find its closest master |
|
39 | + foreach ($edata[$sect_id] as &$c_subnet) { |
|
40 | + if ($c_subnet['action'] == "edit") { |
|
41 | + |
|
42 | + # We only need id and new master |
|
43 | + $values = array("id"=>$c_subnet['id'], "masterSubnetId"=>$c_subnet['new_masterSubnetId']); |
|
44 | + |
|
45 | + # update |
|
46 | + $c_subnet['result'] = $Admin->object_modify("subnets", $c_subnet['action'], "id", $values); |
|
47 | + |
|
48 | + if ($c_subnet['result']) { |
|
49 | + $trc = $colors[$c_subnet['action']]; |
|
50 | + $msg = "Master ".$c_subnet['action']." successful."; |
|
51 | + } else { |
|
52 | + $trc = "danger"; |
|
53 | + $msg = "Master ".$c_subnet['action']." failed."; |
|
54 | + } |
|
55 | + |
|
56 | + $rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$c_subnet['action']]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>"; |
|
57 | + $rows.="<td>".$sect_names[$sect_id]."</td><td>".$c_subnet['ip']."/".$c_subnet['mask']."</td>"; |
|
58 | + $rows.="<td>".$c_subnet['description']."</td><td>".$vrf_name[$c_subnet['vrfId']]."</td><td>"; |
|
59 | + $rows.=$c_subnet['new_master']."</td><td>"._($msg)."</td></tr>\n"; |
|
60 | + |
|
61 | + } |
|
62 | + } |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | print "<table class='table table-condensed table-hover' id='resultstable'><tbody>"; |
@@ -33,29 +33,29 @@ |
||
33 | 33 | |
34 | 34 | # import VRFs |
35 | 35 | foreach ($data as &$cdata) { |
36 | - if (($cdata['action'] == "add") || ($cdata['action'] == "edit")) { |
|
37 | - # set update array |
|
38 | - $values = array("vrfId"=>$cdata['vrfId'], |
|
39 | - "name"=>$cdata['name'], |
|
40 | - "rd"=>$cdata['rd'], |
|
41 | - "description"=>$cdata['description'] |
|
42 | - ); |
|
43 | - # update |
|
44 | - $cdata['result'] = $Admin->object_modify("vrf", $cdata['action'], "vrfId", $values); |
|
36 | + if (($cdata['action'] == "add") || ($cdata['action'] == "edit")) { |
|
37 | + # set update array |
|
38 | + $values = array("vrfId"=>$cdata['vrfId'], |
|
39 | + "name"=>$cdata['name'], |
|
40 | + "rd"=>$cdata['rd'], |
|
41 | + "description"=>$cdata['description'] |
|
42 | + ); |
|
43 | + # update |
|
44 | + $cdata['result'] = $Admin->object_modify("vrf", $cdata['action'], "vrfId", $values); |
|
45 | 45 | |
46 | - if ($cdata['result']) { |
|
47 | - $trc = $colors[$cdata['action']]; |
|
48 | - $msg = "VRF ".$cdata['action']." successful."; |
|
49 | - } else { |
|
50 | - $trc = "danger"; |
|
51 | - $msg = "VRF ".$cdata['action']." failed."; |
|
52 | - } |
|
53 | - $rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$cdata['action']]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td> |
|
46 | + if ($cdata['result']) { |
|
47 | + $trc = $colors[$cdata['action']]; |
|
48 | + $msg = "VRF ".$cdata['action']." successful."; |
|
49 | + } else { |
|
50 | + $trc = "danger"; |
|
51 | + $msg = "VRF ".$cdata['action']." failed."; |
|
52 | + } |
|
53 | + $rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$cdata['action']]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td> |
|
54 | 54 | <td>".$cdata['name']."</td> |
55 | 55 | <td>".$cdata['rd']."</td> |
56 | 56 | <td>".$cdata['description']."</td> |
57 | 57 | <td>"._($msg)."</td></tr>"; |
58 | - } |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | print "<table class='table table-condensed table-hover' id='resultstable'><tbody>"; |
@@ -27,60 +27,60 @@ |
||
27 | 27 | $today = date("Ymd-His"); |
28 | 28 | |
29 | 29 | if (!is_dir($upload_dir) || !is_writable($upload_dir)) { |
30 | - echo '{"status":"error", "error":"Upload directory is not writable, or does not exist."}'; |
|
31 | - exit; |
|
30 | + echo '{"status":"error", "error":"Upload directory is not writable, or does not exist."}'; |
|
31 | + exit; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /* no errors */ |
35 | 35 | if(isset($_FILES['file']) && $_FILES['file']['error'] == 0) { |
36 | - //wrong extension |
|
36 | + //wrong extension |
|
37 | 37 | if(!in_array(strtolower($filetype), $allowed)) { |
38 | - echo '{"status":"error", "error":"Invalid document type"}'; |
|
38 | + echo '{"status":"error", "error":"Invalid document type"}'; |
|
39 | 39 | exit; |
40 | 40 | } |
41 | - //if cannot move |
|
42 | - elseif(!move_uploaded_file($_FILES["file"]["tmp_name"], $upload_dir."data_import.".$filetype )) { |
|
43 | - echo '{"status":"error", "error":"Cannot move file to upload dir"}'; |
|
44 | - exit; |
|
45 | - } |
|
46 | - //other errors |
|
47 | - elseif($_FILES['file']['error'] != 0) { |
|
48 | - echo '{"status":"error", "error":"Error: '.$_FILES['file']['error'].'" }'; |
|
41 | + //if cannot move |
|
42 | + elseif(!move_uploaded_file($_FILES["file"]["tmp_name"], $upload_dir."data_import.".$filetype )) { |
|
43 | + echo '{"status":"error", "error":"Cannot move file to upload dir"}'; |
|
49 | 44 | exit; |
50 | - } |
|
51 | - else { |
|
52 | - //default - success |
|
45 | + } |
|
46 | + //other errors |
|
47 | + elseif($_FILES['file']['error'] != 0) { |
|
48 | + echo '{"status":"error", "error":"Error: '.$_FILES['file']['error'].'" }'; |
|
49 | + exit; |
|
50 | + } |
|
51 | + else { |
|
52 | + //default - success |
|
53 | 53 | |
54 | - // grab first row from CSV |
|
55 | - if (strtolower($filetype) == "csv") { |
|
56 | - /* get file to string */ |
|
57 | - $filehdl = fopen('upload/data_import.csv', 'r'); |
|
58 | - $data = fgets($filehdl); |
|
59 | - fclose($filehdl); |
|
54 | + // grab first row from CSV |
|
55 | + if (strtolower($filetype) == "csv") { |
|
56 | + /* get file to string */ |
|
57 | + $filehdl = fopen('upload/data_import.csv', 'r'); |
|
58 | + $data = fgets($filehdl); |
|
59 | + fclose($filehdl); |
|
60 | 60 | |
61 | - /* format file */ |
|
62 | - $data = str_replace( array("\r\n","\r") , "" , $data); //remove line break |
|
63 | - $data = preg_split("/[;,]/", $data); //split by comma or semi-colon |
|
61 | + /* format file */ |
|
62 | + $data = str_replace( array("\r\n","\r") , "" , $data); //remove line break |
|
63 | + $data = preg_split("/[;,]/", $data); //split by comma or semi-colon |
|
64 | 64 | |
65 | - foreach ($data as $col) { |
|
66 | - $firstrow[] = $col; |
|
67 | - } |
|
68 | - } |
|
69 | - // grab first row from XLS |
|
70 | - elseif(strtolower($filetype) == "xls") { |
|
71 | - # get excel object |
|
72 | - require_once(dirname(__FILE__) . '/../../../functions/php-excel-reader/excel_reader2.php'); //excel reader 2.21 |
|
73 | - $data = new Spreadsheet_Excel_Reader('upload/data_import.xls', false); |
|
74 | - $sheet = 0; $row = 1; |
|
65 | + foreach ($data as $col) { |
|
66 | + $firstrow[] = $col; |
|
67 | + } |
|
68 | + } |
|
69 | + // grab first row from XLS |
|
70 | + elseif(strtolower($filetype) == "xls") { |
|
71 | + # get excel object |
|
72 | + require_once(dirname(__FILE__) . '/../../../functions/php-excel-reader/excel_reader2.php'); //excel reader 2.21 |
|
73 | + $data = new Spreadsheet_Excel_Reader('upload/data_import.xls', false); |
|
74 | + $sheet = 0; $row = 1; |
|
75 | 75 | |
76 | - for($col=1;$col<=$data->colcount($sheet);$col++) { |
|
77 | - $firstrow[] = $data->val($row,$col,$sheet); |
|
78 | - } |
|
79 | - } |
|
76 | + for($col=1;$col<=$data->colcount($sheet);$col++) { |
|
77 | + $firstrow[] = $data->val($row,$col,$sheet); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - echo '{"status":"success","expfields":'.json_encode($expfields,true).',"impfields":'.json_encode($firstrow,true).',"filetype":'.json_encode($filetype,true).'}'; |
|
82 | - exit; |
|
83 | - } |
|
81 | + echo '{"status":"success","expfields":'.json_encode($expfields,true).',"impfields":'.json_encode($firstrow,true).',"filetype":'.json_encode($filetype,true).'}'; |
|
82 | + exit; |
|
83 | + } |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /* default - error */ |
@@ -26,28 +26,28 @@ |
||
26 | 26 | |
27 | 27 | # manually adjust the standard fields |
28 | 28 | foreach($expfields as $std_field) { |
29 | - # extra table and field |
|
30 | - if (isset($extfields[$std_field])) { |
|
31 | - $cfield = $extfields[$std_field]["field"]; |
|
32 | - $ctable = $extfields[$std_field]["table"]; |
|
33 | - $pname = $extfields[$std_field]["pname"]." "; |
|
34 | - } else { |
|
35 | - # default table and field |
|
36 | - $cfield = $std_field; |
|
37 | - $ctable = $mtable; |
|
38 | - $pname = ""; |
|
39 | - } |
|
40 | - |
|
41 | - # read field attributes |
|
42 | - $field = $Tools->fetch_full_field_definition($ctable,$cfield); |
|
43 | - $field = (array) $field; |
|
44 | - |
|
45 | - # mark required fields with * |
|
46 | - $msgr = in_array($std_field,$reqfields) ? "*" : ""; |
|
47 | - |
|
48 | - #prebuild template table rows to avoid useless foreach loops |
|
49 | - $tpl_field_names.= "<th>".$pname.$field['Field'].$msgr."</th>"; |
|
50 | - $tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>"; |
|
29 | + # extra table and field |
|
30 | + if (isset($extfields[$std_field])) { |
|
31 | + $cfield = $extfields[$std_field]["field"]; |
|
32 | + $ctable = $extfields[$std_field]["table"]; |
|
33 | + $pname = $extfields[$std_field]["pname"]." "; |
|
34 | + } else { |
|
35 | + # default table and field |
|
36 | + $cfield = $std_field; |
|
37 | + $ctable = $mtable; |
|
38 | + $pname = ""; |
|
39 | + } |
|
40 | + |
|
41 | + # read field attributes |
|
42 | + $field = $Tools->fetch_full_field_definition($ctable,$cfield); |
|
43 | + $field = (array) $field; |
|
44 | + |
|
45 | + # mark required fields with * |
|
46 | + $msgr = in_array($std_field,$reqfields) ? "*" : ""; |
|
47 | + |
|
48 | + #prebuild template table rows to avoid useless foreach loops |
|
49 | + $tpl_field_names.= "<th>".$pname.$field['Field'].$msgr."</th>"; |
|
50 | + $tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>"; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | ?> |
@@ -45,32 +45,32 @@ |
||
45 | 45 | |
46 | 46 | //write headers |
47 | 47 | if( (isset($_GET['name'])) && ($_GET['name'] == "on") ) { |
48 | - $worksheet->write($lineCount, $rowCount, _('Name') ,$format_header); |
|
49 | - $rowCount++; |
|
48 | + $worksheet->write($lineCount, $rowCount, _('Name') ,$format_header); |
|
49 | + $rowCount++; |
|
50 | 50 | } |
51 | 51 | if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) { |
52 | - $worksheet->write($lineCount, $rowCount, _('Description') ,$format_header); |
|
53 | - $rowCount++; |
|
52 | + $worksheet->write($lineCount, $rowCount, _('Description') ,$format_header); |
|
53 | + $rowCount++; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | $lineCount++; |
57 | 57 | $rowCount = 0; |
58 | 58 | |
59 | 59 | foreach ($vlan_domains as $vlan_domain) { |
60 | - //cast |
|
61 | - $vlan_domain = (array) $vlan_domain; |
|
62 | - |
|
63 | - if( (isset($_GET['name'])) && ($_GET['name'] == "on") ) { |
|
64 | - $worksheet->write($lineCount, $rowCount, $vlan_domain['name'], $format_text); |
|
65 | - $rowCount++; |
|
66 | - } |
|
67 | - if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) { |
|
68 | - $worksheet->write($lineCount, $rowCount, $vlan_domain['description'], $format_text); |
|
69 | - $rowCount++; |
|
70 | - } |
|
71 | - |
|
72 | - $lineCount++; |
|
73 | - $rowCount = 0; |
|
60 | + //cast |
|
61 | + $vlan_domain = (array) $vlan_domain; |
|
62 | + |
|
63 | + if( (isset($_GET['name'])) && ($_GET['name'] == "on") ) { |
|
64 | + $worksheet->write($lineCount, $rowCount, $vlan_domain['name'], $format_text); |
|
65 | + $rowCount++; |
|
66 | + } |
|
67 | + if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) { |
|
68 | + $worksheet->write($lineCount, $rowCount, $vlan_domain['description'], $format_text); |
|
69 | + $rowCount++; |
|
70 | + } |
|
71 | + |
|
72 | + $lineCount++; |
|
73 | + $rowCount = 0; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 |
@@ -25,35 +25,35 @@ |
||
25 | 25 | |
26 | 26 | # manually adjust the standard fields |
27 | 27 | foreach($expfields as $std_field) { |
28 | - if (in_array($std_field,$reqfields)) { |
|
29 | - $msgr = "*"; |
|
30 | - } else { |
|
31 | - $msgr = ""; |
|
32 | - } |
|
33 | - |
|
34 | - $field = $Tools->fetch_full_field_definition("vrf",$std_field); |
|
35 | - $field = (array) $field; |
|
36 | - |
|
37 | - $res[$field['Field']]['name'] = $field['Field']; |
|
38 | - $res[$field['Field']]['type'] = $field['Type']; |
|
39 | - $res[$field['Field']]['Comment'] = $field['Comment']; |
|
40 | - $res[$field['Field']]['Null'] = $field['Null']; |
|
41 | - $res[$field['Field']]['Default'] = $field['Default']; |
|
42 | - |
|
43 | - #prebuild template table rows to avoid useless foreach loops |
|
44 | - $tpl_field_names.= "<th>".$field['Field'].$msgr."</th>"; |
|
45 | - $tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>"; |
|
28 | + if (in_array($std_field,$reqfields)) { |
|
29 | + $msgr = "*"; |
|
30 | + } else { |
|
31 | + $msgr = ""; |
|
32 | + } |
|
33 | + |
|
34 | + $field = $Tools->fetch_full_field_definition("vrf",$std_field); |
|
35 | + $field = (array) $field; |
|
36 | + |
|
37 | + $res[$field['Field']]['name'] = $field['Field']; |
|
38 | + $res[$field['Field']]['type'] = $field['Type']; |
|
39 | + $res[$field['Field']]['Comment'] = $field['Comment']; |
|
40 | + $res[$field['Field']]['Null'] = $field['Null']; |
|
41 | + $res[$field['Field']]['Default'] = $field['Default']; |
|
42 | + |
|
43 | + #prebuild template table rows to avoid useless foreach loops |
|
44 | + $tpl_field_names.= "<th>".$field['Field'].$msgr."</th>"; |
|
45 | + $tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>"; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | # append the custom fields, if any |
49 | 49 | $custom_fields = $Tools->fetch_custom_fields("vrf"); |
50 | 50 | if(sizeof($custom_fields) > 0) { |
51 | - $res[] = $custom_fields; |
|
52 | - foreach($custom_fields as $myField) { |
|
53 | - $tpl_field_names.= "<th>". $myField['name'] ."</th>"; |
|
54 | - $tpl_field_types.= "<td><small>". wordwrap($myField['type'],18,"<br>\n",true) ."</small></td>"; |
|
55 | - $expfields[] = $myField['name']; |
|
56 | - } |
|
51 | + $res[] = $custom_fields; |
|
52 | + foreach($custom_fields as $myField) { |
|
53 | + $tpl_field_names.= "<th>". $myField['name'] ."</th>"; |
|
54 | + $tpl_field_types.= "<td><small>". wordwrap($myField['type'],18,"<br>\n",true) ."</small></td>"; |
|
55 | + $expfields[] = $myField['name']; |
|
56 | + } |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | ?> |
@@ -33,39 +33,39 @@ |
||
33 | 33 | |
34 | 34 | # import VLANs |
35 | 35 | foreach ($data as &$cdata) { |
36 | - if (($cdata['action'] == "add") || ($cdata['action'] == "edit")) { |
|
37 | - # set update array |
|
38 | - $values = array("vlanId"=>$cdata['vlanId'], |
|
39 | - "number"=>$cdata['number'], |
|
40 | - "name"=>$cdata['name'], |
|
41 | - "description"=>$cdata['description'], |
|
42 | - "domainId"=>$cdata['domainId'] |
|
43 | - ); |
|
44 | - # add custom fields |
|
45 | - if(sizeof($custom_fields) > 0) { |
|
46 | - foreach($custom_fields as $myField) { |
|
47 | - if(isset($cdata[$myField['name']])) { $values[$myField['name']] = $cdata[$myField['name']]; } |
|
48 | - } |
|
49 | - } |
|
36 | + if (($cdata['action'] == "add") || ($cdata['action'] == "edit")) { |
|
37 | + # set update array |
|
38 | + $values = array("vlanId"=>$cdata['vlanId'], |
|
39 | + "number"=>$cdata['number'], |
|
40 | + "name"=>$cdata['name'], |
|
41 | + "description"=>$cdata['description'], |
|
42 | + "domainId"=>$cdata['domainId'] |
|
43 | + ); |
|
44 | + # add custom fields |
|
45 | + if(sizeof($custom_fields) > 0) { |
|
46 | + foreach($custom_fields as $myField) { |
|
47 | + if(isset($cdata[$myField['name']])) { $values[$myField['name']] = $cdata[$myField['name']]; } |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - # update |
|
52 | - $cdata['result'] = $Admin->object_modify("vlans", $cdata['action'], "vlanId", $values); |
|
51 | + # update |
|
52 | + $cdata['result'] = $Admin->object_modify("vlans", $cdata['action'], "vlanId", $values); |
|
53 | 53 | |
54 | - if ($cdata['result']) { |
|
55 | - $trc = $colors[$cdata['action']]; |
|
56 | - $msg = "VLAN ".$cdata['action']." successful."; |
|
57 | - } else { |
|
58 | - $trc = "danger"; |
|
59 | - $msg = "VLAN ".$cdata['action']." failed."; |
|
60 | - } |
|
61 | - $rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$cdata['action']]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td> |
|
54 | + if ($cdata['result']) { |
|
55 | + $trc = $colors[$cdata['action']]; |
|
56 | + $msg = "VLAN ".$cdata['action']." successful."; |
|
57 | + } else { |
|
58 | + $trc = "danger"; |
|
59 | + $msg = "VLAN ".$cdata['action']." failed."; |
|
60 | + } |
|
61 | + $rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$cdata['action']]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td> |
|
62 | 62 | <td>".$cdata['name']."</td> |
63 | 63 | <td>".$cdata['number']."</td> |
64 | 64 | <td>".$cdata['description']."</td> |
65 | 65 | <td>".$cdata['domain']."</td> |
66 | 66 | ".$cfieldtds." |
67 | 67 | <td>"._($msg)."</td></tr>"; |
68 | - } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | print "<table class='table table-condensed table-hover' id='resultstable'><tbody>"; |
@@ -26,21 +26,21 @@ discard block |
||
26 | 26 | $edata = array(); $vdom = array(); $vdomid = array(); |
27 | 27 | # process for easier later check |
28 | 28 | foreach ($vlan_domains as $vlan_domain) { |
29 | - //cast |
|
30 | - $vlan_domain = (array) $vlan_domain; |
|
31 | - $vdom[] = $vlan_domain['name']; |
|
32 | - $vdomid[$vlan_domain['name']] = $vlan_domain['id']; |
|
33 | - // read vlans |
|
34 | - $all_vlans = $Admin->fetch_multiple_objects("vlans", "domainId", $vlan_domain['id'], "number"); |
|
35 | - $all_vlans = (array) $all_vlans; |
|
36 | - // skip empty domains |
|
37 | - if (sizeof($all_vlans)==0) { continue; } |
|
38 | - //write all VLAN entries |
|
39 | - foreach ($all_vlans as $vlan) { |
|
40 | - //cast |
|
41 | - $vlan = (array) $vlan; |
|
42 | - $edata[$vlan_domain['name']][$vlan['number']] = $vlan; |
|
43 | - } |
|
29 | + //cast |
|
30 | + $vlan_domain = (array) $vlan_domain; |
|
31 | + $vdom[] = $vlan_domain['name']; |
|
32 | + $vdomid[$vlan_domain['name']] = $vlan_domain['id']; |
|
33 | + // read vlans |
|
34 | + $all_vlans = $Admin->fetch_multiple_objects("vlans", "domainId", $vlan_domain['id'], "number"); |
|
35 | + $all_vlans = (array) $all_vlans; |
|
36 | + // skip empty domains |
|
37 | + if (sizeof($all_vlans)==0) { continue; } |
|
38 | + //write all VLAN entries |
|
39 | + foreach ($all_vlans as $vlan) { |
|
40 | + //cast |
|
41 | + $vlan = (array) $vlan; |
|
42 | + $edata[$vlan_domain['name']][$vlan['number']] = $vlan; |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | $rows = ""; |
@@ -49,68 +49,68 @@ discard block |
||
49 | 49 | |
50 | 50 | # check the fields |
51 | 51 | foreach ($data as &$cdata) { |
52 | - $msg = ""; $action = ""; $cfieldtds = ""; |
|
53 | - |
|
54 | - # set a default domain if none specified |
|
55 | - if ($cdata['domain'] != "") { $cdom = $cdata['domain']; } else { $cdom = "default"; } |
|
56 | - |
|
57 | - # check if domain exists and link ID, otherwise issue error |
|
58 | - if (!in_array($cdom,$vdom)) { |
|
59 | - $msg.= "Missing VLAN domain. Please add/import VLAN domain first."; $action = "error"; |
|
60 | - } else { |
|
61 | - $cdata['domainId'] = $vdomid[$cdom]; |
|
62 | - } |
|
63 | - |
|
64 | - # check if required fields are present and not empty |
|
65 | - foreach($reqfields as $creq) { |
|
66 | - if ((!isset($cdata[$creq])) or ($cdata[$creq] == "")) { $msg.= "Required field ".$creq." missing or empty."; $action = "error"; } |
|
67 | - } |
|
68 | - |
|
69 | - # check data format |
|
70 | - if ($action != "error") { |
|
71 | - if (!preg_match("/^[a-zA-Z0-9-_]+$/", $cdata['name'])) { $msg.="Invalid name format."; $action = "error"; } |
|
72 | - if (!preg_match("/^[0-9]+$/", $cdata['number'])) { $msg.="Invalid number format."; $action = "error"; } |
|
73 | - if (preg_match("/[;'\"]/", $cdata['description'])) { $msg.="Invalid characters in description."; $action = "error"; } |
|
74 | - if (!preg_match("/^[a-zA-Z0-9-_ ]+$/", $cdata['domain'])) { $msg.="Invalid domain format."; $action = "error"; } |
|
75 | - if ($action != "error") { if ($cdata['number']>$User->settings->vlanMax) { $msg.= _('Highest possible VLAN number is ').$User->settings->vlanMax.'!'; $action = "error"; } } |
|
76 | - } |
|
77 | - |
|
78 | - # Generate the custom fields columns |
|
79 | - if(sizeof($custom_fields) > 0) { foreach($custom_fields as $myField) { $cfieldtds.= "<td>".$cdata[$myField['name']]."</td>"; } } |
|
80 | - |
|
81 | - # check if duplicate VLAN |
|
82 | - if (isset($unique[$cdom][$cdata['number']])) { $msg.= "Duplicate VLAN domain and number not supported. Please check import file."; $action = "error"; } |
|
83 | - |
|
84 | - # check if existing |
|
85 | - if ($action != "error") { |
|
86 | - if (isset($edata[$cdom][$cdata['number']])) { |
|
87 | - $cdata['vlanId'] = $edata[$cdom][$cdata['number']]['vlanId']; |
|
88 | - $action = "skip"; # skip duplicate fields if identical, update if different |
|
89 | - if ($cdata['name'] != $edata[$cdom][$cdata['number']]['name']) { $msg.= "VLAN name will be updated."; $action = "edit"; } |
|
90 | - if ($cdata['description'] != $edata[$cdom][$cdata['number']]['description']) { $msg.= "VLAN description will be updated."; $action = "edit"; } |
|
91 | - # Check if the values of the custom fields have changed |
|
92 | - if(sizeof($custom_fields) > 0) { |
|
93 | - foreach($custom_fields as $myField) { |
|
94 | - if ($cdata[$myField['name']] != $edata[$cdom][$cdata['number']][$myField['name']]) { |
|
95 | - $msg.= "VLAN ".$myField['name']." will be updated."; $action = "edit"; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - if ($action == "skip") { |
|
101 | - $msg.= "Duplicate, will skip."; |
|
102 | - } |
|
103 | - } else { |
|
104 | - $msg.="New entry, will be added."; $action = "add"; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - $cdata['msg'].= $msg; |
|
109 | - $cdata['action'] = $action; |
|
110 | - $counters[$action]++; |
|
111 | - if (!isset($unique[$cdom][$cdata['number']])) { $unique[$cdom][$cdata['number']] = $cdata['name']; } |
|
112 | - |
|
113 | - $rows.="<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td> |
|
52 | + $msg = ""; $action = ""; $cfieldtds = ""; |
|
53 | + |
|
54 | + # set a default domain if none specified |
|
55 | + if ($cdata['domain'] != "") { $cdom = $cdata['domain']; } else { $cdom = "default"; } |
|
56 | + |
|
57 | + # check if domain exists and link ID, otherwise issue error |
|
58 | + if (!in_array($cdom,$vdom)) { |
|
59 | + $msg.= "Missing VLAN domain. Please add/import VLAN domain first."; $action = "error"; |
|
60 | + } else { |
|
61 | + $cdata['domainId'] = $vdomid[$cdom]; |
|
62 | + } |
|
63 | + |
|
64 | + # check if required fields are present and not empty |
|
65 | + foreach($reqfields as $creq) { |
|
66 | + if ((!isset($cdata[$creq])) or ($cdata[$creq] == "")) { $msg.= "Required field ".$creq." missing or empty."; $action = "error"; } |
|
67 | + } |
|
68 | + |
|
69 | + # check data format |
|
70 | + if ($action != "error") { |
|
71 | + if (!preg_match("/^[a-zA-Z0-9-_]+$/", $cdata['name'])) { $msg.="Invalid name format."; $action = "error"; } |
|
72 | + if (!preg_match("/^[0-9]+$/", $cdata['number'])) { $msg.="Invalid number format."; $action = "error"; } |
|
73 | + if (preg_match("/[;'\"]/", $cdata['description'])) { $msg.="Invalid characters in description."; $action = "error"; } |
|
74 | + if (!preg_match("/^[a-zA-Z0-9-_ ]+$/", $cdata['domain'])) { $msg.="Invalid domain format."; $action = "error"; } |
|
75 | + if ($action != "error") { if ($cdata['number']>$User->settings->vlanMax) { $msg.= _('Highest possible VLAN number is ').$User->settings->vlanMax.'!'; $action = "error"; } } |
|
76 | + } |
|
77 | + |
|
78 | + # Generate the custom fields columns |
|
79 | + if(sizeof($custom_fields) > 0) { foreach($custom_fields as $myField) { $cfieldtds.= "<td>".$cdata[$myField['name']]."</td>"; } } |
|
80 | + |
|
81 | + # check if duplicate VLAN |
|
82 | + if (isset($unique[$cdom][$cdata['number']])) { $msg.= "Duplicate VLAN domain and number not supported. Please check import file."; $action = "error"; } |
|
83 | + |
|
84 | + # check if existing |
|
85 | + if ($action != "error") { |
|
86 | + if (isset($edata[$cdom][$cdata['number']])) { |
|
87 | + $cdata['vlanId'] = $edata[$cdom][$cdata['number']]['vlanId']; |
|
88 | + $action = "skip"; # skip duplicate fields if identical, update if different |
|
89 | + if ($cdata['name'] != $edata[$cdom][$cdata['number']]['name']) { $msg.= "VLAN name will be updated."; $action = "edit"; } |
|
90 | + if ($cdata['description'] != $edata[$cdom][$cdata['number']]['description']) { $msg.= "VLAN description will be updated."; $action = "edit"; } |
|
91 | + # Check if the values of the custom fields have changed |
|
92 | + if(sizeof($custom_fields) > 0) { |
|
93 | + foreach($custom_fields as $myField) { |
|
94 | + if ($cdata[$myField['name']] != $edata[$cdom][$cdata['number']][$myField['name']]) { |
|
95 | + $msg.= "VLAN ".$myField['name']." will be updated."; $action = "edit"; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + if ($action == "skip") { |
|
101 | + $msg.= "Duplicate, will skip."; |
|
102 | + } |
|
103 | + } else { |
|
104 | + $msg.="New entry, will be added."; $action = "add"; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + $cdata['msg'].= $msg; |
|
109 | + $cdata['action'] = $action; |
|
110 | + $counters[$action]++; |
|
111 | + if (!isset($unique[$cdom][$cdata['number']])) { $unique[$cdom][$cdata['number']] = $cdata['name']; } |
|
112 | + |
|
113 | + $rows.="<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td> |
|
114 | 114 | <td>".$cdata['name']."</td> |
115 | 115 | <td>".$cdata['number']."</td> |
116 | 116 | <td>".$cdata['description']."</td> |
@@ -30,36 +30,36 @@ discard block |
||
30 | 30 | # Pear IPv6 ip2Bin, local copy |
31 | 31 | function my_ip2Bin($pi6,$ip) |
32 | 32 | { |
33 | - $binstr = ''; |
|
33 | + $binstr = ''; |
|
34 | 34 | |
35 | - $ip = $pi6->removeNetmaskSpec($ip); |
|
36 | - $ip = $pi6->Uncompress($ip); |
|
35 | + $ip = $pi6->removeNetmaskSpec($ip); |
|
36 | + $ip = $pi6->Uncompress($ip); |
|
37 | 37 | |
38 | - $parts = explode(':', $ip); |
|
38 | + $parts = explode(':', $ip); |
|
39 | 39 | |
40 | - foreach ( $parts as $v ) { |
|
40 | + foreach ( $parts as $v ) { |
|
41 | 41 | |
42 | - $str = base_convert($v, 16, 2); |
|
43 | - $binstr .= str_pad($str, 16, '0', STR_PAD_LEFT); |
|
42 | + $str = base_convert($v, 16, 2); |
|
43 | + $binstr .= str_pad($str, 16, '0', STR_PAD_LEFT); |
|
44 | 44 | |
45 | - } |
|
45 | + } |
|
46 | 46 | |
47 | - return $binstr; |
|
47 | + return $binstr; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | # Read selected fields and pass them to the save form |
51 | 51 | foreach($_GET as $key => $value) { |
52 | - if (preg_match("/recomputeSection_(\d+)$/",$key,$matches) && ($value == "on")) { |
|
53 | - # Grab provided values |
|
54 | - $rlist[$matches[1]]["IPv4"] = ($_GET['recomputeSectionIPv4_'.$matches[1]] == "on" ? true : false); |
|
55 | - $rlist[$matches[1]]["IPv6"] = ($_GET['recomputeSectionIPv6_'.$matches[1]] == "on" ? true : false); |
|
56 | - $rlist[$matches[1]]["CVRF"] = ($_GET['recomputeSectionCVRF_'.$matches[1]] == "on" ? true : false); |
|
57 | - # Build hidden form inputs |
|
58 | - $pass_inputs.="<input name='".$key."' type='hidden' value='".$value."' style='display:none;'>"; |
|
59 | - $pass_inputs.="<input name='recomputeSectionIPv4_".$matches[1]."' type='hidden' value='".$_GET['recomputeSectionIPv4_'.$matches[1]]."' style='display:none;'>"; |
|
60 | - $pass_inputs.="<input name='recomputeSectionIPv6_".$matches[1]."' type='hidden' value='".$_GET['recomputeSectionIPv6_'.$matches[1]]."' style='display:none;'>"; |
|
61 | - $pass_inputs.="<input name='recomputeSectionCVRF_".$matches[1]."' type='hidden' value='".$_GET['recomputeSectionCVRF_'.$matches[1]]."' style='display:none;'>"; |
|
62 | - } |
|
52 | + if (preg_match("/recomputeSection_(\d+)$/",$key,$matches) && ($value == "on")) { |
|
53 | + # Grab provided values |
|
54 | + $rlist[$matches[1]]["IPv4"] = ($_GET['recomputeSectionIPv4_'.$matches[1]] == "on" ? true : false); |
|
55 | + $rlist[$matches[1]]["IPv6"] = ($_GET['recomputeSectionIPv6_'.$matches[1]] == "on" ? true : false); |
|
56 | + $rlist[$matches[1]]["CVRF"] = ($_GET['recomputeSectionCVRF_'.$matches[1]] == "on" ? true : false); |
|
57 | + # Build hidden form inputs |
|
58 | + $pass_inputs.="<input name='".$key."' type='hidden' value='".$value."' style='display:none;'>"; |
|
59 | + $pass_inputs.="<input name='recomputeSectionIPv4_".$matches[1]."' type='hidden' value='".$_GET['recomputeSectionIPv4_'.$matches[1]]."' style='display:none;'>"; |
|
60 | + $pass_inputs.="<input name='recomputeSectionIPv6_".$matches[1]."' type='hidden' value='".$_GET['recomputeSectionIPv6_'.$matches[1]]."' style='display:none;'>"; |
|
61 | + $pass_inputs.="<input name='recomputeSectionCVRF_".$matches[1]."' type='hidden' value='".$_GET['recomputeSectionCVRF_'.$matches[1]]."' style='display:none;'>"; |
|
62 | + } |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | #print "<pre>";print_r($rlist);print "</pre>"; |
@@ -82,64 +82,64 @@ discard block |
||
82 | 82 | |
83 | 83 | # Read IPs for the sections we need to order |
84 | 84 | foreach ($rlist as $sect_id => $sect_check) { |
85 | - $section_subnets = $Subnets->fetch_section_subnets($sect_id); |
|
86 | - # skip empty sections |
|
87 | - if (sizeof($section_subnets)==0) { continue; } |
|
85 | + $section_subnets = $Subnets->fetch_section_subnets($sect_id); |
|
86 | + # skip empty sections |
|
87 | + if (sizeof($section_subnets)==0) { continue; } |
|
88 | 88 | |
89 | - $isFolder[$sect_id] = array(); |
|
89 | + $isFolder[$sect_id] = array(); |
|
90 | 90 | |
91 | - foreach ($section_subnets as &$subnet) { |
|
92 | - $subnet = (array) $subnet; |
|
93 | - $subnet['ip'] = $Subnets->transform_to_dotted($subnet['subnet']); |
|
94 | - $subnet['type'] = $Subnets->identify_address($subnet['ip']); |
|
95 | - # Precompute subnet in AND format (long for IPv4 and bin str for IPv6) |
|
96 | - $subnet['andip'] = ($subnet['type'] == "IPv4") ? $subnet['subnet'] : my_ip2Bin($pi6,$subnet['ip']); |
|
97 | - # Add to array |
|
98 | - $edata[$sect_id][] = $subnet; |
|
99 | - $isFolder[$sect_id][$subnet['id']] = $subnet['isFolder']; |
|
100 | - } |
|
91 | + foreach ($section_subnets as &$subnet) { |
|
92 | + $subnet = (array) $subnet; |
|
93 | + $subnet['ip'] = $Subnets->transform_to_dotted($subnet['subnet']); |
|
94 | + $subnet['type'] = $Subnets->identify_address($subnet['ip']); |
|
95 | + # Precompute subnet in AND format (long for IPv4 and bin str for IPv6) |
|
96 | + $subnet['andip'] = ($subnet['type'] == "IPv4") ? $subnet['subnet'] : my_ip2Bin($pi6,$subnet['ip']); |
|
97 | + # Add to array |
|
98 | + $edata[$sect_id][] = $subnet; |
|
99 | + $isFolder[$sect_id][$subnet['id']] = $subnet['isFolder']; |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $rows = ""; $counters = array(); |
104 | 104 | |
105 | 105 | # Recompute master/nested relations for the selected sections and address families |
106 | 106 | foreach ($rlist as $sect_id => $sect_check) { |
107 | - # Skip empty sections |
|
108 | - if (!$edata[$sect_id]) { continue; } |
|
109 | - |
|
110 | - # Grab a subnet and find its closest master |
|
111 | - foreach ($edata[$sect_id] as &$c_subnet) { |
|
112 | - if (!$sect_check[$c_subnet['type']]) { continue; } # Skip the IP version we don't want to reorder |
|
113 | - if ($c_subnet['isFolder']) { continue; } # Skip folders |
|
114 | - if ($isFolder[$sect_id][$c_subnet['masterSubnetId']]) { continue; } # Skip changing subne with folder masters |
|
115 | - |
|
116 | - $c_master_id = "0"; $c_master_ip = ""; $c_master_mask = ""; |
|
117 | - |
|
118 | - # Check against all other subnets in section |
|
119 | - foreach ($edata[$sect_id] as $m_subnet) { |
|
120 | - if ($c_subnet['type'] != $m_subnet['type']) { continue; } # Skip if current IP version doesn't match master IP version |
|
121 | - if ((!$sect_check["CVRF"]) && ($c_subnet['vrfId'] != $m_subnet['vrfId'])) { continue; } # Skip IPs from other VRFs if cross VRF reordering is not wanted (default is on) |
|
122 | - # Main logic here - check if subnet within subnet |
|
123 | - if ((($c_subnet['andip'] & $masks[$c_subnet['type']][$m_subnet['mask']]) == $m_subnet['andip']) && ($c_subnet['mask'] > $m_subnet['mask'])) { # We have a match |
|
124 | - if ($m_subnet['mask'] > $c_master_mask) { # If new master is more specific than old master, record the data |
|
125 | - $c_master_id = $m_subnet['id']; $c_master_mask = $m_subnet['mask']; $c_master_ip = $m_subnet['ip']; |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - # At the end, save the new master |
|
131 | - $c_subnet['new_masterSubnetId'] = $c_master_id; |
|
132 | - $c_subnet['new_master'] = (($c_master_id === "0") ? _("Root") : $c_master_ip."/".$c_master_mask); |
|
133 | - $c_subnet['action'] = ($c_subnet['masterSubnetId'] == $c_subnet['new_masterSubnetId'] ? "skip" : "edit"); |
|
134 | - $c_subnet['msg'] = ($c_subnet['masterSubnetId'] == $c_subnet['new_masterSubnetId'] ? _("No change, skip") : _("New master, update")); |
|
135 | - |
|
136 | - $rows.="<tr class='".$colors[$c_subnet['action']]."'><td><i class='fa ".$icons[$c_subnet['action']]."' rel='tooltip' data-placement='bottom' title='"._($c_subnet['msg'])."'></i></td>"; |
|
137 | - $rows.="<td>".$sect_names[$sect_id]."</td><td>".$c_subnet['ip']."/".$c_subnet['mask']."</td>"; |
|
138 | - $rows.="<td>".$c_subnet['description']."</td><td>".$vrf_name[$c_subnet['vrfId']]."</td><td>"; |
|
139 | - $rows.=$c_subnet['new_master']."</td><td>".$c_subnet['msg']."</td></tr>\n"; |
|
140 | - |
|
141 | - $counters[$c_subnet['action']]++; |
|
142 | - } |
|
107 | + # Skip empty sections |
|
108 | + if (!$edata[$sect_id]) { continue; } |
|
109 | + |
|
110 | + # Grab a subnet and find its closest master |
|
111 | + foreach ($edata[$sect_id] as &$c_subnet) { |
|
112 | + if (!$sect_check[$c_subnet['type']]) { continue; } # Skip the IP version we don't want to reorder |
|
113 | + if ($c_subnet['isFolder']) { continue; } # Skip folders |
|
114 | + if ($isFolder[$sect_id][$c_subnet['masterSubnetId']]) { continue; } # Skip changing subne with folder masters |
|
115 | + |
|
116 | + $c_master_id = "0"; $c_master_ip = ""; $c_master_mask = ""; |
|
117 | + |
|
118 | + # Check against all other subnets in section |
|
119 | + foreach ($edata[$sect_id] as $m_subnet) { |
|
120 | + if ($c_subnet['type'] != $m_subnet['type']) { continue; } # Skip if current IP version doesn't match master IP version |
|
121 | + if ((!$sect_check["CVRF"]) && ($c_subnet['vrfId'] != $m_subnet['vrfId'])) { continue; } # Skip IPs from other VRFs if cross VRF reordering is not wanted (default is on) |
|
122 | + # Main logic here - check if subnet within subnet |
|
123 | + if ((($c_subnet['andip'] & $masks[$c_subnet['type']][$m_subnet['mask']]) == $m_subnet['andip']) && ($c_subnet['mask'] > $m_subnet['mask'])) { # We have a match |
|
124 | + if ($m_subnet['mask'] > $c_master_mask) { # If new master is more specific than old master, record the data |
|
125 | + $c_master_id = $m_subnet['id']; $c_master_mask = $m_subnet['mask']; $c_master_ip = $m_subnet['ip']; |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + # At the end, save the new master |
|
131 | + $c_subnet['new_masterSubnetId'] = $c_master_id; |
|
132 | + $c_subnet['new_master'] = (($c_master_id === "0") ? _("Root") : $c_master_ip."/".$c_master_mask); |
|
133 | + $c_subnet['action'] = ($c_subnet['masterSubnetId'] == $c_subnet['new_masterSubnetId'] ? "skip" : "edit"); |
|
134 | + $c_subnet['msg'] = ($c_subnet['masterSubnetId'] == $c_subnet['new_masterSubnetId'] ? _("No change, skip") : _("New master, update")); |
|
135 | + |
|
136 | + $rows.="<tr class='".$colors[$c_subnet['action']]."'><td><i class='fa ".$icons[$c_subnet['action']]."' rel='tooltip' data-placement='bottom' title='"._($c_subnet['msg'])."'></i></td>"; |
|
137 | + $rows.="<td>".$sect_names[$sect_id]."</td><td>".$c_subnet['ip']."/".$c_subnet['mask']."</td>"; |
|
138 | + $rows.="<td>".$c_subnet['description']."</td><td>".$vrf_name[$c_subnet['vrfId']]."</td><td>"; |
|
139 | + $rows.=$c_subnet['new_master']."</td><td>".$c_subnet['msg']."</td></tr>\n"; |
|
140 | + |
|
141 | + $counters[$c_subnet['action']]++; |
|
142 | + } |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | ?> |