Completed
Pull Request — master (#532)
06:37
created
app/admin/import-export/import-ipaddr-select.php 1 patch
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -61,11 +61,12 @@  discard block
 block discarded – undo
61 61
 # manually adjust the standard fields
62 62
 foreach($expfields as $std_field) {
63 63
 	# extra table and field
64
-	if (isset($extfields[$std_field])) {
64
+	if (isset($extfields[$std_field])) {
65 65
 		$cfield = $extfields[$std_field]["field"];
66 66
 		$ctable = $extfields[$std_field]["table"];
67 67
 		$pname  = $extfields[$std_field]["pname"]." ";
68
-	} else {
68
+	}
69
+	else {
69 70
 		# default table and field
70 71
 		$cfield = $std_field;
71 72
 		$ctable = $mtable;
@@ -86,7 +87,7 @@  discard block
 block discarded – undo
86 87
 
87 88
 # append the custom fields, if any
88 89
 $custom_fields = $Tools->fetch_custom_fields($mtable);
89
-if(sizeof($custom_fields) > 0) {
90
+if(sizeof($custom_fields) > 0) {
90 91
 	foreach($custom_fields as $myField) {
91 92
 		# add field to required fields if needed
92 93
 		if ($myField['Null'] == "NO") { $reqfields[] = $myField['name']; }
Please login to merge, or discard this patch.
app/admin/import-export/import-template.php 1 patch
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 $worksheet = $workbook->addWorksheet("template");
25 25
 
26 26
 
27
-if ($type == 'subnets'){
27
+if ($type == 'subnets') {
28 28
 	//get all custom fields!
29 29
 	$custom_address_fields = $Tools->fetch_custom_fields('subnets');
30 30
 	// set headers
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 		$fc++;
42 42
 	}
43 43
 }
44
-elseif ($type == 'ipaddr'){
44
+elseif ($type == 'ipaddr') {
45 45
 	//get all custom fields!
46 46
 	$custom_address_fields = $Tools->fetch_custom_fields('ipaddresses');
47 47
 	// set headers
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$fc++;
65 65
 	}
66 66
 }
67
-elseif ($type == 'vrf'){
67
+elseif ($type == 'vrf') {
68 68
 	//get all custom fields!
69 69
 	$custom_address_fields = $Tools->fetch_custom_fields('vrf');
70 70
 	// set headers
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		$fc++;
78 78
 	}
79 79
 }
80
-elseif ($type == 'vlans'){
80
+elseif ($type == 'vlans') {
81 81
 	//get all custom fields!
82 82
 	$custom_address_fields = $Tools->fetch_custom_fields('vlans');
83 83
 	// set headers
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 		$fc++;
92 92
 	}
93 93
 }
94
-elseif ($type == 'l2dom'){
94
+elseif ($type == 'l2dom') {
95 95
 	// set headers
96 96
 	$worksheet->write($lineCount, 0, _('Name'));
97 97
 	$worksheet->write($lineCount, 1, _('Description'));
Please login to merge, or discard this patch.
app/admin/import-export/import-ipaddr-preview.php 1 patch
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
 </div>
66 66
 
67 67
 <?php
68
-if (($counters['add'] > 0) || ($counters['edit'] > 0)) {
68
+if (($counters['add'] > 0) || ($counters['edit'] > 0)) {
69 69
 ?>
70 70
 
71 71
 	<script type="text/javascript">
Please login to merge, or discard this patch.
app/admin/import-export/import-ipaddr-check.php 1 patch
Braces   +48 added lines, -35 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 # Load available devices
94 94
 $device_data = array();
95 95
 $devices = $Tools->fetch_all_objects("devices", "hostname");
96
-if ($devices!==false) {
96
+if ($devices!==false) {
97 97
 	foreach($devices as $c_dev) {
98 98
 		$c_dev = (array) $c_dev;
99 99
 		$c_dev_sections=explode(";", $c_dev['sections']);
@@ -116,84 +116,95 @@  discard block
 block discarded – undo
116 116
 	}
117 117
 
118 118
 	# if the subnet contains "/", split it in network and mask
119
-	if ($action != "error") {
120
-		if (preg_match("/\//", $cdata['subnet'])) {
119
+	if ($action != "error") {
120
+		if (preg_match("/\//", $cdata['subnet'])) {
121 121
 			list($caddr,$cmask) = explode("/",$cdata['subnet'],2);
122 122
 			$cdata['mask'] = $cmask;
123 123
 			$cdata['subnet'] = $caddr;
124
-		} 
124
+		}
125 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']))) {
126
+		if ((!empty($cdata['mask'])) && (!preg_match("/^([0-9]+|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/", $cdata['mask']))) {
127 127
 			$msg.="Invalid network mask format."; $action = "error";
128
-		} else {
128
+		}
129
+		else {
129 130
 			$cdata['type'] = $Subnets->identify_address($cdata['subnet']);
130 131
 			if (($cdata['type'] == "IPv6") && (($cdata['mask']<0) || ($cdata['mask']>128))) { $msg.="Invalid IPv6 network mask."; $action = "error"; }
131 132
 		}
132 133
 	}
133 134
 
134 135
 	# Check if section is provided and valid and link it if it is
135
-	if (!isset($section_names[strtolower($cdata['section'])])) {
136
+	if (!isset($section_names[strtolower($cdata['section'])])) {
136 137
 		$msg.= "Invalid section."; $action = "error";
137
-	} else {
138
+	}
139
+	else {
138 140
 		$cdata['sectionId'] = $section_names[strtolower($cdata['section'])]['id'];
139 141
 	}
140 142
 
141 143
 	# 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
+	if (!empty($cdata['vrf'])) {
145
+		if (!isset($vrf_data[$cdata['vrf']])) {
144 146
 			$msg.= "Invalid VRF."; $action = "error";
145
-		} else {
147
+		}
148
+		else {
146 149
 			$cdata['vrfId'] = $vrf_data[$cdata['vrf']]['vrfId'];
147 150
 		}
148
-	} else {
151
+	}
152
+	else {
149 153
 		# no VRF provided, using default
150 154
 		$cdata['vrfId'] = 0;
151 155
 	}
152 156
 
153 157
 	# 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']])) {
158
+	if ((!empty($cdata['subnet'])) and (!empty($cdata['mask']))) {
159
+		if (!isset($subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']])) {
156 160
 			$msg.= "Invalid Subnet."; $action = "error";
157
-		} else {
161
+		}
162
+		else {
158 163
 			$cdata['subnetId'] = $subnet_data[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']]['id'];
159 164
 		}
160
-	} else {
165
+	}
166
+	else {
161 167
 		# no subnet provided, search not implemented yet, giving out error.
162 168
 		$msg.= "Subnet/Mask not provided."; $action = "error";
163 169
 	}
164 170
 
165 171
 	# Match device name against device IDs
166
-	if (!empty($cdata['device'])) {
167
-		if (!isset($device_data[$cdata['sectionId']][$cdata['device']])) {
172
+	if (!empty($cdata['device'])) {
173
+		if (!isset($device_data[$cdata['sectionId']][$cdata['device']])) {
168 174
 			$msg.= "Invalid device hostname."; $action = "error";
169
-		} else {
175
+		}
176
+		else {
170 177
 			$cdata['switch'] = $device_data[$cdata['sectionId']][$cdata['device']]['id'];
171 178
 		}
172
-	} else {
179
+	}
180
+	else {
173 181
 		$cdata['switch'] = 0;
174 182
 	}
175 183
 
176 184
 	# 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']])) {
185
+	if (!empty($cdata['tag'])) {
186
+		if (!isset($tag_data[$cdata['tag']])) {
179 187
 			$msg.= "Invalid tag."; $action = "error";
180
-		} else {
188
+		}
189
+		else {
181 190
 			$cdata['state'] = $tag_data[$cdata['tag']]['id'];
182 191
 		}
183
-	} else {
192
+	}
193
+	else {
184 194
 		# no tag provided, using default
185 195
 		$cdata['state'] = 2;
186 196
 	}
187 197
 
188 198
 	
189 199
 	# Verify gateway
190
-	if (in_array(strtolower($cdata['is_gateway']),array("yes","true","1"))) { $cdata['is_gateway'] = 1; } else { $cdata['is_gateway'] = 0; }
200
+	if (in_array(strtolower($cdata['is_gateway']),array("yes","true","1"))) { $cdata['is_gateway'] = 1; }
201
+	else { $cdata['is_gateway'] = 0; }
191 202
 	
192
-	if ($action != "error") {
203
+	if ($action != "error") {
193 204
     	if(!$Addresses->validate_ip($cdata['ip_addr'])) { $msg.="Invalid IP address."; $action = "error"; }
194 205
 		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 206
 		if (preg_match("/[;'\"]/", $cdata['description'])) { $msg.="Invalid characters in description."; $action = "error"; }
196
-		if ($cdata['mac']) {
207
+		if ($cdata['mac']) {
197 208
 			if (!preg_match("/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/", $cdata['mac'])) { $msg.="Invalid MAC address."; $action = "error"; }
198 209
 		}
199 210
 		if (preg_match("/[;'\"]/", $cdata['owner'])) { $msg.="Invalid characters in owner name."; $action = "error"; }
@@ -201,13 +212,13 @@  discard block
 block discarded – undo
201 212
 	}
202 213
 
203 214
 	# check if duplicate in the import data
204
-	if ($action != "error") {
215
+	if ($action != "error") {
205 216
 		if (isset($ndata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) { $msg.="Duplicate entry in imported data."; $action = "error"; }
206 217
 	}
207 218
 
208 219
 	# check if existing in database
209
-	if ($action != "error") {
210
-		if (isset($edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) {
220
+	if ($action != "error") {
221
+		if (isset($edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']])) {
211 222
 			# copy content to a variable for easier checks
212 223
 			$cedata = $edata[$cdata['sectionId']][$cdata['vrfId']][$cdata['subnet']][$cdata['mask']][$cdata['ip_addr']];
213 224
 
@@ -222,17 +233,18 @@  discard block
 block discarded – undo
222 233
 			if ($cdata['state'] != $cedata['state']) { $msg.= "Address tag (state) will be updated."; $action = "edit"; }
223 234
 
224 235
 			# Check if the values of the custom fields have changed
225
-			if(sizeof($custom_fields) > 0) {
236
+			if(sizeof($custom_fields) > 0) {
226 237
 				foreach($custom_fields as $myField) {
227
-					if ($cdata[$myField['name']] != $cedata[$myField['name']]) {
238
+					if ($cdata[$myField['name']] != $cedata[$myField['name']]) {
228 239
 						$msg.= $myField['name']." will be updated."; $action = "edit";
229 240
 					}
230 241
 				}
231 242
 			}
232 243
 
233
-			if ($action == "skip") {
244
+			if ($action == "skip") {
234 245
 				$msg.= "Duplicate, will skip.";
235
-			} else {
246
+			}
247
+			else {
236 248
 				# set id of matched subnet
237 249
 				$cdata['id'] = $cedata['id'];
238 250
 				# copy some fields which we don't import, but need to set
@@ -241,7 +253,8 @@  discard block
 block discarded – undo
241 253
 // 				$cdata['PTRignore'] = $cedata['PTRignore']; $cdata['PTR'] = $cedata['PTR']; $cdata['NAT'] = $cedata['NAT'];
242 254
 // 				$cdata['firewallAddressObject'] = $cedata['firewallAddressObject'];
243 255
 			}
244
-		} else {
256
+		}
257
+		else {
245 258
 			$msg.="New entry, will be added."; $action = "add";
246 259
 
247 260
 			# Add it to ndata for duplicate check
Please login to merge, or discard this patch.