Example #1
0
function netbios_setup($name)
{
    $infp = XNODE_getpathbytarget("", "inf", "uid", $name, 0);
    $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $name, 0);
    if ($infp == "" || $stsp == "") {
        SHELL_info($_GLOBALS["START"], "infsvcs_setup: (" . $name . ") not exist.");
        SHELL_info($_GLOBALS["STOP"], "infsvcs_setup: (" . $name . ") not exist.");
        return;
    }
    $addrtype = query($stsp . "/inet/addrtype");
    $ipaddr = query($stsp . "/inet/ipv4/ipaddr");
    $devnam = query($stsp . "/devnam");
    $hostname = query("device/hostname");
    startcmd("hostname " . $hostname . "\n");
    if ($ipaddr == "" || $devnam == "") {
        return;
    }
    if ($addrtype == "ipv4" || $addrtype == "ipv6") {
        //jef add +   for support use shareport.local to access shareportmobile
        $web_file_access = query("/webaccess/enable");
        if ($web_file_access == 1) {
            startcmd("netbios -i " . $devnam . " -r " . $hostname . " -r shareport.local -r shareport &\n");
            startcmd("llmnresp -i " . $devnam . " -r " . $hostname . "  -r shareport.local -r shareport &\n");
        } else {
            //jef add -
            startcmd("netbios -i " . $devnam . " -r " . $hostname . " &\n");
            startcmd("llmnresp -i " . $devnam . " -r " . $hostname . " &\n");
        }
        stopcmd("killall netbios");
        stopcmd("killall llmnresp");
    }
}
Example #2
0
function dhcps_setcfg($prefix, $svc)
{
    /* set dhcpX of inf */
    $inf = cut($svc, 1, ".");
    $svc = tolower(cut($svc, 0, "."));
    $base = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
    $dhcps_uid = query($prefix . "/inf/" . $svc);
    set($base . "/" . $svc, $dhcps_uid);
    /* copy the dhcp profile. */
    $uid = INF_getinfinfo($inf, $svc);
    $spath = XNODE_getpathbytarget($prefix . "/" . $svc, "entry", "uid", $dhcps_uid, 0);
    $dhcps = XNODE_getpathbytarget("/" . $svc, "entry", "uid", $uid, 0);
    if ($dhcps != "") {
        if ($svc == "dhcps4") {
            copy_dhcps4($spath, $dhcps);
        } else {
            if ($svc == "dhcps6") {
                $_GLOBALS["SETCFG_DHCPS6_SRC_PATH"] = $spath;
                $_GLOBALS["SETCFG_DHCPS6_DST_PATH"] = $dhcps;
                $b = "/htdocs/phplib/setcfg/libs";
                dophp("load", $b . "/dhcps6.php");
            }
        }
    } else {
        TRACE_error("SETCFG/DHCPS: no dhcps entry for [" . $uid . "] found!");
    }
}
Example #3
0
function fatlady_phyinf($prefix, $inf)
{
    /* Check the interface setting */
    if (query($prefix . "/inf/uid") != $inf) {
        /* internet error, no i18n(). */
        set_result("FAILED", $prefix . "/inf/uid", "INF UID mismatch");
        return;
    }
    /* Check PHYINF */
    $phy = query($prefix . "/inf/phyinf");
    $phyp = XNODE_getpathbytarget($prefix, "phyinf", "uid", $phy, 0);
    if ($phy == "" || $phyp == "") {
        /* internet error, no i18n(). */
        set_result("FAILED", $prefix . "/inf/phyinf", "Invalid phyinf");
        return;
    }
    /* Check MACADDR */
    $macaddr = query($phyp . "/macaddr");
    if ($macaddr != "" && PHYINF_validmacaddr($macaddr) != "1") {
        set_result("FAILED", $phyp . "/macaddr", i18n("Invalid MAC address"));
        return;
    }
    $type = query($phyp . "/type");
    if ($type == "eth") {
        $media = query($phyp . "/media/linktype");
        if ($media != "" && $media != "AUTO" && $media != "1000F" && $media != "1000H" && $media != "100F" && $media != "100H" && $media != "10F" && $media != "10H") {
            set_result("FAILED", $phyp . "/media/linktype", i18n("Invalid media type"));
            return;
        }
    }
    /* We only validate the 'macaddr' & 'media' here,
     * so be sure to save 'macaddr' & 'media' only at 'setcfg' */
    set($prefix . "/valid", 1);
    set_result("OK", "", "");
}
Example #4
0
function chkconn($inf)
{
    $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
    $inet = query($infp . "/inet");
    $inetp = XNODE_getpathbytarget("inet", "entry", "uid", $inet, 0);
    $addrtype = query($inetp . "/addrtype");
    if ($addrtype == "ppp4") {
        $dialupmode = query($inetp . "/" . $addrtype . "/dialup/mode");
    }
    $active = query($infp . "/active");
    $disable = query($infp . "/disable");
    $backup = query($infp . "/backup");
    $interval = query($infp . "/chkinterval");
    if ($interval == "" || $interval < 15) {
        $interval = 15;
    }
    if ($addrtype == "ipv4") {
        $check = "yes";
    } else {
        if ($addrtype == "ppp4" && $dialupmode == "auto") {
            $check = "yes";
        } else {
            $check = "no";
        }
    }
    if ($active == 1 && $disable == 0 && $backup != "" && $check == "yes") {
        fwrite(a, $_GLOBALS["START"], 'xmldbc -t chkconn.' . $inf . ':' . $interval . ':"sh /etc/scripts/backupconn.sh NULL ' . $inf . ' connected"\\n');
        fwrite(a, $_GLOBALS["STOP"], 'killall chkconn\\n');
        fwrite(a, $_GLOBALS["STOP"], 'xmldbc -k chkconn.' . $inf . '\\n');
    }
}
Example #5
0
function start_proxyd()
{
    echo "killall -9 proxyd\n";
    $r_infp = XNODE_getpathbytarget("/runtime", "inf", "uid", "LAN-1", 0);
    $lanif = query($r_infp . "/devnam");
    if ($lanif == "") {
        echo "echo   Not found the name of LAN interface, set it as br0\n";
        $lanif = "br0";
    }
    $proxyd_port = "5449";
    $config_file = "/var/run/proxyd.conf";
    fwrite("w", $config_file, "CONTROL\n{\n");
    fwrite("a", $config_file, "\tTIMEOUT_CONNECT\t30\n");
    fwrite("a", $config_file, "\tTIMEOUT_READ\t30\n");
    fwrite("a", $config_file, "\tTIMEOUT_WRITE\t30\n");
    fwrite("a", $config_file, "\tMAX_CLIENT\t32\n");
    fwrite("a", $config_file, "}\n\n");
    fwrite("a", $config_file, "HTTP\n{\n");
    fwrite("a", $config_file, "\tINTERFACE\t" . $lanif . "\n");
    fwrite("a", $config_file, "\tPORT\t" . $proxyd_port . "\n");
    fwrite("a", $config_file, "\tALLOW_TYPE\t{ gif jpg css png }\n");
    fwrite("a", $config_file, "\tERROR_PAGE\n\t{\n");
    fwrite("a", $config_file, "\t\tdefault\t/htdocs/smart404/index.php\n");
    fwrite("a", $config_file, "\t\t403\t/htdocs/smart404/index.php\n");
    fwrite("a", $config_file, "\t\t404\t/none_exist_file\n");
    fwrite("a", $config_file, "\t}\n}\n\n");
    $config_url_file = "/var/run/proxyd_url.conf";
    fwrite("w", $config_url_file, "0\n");
    // Allow to access,
    echo "proxyd -m 1.33.203.39 -f " . $config_file . " -u " . $config_url_file . " & > /dev/console\n";
    echo "iptables -t nat -D PREROUTING -d 1.33.203.39 -p tcp --dport 80 -j REDIRECT --to-ports " . $proxyd_port . " 2>&-\n";
    echo "iptables -t nat -I PREROUTING -d 1.33.203.39 -p tcp --dport 80 -j REDIRECT --to-ports " . $proxyd_port . "\n";
}
Example #6
0
function mk_neapscfg($name, $neaps_conf)
{
    /* the interface status <runtime><inf> */
    $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $name, 0);
    $addrtype = query($stsp . "/inet/addrtype");
    if ($addrtype == "ipv4") {
        $ipaddr = query($stsp . "/inet/ipv4/ipaddr");
    } else {
        $ipaddr = query($stsp . "/inet/ppp4/local");
    }
    $mask = query($stsp . "/inet/ipv4/mask");
    $netmask = ipv4int2mask($mask);
    $phyinf = query($stsp . "/phyinf");
    /* the interface status <runtime><phyinf> */
    $rphyinf = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phyinf, 0);
    $rmacaddr = query($rphyinf . "/macaddr");
    $rname = query($rphyinf . "/name");
    /* Get other info*/
    $vender = "D-Link";
    $model = query("/runtime/device/modelname");
    $description = $vender . " " . $model . " Wireless Broadband Router";
    $version = "v0.5.0";
    fwrite("w", $neaps_conf, 'ipaddr=' . $ipaddr . '\\n' . 'netmask=' . $netmask . '\\n' . 'macaddr=' . $rmacaddr . '\\n' . 'vender=' . $vender . '\\n' . 'description=' . $description . '\\n' . 'model=' . $model . '\\n' . 'version=' . $version . '\\n');
    return $rname;
}
Example #7
0
function sshdsetup($name)
{
    /* Get the interface */
    $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $name, 0);
    $infp = XNODE_getpathbytarget("", "inf", "uid", $name, 0);
    if ($stsp == "" || $infp == "") {
        SHELL_info($_GLOBALS["START"], "sshdsetup: (" . $name . ") no interface.");
        SHELL_info($_GLOBALS["STOP"], "sshdsetup: (" . $name . ") no interface.");
        return;
    }
    /* Is this interface active ? */
    $active = query($infp . "/active");
    $sshd = query($infp . "/sshd");
    if ($active != "1" || $sshd == "") {
        SHELL_info($_GLOBALS["START"], "sshdsetup: (" . $name . ") not active.");
        SHELL_info($_GLOBALS["STOP"], "sshdsetup: (" . $name . ") not active.");
        return;
    }
    /* Get the profile */
    $sshdpro = XNODE_getpathbytarget("/sshd", "entry", "uid", $sshd, 0);
    if ($sshdpro == "") {
        SHELL_info($_GLOBALS["START"], "sshdsetup: (" . $name . ") no profile.");
        SHELL_info($_GLOBALS["STOP"], "sshdsetup: (" . $name . ") no profile.");
        return;
    }
    sshdstart($name, $sshdpro);
    sshdstop($name, $sshdpro);
}
Example #8
0
function IP6TLAN_build_command($name)
{
    fwrite("w", $_GLOBALS["START"], "#!/bin/sh\n");
    fwrite("a", $_GLOBALS["START"], "ip6tables -t filter -F FWD." . $name . "\n");
    fwrite("a", $_GLOBALS["START"], "ip6tables -t filter -F INP." . $name . "\n");
    $iptcmdFWD = "ip6tables -t filter -A FWD." . $name;
    $iptcmdIN = "ip6tables -t filter -A INP." . $name;
    $path = XNODE_getpathbytarget("", "inf", "uid", $name, 0);
    if ($path != "") {
        $fw = XNODE_get_var("FIREWALL6.USED");
        $security = query("/device/simple_security");
        if ($fw > 0) {
            fwrite("a", $_GLOBALS["START"], $iptcmdFWD . " -j FIREWALL\n");
        }
        if ($security > 0) {
            fwrite("a", $_GLOBALS["START"], $iptcmdFWD . " -j FWD.SMPSECURITY." . $name . "\n");
        }
        if ($fw > 0) {
            fwrite("a", $_GLOBALS["START"], $iptcmdFWD . " -j FIREWALL_POLICY\n");
        }
        /* Outbound filter will be run faster to drop some packets. */
        fwrite("a", $_GLOBALS["START"], $iptcmdFWD . " -j FWD.OBFILTER\n");
        fwrite("a", $_GLOBALS["START"], $iptcmdIN . " -j INP.OBFILTER\n");
    }
    fwrite("a", $_GLOBALS["START"], "exit 0\n");
    fwrite("w", $_GLOBALS["STOP"], "#!/bin/sh\n");
    fwrite("a", $_GLOBALS["STOP"], "ip6tables -t filter -F FWD." . $name . "\n");
    fwrite("a", $_GLOBALS["STOP"], "ip6tables -t filter -F INP." . $name . "\n");
    fwrite("a", $_GLOBALS["STOP"], "exit 0\n");
}
Example #9
0
function init_update_status_for_station($PHY_UID)
{
    if (get_phyinf_freq($PHY_UID) == 5) {
        $upwifistats_pidfile = "/var/run/upwifistats5g.pid";
        $helper_script = "/etc/scripts/upwifistatshlper_A_band.sh";
    } else {
        $upwifistats_pidfile = "/var/run/upwifistats24g.pid";
        $helper_script = "/etc/scripts/upwifistatshlper_G_band.sh";
    }
    $pid = fread("", $upwifistats_pidfile);
    if ($pid != "") {
        echo "kill " . $pid . "\n";
    }
    $upwifi_attr0 = "updatewifistats -s " . $helper_script . " -m bcm -i " . devname($PHY_UID) . " ";
    $upwifi_attr1 = "-x ";
    //for upwifistats argument (-x --> /phyinf:#)
    $upwifi_attr2 = "-r ";
    //for upwifistats argument (-r --> /runtime/phyinf:#)
    $p = XNODE_getpathbytarget("", "phyinf", "uid", $PHY_UID, 0);
    if ($p == "") {
        return;
    }
    $r = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $PHY_UID, 0);
    if ($r == "") {
        return;
    }
    $upwifi_attr1 = $upwifi_attr1 . $p . " ";
    $upwifi_attr2 = $upwifi_attr2 . $r . " ";
    $cmd = $upwifi_attr0 . $upwifi_attr1 . $upwifi_attr2 . " &";
    TRACE_error($cmd);
    echo $cmd . "\n";
    echo "echo \$! > " . $upwifistats_pidfile . "\n";
}
Example #10
0
function setup_mdns($uid, $port, $srvname, $srvcfg)
{
    $dirty = 0;
    $stsp = XNODE_getpathbytarget("/runtime/services/mdnsresponder", "server", "uid", $uid, 0);
    if ($stsp == "") {
        if ($port != "0") {
            $dirty++;
            $stsp = XNODE_getpathbytarget("/runtime/services/mdnsresponder", "server", "uid", $uid, 1);
            set($stsp . "/srvname", $srvname);
            set($stsp . "/port", $port);
            set($stsp . "/srvcfg", $srvcfg);
        }
    } else {
        if ($port == "0") {
            $dirty++;
            del($stsp);
        } else {
            if (query($stsp . "/srvname") != $srvname) {
                $dirty++;
                set($stsp . "/srvname", $srvname);
            }
            if (query($stsp . "/port") != $port) {
                $dirty++;
                set($stsp . "/port", $port);
            }
            if (query($stsp . "/srvcfg") != $srvcfg) {
                $dirty++;
                set($stsp . "/srvcfg", $srvcfg);
            }
        }
    }
    return $dirty;
}
Example #11
0
function INET_getinetinfo($inet, $info)
{
    $infp = XNODE_getpathbytarget("/inet", "entry", "uid", $inet, 0);
    if ($infp != "") {
        return query($infp . "/" . $info);
    }
    return "";
}
Example #12
0
function get_runtime_wifi_path($uid)
{
    $p = XNODE_getpathbytarget("", "phyinf", "wifi", $uid);
    if ($p == "") {
        return $p;
    }
    return XNODE_getpathbytarget("/runtime", "phyinf", "uid", query($p . "/uid"));
}
Example #13
0
function dhcpc6setup($inf)
{
    $hlp = "/var/servd/" . $inf . "-dhcp6c.sh";
    $pid = "/var/servd/" . $inf . "-dhcp6c.pid";
    $cfg = "/var/servd/" . $inf . "-dhcp6c.cfg";
    /* DHCP over PPP session ? */
    //$previnf = XNODE_get_var($inf."_PREVINF");
    //XNODE_del_var($inf."_PREVINF");
    $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
    $previnf = query($infp . "/infprevious");
    $phyinf = query($infp . "/phyinf");
    $inet = query($infp . "/inet");
    $inetp = XNODE_getpathbytarget("/inet", "entry", "uid", $inet, 0);
    $devnam = PHYINF_getifname($phyinf);
    /* dslite ? */
    $nextinf = query($infp . "/infnext");
    //if ($mode=="PPPDHCP" && $_GLOBALS["PREVINF"]!="")
    //msg("mode is ".$mode.", previnf is ".$previnf);
    startcmd('# dhcpc6setup(' . $inf . ',' . $inetp . ')');
    startcmd("previnf is " . $previnf . ", nextinf is " . $nextinf);
    //if ($mode=="PPPDHCP" && $previnf!="")
    //{
    //	$pppdev = PHYINF_getruntimeifname($previnf);
    //	if ($pppdev=="") return error("no PPP device.");
    //}
    /* Gererate DHCP-IAID from 32-bit of mac address*/
    $mac = PHYINF_getphymac($inf);
    $mac1 = cut($mac, 3, ":");
    $mac2 = cut($mac, 0, ":");
    $mac3 = cut($mac, 1, ":");
    $mac4 = cut($mac, 2, ":");
    $iaidstr = $mac1 . $mac2 . $mac3 . $mac4;
    $iaid = strtoul($iaidstr, 16);
    /* Generate configuration file. */
    $send = "\tinformation-only;\n";
    $idas = "";
    //if($mode=="PPPDHCP") $dname = $pppdev;
    //else $dname = $devnam;
    $dname = $devnam;
    $nextinfp = XNODE_getpathbytarget("", "inf", "uid", $nextinf, 0);
    $nextinet = query($nextinfp . "/inet");
    $nextinetp = XNODE_getpathbytarget("inet", "entry", "uid", $nextinet, 0);
    $nextmode = query($nextinetp . "/ipv4/ipv4in6/mode");
    if ($nextinf != "" && $nextmode == "dslite") {
        $rqstmsg = "\trequest aftr-server-domain-name;\n";
    } else {
        $rqstmsg = "";
    }
    fwrite(w, $cfg, "interface " . $dname . " {\n" . $send . $rqstmsg . "\tscript \"" . $hlp . "\";\n" . "};\n" . $idas);
    /* generate callback script */
    fwrite(w, $hlp, "#!/bin/sh\n" . "phpsh /etc/services/INET/inet6_dhcpc_helper.php" . " INF=" . $inf . " MODE=INFOONLY" . " DEVNAM=" . $dname . " GATEWAY=" . "" . " DHCPOPT=" . "" . ' "NAMESERVERS=$new_domain_name_servers"' . ' "NEW_ADDR=$new_addr"' . ' "NEW_PD_PREFIX=$new_pd_prefix"' . ' "NEW_PD_PLEN=$new_pd_plen"' . ' "DNS=' . "" . '"' . ' "NEW_AFTR_NAME=$new_aftr_name"' . ' "NTPSERVER=$new_ntp_servers"' . "\n");
    /* Start DHCP client */
    startcmd("chmod +x " . $hlp);
    //if ($pppdev=="")
    startcmd("dhcp6c -c " . $cfg . " -p " . $pid . " -t LL " . $devnam);
    //else startcmd("dhcp6c -c ".$cfg." -p ".$pid." -t LL -o ".$devnam." ".$pppdev);
    stopcmd("/etc/scripts/killpid.sh /var/servd/" . $inf . "-dhcp6c.pid");
}
Example #14
0
function getphyinf($inf)
{
    $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
    if ($infp == "") {
        return "";
    }
    $phyinf = query($infp . "/phyinf");
    return PHYINF_getifname($phyinf);
}
Example #15
0
function wanlinkstatus($inf)
{
    $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
    $phyinf = query($infp . "/phyinf");
    $phyinfp = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phyinf, 0);
    $linkstatus = query($phyinfp . "/linkstatus");
    if ($linkstatus == "") {
        return "down";
    }
    return $linkstatus;
}
Example #16
0
function get_br0ip()
{
    $phyp = XNODE_getpathbytarget("/runtime", "phyinf", "name", "br0", 0);
    if ($phyp != "" && query($phyp . "/valid") == "1") {
        $phyuid = query($phyp . "/uid");
    }
    $infp = XNODE_getpathbytarget("/runtime", "inf", "phyinf", $phyuid, 0);
    if ($infp != "") {
        $ipaddr = query($infp . "/inet/ipv4/ipaddr");
    }
    return $ipaddr;
}
Example #17
0
function changes_default_wifi($phyinfuid, $ssid, $password, $mac, $country)
{
    $authtype = "WPA+2PSK";
    $encrtype = "TKIP+AES";
    $p = XNODE_getpathbytarget("", "phyinf", "uid", $phyinfuid, 0);
    $wifi = XNODE_getpathbytarget("/wifi", "entry", "uid", query($p . "/wifi"), 0);
    if ($p == "" || $wifi == "") {
        return;
    }
    anchor($wifi);
    if ($ssid == "") {
        $n5 = cut($mac, 4, ":");
        $n6 = cut($mac, 5, ":");
        $ssidsuffix = $n5 . $n6;
        $ssid = query("ssid");
        if ($ssidsuffix != "") {
            //For dlink product, make the default SSID "dlink-mac" for 2.4GHz and "dlink-5GHz-mac" for 5GHz.
            if (substr($ssid, 0, 5) == "dlink") {
                $ssid1 = "dlink";
                $ssid2 = scut($ssid, 0, "dlink");
                $ssid = $ssid1 . $ssid2 . "-" . toupper($ssidsuffix);
            }
        }
    }
    //set default value for CN
    if ($country == "CN") {
        //$ssid = "D-Link_DIR-802";
        $authtype = "OPEN";
        $encrtype = "NONE";
        set("authtype", $authtype);
        set("encrtype", $encrtype);
        set("ssid", $ssid);
        set("nwkey/psk/passphrase", "");
        //20130812 jack add for hostapd error
        set("nwkey/psk/key", "");
        return;
    }
    //TRACE_error("ssid=".$ssid."=password="******"");
    if ($password != "" && $ssid != "") {
        //chanhe the mode to wpa-auto psk
        set("authtype", "WPA+2PSK");
        set("encrtype", "TKIP+AES");
        set("wps/configured", "1");
        set("ssid", $ssid);
        set("nwkey/psk/passphrase", "1");
        set("nwkey/psk/key", $password);
        set("nwkey/wpa/groupintv", "3600");
        set("nwkey/rekey/gtk", "1800");
    } else {
        TRACE_error("the mfc do not init wifi password,using default");
    }
}
Example #18
0
function dmz_setcfg($prefix, $svc)
{
    $nat = cut($svc, 1, ".");
    $base = XNODE_getpathbytarget("/nat", "entry", "uid", $nat);
    $dmzenable = query($prefix . "/nat/entry/dmz/enable");
    $dmzinf = query($prefix . "/nat/entry/dmz/inf");
    $dmzhostid = query($prefix . "/nat/entry/dmz/hostid");
    $dmzsch = query($prefix . "/nat/entry/dmz/schedule");
    set($base . "/dmz/enable", $dmzenable);
    set($base . "/dmz/hostid", $dmzhostid);
    set($base . "/dmz/inf", $dmzinf);
    set($base . "/dmz/schedule", $dmzsch);
}
function getipaddr($inf_uid)
{
    $p = XNODE_getpathbytarget("/runtime", "inf", "uid", $inf_uid, 0);
    $t = query($p . "/inet/addrtype");
    if (query($p . "/inet/" . $t . "/valid") == 1) {
        if ($t == "ppp4") {
            return query($p . "/inet/" . $t . "/local");
        } else {
            return query($p . "/inet/" . $t . "/ipaddr");
        }
    }
    return "";
}
Example #20
0
function check_remote($entry)
{
    $port = query($entry . "/inf/web");
    if ($port != "") {
        if (isdigit($port) != "1") {
            set_result("FAILED", $entry . "/inf/web", i18n("Invalid port number"));
            return 0;
        }
        if ($port < 1 || $port > 65535) {
            set_result("FAILED", $entry . "/inf/web", i18n("Invalid port range"));
            return 0;
        }
        // Check with VSVR and PFWD. Currently only with NAT-1;
        $nat = XNODE_getpathbytarget("/nat", "entry", "uid", "NAT-1");
        if ($nat != "") {
            $i = 1;
            while ($i <= 2) {
                if ($i == 1) {
                    $target = "portforward";
                    $svr_str = i18n("PORT FORWARDING");
                } else {
                    $target = "virtualserver";
                    $svr_str = i18n("VIRTUAL SERVER");
                }
                $count = query($nat . "/" . $target . "/entry#");
                TRACE_debug("FATLADY: check HTTP.WAN with " . $nat . "/" . $target . " count:" . $count);
                $j = 1;
                while ($j <= $count) {
                    $CurBase = $nat . "/" . $target . "/entry:" . $j;
                    if (query($CurBase . "/protocol") == "TCP+UDP" || query($CurBase . "/protocol") == "TCP") {
                        if ($port >= query($CurBase . "/external/start") && $port <= query($CurBase . "/external/end")) {
                            set_result("FAILED", $entry . "/inf/web", i18n("The port number is used by") . " " . i18n($svr_str) . ".");
                            return 0;
                        }
                    }
                    $j++;
                }
                $i++;
            }
        }
    }
    $host = query($entry . "/inf/weballow/hostv4ip");
    if ($host != "") {
        if (INET_validv4addr($host) != "1") {
            set_result("FAILED", $entry . "/inf/weballow/hostv4ip", i18n("Invalid host IP address"));
            return 0;
        }
    }
    set_result("OK", "", "");
    return 1;
}
Example #21
0
function combo_inf($uid, $infp, $lower)
{
    $inet = query($infp . "/inet");
    if ($inet == "") {
        return "9";
    }
    /* Get the profile. */
    $inetp = XNODE_getpathbytarget("/inet", "entry", "uid", $inet, 0);
    if ($inetp == "") {
        return "9";
    }
    /* Determine "redial" */
    $redail = 0;
    $addrtype = query($inetp . "/addrtype");
    if ($addrtype != "ppp4") {
        return "9";
    }
    /* Check dialup mode */
    $dial = query($inetp . "/ppp4/dialup/mode");
    if ($dial == "auto") {
        startcmd('event ' . $uid . '.COMBO.DIALUP add "service INET.' . $lower . ' restart"');
        startcmd('event ' . $uid . '.COMBO.HANGUP add "service INET.' . $uid . ' stop"');
        $redail++;
    } else {
        if ($dial == "ondemand") {
            startcmd('event ' . $uid . '.COMBO.DIALUP add "event ' . $uid . '.PPP.DIALUP"');
            startcmd('event ' . $uid . '.COMBO.HANGUP add "event ' . $uid . '.PPP.HANGUP"');
            $redail++;
        } else {
            $dial = "manual";
            startcmd('event ' . $uid . '.COMBO.DIALUP add "service INET.' . $lower . ' restart"');
            startcmd('event ' . $uid . '.COMBO.HANGUP add "service INET.' . $uid . ' stop"');
        }
    }
    /* If we need to auto-redial, trigger the service start at lowerlayer-down event. */
    if ($redail > 0) {
        startcmd('event INFSVCS.' . $lower . '.DOWN add "service INET.' . $lower . ' restart"');
    } else {
        startcmd('event INFSVCS.' . $lower . '.DOWN add true');
    }
    /* Starting from lowerlayer. */
    if ($dial != "manual") {
        startcmd('service INET.' . $lower . ' start');
    }
    /* Stopping from upperlayer. */
    stop_cmd('event INFSVCS.' . $lower . '.DOWN add true');
    stop_cmd('event ' . $uid . '.COMBO.DIALUP add true');
    stop_cmd('event ' . $uid . '.COMBO.HANGUP add true');
    stop_cmd('service INET.' . $uid . ' stop');
    return "0";
}
function find_hotstname($mac, $inf)
{
    $path = XNODE_getpathbytarget("/runtime", "inf", "uid", $inf, 0);
    $entry_path = $path . "/dhcps4/leases/entry";
    $cnt = query($entry_path . "#");
    while ($cnt > 0) {
        $mac2 = query($entry_path . ":" . $cnt . "/macaddr");
        $hostname = query($entry_path . ":" . $cnt . "/hostname");
        if (toupper($mac2) == toupper($mac)) {
            return $hostname;
        }
        $cnt--;
    }
    return "";
}
Example #23
0
function calcute_ds_port()
{
    $ds_port = 48820;
    $inffp = XNODE_getpathbytarget("/runtime", "inf", "uid", "LAN-1");
    $phy = query($inffp . "/phyinf");
    $phyfp = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phy);
    $mac = query($phyfp . "/macaddr");
    //use last two part of mac calcute a 4-digit number
    if ($mac != "") {
        $count = cut_count($mac, ":");
        $mac_cut = cut($mac, $count - 2, ":") . cut($mac, $count - 1, ":");
        $tmp = strtoul($mac_cut, 16) % 10000;
        $ds_port = 40000 + $tmp;
    }
    return $ds_port;
}
Example #24
0
function UPNP_getdevpathbytype($inf, $type)
{
    /* check this interface supports the upnp device.*/
    $inf_path = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
    if ($inf_path == "") {
        return "";
    }
    $count = query($inf_path . "/upnp/count");
    $i = 0;
    while ($i < $count) {
        $i++;
        if (query($inf_path . "/upnp/entry:" . $i) == $type) {
            return XNODE_getpathbytarget("/runtime/upnp", "dev", "deviceType", $type, 0);
        }
    }
    return "";
}
Example #25
0
function setup_dhcpc($prefix)
{
    $i = 1;
    while ($i > 0) {
        $ifname = $prefix . "-" . $i;
        $ifpath = XNODE_getpathbytarget("/runtime", "inf", "uid", $ifname, 0);
        if ($ifpath == "") {
            $i = 0;
            break;
        }
        if (query($ifpath . "/inet/addrtype") == "ipv4" && query($ifpath . "/inet/ipv4/static") == "0" && query($ifpath . "/inet/ipv4/valid") == "1") {
            TRACE_debug("Restart DHCP client: ifname = " . $ifname);
            startcmd("service INET." . $ifname . " restart");
        }
        $i++;
    }
}
Example #26
0
function del_tunnel($uid)
{
    $p = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $uid, 0);
    if ($p == "") {
        TRACE_debug("Woops !!!!!!! " . $uid . " is not exist!");
        return;
    }
    anchor($p);
    $mode = query("tunnel/mode");
    $type = query("tunnel/type");
    $name = query("name");
    if ($mode == "6IN4") {
        $tunnel = "tunnel";
    } else {
        if ($mode == "6TO4") {
            $tunnel = "tunnel";
        } else {
            if ($mode == "6RD") {
                $tunnel = "tunnel";
            } else {
                if ($mode == "TSP") {
                    if ($type == "v6v4") {
                        $tunnel = "tunnel";
                    } else {
                        $tunnel = "tuntap";
                    }
                } else {
                    return;
                }
            }
        }
    }
    /* The TSPC will destroy the tunnel device, so we don't need to del the tunnel. */
    if ($mode != "TSP") {
        echo "ip link set " . $name . " down\n";
        if ($tunnel == "tunnel") {
            echo "ip tunnel del " . $name . "\n";
        } else {
            if ($tunnel == "tuntap") {
                echo "ip tuntap del " . $name . " mode tun\n";
            }
        }
    }
    echo "/etc/scripts/delpathbytarget.sh /runtime phyinf uid " . $uid . "\n";
}
Example #27
0
function dns4_setcfg($prefix, $inf)
{
    /* find interface path */
    $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
    $profile = query($prefix . "/inf/dns4");
    set($infp . "/dns4", $profile);
    /* move the dns profile. */
    if ($profile != "") {
        $dst = XNODE_getpathbytarget("/dns4", "entry", "uid", $profile, 0);
        if ($dst == "") {
            $dst = XNODE_add_entry("/dns4", "DNS4");
        }
        $src = XNODE_getpathbytarget($prefix . "/dns4", "entry", "uid", $profile, 0);
        if ($src != "" || $dst != "") {
            movc($src, $dst);
        }
    }
}
Example #28
0
function starspeed($name)
{
    /* Get the interface */
    $infp = XNODE_getpathbytarget("", "inf", "uid", $name, 0);
    if ($infp == "") {
        return;
    }
    $inet = query($infp . "/inet");
    $inetp = XNODE_getpathbytarget("/inet", "entry", "uid", $inet, 0);
    $phyinf = query($infp . "/phyinf");
    $user = get("s", $inetp . "/ppp4/username");
    $pass = get("s", $inetp . "/ppp4/password");
    $ifname = PHYINF_getifname($phyinf);
    $enable = query($inetp . "/ppp4/pppoe/starspeed/enable");
    $region = get("s", $inetp . "/ppp4/pppoe/starspeed/region");
    if ($enable == 1) {
        fwrite("a", $_GLOBALS["START"], "/etc/scripts/starspeed.sh \"" . $user . "\" \"" . $pass . "\" \"" . $ifname . "\" \"" . $region . "\"\n");
    }
}
Example #29
0
function filter_setcfg($prefix, $inf)
{
    $base = XNODE_getpathbytarget("", "inf", "uid", $inf, 0);
    $phyinf_name = query($base . "/phyinf");
    //TRACE_debug("1. base=".$base.", phyinf=".$phyinf_name);
    /* Check FILTER */
    $phyinf_base = XNODE_getpathbytarget("", "phyinf", "uid", $phyinf_name, 0);
    $filter_uid = query($phyinf_base . "/filter");
    //TRACE_debug("2. phyinf_base=".$phyinf_base.", filter_uid=".$filter_uid);
    //$filter_uid = query($prefix."/phyinf/filter");
    $filterp = XNODE_getpathbytarget($prefix . "/filter", "remote_mnt", "uid", $filter_uid, 0);
    //if ($filterp == "")
    //{
    /* internet error, no i18n(). */
    //	set_result("FAILED", $prefix."/inf/phyinf", "Invalid filter");
    //	return;
    //}
    /* set filter name from runtime node. */
    /*
    <phyinf>
    	<uid>ETH-1</uid>
    	<active>1</active>
    	<type>eth</type>
    	<filter>FILTER-1</filter>
    </phyinf>
    */
    $runtime_phyinf_base = XNODE_getpathbytarget($prefix, "phyinf", "uid", $phyinf_name, 0);
    $runtime_filter_uid = query($runtime_phyinf_base . "/filter");
    //TRACE_debug("2. runtime_phyinf_base=".$runtime_phyinf_base);
    //TRACE_debug("2. runtime_filter_uid=".$runtime_filter_uid);
    $dst_phyinfp = XNODE_getpathbytarget("", "phyinf", "uid", $phyinf_name, 0);
    set($dst_phyinfp . "/filter", $runtime_filter_uid);
    //TRACE_debug("3. dst_phyinfp=".$dst_phyinfp.", runtime_filter_uid=".$runtime_filter_uid);
    /* move the filter profile. */
    if ($filterp != "") {
        $dst = XNODE_getpathbytarget("/filter", "remote_mnt", "uid", $filter_uid, 0);
        $src = XNODE_getpathbytarget($prefix . "/filter", "remote_mnt", "uid", $filter_uid, 0);
        if ($src != "" || $dst != "") {
            movc($src, $dst);
        }
        //set($to."/entry:".$bwc_index."/enable",		query("enable"));
    }
}
Example #30
0
function phyinf_setcfg($prefix)
{
    $phy = query($prefix . "/inf/phyinf");
    $phytmp = XNODE_getpathbytarget($prefix, "phyinf", "uid", $phy, 0);
    $phyinf = XNODE_getpathbytarget("", "phyinf", "uid", $phy, 0);
    if ($phy == "" || $phytmp == "" || $phyinf == "") {
        TRACE_error("SETCFG/PHYINF: no phyinf entry for [" . $phy . "] found !");
        return;
    }
    /* We only valid 'macaddr' & 'media' in 'fatlady',
     * so only save these 2 nodes. */
    $macaddr = query($phytmp . "/macaddr");
    set($phyinf . "/macaddr", $macaddr);
    $type = query($phytmp . "/type");
    if ($type == "eth") {
        $media = query($phytmp . "/media/linktype");
        set($phyinf . "/media/linktype", $media);
    }
}