Project

General

Profile

« Previous | Next » 

Revision 9d9bac0a

Added by Scott Ullrich over 18 years ago

get_interface_info is now in pfsense-utils.inc. Who moved this function without testing the rest of the pages!?

View differences:

usr/local/www/load_balancer_pool_edit.php
163 163
	}
164 164
}
165 165

  
166
function get_interface_info($ifdescr) {
167
	
168
	global $config, $linkinfo, $netstatrninfo;
169
	
170
	$ifinfo = array();
171
	
172
	/* find out interface name */
173
	$ifinfo['hwif'] = $config['interfaces'][$ifdescr]['if'];
174
	if ($ifdescr == "wan")
175
		$ifinfo['if'] = get_real_wan_interface();
176
	else
177
		$ifinfo['if'] = $ifinfo['hwif'];
178
	
179
	/* run netstat to determine link info */
180
	
181
	unset($linkinfo);
182
	exec("/usr/bin/netstat -I " . $ifinfo['hwif'] . " -nWb -f link", $linkinfo);
183
	$linkinfo = preg_split("/\s+/", $linkinfo[1]);
184
	if (preg_match("/\*$/", $linkinfo[0])) {
185
		$ifinfo['status'] = "down";
186
	} else {
187
		$ifinfo['status'] = "up";
188
	}
189
	
190
	/* PPPoE interface? -> get status from virtual interface */
191
	if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pppoe")) {
192
		unset($linkinfo);
193
		exec("/usr/bin/netstat -I " . $ifinfo['if'] . " -nWb -f link", $linkinfo);
194
		$linkinfo = preg_split("/\s+/", $linkinfo[1]);
195
		if (preg_match("/\*$/", $linkinfo[0])) {
196
			$ifinfo['pppoelink'] = "down";
197
		} else {
198
			/* get PPPoE link status for dial on demand */
199
			$ifconfiginfo = "";
200
			unset($ifconfiginfo);
201
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
202
			
203
			$ifinfo['pppoelink'] = "up";
204
			
205
			foreach ($ifconfiginfo as $ici) {
206
				if (strpos($ici, 'LINK0') !== false)
207
					$ifinfo['pppoelink'] = "down";
208
			}
209
		}
210
	}
211
	
212
	/* PPTP interface? -> get status from virtual interface */
213
	if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pptp")) {
214
		unset($linkinfo);
215
		exec("/usr/bin/netstat -I " . $ifinfo['if'] . " -nWb -f link", $linkinfo);
216
		$linkinfo = preg_split("/\s+/", $linkinfo[1]);
217
		if (preg_match("/\*$/", $linkinfo[0])) {
218
			$ifinfo['pptplink'] = "down";
219
		} else {
220
			/* get PPTP link status for dial on demand */
221
			unset($ifconfiginfo);
222
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
223
			
224
			$ifinfo['pptplink'] = "up";
225
			
226
			foreach ($ifconfiginfo as $ici) {
227
				if (strpos($ici, 'LINK0') !== false)
228
					$ifinfo['pptplink'] = "down";
229
			}
230
		}
231
	}
232
	
233
	if ($ifinfo['status'] == "up") {
234
		/* try to determine media with ifconfig */
235
		$matches = "";
236
		
237
		if ($ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down") {
238
			/* try to determine IP address and netmask with ifconfig */
239
			unset($ifconfiginfo);
240
			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
241
			
242
			foreach ($ifconfiginfo as $ici) {
243
				if (preg_match("/inet (\S+)/", $ici, $matches)) {
244
					$ifinfo['ipaddr'] = $matches[1];
245
				}
246
				if (preg_match("/netmask (\S+)/", $ici, $matches)) {
247
					if (preg_match("/^0x/", $matches[1]))
248
						$ifinfo['subnet'] = long2ip(hexdec($matches[1]));
249
				}
250
			}
251
			
252
			if ($ifdescr == "wan") {
253
				/* run netstat to determine the default gateway */
254
				unset($netstatrninfo);
255
				exec("/usr/bin/netstat -rnf inet", $netstatrninfo);
256
				
257
				foreach ($netstatrninfo as $nsr) {
258
					if (preg_match("/^default\s*(\S+)/", $nsr, $matches)) {
259
						$ifinfo['gateway'] = $matches[1];
260
					}
261
				}
262
			} else {
263
				/* deterimine interface gateway */
264
				$int = convert_friendly_interface_to_real_interface_name($ifdescr);
265
				$gw = get_interface_gateway($int);
266
				if($gw)
267
					$ifinfo['gateway'] = $gw;
268
			}
269
		}
270
	}
271
	
272
	return $ifinfo;
273
}
274

  
275

  
276 166
$pgtitle = "Load Balancer: Pool: Edit";
277 167
include("head.inc");
278 168

  

Also available in: Unified diff