Commit 81ce2c2d authored by Ad Schellevis's avatar Ad Schellevis

(legacy) cleanups related to interfaces.inc (remove unused, move single usage, isset issues)

parent e2196365
This diff is collapsed.
......@@ -43,6 +43,42 @@ function xmlrpc_publishable_legacy()
return $publish;
}
/*
* does_vip_exist($vip): return true or false if a vip is
* configured.
*/
function does_vip_exist($vip) {
global $config;
if(!$vip)
return false;
switch ($vip['mode']) {
case "carp":
case "ipalias":
/* XXX: Make proper checks? */
$realif = get_real_interface($vip['interface']);
if (!does_interface_exist($realif)) {
return false;
}
break;
case "proxyarp":
/* XXX: Implement this */
default:
return false;
}
$ifacedata = pfSense_getall_interface_addresses($realif);
foreach ($ifacedata as $vipips) {
if ($vipips == "{$vip['subnet']}/{$vip['subnet_bits']}")
return true;
}
return false;
}
/**
* @param null $category
* @return mixed
......
......@@ -30,6 +30,26 @@
require_once("guiconfig.inc");
require_once("globals.inc");
function interfaces_carp_set_maintenancemode($carp_maintenancemode){
global $config;
if (isset($config["virtualip_carp_maintenancemode"]) && $carp_maintenancemode == false) {
unset($config["virtualip_carp_maintenancemode"]);
write_config("Leave CARP maintenance mode");
} else
if (!isset($config["virtualip_carp_maintenancemode"]) && $carp_maintenancemode == true) {
$config["virtualip_carp_maintenancemode"] = true;
write_config("Enter CARP maintenance mode");
}
$viparr = &$config['virtualip']['vip'];
foreach ($viparr as $vip) {
if ($vip['mode'] == "carp") {
interface_carp_configure($vip);
}
}
}
unset($interface_arr_cache);
unset($carp_interface_count_cache);
unset($interface_ip_arr_cache);
......
......@@ -39,6 +39,74 @@ require_once("rrd.inc");
require_once("vpn.inc");
require_once("xmlparse_attr.inc");
function get_wireless_modes($interface) {
/* return wireless modes and channels */
$wireless_modes = array();
$cloned_interface = get_real_interface($interface);
if($cloned_interface && is_interface_wireless($cloned_interface)) {
$chan_list = "/sbin/ifconfig {$cloned_interface} list chan";
$stack_list = "/usr/bin/awk -F\"Channel \" '{ gsub(/\\*/, \" \"); print \$2 \"\\\n\" \$3 }'";
$format_list = "/usr/bin/awk '{print \$5 \" \" \$6 \",\" \$1}'";
$interface_channels = "";
exec("$chan_list | $stack_list | sort -u | $format_list 2>&1", $interface_channels);
$interface_channel_count = count($interface_channels);
$c = 0;
while ($c < $interface_channel_count) {
$channel_line = explode(",", $interface_channels["$c"]);
$wireless_mode = trim($channel_line[0]);
$wireless_channel = trim($channel_line[1]);
if(trim($wireless_mode) != "") {
/* if we only have 11g also set 11b channels */
if($wireless_mode == "11g") {
if(!isset($wireless_modes["11b"]))
$wireless_modes["11b"] = array();
} else if($wireless_mode == "11g ht") {
if(!isset($wireless_modes["11b"]))
$wireless_modes["11b"] = array();
if(!isset($wireless_modes["11g"]))
$wireless_modes["11g"] = array();
$wireless_mode = "11ng";
} else if($wireless_mode == "11a ht") {
if(!isset($wireless_modes["11a"]))
$wireless_modes["11a"] = array();
$wireless_mode = "11na";
}
$wireless_modes["$wireless_mode"]["$c"] = $wireless_channel;
}
$c++;
}
}
return($wireless_modes);
}
/* return channel numbers, frequency, max txpower, and max regulation txpower */
function get_wireless_channel_info($interface) {
$wireless_channels = array();
$cloned_interface = get_real_interface($interface);
if($cloned_interface && is_interface_wireless($cloned_interface)) {
$chan_list = "/sbin/ifconfig {$cloned_interface} list txpower";
$stack_list = "/usr/bin/awk -F\"Channel \" '{ gsub(/\\*/, \" \"); print \$2 \"\\\n\" \$3 }'";
$format_list = "/usr/bin/awk '{print \$1 \",\" \$3 \" \" \$4 \",\" \$5 \",\" \$7}'";
$interface_channels = "";
exec("$chan_list | $stack_list | sort -u | $format_list 2>&1", $interface_channels);
foreach ($interface_channels as $channel_line) {
$channel_line = explode(",", $channel_line);
if(!isset($wireless_channels[$channel_line[0]]))
$wireless_channels[$channel_line[0]] = $channel_line;
}
}
return($wireless_channels);
}
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
// Get configured interface list
......
......@@ -34,6 +34,41 @@ require_once("functions.inc");
require_once("filter.inc");
require_once("rrd.inc");
/*
* find_ip_interface($ip): return the interface where an ip is defined
* (or if $bits is specified, where an IP within the subnet is defined)
*/
function find_ip_interface($ip, $bits = null) {
if (!is_ipaddr($ip))
return false;
$isv6ip = is_ipaddrv6($ip);
/* if list */
$ifdescrs = get_configured_interface_list();
foreach ($ifdescrs as $ifdescr => $ifname) {
$ifip = ($isv6ip) ? get_interface_ipv6($ifname) : get_interface_ip($ifname);
if (is_null($ifip))
continue;
if (is_null($bits)) {
if ($ip == $ifip) {
$int = get_real_interface($ifname);
return $int;
}
}
else {
if (ip_in_subnet($ifip, $ip . "/" . $bits)) {
$int = get_real_interface($ifname);
return $int;
}
}
}
return false;
}
global $g;
$stepid = htmlspecialchars($_GET['stepid']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment