@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | |
28 | 28 | # Lets do some reordering to show slaves! |
29 | 29 | if($all_sections !== false) { |
30 | - foreach($all_sections as $s) { |
|
31 | - if($s->masterSection=="0") { |
|
32 | - # it is master |
|
33 | - $s->class = "master"; |
|
34 | - $sectionssorted[] = $s; |
|
35 | - # check for slaves |
|
36 | - foreach($all_sections as $ss) { |
|
37 | - if($ss->masterSection==$s->id) { |
|
38 | - $ss->class = "slave"; |
|
39 | - $sectionssorted[] = $ss; |
|
40 | - } |
|
41 | - } |
|
42 | - } |
|
43 | - } |
|
44 | - # set new array |
|
45 | - $sections_sorted = @$sectionssorted; |
|
30 | + foreach($all_sections as $s) { |
|
31 | + if($s->masterSection=="0") { |
|
32 | + # it is master |
|
33 | + $s->class = "master"; |
|
34 | + $sectionssorted[] = $s; |
|
35 | + # check for slaves |
|
36 | + foreach($all_sections as $ss) { |
|
37 | + if($ss->masterSection==$s->id) { |
|
38 | + $ss->class = "slave"; |
|
39 | + $sectionssorted[] = $ss; |
|
40 | + } |
|
41 | + } |
|
42 | + } |
|
43 | + } |
|
44 | + # set new array |
|
45 | + $sections_sorted = @$sectionssorted; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | |
@@ -73,81 +73,81 @@ discard block |
||
73 | 73 | |
74 | 74 | //write headers |
75 | 75 | if( (isset($_GET['section'])) && ($_GET['section'] == "on") ) { |
76 | - $worksheet->write($lineCount, $rowCount, _('Section') ,$format_header); |
|
77 | - $rowCount++; |
|
76 | + $worksheet->write($lineCount, $rowCount, _('Section') ,$format_header); |
|
77 | + $rowCount++; |
|
78 | 78 | } |
79 | 79 | if( (isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on") ) { |
80 | - $worksheet->write($lineCount, $rowCount, _('IP Address') ,$format_header); |
|
81 | - $rowCount++; |
|
80 | + $worksheet->write($lineCount, $rowCount, _('IP Address') ,$format_header); |
|
81 | + $rowCount++; |
|
82 | 82 | } |
83 | 83 | if( (isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on") ) { |
84 | - $worksheet->write($lineCount, $rowCount, _('Hostname') ,$format_header); |
|
85 | - $rowCount++; |
|
84 | + $worksheet->write($lineCount, $rowCount, _('Hostname') ,$format_header); |
|
85 | + $rowCount++; |
|
86 | 86 | } |
87 | 87 | if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) { |
88 | - $worksheet->write($lineCount, $rowCount, _('Description') ,$format_header); |
|
89 | - $rowCount++; |
|
88 | + $worksheet->write($lineCount, $rowCount, _('Description') ,$format_header); |
|
89 | + $rowCount++; |
|
90 | 90 | } |
91 | 91 | if( (isset($_GET['vrf'])) && ($_GET['vrf'] == "on") ) { |
92 | - $worksheet->write($lineCount, $rowCount, _('VRF') ,$format_header); |
|
93 | - $rowCount++; |
|
94 | - # fetch all VRFs |
|
95 | - $all_vrfs = $Admin->fetch_all_objects("vrf", "vrfId"); |
|
96 | - if (!$all_vrfs) { $all_vrfs = array(); } |
|
97 | - # prepare list for easy processing |
|
98 | - $vrfs = array(); $vrfs[0] = "default"; |
|
99 | - foreach ($all_vrfs as $vrf) { $vrf = (array) $vrf; $vrfs[$vrf['vrfId']] = $vrf['name']; } |
|
92 | + $worksheet->write($lineCount, $rowCount, _('VRF') ,$format_header); |
|
93 | + $rowCount++; |
|
94 | + # fetch all VRFs |
|
95 | + $all_vrfs = $Admin->fetch_all_objects("vrf", "vrfId"); |
|
96 | + if (!$all_vrfs) { $all_vrfs = array(); } |
|
97 | + # prepare list for easy processing |
|
98 | + $vrfs = array(); $vrfs[0] = "default"; |
|
99 | + foreach ($all_vrfs as $vrf) { $vrf = (array) $vrf; $vrfs[$vrf['vrfId']] = $vrf['name']; } |
|
100 | 100 | } |
101 | 101 | if( (isset($_GET['subnet'])) && ($_GET['subnet'] == "on") ) { |
102 | - $worksheet->write($lineCount, $rowCount, _('Subnet') ,$format_header); |
|
103 | - $rowCount++; |
|
102 | + $worksheet->write($lineCount, $rowCount, _('Subnet') ,$format_header); |
|
103 | + $rowCount++; |
|
104 | 104 | } |
105 | 105 | if( (isset($_GET['mac'])) && ($_GET['mac'] == "on") ) { |
106 | - $worksheet->write($lineCount, $rowCount, _('MAC') ,$format_header); |
|
107 | - $rowCount++; |
|
106 | + $worksheet->write($lineCount, $rowCount, _('MAC') ,$format_header); |
|
107 | + $rowCount++; |
|
108 | 108 | } |
109 | 109 | if( (isset($_GET['owner'])) && ($_GET['owner'] == "on") ) { |
110 | - $worksheet->write($lineCount, $rowCount, _('Owner') ,$format_header); |
|
111 | - $rowCount++; |
|
110 | + $worksheet->write($lineCount, $rowCount, _('Owner') ,$format_header); |
|
111 | + $rowCount++; |
|
112 | 112 | } |
113 | 113 | if( (isset($_GET['device'])) && ($_GET['device'] == "on") ) { |
114 | - $worksheet->write($lineCount, $rowCount, _('Device') ,$format_header); |
|
115 | - $rowCount++; |
|
116 | - # get Devices and reorder |
|
117 | - $devices = $Tools->fetch_all_objects ("devices", "hostname"); |
|
118 | - $devices_indexed = array(); |
|
119 | - if ($devices!==false) { |
|
120 | - foreach($devices as $d) { |
|
121 | - $devices_indexed[$d->id] = $d; |
|
122 | - } |
|
123 | - } |
|
114 | + $worksheet->write($lineCount, $rowCount, _('Device') ,$format_header); |
|
115 | + $rowCount++; |
|
116 | + # get Devices and reorder |
|
117 | + $devices = $Tools->fetch_all_objects ("devices", "hostname"); |
|
118 | + $devices_indexed = array(); |
|
119 | + if ($devices!==false) { |
|
120 | + foreach($devices as $d) { |
|
121 | + $devices_indexed[$d->id] = $d; |
|
122 | + } |
|
123 | + } |
|
124 | 124 | } |
125 | 125 | if( (isset($_GET['note'])) && ($_GET['note'] == "on") ) { |
126 | - $worksheet->write($lineCount, $rowCount, _('Note') ,$format_header); |
|
127 | - $rowCount++; |
|
126 | + $worksheet->write($lineCount, $rowCount, _('Note') ,$format_header); |
|
127 | + $rowCount++; |
|
128 | 128 | } |
129 | 129 | if( (isset($_GET['tag'])) && ($_GET['tag'] == "on") ) { |
130 | - $worksheet->write($lineCount, $rowCount, _('Tag') ,$format_header); |
|
131 | - $rowCount++; |
|
132 | - # get IP address types |
|
133 | - $ip_types = $Addresses->addresses_types_fetch(); |
|
130 | + $worksheet->write($lineCount, $rowCount, _('Tag') ,$format_header); |
|
131 | + $rowCount++; |
|
132 | + # get IP address types |
|
133 | + $ip_types = $Addresses->addresses_types_fetch(); |
|
134 | 134 | } |
135 | 135 | if( (isset($_GET['gateway'])) && ($_GET['gateway'] == "on") ) { |
136 | - $worksheet->write($lineCount, $rowCount, _('Gateway') ,$format_header); |
|
137 | - $rowCount++; |
|
136 | + $worksheet->write($lineCount, $rowCount, _('Gateway') ,$format_header); |
|
137 | + $rowCount++; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | //custom fields |
141 | 141 | if(sizeof($custom_fields) > 0) { |
142 | - foreach($custom_fields as $myField) { |
|
143 | - //set temp name - replace space with three ___ |
|
144 | - $myField['nameTemp'] = str_replace(" ", "___", $myField['name']); |
|
145 | - |
|
146 | - if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) { |
|
147 | - $worksheet->write($lineCount, $rowCount, $myField['name'] ,$format_header); |
|
148 | - $rowCount++; |
|
149 | - } |
|
150 | - } |
|
142 | + foreach($custom_fields as $myField) { |
|
143 | + //set temp name - replace space with three ___ |
|
144 | + $myField['nameTemp'] = str_replace(" ", "___", $myField['name']); |
|
145 | + |
|
146 | + if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) { |
|
147 | + $worksheet->write($lineCount, $rowCount, $myField['name'] ,$format_header); |
|
148 | + $rowCount++; |
|
149 | + } |
|
150 | + } |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | $rowCount = 0; |
@@ -155,171 +155,171 @@ discard block |
||
155 | 155 | |
156 | 156 | //write Subnet entries for the selected sections |
157 | 157 | if($all_sections!==false) { |
158 | - foreach ($all_sections as $section) { |
|
159 | - //cast |
|
160 | - $section = (array) $section; |
|
161 | - |
|
162 | - if( (isset($_GET['exportSection__'.$section['name']])) && ($_GET['exportSection__'.$section['name']] == "on") ) { |
|
163 | - // get all subnets in section |
|
164 | - $section_subnets = $Subnets->fetch_section_subnets($section['id']); |
|
165 | - |
|
166 | - if (sizeof($section_subnets)==0) { continue; } |
|
167 | - |
|
168 | - foreach ($section_subnets as $subnet) { |
|
169 | - |
|
170 | - $subnet = (array) $subnet; |
|
171 | - |
|
172 | - // ignore folders |
|
173 | - if($subnet['isFolder']) { continue; } |
|
174 | - |
|
175 | - // grab IP addresses |
|
176 | - $ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']); |
|
177 | - |
|
178 | - if (sizeof($ipaddresses)==0) { continue; } |
|
179 | - |
|
180 | - foreach ($ipaddresses as $ip) { |
|
181 | - |
|
182 | - //cast |
|
183 | - $ip = (array) $ip; |
|
184 | - |
|
185 | - |
|
186 | - if( (isset($_GET['section'])) && ($_GET['section'] == "on") ) { |
|
187 | - $worksheet->write($lineCount, $rowCount, $section['name'], $format_text); |
|
188 | - $rowCount++; |
|
189 | - } |
|
190 | - |
|
191 | - if( (isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on") ) { |
|
192 | - $worksheet->write($lineCount, $rowCount, $Subnets->transform_to_dotted($ip['ip_addr']), $format_text); |
|
193 | - $rowCount++; |
|
194 | - } |
|
195 | - |
|
196 | - if( (isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on") ) { |
|
197 | - $worksheet->write($lineCount, $rowCount, $ip['dns_name'], $format_text); |
|
198 | - $rowCount++; |
|
199 | - } |
|
200 | - |
|
201 | - if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) { |
|
202 | - $worksheet->write($lineCount, $rowCount, $ip['description'], $format_text); |
|
203 | - $rowCount++; |
|
204 | - } |
|
205 | - |
|
206 | - if( (isset($_GET['vrf'])) && ($_GET['vrf'] == "on") ) { |
|
207 | - $worksheet->write($lineCount, $rowCount, $vrfs[$subnet['vrfId']], $format_text); |
|
208 | - $rowCount++; |
|
209 | - } |
|
210 | - |
|
211 | - if( (isset($_GET['subnet'])) && ($_GET['subnet'] == "on") ) { |
|
212 | - $worksheet->write($lineCount, $rowCount, $subnet['ip']."/".$subnet['mask'], $format_text); |
|
213 | - $rowCount++; |
|
214 | - } |
|
215 | - |
|
216 | - if( (isset($_GET['state'])) && ($_GET['state'] == "on") ) { |
|
217 | - $worksheet->write($lineCount, $rowCount, $ip['state'], $format_text); |
|
218 | - $rowCount++; |
|
219 | - } |
|
220 | - |
|
221 | - if( (isset($_GET['mac'])) && ($_GET['mac'] == "on") ) { |
|
222 | - $worksheet->write($lineCount, $rowCount, $ip['mac'], $format_text); |
|
223 | - $rowCount++; |
|
224 | - } |
|
225 | - |
|
226 | - if( (isset($_GET['owner'])) && ($_GET['owner'] == "on") ) { |
|
227 | - $worksheet->write($lineCount, $rowCount, $ip['owner'], $format_text); |
|
228 | - $rowCount++; |
|
229 | - } |
|
230 | - |
|
231 | - if( (isset($_GET['device'])) && ($_GET['device'] == "on") ) { |
|
232 | - //change device to name |
|
233 | - $ip['device'] = is_null($ip['switch'])||strlen($ip['switch'])==0||$ip['switch']==0 ? "" : $devices_indexed[$ip['switch']]->hostname; |
|
234 | - $worksheet->write($lineCount, $rowCount, $ip['device'], $format_text); |
|
235 | - $rowCount++; |
|
236 | - } |
|
237 | - |
|
238 | - if( (isset($_GET['note'])) && ($_GET['note'] == "on") ) { |
|
239 | - $worksheet->write($lineCount, $rowCount, $ip['note'], $format_text); |
|
240 | - $rowCount++; |
|
241 | - } |
|
242 | - |
|
243 | - if( (isset($_GET['tag'])) && ($_GET['tag'] == "on") ) { |
|
244 | - //reformat tag |
|
245 | - $ip['tag'] = (@$ip_types[$ip['state']]['showtag']) ? $ip_types[$ip['state']]['type'] : ""; |
|
246 | - $worksheet->write($lineCount, $rowCount, $ip['tag'], $format_text); |
|
247 | - $rowCount++; |
|
248 | - } |
|
249 | - |
|
250 | - if( (isset($_GET['gateway'])) && ($_GET['gateway'] == "on") ) { |
|
251 | - $ip['gateway'] = ($ip['is_gateway']) ? _("Yes") : _("No"); |
|
252 | - $worksheet->write($lineCount, $rowCount, $ip['gateway'], $format_text); |
|
253 | - $rowCount++; |
|
254 | - } |
|
255 | - |
|
256 | - //custom fields, per subnet |
|
257 | - if(sizeof($custom_fields) > 0) { |
|
258 | - foreach($custom_fields as $myField) { |
|
259 | - //set temp name - replace space with three ___ |
|
260 | - $myField['nameTemp'] = str_replace(" ", "___", $myField['name']); |
|
261 | - |
|
262 | - if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) { |
|
263 | - $worksheet->write($lineCount, $rowCount, $ip[$myField['name']], $format_text); |
|
264 | - $rowCount++; |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - //reset row count |
|
270 | - $rowCount = 0; |
|
271 | - $lineCount++; |
|
272 | - } |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
158 | + foreach ($all_sections as $section) { |
|
159 | + //cast |
|
160 | + $section = (array) $section; |
|
161 | + |
|
162 | + if( (isset($_GET['exportSection__'.$section['name']])) && ($_GET['exportSection__'.$section['name']] == "on") ) { |
|
163 | + // get all subnets in section |
|
164 | + $section_subnets = $Subnets->fetch_section_subnets($section['id']); |
|
165 | + |
|
166 | + if (sizeof($section_subnets)==0) { continue; } |
|
167 | + |
|
168 | + foreach ($section_subnets as $subnet) { |
|
169 | + |
|
170 | + $subnet = (array) $subnet; |
|
171 | + |
|
172 | + // ignore folders |
|
173 | + if($subnet['isFolder']) { continue; } |
|
174 | + |
|
175 | + // grab IP addresses |
|
176 | + $ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']); |
|
177 | + |
|
178 | + if (sizeof($ipaddresses)==0) { continue; } |
|
179 | + |
|
180 | + foreach ($ipaddresses as $ip) { |
|
181 | + |
|
182 | + //cast |
|
183 | + $ip = (array) $ip; |
|
184 | + |
|
185 | + |
|
186 | + if( (isset($_GET['section'])) && ($_GET['section'] == "on") ) { |
|
187 | + $worksheet->write($lineCount, $rowCount, $section['name'], $format_text); |
|
188 | + $rowCount++; |
|
189 | + } |
|
190 | + |
|
191 | + if( (isset($_GET['ip_addr'])) && ($_GET['ip_addr'] == "on") ) { |
|
192 | + $worksheet->write($lineCount, $rowCount, $Subnets->transform_to_dotted($ip['ip_addr']), $format_text); |
|
193 | + $rowCount++; |
|
194 | + } |
|
195 | + |
|
196 | + if( (isset($_GET['dns_name'])) && ($_GET['dns_name'] == "on") ) { |
|
197 | + $worksheet->write($lineCount, $rowCount, $ip['dns_name'], $format_text); |
|
198 | + $rowCount++; |
|
199 | + } |
|
200 | + |
|
201 | + if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) { |
|
202 | + $worksheet->write($lineCount, $rowCount, $ip['description'], $format_text); |
|
203 | + $rowCount++; |
|
204 | + } |
|
205 | + |
|
206 | + if( (isset($_GET['vrf'])) && ($_GET['vrf'] == "on") ) { |
|
207 | + $worksheet->write($lineCount, $rowCount, $vrfs[$subnet['vrfId']], $format_text); |
|
208 | + $rowCount++; |
|
209 | + } |
|
210 | + |
|
211 | + if( (isset($_GET['subnet'])) && ($_GET['subnet'] == "on") ) { |
|
212 | + $worksheet->write($lineCount, $rowCount, $subnet['ip']."/".$subnet['mask'], $format_text); |
|
213 | + $rowCount++; |
|
214 | + } |
|
215 | + |
|
216 | + if( (isset($_GET['state'])) && ($_GET['state'] == "on") ) { |
|
217 | + $worksheet->write($lineCount, $rowCount, $ip['state'], $format_text); |
|
218 | + $rowCount++; |
|
219 | + } |
|
220 | + |
|
221 | + if( (isset($_GET['mac'])) && ($_GET['mac'] == "on") ) { |
|
222 | + $worksheet->write($lineCount, $rowCount, $ip['mac'], $format_text); |
|
223 | + $rowCount++; |
|
224 | + } |
|
225 | + |
|
226 | + if( (isset($_GET['owner'])) && ($_GET['owner'] == "on") ) { |
|
227 | + $worksheet->write($lineCount, $rowCount, $ip['owner'], $format_text); |
|
228 | + $rowCount++; |
|
229 | + } |
|
230 | + |
|
231 | + if( (isset($_GET['device'])) && ($_GET['device'] == "on") ) { |
|
232 | + //change device to name |
|
233 | + $ip['device'] = is_null($ip['switch'])||strlen($ip['switch'])==0||$ip['switch']==0 ? "" : $devices_indexed[$ip['switch']]->hostname; |
|
234 | + $worksheet->write($lineCount, $rowCount, $ip['device'], $format_text); |
|
235 | + $rowCount++; |
|
236 | + } |
|
237 | + |
|
238 | + if( (isset($_GET['note'])) && ($_GET['note'] == "on") ) { |
|
239 | + $worksheet->write($lineCount, $rowCount, $ip['note'], $format_text); |
|
240 | + $rowCount++; |
|
241 | + } |
|
242 | + |
|
243 | + if( (isset($_GET['tag'])) && ($_GET['tag'] == "on") ) { |
|
244 | + //reformat tag |
|
245 | + $ip['tag'] = (@$ip_types[$ip['state']]['showtag']) ? $ip_types[$ip['state']]['type'] : ""; |
|
246 | + $worksheet->write($lineCount, $rowCount, $ip['tag'], $format_text); |
|
247 | + $rowCount++; |
|
248 | + } |
|
249 | + |
|
250 | + if( (isset($_GET['gateway'])) && ($_GET['gateway'] == "on") ) { |
|
251 | + $ip['gateway'] = ($ip['is_gateway']) ? _("Yes") : _("No"); |
|
252 | + $worksheet->write($lineCount, $rowCount, $ip['gateway'], $format_text); |
|
253 | + $rowCount++; |
|
254 | + } |
|
255 | + |
|
256 | + //custom fields, per subnet |
|
257 | + if(sizeof($custom_fields) > 0) { |
|
258 | + foreach($custom_fields as $myField) { |
|
259 | + //set temp name - replace space with three ___ |
|
260 | + $myField['nameTemp'] = str_replace(" ", "___", $myField['name']); |
|
261 | + |
|
262 | + if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) { |
|
263 | + $worksheet->write($lineCount, $rowCount, $ip[$myField['name']], $format_text); |
|
264 | + $rowCount++; |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + //reset row count |
|
270 | + $rowCount = 0; |
|
271 | + $lineCount++; |
|
272 | + } |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | 276 | } |
277 | 277 | //new line |
278 | 278 | $lineCount++; |
279 | 279 | |
280 | 280 | //write section sheet |
281 | 281 | if( (isset($_GET['exportSections'])) && ($_GET['exportSections'] == "on") ) { |
282 | - // Create a worksheet |
|
283 | - $worksheet_sections =& $workbook->addWorksheet('Sections'); |
|
284 | - |
|
285 | - $lineCount = 0; |
|
286 | - $rowCount = 0; |
|
287 | - |
|
288 | - //write headers |
|
289 | - $worksheet_sections->write($lineCount, $rowCount, _('Name') ,$format_header); |
|
290 | - $rowCount++; |
|
291 | - $worksheet_sections->write($lineCount, $rowCount, _('Description') ,$format_header); |
|
292 | - $rowCount++; |
|
293 | - $worksheet_sections->write($lineCount, $rowCount, _('Parent') ,$format_header); |
|
294 | - $rowCount++; |
|
295 | - |
|
296 | - $lineCount++; |
|
297 | - $rowCount = 0; |
|
298 | - |
|
299 | - foreach ($sections_sorted as $section) { |
|
300 | - //cast |
|
301 | - $section = (array) $section; |
|
302 | - |
|
303 | - if( (isset($_GET['exportSection__'.str_replace(" ", "_", $section['name'])])) && ($_GET['exportSection__'.str_replace(" ", "_", $section['name'])] == "on") ) { |
|
304 | - $worksheet_sections->write($lineCount, $rowCount, $section['name'], $format_text); |
|
305 | - $rowCount++; |
|
306 | - $worksheet_sections->write($lineCount, $rowCount, $section['description'], $format_text); |
|
307 | - $rowCount++; |
|
308 | - //master Section |
|
309 | - if($section['masterSection']!=0) { |
|
310 | - # get section details |
|
311 | - $ssec = $Admin->fetch_object("sections", "id", $section['masterSection']); |
|
312 | - $worksheet_sections->write($lineCount, $rowCount, $ssec->name, $format_text); |
|
313 | - $rowCount++; |
|
314 | - } else { |
|
315 | - $worksheet_sections->write($lineCount, $rowCount, "/", $format_text); |
|
316 | - $rowCount++; |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - $lineCount++; |
|
321 | - $rowCount = 0; |
|
322 | - } |
|
282 | + // Create a worksheet |
|
283 | + $worksheet_sections =& $workbook->addWorksheet('Sections'); |
|
284 | + |
|
285 | + $lineCount = 0; |
|
286 | + $rowCount = 0; |
|
287 | + |
|
288 | + //write headers |
|
289 | + $worksheet_sections->write($lineCount, $rowCount, _('Name') ,$format_header); |
|
290 | + $rowCount++; |
|
291 | + $worksheet_sections->write($lineCount, $rowCount, _('Description') ,$format_header); |
|
292 | + $rowCount++; |
|
293 | + $worksheet_sections->write($lineCount, $rowCount, _('Parent') ,$format_header); |
|
294 | + $rowCount++; |
|
295 | + |
|
296 | + $lineCount++; |
|
297 | + $rowCount = 0; |
|
298 | + |
|
299 | + foreach ($sections_sorted as $section) { |
|
300 | + //cast |
|
301 | + $section = (array) $section; |
|
302 | + |
|
303 | + if( (isset($_GET['exportSection__'.str_replace(" ", "_", $section['name'])])) && ($_GET['exportSection__'.str_replace(" ", "_", $section['name'])] == "on") ) { |
|
304 | + $worksheet_sections->write($lineCount, $rowCount, $section['name'], $format_text); |
|
305 | + $rowCount++; |
|
306 | + $worksheet_sections->write($lineCount, $rowCount, $section['description'], $format_text); |
|
307 | + $rowCount++; |
|
308 | + //master Section |
|
309 | + if($section['masterSection']!=0) { |
|
310 | + # get section details |
|
311 | + $ssec = $Admin->fetch_object("sections", "id", $section['masterSection']); |
|
312 | + $worksheet_sections->write($lineCount, $rowCount, $ssec->name, $format_text); |
|
313 | + $rowCount++; |
|
314 | + } else { |
|
315 | + $worksheet_sections->write($lineCount, $rowCount, "/", $format_text); |
|
316 | + $rowCount++; |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + $lineCount++; |
|
321 | + $rowCount = 0; |
|
322 | + } |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | // sending HTTP headers |
@@ -60,44 +60,44 @@ |
||
60 | 60 | |
61 | 61 | # manually adjust the standard fields |
62 | 62 | foreach($expfields as $std_field) { |
63 | - # extra table and field |
|
64 | - if (isset($extfields[$std_field])) { |
|
65 | - $cfield = $extfields[$std_field]["field"]; |
|
66 | - $ctable = $extfields[$std_field]["table"]; |
|
67 | - $pname = $extfields[$std_field]["pname"]." "; |
|
68 | - } else { |
|
69 | - # default table and field |
|
70 | - $cfield = $std_field; |
|
71 | - $ctable = $mtable; |
|
72 | - $pname = ""; |
|
73 | - } |
|
74 | - |
|
75 | - # read field attributes |
|
76 | - $field = $Tools->fetch_full_field_definition($ctable,$cfield); |
|
77 | - $field = (array) $field; |
|
78 | - |
|
79 | - # mark required fields with * |
|
80 | - $msgr = in_array($std_field,$reqfields) ? "*" : ""; |
|
81 | - |
|
82 | - #prebuild template table rows to avoid useless foreach loops |
|
83 | - $tpl_field_names.= "<th>".($pname ? $pname : $field['Field']).$msgr."</th>"; |
|
84 | - $tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>"; |
|
63 | + # extra table and field |
|
64 | + if (isset($extfields[$std_field])) { |
|
65 | + $cfield = $extfields[$std_field]["field"]; |
|
66 | + $ctable = $extfields[$std_field]["table"]; |
|
67 | + $pname = $extfields[$std_field]["pname"]." "; |
|
68 | + } else { |
|
69 | + # default table and field |
|
70 | + $cfield = $std_field; |
|
71 | + $ctable = $mtable; |
|
72 | + $pname = ""; |
|
73 | + } |
|
74 | + |
|
75 | + # read field attributes |
|
76 | + $field = $Tools->fetch_full_field_definition($ctable,$cfield); |
|
77 | + $field = (array) $field; |
|
78 | + |
|
79 | + # mark required fields with * |
|
80 | + $msgr = in_array($std_field,$reqfields) ? "*" : ""; |
|
81 | + |
|
82 | + #prebuild template table rows to avoid useless foreach loops |
|
83 | + $tpl_field_names.= "<th>".($pname ? $pname : $field['Field']).$msgr."</th>"; |
|
84 | + $tpl_field_types.= "<td><small>". wordwrap($field['Type'],18,"<br>\n",true) ."</small></td>"; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | # append the custom fields, if any |
88 | 88 | $custom_fields = $Tools->fetch_custom_fields($mtable); |
89 | 89 | if(sizeof($custom_fields) > 0) { |
90 | - foreach($custom_fields as $myField) { |
|
91 | - # add field to required fields if needed |
|
92 | - if ($myField['Null'] == "NO") { $reqfields[] = $myField['name']; } |
|
93 | - # mark required fields with * |
|
94 | - $msgr = in_array($myField['name'],$reqfields) ? "*" : ""; |
|
95 | - |
|
96 | - $tpl_field_names.= "<th>".$myField['name'].$msgr."</th>"; |
|
97 | - $tpl_field_types.= "<td><small>". wordwrap($myField['type'],18,"<br>\n",true) ."</small></td>"; |
|
98 | - $expfields[] = $myField['name']; |
|
90 | + foreach($custom_fields as $myField) { |
|
91 | + # add field to required fields if needed |
|
92 | + if ($myField['Null'] == "NO") { $reqfields[] = $myField['name']; } |
|
93 | + # mark required fields with * |
|
94 | + $msgr = in_array($myField['name'],$reqfields) ? "*" : ""; |
|
95 | + |
|
96 | + $tpl_field_names.= "<th>".$myField['name'].$msgr."</th>"; |
|
97 | + $tpl_field_types.= "<td><small>". wordwrap($myField['type'],18,"<br>\n",true) ."</small></td>"; |
|
98 | + $expfields[] = $myField['name']; |
|
99 | 99 | // $disfields[] = $myField['name']; |
100 | - } |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | ?> |
@@ -25,77 +25,77 @@ |
||
25 | 25 | |
26 | 26 | |
27 | 27 | if ($type == 'subnets'){ |
28 | - //get all custom fields! |
|
29 | - $custom_address_fields = $Tools->fetch_custom_fields('subnets'); |
|
30 | - // set headers |
|
31 | - $worksheet->write($lineCount, 0, _('Section')); |
|
32 | - $worksheet->write($lineCount, 1, _('Subnet')); |
|
33 | - $worksheet->write($lineCount, 2, _('Mask')); |
|
34 | - $worksheet->write($lineCount, 3, _('Description')); |
|
35 | - $worksheet->write($lineCount, 4, _('VLAN')); |
|
36 | - $worksheet->write($lineCount, 5, _('VLAN Domain')); |
|
37 | - $worksheet->write($lineCount, 6, _('VRF')); |
|
38 | - $fc =7 ; |
|
39 | - foreach($custom_address_fields as $k=>$f) { |
|
40 | - $worksheet->write($lineCount, $fc, $k); |
|
41 | - $fc++; |
|
42 | - } |
|
28 | + //get all custom fields! |
|
29 | + $custom_address_fields = $Tools->fetch_custom_fields('subnets'); |
|
30 | + // set headers |
|
31 | + $worksheet->write($lineCount, 0, _('Section')); |
|
32 | + $worksheet->write($lineCount, 1, _('Subnet')); |
|
33 | + $worksheet->write($lineCount, 2, _('Mask')); |
|
34 | + $worksheet->write($lineCount, 3, _('Description')); |
|
35 | + $worksheet->write($lineCount, 4, _('VLAN')); |
|
36 | + $worksheet->write($lineCount, 5, _('VLAN Domain')); |
|
37 | + $worksheet->write($lineCount, 6, _('VRF')); |
|
38 | + $fc =7 ; |
|
39 | + foreach($custom_address_fields as $k=>$f) { |
|
40 | + $worksheet->write($lineCount, $fc, $k); |
|
41 | + $fc++; |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | elseif ($type == 'ipaddr'){ |
45 | - //get all custom fields! |
|
46 | - $custom_address_fields = $Tools->fetch_custom_fields('ipaddresses'); |
|
47 | - // set headers |
|
48 | - // "section","ip_addr","dns_name","description","vrf","subnet","mac","owner","device","note","tag","gateway" |
|
49 | - $worksheet->write($lineCount, 0, _('Section')); |
|
50 | - $worksheet->write($lineCount, 1, _('IP address')); |
|
51 | - $worksheet->write($lineCount, 2, _('DNS Hostname')); |
|
52 | - $worksheet->write($lineCount, 3, _('Description')); |
|
53 | - $worksheet->write($lineCount, 4, _('VRF')); |
|
54 | - $worksheet->write($lineCount, 4, _('Subnet')); |
|
55 | - $worksheet->write($lineCount, 5, _('MAC')); |
|
56 | - $worksheet->write($lineCount, 6, _('Owner')); |
|
57 | - $worksheet->write($lineCount, 7, _('Device')); |
|
58 | - $worksheet->write($lineCount, 8, _('Note')); |
|
59 | - $worksheet->write($lineCount, 9, _('Tag')); |
|
60 | - $worksheet->write($lineCount, 10, _('Gateway')); |
|
61 | - $fc =7 ; |
|
62 | - foreach($custom_address_fields as $k=>$f) { |
|
63 | - $worksheet->write($lineCount, $fc, $k); |
|
64 | - $fc++; |
|
65 | - } |
|
45 | + //get all custom fields! |
|
46 | + $custom_address_fields = $Tools->fetch_custom_fields('ipaddresses'); |
|
47 | + // set headers |
|
48 | + // "section","ip_addr","dns_name","description","vrf","subnet","mac","owner","device","note","tag","gateway" |
|
49 | + $worksheet->write($lineCount, 0, _('Section')); |
|
50 | + $worksheet->write($lineCount, 1, _('IP address')); |
|
51 | + $worksheet->write($lineCount, 2, _('DNS Hostname')); |
|
52 | + $worksheet->write($lineCount, 3, _('Description')); |
|
53 | + $worksheet->write($lineCount, 4, _('VRF')); |
|
54 | + $worksheet->write($lineCount, 4, _('Subnet')); |
|
55 | + $worksheet->write($lineCount, 5, _('MAC')); |
|
56 | + $worksheet->write($lineCount, 6, _('Owner')); |
|
57 | + $worksheet->write($lineCount, 7, _('Device')); |
|
58 | + $worksheet->write($lineCount, 8, _('Note')); |
|
59 | + $worksheet->write($lineCount, 9, _('Tag')); |
|
60 | + $worksheet->write($lineCount, 10, _('Gateway')); |
|
61 | + $fc =7 ; |
|
62 | + foreach($custom_address_fields as $k=>$f) { |
|
63 | + $worksheet->write($lineCount, $fc, $k); |
|
64 | + $fc++; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | elseif ($type == 'vrf'){ |
68 | - //get all custom fields! |
|
69 | - $custom_address_fields = $Tools->fetch_custom_fields('vrf'); |
|
70 | - // set headers |
|
71 | - $worksheet->write($lineCount, 0, _('Name')); |
|
72 | - $worksheet->write($lineCount, 1, _('RD')); |
|
73 | - $worksheet->write($lineCount, 2, _('Description')); |
|
74 | - $fc =3 ; |
|
75 | - foreach($custom_address_fields as $k=>$f) { |
|
76 | - $worksheet->write($lineCount, $fc, $k); |
|
77 | - $fc++; |
|
78 | - } |
|
68 | + //get all custom fields! |
|
69 | + $custom_address_fields = $Tools->fetch_custom_fields('vrf'); |
|
70 | + // set headers |
|
71 | + $worksheet->write($lineCount, 0, _('Name')); |
|
72 | + $worksheet->write($lineCount, 1, _('RD')); |
|
73 | + $worksheet->write($lineCount, 2, _('Description')); |
|
74 | + $fc =3 ; |
|
75 | + foreach($custom_address_fields as $k=>$f) { |
|
76 | + $worksheet->write($lineCount, $fc, $k); |
|
77 | + $fc++; |
|
78 | + } |
|
79 | 79 | } |
80 | 80 | elseif ($type == 'vlans'){ |
81 | - //get all custom fields! |
|
82 | - $custom_address_fields = $Tools->fetch_custom_fields('vlans'); |
|
83 | - // set headers |
|
84 | - $worksheet->write($lineCount, 0, _('Name')); |
|
85 | - $worksheet->write($lineCount, 1, _('Number')); |
|
86 | - $worksheet->write($lineCount, 2, _('Description')); |
|
87 | - $worksheet->write($lineCount, 3, _('Domain name')); |
|
88 | - $fc =4 ; |
|
89 | - foreach($custom_address_fields as $k=>$f) { |
|
90 | - $worksheet->write($lineCount, $fc, $k); |
|
91 | - $fc++; |
|
92 | - } |
|
81 | + //get all custom fields! |
|
82 | + $custom_address_fields = $Tools->fetch_custom_fields('vlans'); |
|
83 | + // set headers |
|
84 | + $worksheet->write($lineCount, 0, _('Name')); |
|
85 | + $worksheet->write($lineCount, 1, _('Number')); |
|
86 | + $worksheet->write($lineCount, 2, _('Description')); |
|
87 | + $worksheet->write($lineCount, 3, _('Domain name')); |
|
88 | + $fc =4 ; |
|
89 | + foreach($custom_address_fields as $k=>$f) { |
|
90 | + $worksheet->write($lineCount, $fc, $k); |
|
91 | + $fc++; |
|
92 | + } |
|
93 | 93 | } |
94 | 94 | elseif ($type == 'l2dom'){ |
95 | - // set headers |
|
96 | - $worksheet->write($lineCount, 0, _('Name')); |
|
97 | - $worksheet->write($lineCount, 1, _('Description')); |
|
98 | - $fc =2 ; |
|
95 | + // set headers |
|
96 | + $worksheet->write($lineCount, 0, _('Name')); |
|
97 | + $worksheet->write($lineCount, 1, _('Description')); |
|
98 | + $fc =2 ; |
|
99 | 99 | } |
100 | 100 | // sending HTTP headers |
101 | 101 | $workbook->send($filename); |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | # process for easier later check |
35 | 35 | $vrf_data = array(); |
36 | 36 | foreach ($all_vrfs as $vrf) { |
37 | - //cast |
|
38 | - $vrf = (array) $vrf; |
|
39 | - $vrf_data[$vrf['name']] = $vrf; |
|
40 | - $vrf_data[$vrf['rd']] = $vrf; # add also RD as VRF name, will allow matches against both name and RD |
|
37 | + //cast |
|
38 | + $vrf = (array) $vrf; |
|
39 | + $vrf_data[$vrf['name']] = $vrf; |
|
40 | + $vrf_data[$vrf['rd']] = $vrf; # add also RD as VRF name, will allow matches against both name and RD |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | # fetch all sections and load all subnets |
@@ -49,41 +49,41 @@ discard block |
||
49 | 49 | $subnet_data = array(); |
50 | 50 | |
51 | 51 | foreach ($all_sections as $section) { |
52 | - $section = (array) $section; |
|
53 | - $section_names[strtolower($section['name'])] = $section; |
|
52 | + $section = (array) $section; |
|
53 | + $section_names[strtolower($section['name'])] = $section; |
|
54 | 54 | |
55 | - # skip sections we're not importing for, so we save cpu time and memory |
|
56 | - if (!isset($used_section[strtolower($section['name'])])) { continue; } |
|
55 | + # skip sections we're not importing for, so we save cpu time and memory |
|
56 | + if (!isset($used_section[strtolower($section['name'])])) { continue; } |
|
57 | 57 | |
58 | - $section_subnets = $Subnets->fetch_section_subnets($section['id']); |
|
58 | + $section_subnets = $Subnets->fetch_section_subnets($section['id']); |
|
59 | 59 | |
60 | - # skip empty sections |
|
61 | - if (sizeof($section_subnets)==0) { continue; } |
|
60 | + # skip empty sections |
|
61 | + if (sizeof($section_subnets)==0) { continue; } |
|
62 | 62 | |
63 | - foreach ($section_subnets as $subnet) { |
|
64 | - $subnet = (array) $subnet; |
|
63 | + foreach ($section_subnets as $subnet) { |
|
64 | + $subnet = (array) $subnet; |
|
65 | 65 | |
66 | - # ignore folders |
|
67 | - if($subnet['isFolder']) { continue; } |
|
66 | + # ignore folders |
|
67 | + if($subnet['isFolder']) { continue; } |
|
68 | 68 | |
69 | - # store needed subnet information |
|
70 | - $subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']] = $subnet; |
|
71 | - $subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']]['type'] = $Subnets->identify_address($subnet['ip']); |
|
69 | + # store needed subnet information |
|
70 | + $subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']] = $subnet; |
|
71 | + $subnet_data[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']]['type'] = $Subnets->identify_address($subnet['ip']); |
|
72 | 72 | |
73 | - # grab IP addresses |
|
74 | - $ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']); |
|
73 | + # grab IP addresses |
|
74 | + $ipaddresses = $Addresses->fetch_subnet_addresses ($subnet['id']); |
|
75 | 75 | |
76 | - if (sizeof($ipaddresses)==0) { continue; } |
|
76 | + if (sizeof($ipaddresses)==0) { continue; } |
|
77 | 77 | |
78 | - foreach ($ipaddresses as $ip) { |
|
78 | + foreach ($ipaddresses as $ip) { |
|
79 | 79 | |
80 | - //cast |
|
81 | - $ip = (array) $ip; |
|
80 | + //cast |
|
81 | + $ip = (array) $ip; |
|
82 | 82 | |
83 | - $edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']][$Subnets->transform_address($ip['ip_addr'], "dotted")] = $ip; |
|
83 | + $edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']][$Subnets->transform_address($ip['ip_addr'], "dotted")] = $ip; |
|
84 | 84 | |
85 | - } |
|
86 | - } |
|
85 | + } |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | # Load available tags |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | $device_data = array(); |
95 | 95 | $devices = $Tools->fetch_all_objects("devices", "hostname"); |
96 | 96 | if ($devices!==false) { |
97 | - foreach($devices as $c_dev) { |
|
98 | - $c_dev = (array) $c_dev; |
|
99 | - $c_dev_sections=explode(";", $c_dev['sections']); |
|
100 | - # Populate each section with the devices it has |
|
101 | - foreach($c_dev_sections as $c_dev_sect) { $device_data[$c_dev_sect][$c_dev['hostname']] = $c_dev;} |
|
102 | - } |
|
97 | + foreach($devices as $c_dev) { |
|
98 | + $c_dev = (array) $c_dev; |
|
99 | + $c_dev_sections=explode(";", $c_dev['sections']); |
|
100 | + # Populate each section with the devices it has |
|
101 | + foreach($c_dev_sections as $c_dev_sect) { $device_data[$c_dev_sect][$c_dev['hostname']] = $c_dev;} |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | $rows = ""; |
@@ -108,156 +108,156 @@ discard block |
||
108 | 108 | |
109 | 109 | # check the fields |
110 | 110 | foreach ($data as &$cdata) { |
111 | - $msg = ""; $action = ""; $cfieldtds = ""; |
|
112 | - |
|
113 | - # check if required fields are present and not empty |
|
114 | - foreach($reqfields as $creq) { |
|
115 | - if ((!isset($cdata[$creq]) or ($cdata[$creq] == ""))) { $msg.= "Required field ".$creq." missing or empty."; $action = "error"; } |
|
116 | - } |
|
117 | - |
|
118 | - # if the subnet contains "/", split it in network and mask |
|
119 | - if ($action != "error") { |
|
120 | - if (preg_match("/\//", $cdata['subnet'])) { |
|
121 | - list($caddr,$cmask) = explode("/",$cdata['subnet'],2); |
|
122 | - $cdata['mask'] = $cmask; |
|
123 | - $cdata['subnet'] = $caddr; |
|
124 | - } |
|
125 | - else { $msg.= "The subnet needs to have the mask defined as /BM (Bit Mask)"; $action = "error"; } |
|
126 | - if ((!empty($cdata['mask'])) && (!preg_match("/^([0-9]+|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/", $cdata['mask']))) { |
|
127 | - $msg.="Invalid network mask format."; $action = "error"; |
|
128 | - } else { |
|
129 | - $cdata['type'] = $Subnets->identify_address($cdata['subnet']); |
|
130 | - if (($cdata['type'] == "IPv6") && (($cdata['mask']<0) || ($cdata['mask']>128))) { $msg.="Invalid IPv6 network mask."; $action = "error"; } |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - # Check if section is provided and valid and link it if it is |
|
135 | - if (!isset($section_names[strtolower($cdata['section'])])) { |
|
136 | - $msg.= "Invalid section."; $action = "error"; |
|
137 | - } else { |
|
138 | - $cdata['sectionId'] = $section_names[strtolower($cdata['section'])]['id']; |
|
139 | - } |
|
140 | - |
|
141 | - # Check if VRF is provided and valid and link it if it is |
|
142 | - if (!empty($cdata['vrf'])) { |
|
143 | - if (!isset($vrf_data[$cdata['vrf']])) { |
|
144 | - $msg.= "Invalid VRF."; $action = "error"; |
|
145 | - } else { |
|
146 | - $cdata['vrfId'] = $vrf_data[$cdata['vrf']]['vrfId']; |
|
147 | - } |
|
148 | - } else { |
|
149 | - # no VRF provided, using default |
|
150 | - $cdata['vrfId'] = 0; |
|
151 | - } |
|
152 | - |
|
153 | - # Check if Subnet is provided and valid and link it if it is |
|
154 | - if ((!empty($cdata['subnet'])) and (!empty($cdata['mask']))) { |
|
155 | - if (!isset($subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']])) { |
|
156 | - $msg.= "Invalid Subnet."; $action = "error"; |
|
157 | - } else { |
|
158 | - $cdata['subnetId'] = $subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']]['id']; |
|
159 | - } |
|
160 | - } else { |
|
161 | - # no subnet provided, search not implemented yet, giving out error. |
|
162 | - $msg.= "Subnet/Mask not provided."; $action = "error"; |
|
163 | - } |
|
164 | - |
|
165 | - # Match device name against device IDs |
|
166 | - if (!empty($cdata['device'])) { |
|
167 | - if (!isset($device_data[$cdata['sectionId']][$cdata['device']])) { |
|
168 | - $msg.= "Invalid device hostname."; $action = "error"; |
|
169 | - } else { |
|
170 | - $cdata['switch'] = $device_data[$cdata['sectionId']][$cdata['device']]['id']; |
|
171 | - } |
|
172 | - } else { |
|
173 | - $cdata['switch'] = 0; |
|
174 | - } |
|
175 | - |
|
176 | - # Check if a tag is provided and valid and link it if it is |
|
177 | - if (!empty($cdata['tag'])) { |
|
178 | - if (!isset($tag_data[$cdata['tag']])) { |
|
179 | - $msg.= "Invalid tag."; $action = "error"; |
|
180 | - } else { |
|
181 | - $cdata['state'] = $tag_data[$cdata['tag']]['id']; |
|
182 | - } |
|
183 | - } else { |
|
184 | - # no tag provided, using default |
|
185 | - $cdata['state'] = 2; |
|
186 | - } |
|
111 | + $msg = ""; $action = ""; $cfieldtds = ""; |
|
112 | + |
|
113 | + # check if required fields are present and not empty |
|
114 | + foreach($reqfields as $creq) { |
|
115 | + if ((!isset($cdata[$creq]) or ($cdata[$creq] == ""))) { $msg.= "Required field ".$creq." missing or empty."; $action = "error"; } |
|
116 | + } |
|
117 | + |
|
118 | + # if the subnet contains "/", split it in network and mask |
|
119 | + if ($action != "error") { |
|
120 | + if (preg_match("/\//", $cdata['subnet'])) { |
|
121 | + list($caddr,$cmask) = explode("/",$cdata['subnet'],2); |
|
122 | + $cdata['mask'] = $cmask; |
|
123 | + $cdata['subnet'] = $caddr; |
|
124 | + } |
|
125 | + else { $msg.= "The subnet needs to have the mask defined as /BM (Bit Mask)"; $action = "error"; } |
|
126 | + if ((!empty($cdata['mask'])) && (!preg_match("/^([0-9]+|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/", $cdata['mask']))) { |
|
127 | + $msg.="Invalid network mask format."; $action = "error"; |
|
128 | + } else { |
|
129 | + $cdata['type'] = $Subnets->identify_address($cdata['subnet']); |
|
130 | + if (($cdata['type'] == "IPv6") && (($cdata['mask']<0) || ($cdata['mask']>128))) { $msg.="Invalid IPv6 network mask."; $action = "error"; } |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + # Check if section is provided and valid and link it if it is |
|
135 | + if (!isset($section_names[strtolower($cdata['section'])])) { |
|
136 | + $msg.= "Invalid section."; $action = "error"; |
|
137 | + } else { |
|
138 | + $cdata['sectionId'] = $section_names[strtolower($cdata['section'])]['id']; |
|
139 | + } |
|
140 | + |
|
141 | + # Check if VRF is provided and valid and link it if it is |
|
142 | + if (!empty($cdata['vrf'])) { |
|
143 | + if (!isset($vrf_data[$cdata['vrf']])) { |
|
144 | + $msg.= "Invalid VRF."; $action = "error"; |
|
145 | + } else { |
|
146 | + $cdata['vrfId'] = $vrf_data[$cdata['vrf']]['vrfId']; |
|
147 | + } |
|
148 | + } else { |
|
149 | + # no VRF provided, using default |
|
150 | + $cdata['vrfId'] = 0; |
|
151 | + } |
|
152 | + |
|
153 | + # Check if Subnet is provided and valid and link it if it is |
|
154 | + if ((!empty($cdata['subnet'])) and (!empty($cdata['mask']))) { |
|
155 | + if (!isset($subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']])) { |
|
156 | + $msg.= "Invalid Subnet."; $action = "error"; |
|
157 | + } else { |
|
158 | + $cdata['subnetId'] = $subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']]['id']; |
|
159 | + } |
|
160 | + } else { |
|
161 | + # no subnet provided, search not implemented yet, giving out error. |
|
162 | + $msg.= "Subnet/Mask not provided."; $action = "error"; |
|
163 | + } |
|
164 | + |
|
165 | + # Match device name against device IDs |
|
166 | + if (!empty($cdata['device'])) { |
|
167 | + if (!isset($device_data[$cdata['sectionId']][$cdata['device']])) { |
|
168 | + $msg.= "Invalid device hostname."; $action = "error"; |
|
169 | + } else { |
|
170 | + $cdata['switch'] = $device_data[$cdata['sectionId']][$cdata['device']]['id']; |
|
171 | + } |
|
172 | + } else { |
|
173 | + $cdata['switch'] = 0; |
|
174 | + } |
|
175 | + |
|
176 | + # Check if a tag is provided and valid and link it if it is |
|
177 | + if (!empty($cdata['tag'])) { |
|
178 | + if (!isset($tag_data[$cdata['tag']])) { |
|
179 | + $msg.= "Invalid tag."; $action = "error"; |
|
180 | + } else { |
|
181 | + $cdata['state'] = $tag_data[$cdata['tag']]['id']; |
|
182 | + } |
|
183 | + } else { |
|
184 | + # no tag provided, using default |
|
185 | + $cdata['state'] = 2; |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | - # Verify gateway |
|
190 | - if (in_array(strtolower($cdata['is_gateway']),array("yes","true","1"))) { $cdata['is_gateway'] = 1; } else { $cdata['is_gateway'] = 0; } |
|
189 | + # Verify gateway |
|
190 | + if (in_array(strtolower($cdata['is_gateway']),array("yes","true","1"))) { $cdata['is_gateway'] = 1; } else { $cdata['is_gateway'] = 0; } |
|
191 | 191 | |
192 | - if ($action != "error") { |
|
193 | - if(!$Addresses->validate_ip($cdata['ip_addr'])) { $msg.="Invalid IP address."; $action = "error"; } |
|
194 | - if ((!empty($cdata['dns_name'])) and (!preg_match("/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/", $cdata['dns_name']))) { $msg.="Invalid DNS name."; $action = "error"; } |
|
195 | - if (preg_match("/[;'\"]/", $cdata['description'])) { $msg.="Invalid characters in description."; $action = "error"; } |
|
196 | - if ($cdata['mac']) { |
|
197 | - if (!preg_match("/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/", $cdata['mac'])) { $msg.="Invalid MAC address."; $action = "error"; } |
|
198 | - } |
|
199 | - if (preg_match("/[;'\"]/", $cdata['owner'])) { $msg.="Invalid characters in owner name."; $action = "error"; } |
|
200 | - if (preg_match("/[;'\"]/", $cdata['note'])) { $msg.="Invalid characters in note."; $action = "error"; } |
|
201 | - } |
|
202 | - |
|
203 | - # check if duplicate in the import data |
|
204 | - if ($action != "error") { |
|
205 | - if (isset($ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) { $msg.="Duplicate entry in imported data."; $action = "error"; } |
|
206 | - } |
|
207 | - |
|
208 | - # check if existing in database |
|
209 | - if ($action != "error") { |
|
210 | - if (isset($edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) { |
|
211 | - # copy content to a variable for easier checks |
|
212 | - $cedata = $edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']]; |
|
213 | - |
|
214 | - # Check if we need to change any fields |
|
215 | - $action = "skip"; # skip duplicate fields if identical, update if different |
|
216 | - if ($cdata['dns_name'] != $cedata['dns_name']) { $msg.= "Address DNS name will be updated."; $action = "edit"; } |
|
217 | - if ($cdata['description'] != $cedata['description']) { $msg.= "Address description will be updated."; $action = "edit"; } |
|
218 | - if ($cdata['mac'] != $cedata['mac']) { $msg.= "Address MAC address will be updated."; $action = "edit"; } |
|
219 | - if ($cdata['owner'] != $cedata['owner']) { $msg.= "Address owner will be updated."; $action = "edit"; } |
|
220 | - if ($cdata['switch'] != $cedata['switch']) { $msg.= "Device will be updated."; $action = "edit"; } |
|
221 | - if ($cdata['note'] != $cedata['note']) { $msg.= "Address note will be updated."; $action = "edit"; } |
|
222 | - if ($cdata['state'] != $cedata['state']) { $msg.= "Address tag (state) will be updated."; $action = "edit"; } |
|
223 | - |
|
224 | - # Check if the values of the custom fields have changed |
|
225 | - if(sizeof($custom_fields) > 0) { |
|
226 | - foreach($custom_fields as $myField) { |
|
227 | - if ($cdata[$myField['name']] != $cedata[$myField['name']]) { |
|
228 | - $msg.= $myField['name']." will be updated."; $action = "edit"; |
|
229 | - } |
|
230 | - } |
|
231 | - } |
|
232 | - |
|
233 | - if ($action == "skip") { |
|
234 | - $msg.= "Duplicate, will skip."; |
|
235 | - } else { |
|
236 | - # set id of matched subnet |
|
237 | - $cdata['id'] = $cedata['id']; |
|
238 | - # copy some fields which we don't import, but need to set |
|
192 | + if ($action != "error") { |
|
193 | + if(!$Addresses->validate_ip($cdata['ip_addr'])) { $msg.="Invalid IP address."; $action = "error"; } |
|
194 | + if ((!empty($cdata['dns_name'])) and (!preg_match("/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/", $cdata['dns_name']))) { $msg.="Invalid DNS name."; $action = "error"; } |
|
195 | + if (preg_match("/[;'\"]/", $cdata['description'])) { $msg.="Invalid characters in description."; $action = "error"; } |
|
196 | + if ($cdata['mac']) { |
|
197 | + if (!preg_match("/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/", $cdata['mac'])) { $msg.="Invalid MAC address."; $action = "error"; } |
|
198 | + } |
|
199 | + if (preg_match("/[;'\"]/", $cdata['owner'])) { $msg.="Invalid characters in owner name."; $action = "error"; } |
|
200 | + if (preg_match("/[;'\"]/", $cdata['note'])) { $msg.="Invalid characters in note."; $action = "error"; } |
|
201 | + } |
|
202 | + |
|
203 | + # check if duplicate in the import data |
|
204 | + if ($action != "error") { |
|
205 | + if (isset($ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) { $msg.="Duplicate entry in imported data."; $action = "error"; } |
|
206 | + } |
|
207 | + |
|
208 | + # check if existing in database |
|
209 | + if ($action != "error") { |
|
210 | + if (isset($edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) { |
|
211 | + # copy content to a variable for easier checks |
|
212 | + $cedata = $edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']]; |
|
213 | + |
|
214 | + # Check if we need to change any fields |
|
215 | + $action = "skip"; # skip duplicate fields if identical, update if different |
|
216 | + if ($cdata['dns_name'] != $cedata['dns_name']) { $msg.= "Address DNS name will be updated."; $action = "edit"; } |
|
217 | + if ($cdata['description'] != $cedata['description']) { $msg.= "Address description will be updated."; $action = "edit"; } |
|
218 | + if ($cdata['mac'] != $cedata['mac']) { $msg.= "Address MAC address will be updated."; $action = "edit"; } |
|
219 | + if ($cdata['owner'] != $cedata['owner']) { $msg.= "Address owner will be updated."; $action = "edit"; } |
|
220 | + if ($cdata['switch'] != $cedata['switch']) { $msg.= "Device will be updated."; $action = "edit"; } |
|
221 | + if ($cdata['note'] != $cedata['note']) { $msg.= "Address note will be updated."; $action = "edit"; } |
|
222 | + if ($cdata['state'] != $cedata['state']) { $msg.= "Address tag (state) will be updated."; $action = "edit"; } |
|
223 | + |
|
224 | + # Check if the values of the custom fields have changed |
|
225 | + if(sizeof($custom_fields) > 0) { |
|
226 | + foreach($custom_fields as $myField) { |
|
227 | + if ($cdata[$myField['name']] != $cedata[$myField['name']]) { |
|
228 | + $msg.= $myField['name']." will be updated."; $action = "edit"; |
|
229 | + } |
|
230 | + } |
|
231 | + } |
|
232 | + |
|
233 | + if ($action == "skip") { |
|
234 | + $msg.= "Duplicate, will skip."; |
|
235 | + } else { |
|
236 | + # set id of matched subnet |
|
237 | + $cdata['id'] = $cedata['id']; |
|
238 | + # copy some fields which we don't import, but need to set |
|
239 | 239 | // $cdata['port'] = $cedata['port']; $cdata['lastseen'] = $cedata['lastseen']; |
240 | 240 | // $cdata['excludePing'] = $cedata['excludePing']; |
241 | 241 | // $cdata['PTRignore'] = $cedata['PTRignore']; $cdata['PTR'] = $cedata['PTR']; $cdata['NAT'] = $cedata['NAT']; |
242 | 242 | // $cdata['firewallAddressObject'] = $cedata['firewallAddressObject']; |
243 | - } |
|
244 | - } else { |
|
245 | - $msg.="New entry, will be added."; $action = "add"; |
|
243 | + } |
|
244 | + } else { |
|
245 | + $msg.="New entry, will be added."; $action = "add"; |
|
246 | 246 | |
247 | - # Add it to ndata for duplicate check |
|
248 | - $ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']] = $cdata; |
|
249 | - } |
|
250 | - } |
|
247 | + # Add it to ndata for duplicate check |
|
248 | + $ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']] = $cdata; |
|
249 | + } |
|
250 | + } |
|
251 | 251 | |
252 | - $cdata['msg'].= $msg; |
|
253 | - $cdata['action'] = $action; |
|
254 | - $counters[$action]++; |
|
252 | + $cdata['msg'].= $msg; |
|
253 | + $cdata['action'] = $action; |
|
254 | + $counters[$action]++; |
|
255 | 255 | |
256 | - $cdata['subnet'] = $cdata['subnet']."/".$cdata['mask']; |
|
256 | + $cdata['subnet'] = $cdata['subnet']."/".$cdata['mask']; |
|
257 | 257 | |
258 | - $rows.="<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>"; |
|
259 | - foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; } |
|
260 | - $rows.= "<td>"._($cdata['msg'])."</td></tr>"; |
|
258 | + $rows.="<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>"; |
|
259 | + foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; } |
|
260 | + $rows.= "<td>"._($cdata['msg'])."</td></tr>"; |
|
261 | 261 | |
262 | 262 | } |
263 | 263 |
@@ -33,45 +33,45 @@ |
||
33 | 33 | |
34 | 34 | # import IP Addresses |
35 | 35 | foreach ($data as &$cdata) { |
36 | - if (($cdata['action'] == "add") || ($cdata['action'] == "edit")) { |
|
37 | - // # set update array |
|
38 | - |
|
39 | - $values = array("id"=>$cdata['id'], |
|
40 | - "ip_addr"=>$Addresses->transform_address($cdata['ip_addr'],"decimal"), |
|
41 | - "subnetId"=>$cdata['subnetId'], |
|
42 | - "dns_name"=>$cdata['dns_name'], |
|
43 | - "description"=>$cdata['description'], |
|
44 | - "mac"=>$cdata['mac'], |
|
45 | - "owner"=>$cdata['owner'], |
|
46 | - "switch"=>$cdata['switch'], |
|
47 | - "state"=>$cdata['state'], |
|
48 | - "note"=>$cdata['note'], |
|
49 | - "is_gateway"=>$cdata['is_gateway'] |
|
50 | - ); |
|
51 | - |
|
52 | - # add custom fields |
|
53 | - if(sizeof($custom_fields) > 0) { |
|
54 | - foreach($custom_fields as $myField) { |
|
55 | - if(isset($cdata[$myField['name']])) { $values[$myField['name']] = $cdata[$myField['name']]; } |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - # update |
|
60 | - $cdata['result'] = $Admin->object_modify("ipaddresses", $cdata['action'], "id", $values); |
|
61 | - |
|
62 | - if ($cdata['result']) { |
|
63 | - $trc = $colors[$cdata['action']]; |
|
64 | - $msg = "IP Address ".$cdata['action']." successful."; |
|
65 | - } else { |
|
66 | - $trc = "danger"; |
|
67 | - $msg = "IP Address ".$cdata['action']." failed."; |
|
68 | - } |
|
69 | - |
|
70 | - $rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>"; |
|
71 | - foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; } |
|
72 | - $rows.= "<td>"._($msg)."</td></tr>"; |
|
73 | - |
|
74 | - } |
|
36 | + if (($cdata['action'] == "add") || ($cdata['action'] == "edit")) { |
|
37 | + // # set update array |
|
38 | + |
|
39 | + $values = array("id"=>$cdata['id'], |
|
40 | + "ip_addr"=>$Addresses->transform_address($cdata['ip_addr'],"decimal"), |
|
41 | + "subnetId"=>$cdata['subnetId'], |
|
42 | + "dns_name"=>$cdata['dns_name'], |
|
43 | + "description"=>$cdata['description'], |
|
44 | + "mac"=>$cdata['mac'], |
|
45 | + "owner"=>$cdata['owner'], |
|
46 | + "switch"=>$cdata['switch'], |
|
47 | + "state"=>$cdata['state'], |
|
48 | + "note"=>$cdata['note'], |
|
49 | + "is_gateway"=>$cdata['is_gateway'] |
|
50 | + ); |
|
51 | + |
|
52 | + # add custom fields |
|
53 | + if(sizeof($custom_fields) > 0) { |
|
54 | + foreach($custom_fields as $myField) { |
|
55 | + if(isset($cdata[$myField['name']])) { $values[$myField['name']] = $cdata[$myField['name']]; } |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + # update |
|
60 | + $cdata['result'] = $Admin->object_modify("ipaddresses", $cdata['action'], "id", $values); |
|
61 | + |
|
62 | + if ($cdata['result']) { |
|
63 | + $trc = $colors[$cdata['action']]; |
|
64 | + $msg = "IP Address ".$cdata['action']." successful."; |
|
65 | + } else { |
|
66 | + $trc = "danger"; |
|
67 | + $msg = "IP Address ".$cdata['action']." failed."; |
|
68 | + } |
|
69 | + |
|
70 | + $rows.="<tr class='".$trc."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>"; |
|
71 | + foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; } |
|
72 | + $rows.= "<td>"._($msg)."</td></tr>"; |
|
73 | + |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | print "<table class='table table-condensed table-hover' id='resultstable'><tbody>"; |
77 | 77 | print "<tr class='active'>".$hrow."<th>Result</th></tr>"; |