Esempio n. 1
0
function add_tunnel($mode, $type, $devnam, $inf, $remote, $local, $mtu)
{
    /* Prepare the remote/local commands. */
    if ($remote != "") {
        $rcmd = " remote " . $remote;
    }
    if ($local != "") {
        $lcmd = " local " . $local;
    }
    /* add the tunnel. */
    if ($mode == "6IN4" || $mode == "6TO4" || $mode == "6RD") {
        echo "ip tunnel add " . $devnam . " mode sit ttl 128" . $rcmd . $lcmd . "\n";
    } else {
        if ($mode == "TSP") {
            if ($type == "v6v4") {
                echo "ip tunnel add " . $devnam . " mode sit ttl 64" . $rcmd . $lcmd . "\n";
            } else {
                echo "ip tuntap add " . $devnam . " mode tun\n";
            }
        } else {
            return "";
        }
    }
    if ($mode == "6RD") {
        $p = XNODE_getpathbytarget("/runtime", "inf", "uid", $inf, 0);
        $ipaddr = query($p . "/inet/ipv6/ipv6in4/rd/ipaddr");
        $prefix = query($p . "/inet/ipv6/ipv6in4/rd/prefix");
        $v4mask = query($p . "/inet/ipv6/ipv6in4/rd/v4mask");
        $hubspoke = query($p . "/inet/ipv6/ipv6in4/rd/hubspokemode");
        $networkid = ipv4networkid($local, $v4mask);
        if ($v4mask != "0") {
            $rpcmd = " 6rd-relay_prefix " . $networkid . "/" . $v4mask;
        } else {
            $rpcmd = "";
        }
        if ($hubspoke != "1") {
            echo "ip tunnel 6rd dev " . $devnam . " 6rd-prefix " . $ipaddr . "/" . $prefix . $rpcmd . "\n";
        }
    }
    /* Enable IPv6 on the tunnel device. */
    if ($mtu != "") {
        echo "ip link set " . $devnam . " mtu " . $mtu . "\n";
    }
    echo "ip link set " . $devnam . " up\n";
    echo "echo 0 > /proc/sys/net/ipv6/conf/" . $devnam . "/disable_ipv6\n";
    $uid = "TUN." . $inf;
    $p = PHYINF_setup($uid, "tunnel", $devnam);
    set($p . "/tunnel/mode", $mode);
    set($p . "/tunnel/type", $type);
    set($p . "/tunnel/remote", $remote);
    set($p . "/tunnel/local", $local);
    return $uid;
}
Esempio n. 2
0
function INET_validv4network($ipaddr, $lanip, $mask)
{
    $ipid = ipv4networkid($ipaddr, $mask);
    if ($ipid == "") {
        return 0;
    }
    $lanid = ipv4networkid($lanip, $mask);
    if ($lanid == "") {
        return 0;
    }
    if ($ipid == $lanid) {
        return 1;
    } else {
        return 0;
    }
}
Esempio n. 3
0
function check_ipv4($path, $needgw)
{
    anchor($path);
    $static = query("static");
    if ($static != "1") {
        set("static", "0");
    }
    TRACE_debug("FATLADY: INET_IPV4: static = " . $static);
    if ($static == "1") {
        $ip = query("ipaddr");
        $mask = query("mask");
        $dhcps4 = INF_getinfinfo($_GLOBALS["FATLADY_INF_UID"], "dhcps4");
        TRACE_debug("FATLADY: INET_IPV4: ip = " . $ip);
        TRACE_debug("FATLADY: INET_IPV4: mask = " . $mask);
        if (INET_validv4addr($ip) == 0) {
            set_result("FAILED", $path . "/ipaddr", i18n("Invalid IP address"));
            return;
        }
        if ($mask == "") {
            set_result("FAILED", $path . "/mask", i18n("No Subnet Mask value"));
            return;
        }
        if ($mask < 0 || $mask > 32) {
            set_result("FAILED", $path . "/mask", i18n("Invalid Subnet Mask value"));
            return;
        }
        if (INET_validv4host($ip, $mask) == 0) {
            set_result("FAILED", $path . "/ipaddr", i18n("Invalid IP address"));
            return;
        }
        if (INET_addr_strip0($gw) == $ip) {
            set_result("FAILED", $path . "/gateway", i18n("The IP address and gateway address cannot be the same"));
            return;
        }
        set("ipaddr", INET_addr_strip0($ip));
        $ip = query("ipaddr");
        $gw = query("gateway");
        TRACE_debug("FATLADY: INET_IPV4: gw=" . $gw);
        if ($gw == "") {
            if ($needgw == "1" && $static == "1") {
                set_result("FAILED", $path . "/gateway", i18n("No default gateway IP address"));
                return;
            }
        } else {
            if (INET_validv4host($gw, $mask) == 0) {
                set_result("FAILED", $path . "/gateway", i18n("Invalid default gateway IP address"));
                return;
            }
            if (ipv4networkid($gw, $mask) != ipv4networkid($ip, $mask)) {
                set_result("FAILED", $path . "/gateway", i18n("The default gateway should be in the same network"));
                return;
            }
            if (INET_addr_strip0($gw) == $ip) {
                set_result("FAILED", $path . "/gateway", i18n("The IP address and gateway address cannot be the same"));
                return;
            }
            set("gateway", INET_addr_strip0($gw));
        }
    } else {
        if (query("dhcpplus/enable") != "") {
            /* User Name & Password */
            if (query("dhcpplus/enable") == "1" && query("dhcpplus/username") == "") {
                set_result("FAILED", $path . "/dhcpplus/username", i18n("The user name cannot be empty"));
                return;
            }
        }
    }
    $cnt = query("dns/count");
    $i = 0;
    while ($i < $cnt) {
        $i++;
        $value = query("dns/entry:" . $i);
        TRACE_debug("FATLADY: INET_IPV4: dns" . $i . "=" . $value);
        if (INET_validv4addr($value) == 0) {
            set_result("FAILED", $path . "/dns/entry:" . $i, i18n("Invalid DNS address"));
            return;
        }
        set("dns/entry:" . $i, INET_addr_strip0($value));
        if ($static == "1") {
            if (ipv4networkid($value, $mask) == ipv4networkid($ip, $mask)) {
                TRACE_debug("FATLADY: INET_IPV4: dns" . $i . "=" . $value . " is in the same network as IP:" . $ip);
                if (INET_validv4host($value, $mask) == 0) {
                    set_result("FAILED", $path . "/dns/entry:" . $i, i18n("Invalid DNS address"));
                    return;
                }
                if ($value == $ip) {
                    set_result("FAILED", $path . "/dns/entry:" . $i, i18n("Invalid DNS address"));
                    return;
                }
            }
        }
        if ($i > 1) {
            $j = $i - 1;
            $k = 0;
            while ($k < $j) {
                $k++;
                $dns = query("dns/entry:" . $k);
                if ($value == $dns) {
                    set_result("FAILED", $path . "/dns/entry:2", i18n("Secondary DNS server should not be the same as Primary DNS server."));
                    return;
                }
            }
        }
    }
    $mtu = query("mtu");
    TRACE_debug("FATLADY: INET_IPV4: mtu=" . $mtu);
    if ($mtu != "") {
        if (isdigit($mtu) == "0") {
            set_result("FAILED", $path . "/mtu", i18n("The MTU value is invalid."));
            return;
        }
        if ($mtu < 576) {
            set_result("FAILED", $path . "/mtu", i18n("The MTU value is too small, the valid value is 576 ~ 1500."));
            return;
        }
        if ($mtu > 1500) {
            set_result("FAILED", $path . "/mtu", i18n("The MTU value is too large, the valid value is 576 ~ 1500."));
            return;
        }
    }
    set_result("OK", "", "");
}
Esempio n. 4
0
function check_ipv4($path, $needgw)
{
    include "/htdocs/webinc/feature.php";
    anchor($path);
    $static = query("static");
    $ipipmode = query($path . "/ipv4in6/mode");
    if ($ipipmode != "") {
        TRACE_debug("FATLADY: INET_IPV4: IPIP mode :" . $ipipmode);
        $ipipremote = query($path . "/ipv4in6/remote");
        if ($ipipremote != "") {
            TRACE_debug("FATLADY: IPIP remote IPv6 address :" . $ipipremote);
            //if(INET_validv6addr($ipipremote) == 0)
            if (ipv6checkip($ipipremote) != 1) {
                set_result("FAILED", $path . "/ipaddr", i18n("Invalid IPv6 address"));
                return;
            }
            //$type = INET_v6addrtype($ipipremote);
            $type = ipv6addrtype($ipipremote);
            TRACE_debug("FATLADY: IPIP remote IPv6 address type :" . $type);
            if ($type == "ANY" || $type == "MULTICAST" || $type == "LOOPBACK") {
                set_result("FAILED", $path . "/ipaddr", i18n("Invalid IPv6 address type"));
                return;
            }
        }
        $ip = query("ipaddr");
        /* ip address of B4 */
        if ($ip != "") {
            $ip_part = cut($ip, 3, '.');
            if ($ip_part < 2 || $ip_part > 7) {
                set_result("FAILED", $path . "/ipaddr", i18n("The range of B4 IPv4 address is from 192.0.0.2 to 192.0.0.7"));
                return;
            }
        }
        set_result("OK", "", "");
        return;
    }
    if ($static != "1") {
        set("static", "0");
    }
    TRACE_debug("FATLADY: INET_IPV4: static = " . $static);
    if ($static == "1") {
        $ip = query("ipaddr");
        $mask = query("mask");
        $dhcps4 = INF_getinfinfo($_GLOBALS["FATLADY_INF_UID"], "dhcps4");
        TRACE_debug("FATLADY: INET_IPV4: ip = " . $ip);
        TRACE_debug("FATLADY: INET_IPV4: mask = " . $mask);
        if (INET_validv4addr($ip) == 0) {
            set_result("FAILED", $path . "/ipaddr", i18n("Invalid IP Address"));
            return;
        }
        if ($mask == "") {
            set_result("FAILED", $path . "/mask", i18n("No Subnet Mask value"));
            return;
        }
        if ($mask < 0 || $mask > 32) {
            set_result("FAILED", $path . "/mask", i18n("Invalid Subnet Mask value"));
            return;
        }
        if ($mask < 8) {
            set_result("FAILED", $path . "/mask", i18n("The router would not support the subnet mask which length is less than Class A."));
            return;
        }
        if (INET_validv4host($ip, $mask) == 0) {
            set_result("FAILED", $path . "/ipaddr", i18n("Invalid IP Address"));
            return;
        }
        if (INET_addr_strip0($gw) == $ip) {
            set_result("FAILED", $path . "/gateway", i18n("The IP address can not be equal to the gateway address"));
            return;
        }
        set("ipaddr", INET_addr_strip0($ip));
        $ip = query("ipaddr");
        $gw = query("gateway");
        TRACE_debug("FATLADY: INET_IPV4: gw=" . $gw);
        if ($gw == "") {
            if ($needgw == "1" && $static == "1") {
                set_result("FAILED", $path . "/gateway", i18n("No  gateway  address"));
                return;
            }
        } else {
            if (INET_validv4host($gw, $mask) == 0) {
                set_result("FAILED", $path . "/gateway", i18n("Invalid Default Gateway address"));
                return;
            }
            if (ipv4networkid($gw, $mask) != ipv4networkid($ip, $mask)) {
                set_result("FAILED", $path . "/gateway", i18n("The default gateway should be in the same network"));
                return;
            }
            if (INET_addr_strip0($gw) == $ip) {
                set_result("FAILED", $path . "/gateway", i18n("The IP address can not be equal to the Default Gateway address"));
                return;
            }
            set("gateway", INET_addr_strip0($gw));
        }
    } else {
        if (query("dhcpplus/enable") != "") {
            /* User Name & Password */
            if (query("dhcpplus/enable") == "1" && query("dhcpplus/username") == "") {
                set_result("FAILED", $path . "/dhcpplus/username", i18n("The user name can not be empty"));
                return;
            }
        }
    }
    $cnt = query("dns/count");
    $i = 0;
    while ($i < $cnt) {
        $i++;
        $value = query("dns/entry:" . $i);
        TRACE_debug("FATLADY: INET_IPV4: dns" . $i . "=" . $value);
        if (INET_validv4addr($value) == 0) {
            set_result("FAILED", $path . "/dns/entry:" . $i, i18n("Invalid DNS address"));
            return;
        }
        set("dns/entry:" . $i, INET_addr_strip0($value));
        if ($static == "1") {
            if (ipv4networkid($value, $mask) == ipv4networkid($ip, $mask)) {
                TRACE_debug("FATLADY: INET_IPV4: dns" . $i . "=" . $value . " is in the same network as IP:" . $ip);
                if (INET_validv4host($value, $mask) == 0) {
                    set_result("FAILED", $path . "/dns/entry:" . $i, i18n("Invalid DNS address"));
                    return;
                }
                if ($value == $ip) {
                    set_result("FAILED", $path . "/dns/entry:" . $i, i18n("Invalid DNS address"));
                    return;
                }
            }
        }
        if ($i > 1) {
            $j = $i - 1;
            $k = 0;
            while ($k < $j) {
                $k++;
                $dns = query("dns/entry:" . $k);
                if ($value == $dns) {
                    set_result("FAILED", $path . "/dns/entry:2", i18n("Secondary DNS server should not be the same as Primary DNS server."));
                    return;
                }
            }
        }
    }
    $mtu = query("mtu");
    TRACE_debug("FATLADY: INET_IPV4: mtu=" . $mtu);
    if ($mtu != "") {
        if (isdigit($mtu) == "0") {
            set_result("FAILED", $path . "/mtu", i18n("The MTU value is invalid."));
            return;
        }
        if ($mtu < 576 && $FEATURE_NOIPV6 == 1) {
            set_result("FAILED", $path . "/mtu", i18n("The MTU value is too small, the valid value is 576 ~ 1500."));
            return;
        }
        if ($mtu < 1280 && $FEATURE_NOIPV6 == 0) {
            set_result("FAILED", $path . "/mtu", i18n("The MTU value is too small, the valid value is 1280 ~ 1500."));
            return;
        }
        if ($mtu > 1500) {
            if ($FEATURE_NOIPV6 == 0) {
                set_result("FAILED", $path . "/mtu", i18n("The MTU value is too large, the valid value is 1280 ~ 1500."));
            } else {
                set_result("FAILED", $path . "/mtu", i18n("The MTU value is too large, the valid value is 576 ~ 1500."));
            }
            return;
        }
    }
    set_result("OK", "", "");
}
Esempio n. 5
0
         */
     $laninf = PHYINF_getruntimeifname("LAN-1");
     if ($SSL == '0') {
         $ipt_cmd = "PRE.WFA -i " . $laninf . " -p tcp --dport " . $E_PORT . " -j DNAT --to-destination " . $wan_ip . ":" . query("/webaccess/httpport") . " &";
     } else {
         $ipt_cmd = "PRE.WFA -i " . $laninf . " -p tcp --dport " . $E_PORT . " -j DNAT --to-destination " . $wan_ip . ":" . query("/webaccess/httpsport") . " &";
     }
     if ($ipt_cmd != "") {
         $del_ipt = "iptables -t nat -D " . $ipt_cmd;
         exe_ouside_cmd($del_ipt);
         $add_ipt = "iptables -t nat -A " . $ipt_cmd;
         exe_ouside_cmd($add_ipt);
     }
     //if($wan_st!="public" && $mask != "")
     if ($wan_st != "ppp" && $mask != "") {
         $host_ip = ipv4networkid($wan_ip, $mask);
         if ($SSL == '0') {
             $ipt_cmd = "PRE.WFA -p tcp -s " . $host_ip . "/" . $mask . " --dport " . $E_PORT . " -j REDIRECT --to-ports " . query("/webaccess/httpport") . " &";
         } else {
             $ipt_cmd = "PRE.WFA -p tcp -s " . $host_ip . "/" . $mask . " --dport " . $E_PORT . " -j REDIRECT --to-ports " . query("/webaccess/httpsport") . " &";
         }
         if ($ipt_cmd != "") {
             $del_ipt = "iptables -t nat -D " . $ipt_cmd;
             exe_ouside_cmd($del_ipt);
             $add_ipt = "iptables -t nat -A " . $ipt_cmd;
             exe_ouside_cmd($add_ipt);
         }
     }
     // }
     //}
 }