/**
 * list available interfaces for lagg
 * @param null $selected_id selected item index
 * @return array
 */
function available_interfaces($selected_id = null)
{
    global $config;
    // configured interfaces
    $configured_interfaces = array();
    foreach (get_configured_interface_list(false, true) as $intf) {
        $configured_interfaces[] = get_real_interface($intf);
    }
    // lagg members from other lagg interfaces
    $lagg_member_interfaces = array();
    foreach ($config['laggs']['lagg'] as $lagg_idx => $lagg) {
        if ($lagg_idx == $selected_id) {
            continue;
        }
        foreach (explode(",", $lagg['members']) as $lagg_member) {
            $lagg_member_interfaces[] = get_real_interface($lagg_member);
        }
    }
    $interfaces = array();
    foreach (get_interface_list() as $intf => $intf_info) {
        if (strpos($intf, '_vlan')) {
            // skip vlans
            continue;
        } elseif (in_array($intf, $lagg_member_interfaces)) {
            // skip members of other lagg interfaces
            continue;
        } elseif (in_array($intf, $configured_interfaces)) {
            // skip configured interfaces
            continue;
        }
        $interfaces[$intf] = $intf_info;
    }
    return $interfaces;
}
Example #2
0
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;
}
Example #3
0
function qinq_inuse($num)
{
    global $config, $a_qinqs;
    $iflist = get_configured_interface_list(false, true);
    foreach ($iflist as $if) {
        if ($config['interfaces'][$if]['if'] == $a_qinqs[$num]['qinqif']) {
            return true;
        }
    }
    return false;
}
function clone_inuse($cloneif)
{
    global $config;
    $iflist = get_configured_interface_list(false, true);
    foreach ($iflist as $if) {
        if ($config['interfaces'][$if]['if'] == $cloneif) {
            return true;
        }
    }
    return false;
}
Example #5
0
function ppp_inuse($num)
{
    global $config, $g;
    $iflist = get_configured_interface_list(false, true);
    if (!is_array($config['ppps']['ppp'])) {
        return false;
    }
    foreach ($iflist as $if) {
        if ($config['interfaces'][$if]['if'] == $config['ppps']['ppp'][$num]['if']) {
            return true;
        }
    }
    return false;
}
Example #6
0
function lagg_inuse($num)
{
    global $config, $a_laggs;
    $iflist = get_configured_interface_list(false, true);
    foreach ($iflist as $if) {
        if ($config['interfaces'][$if]['if'] == $a_laggs[$num]['laggif']) {
            return true;
        }
    }
    if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
        foreach ($config['vlans']['vlan'] as $vlan) {
            if ($vlan['if'] == $a_laggs[$num]['laggif']) {
                return true;
            }
        }
    }
    return false;
}
Example #7
0
function lagg_inuse($lagg_intf)
{
    global $config;
    $iflist = get_configured_interface_list(false, true);
    foreach ($iflist as $if) {
        if ($config['interfaces'][$if]['if'] == $lagg_intf) {
            return true;
        }
    }
    if (isset($config['vlans']['vlan'])) {
        foreach ($config['vlans']['vlan'] as $vlan) {
            if ($vlan['if'] == $lagg_intf) {
                return true;
            }
        }
    }
    return false;
}
Example #8
0
}
if (!$pconfig['timeservers']) {
    $pconfig['timeservers'] = "pool.ntp.org";
}
$changedesc = gettext("System") . ": ";
$changecount = 0;
function is_timezone($elt)
{
    return !preg_match("/\\/\$/", $elt);
}
if ($pconfig['timezone'] != $_POST['timezone']) {
    filter_pflog_start(true);
}
$timezonelist = system_get_timezone_list();
$multiwan = false;
$interfaces = get_configured_interface_list();
foreach ($interfaces as $interface) {
    if (interface_has_gateway($interface)) {
        $multiwan = true;
    }
}
if ($_POST) {
    $changecount++;
    unset($input_errors);
    $pconfig = $_POST;
    /* input validation */
    $reqdfields = explode(" ", "hostname domain");
    $reqdfieldsn = array(gettext("Hostname"), gettext("Domain"));
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
    if ($_POST['webguicss']) {
        $config['system']['webgui']['webguicss'] = $_POST['webguicss'];
Example #9
0
 if ($config['rrddata']) {
     restore_rrddata();
     unset($config['rrddata']);
     unlink_if_exists("{$g['tmp_path']}/config.cache");
     write_config();
     add_base_packages_menu_items();
     convert_config();
     conf_mount_ro();
 }
 if ($m0n0wall_upgrade == true) {
     if ($config['system']['gateway'] != "") {
         $config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
     }
     unset($config['shaper']);
     /* optional if list */
     $ifdescrs = get_configured_interface_list(true, true);
     /* remove special characters from interface descriptions */
     if (is_array($ifdescrs)) {
         foreach ($ifdescrs as $iface) {
             $config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
         }
     }
     /* check for interface names with an alias */
     if (is_array($ifdescrs)) {
         foreach ($ifdescrs as $iface) {
             if (is_alias($config['interfaces'][$iface]['descr'])) {
                 // Firewall rules
                 $origname = $config['interfaces'][$iface]['descr'];
                 $newname = $config['interfaces'][$iface]['descr'] . "Alias";
                 update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
                 update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
require_once "shaper.inc";
$pgtitle = array(gettext("Firewall"), gettext("Aliases"), gettext("Edit"));
if (isset($_POST['referer'])) {
    $referer = $_POST['referer'];
} else {
    $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_aliases.php';
}
// Keywords not allowed in names
$reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec");
// Add all Load balance names to reserved_keywords
if (is_array($config['load_balancer']['lbpool'])) {
    foreach ($config['load_balancer']['lbpool'] as $lbpool) {
        $reserved_keywords[] = $lbpool['name'];
    }
}
$reserved_ifs = get_configured_interface_list(false, true);
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names);
$max_alias_addresses = 5000;
if (!is_array($config['aliases']['alias'])) {
    $config['aliases']['alias'] = array();
}
$a_aliases =& $config['aliases']['alias'];
$tab = $_REQUEST['tab'];
if ($_POST) {
    $origname = $_POST['origname'];
}
// Debugging
if ($debug) {
    unlink_if_exists("{$g['tmp_path']}/alias_rename_log.txt");
}
function alias_same_type($name, $type)
Example #11
0
function get_interfacestats()
{
    global $config;
    //build interface list for widget use
    $ifdescrs = get_configured_interface_list();
    $array_in_packets = array();
    $array_out_packets = array();
    $array_in_bytes = array();
    $array_out_bytes = array();
    $array_in_errors = array();
    $array_out_errors = array();
    $array_collisions = array();
    $array_interrupt = array();
    $new_data = "";
    //build data arrays
    foreach ($ifdescrs as $ifdescr => $ifname) {
        $ifinfo = get_interface_info($ifdescr);
        $new_data .= "{$ifinfo['inpkts']},";
        $new_data .= "{$ifinfo['outpkts']},";
        $new_data .= format_bytes($ifinfo['inbytes']) . ",";
        $new_data .= format_bytes($ifinfo['outbytes']) . ",";
        if (isset($ifinfo['inerrs'])) {
            $new_data .= "{$ifinfo['inerrs']},";
            $new_data .= "{$ifinfo['outerrs']},";
        } else {
            $new_data .= "0,";
            $new_data .= "0,";
        }
        if (isset($ifinfo['collisions'])) {
            $new_data .= htmlspecialchars($ifinfo['collisions']) . ",";
        } else {
            $new_data .= "0,";
        }
    }
    //end for
    return $new_data;
}
    $graphcmd .= "GPRINT:\"{$curif}-out6_bits_block:MAX:%7.2lf %sb/s\" ";
    $graphcmd .= "GPRINT:\"{$curif}-out6_bits_block:AVERAGE:%7.2lf %Sb/s\" ";
    $graphcmd .= "GPRINT:\"{$curif}-out6_bits_block:LAST:%7.2lf %Sb/s\" ";
    $graphcmd .= "GPRINT:\"{$curif}-bytes_out6_t_block:AVERAGE:%7.2lf %sB o\" ";
    $graphcmd .= "COMMENT:\"\\n\" ";
    $graphcmd .= "COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t" . strftime('%b %d %H\\:%M\\:%S %Y') . "\" ";
} elseif (strstr($curdatabase, "-throughput.rrd")) {
    /* define graphcmd for throughput stats */
    /* this gathers all interface statistics, the database does not actually exist */
    $graphcmd = "{$rrdtool} graph " . escapeshellarg("{$rrdtmppath}{$curdatabase}-{$curgraph}.png") . " ";
    $graphcmd .= "--start {$start} --end {$end} --step {$step} ";
    $graphcmd .= "--vertical-label \"bits/sec\" ";
    $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee ";
    $graphcmd .= "--title \"" . php_uname('n') . " - {$prettydb} - {$hperiod} - {$havg} average\" ";
    $graphcmd .= "--height 200 --width 620 ";
    $iflist = get_configured_interface_list();
    $g = 0;
    $operand = "";
    $comma = "";
    $graphtputbip = "";
    $graphtputbop = "";
    $graphtputbtp = "";
    $graphtputbib = "";
    $graphtputbob = "";
    $graphtputbtb = "";
    $graphtputbyip = "";
    $graphtputbyop = "";
    $graphtputbytp = "";
    $graphtputbyib = "";
    $graphtputbyob = "";
    $graphtputbytb = "";
$portlist = get_interface_list();
$laggprotos = array("none", "lacp", "failover", "fec", "loadbalance", "roundrobin");
$laggprotosuc = array(gettext("NONE"), gettext("LACP"), gettext("FAILOVER"), gettext("FEC"), gettext("LOADBALANCE"), gettext("ROUNDROBIN"));
$protohelp = '<ul>' . '<li>' . '<strong>' . $laggprotosuc[0] . '</strong><br />' . gettext('This protocol is intended to do nothing: it disables any ' . 'traffic without disabling the lagg interface itself.') . '</li>' . '<li>' . '<strong>' . $laggprotosuc[1] . '</strong><br />' . gettext('Supports the IEEE 802.3ad Link Aggregation Control Protocol ' . '(LACP) and the Marker Protocol.	LACP will negotiate a set ' . 'of aggregable links with the peer in to one or more Link ' . 'Aggregated Groups.  Each LAG is composed of ports of the ' . 'same speed, set to full-duplex operation.  The traffic will ' . 'be balanced across the ports in the LAG with the greatest ' . 'total speed, in most cases there will only be one LAG which ' . 'contains all ports.	In the event of changes in physical ' . 'connectivity, Link Aggregation will quickly converge to a ' . 'new configuration.') . '</li>' . '<li>' . '<strong>' . $laggprotosuc[2] . '</strong><br />' . gettext('Sends and receives traffic only through the master port.  If ' . 'the master port becomes unavailable, the next active port is ' . 'used.	The first interface added is the master port; any ' . 'interfaces added after that are used as failover devices.') . '</li>' . '<li>' . '<strong>' . $laggprotosuc[3] . '</strong><br />' . gettext('Supports Cisco EtherChannel.  This is a static setup and ' . 'does not negotiate aggregation with the peer or exchange ' . 'frames to monitor the link.') . '</li>' . '<li>' . '<strong>' . $laggprotosuc[4] . '</strong><br />' . gettext('Balances outgoing traffic across the active ports based on ' . 'hashed protocol header information and accepts incoming ' . 'traffic from any active port.	 This is a static setup and ' . 'does not negotiate aggregation with the peer or exchange ' . 'frames to monitor the link.  The hash includes the Ethernet ' . 'source and destination address, and, if available, the VLAN ' . 'tag, and the IP source and destination address.') . '</li>' . '<li>' . '<strong>' . $laggprotosuc[5] . '</strong><br />' . gettext('Distributes outgoing traffic using a round-robin scheduler ' . 'through all active ports and accepts incoming traffic from ' . 'any active port.') . '</li>' . '</ul>';
$realifchecklist = array();
/* add LAGG interfaces */
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
    foreach ($config['laggs']['lagg'] as $lagg) {
        unset($portlist[$lagg['laggif']]);
        $laggiflist = explode(",", $lagg['members']);
        foreach ($laggiflist as $tmpif) {
            $realifchecklist[get_real_interface($tmpif)] = $tmpif;
        }
    }
}
$checklist = get_configured_interface_list(false, true);
foreach ($checklist as $tmpif) {
    $realifchecklist[get_real_interface($tmpif)] = $tmpif;
}
if (is_numericint($_GET['id'])) {
    $id = $_GET['id'];
}
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
    $id = $_POST['id'];
}
if (isset($id) && $a_laggs[$id]) {
    $pconfig['laggif'] = $a_laggs[$id]['laggif'];
    $pconfig['members'] = $a_laggs[$id]['members'];
    $laggiflist = explode(",", $a_laggs[$id]['members']);
    foreach ($laggiflist as $tmpif) {
        unset($realifchecklist[get_real_interface($tmpif)]);
Example #14
0
    $pconfig['name'] = "dnsmasq";
    $pconfig['description'] = gettext("DNS Forwarder");
    $services[] = $pconfig;
}
$pconfig = array();
$pconfig['name'] = "ntpd";
$pconfig['description'] = gettext("NTP clock sync");
$services[] = $pconfig;
if (isset($config['captiveportal']['enable'])) {
    $pconfig = array();
    $pconfig['name'] = "captiveportal";
    $pconfig['description'] = gettext("Captive Portal");
    $services[] = $pconfig;
}
$iflist = array();
$ifdescrs = get_configured_interface_list();
foreach ($ifdescrs as $if) {
    $oc = $config['interfaces'][$if];
    if ($oc['if'] && !link_interface_to_bridge($if)) {
        $iflist[$if] = $if;
    }
}
$show_dhcprelay = false;
foreach ($iflist as $if) {
    if (isset($config['dhcrelay'][$if]['enable'])) {
        $show_dhcprelay = true;
    }
}
if ($show_dhcprelay == true) {
    $pconfig = array();
    $pconfig['name'] = "dhcrelay";