Beispiel #1
0
function wiz_set_LANGPACK()
{
    $lcode = $_GET["language"];
    //TRACE_error("lcode=".$lcode);
    if ($lcode == "auto" || $lcode == "") {
        $count = cut_count($_SERVER["HTTP_ACCEPT_LANGUAGE"], ',');
        $i = 0;
        while ($i < $count) {
            $tag = cut($_SERVER["HTTP_ACCEPT_LANGUAGE"], $i, ',');
            $pri = cut($tag, 0, '-');
            $sub = cut($tag, 1, '-');
            $lcode = convert_lcode($pri, $sub);
            //The accept language for Japan from IE is ja-JP and the language code for our language pack is jp.
            if ($lcode == "ja") {
                $lcode = "jp";
            }
            if (wiz_load_slp($lcode) > 0) {
                return $lcode;
            }
            $i++;
        }
    } else {
        if (wiz_load_slp($lcode) > 0) {
            return $lcode;
        }
    }
    sealpac("/etc/sealpac/wizard/wiz_en.slp");
    // Use system default language, en.
    return "en";
}
Beispiel #2
0
function check_pin($pin)
{
    /* more checking added for WPS 2.0 
    		We allow pin with : xxxx-xxxx
    							xxxx xxxx
    							xxxxxxxx
    	*/
    $len = strlen($pin);
    $delim = "";
    //we support 4 digits
    if ($len == 4) {
        if (isdigit($pin) != 1) {
            return 0;
        } else {
            return $pin;
        }
    }
    if ($len == 9) {
        if (cut_count($pin, "-") == 2) {
            $delim = "-";
        } else {
            if (cut_count($pin, " ") == 2) {
                $delim = " ";
            } else {
                return 0;
            }
        }
        $val1 = cut($pin, 0, $delim);
        $val2 = cut($pin, 1, $delim);
        if (strlen($val1) != 4 || strlen($val2) != 4) {
            return 0;
        }
        $pin = $val1 . $val2;
    }
    if (isdigit($pin) != 1) {
        return 0;
    }
    if (strlen($pin) != 8) {
        return 0;
    }
    $i = 0;
    $pow = 3;
    $sum = 0;
    while ($i < 8) {
        $sum = $pow * substr($pin, $i, 1) + $sum;
        if ($pow == 3) {
            $pow = 1;
        } else {
            $pow = 3;
        }
        $i++;
    }
    $sum = $sum % 10;
    if ($sum == 0) {
        return $pin;
    } else {
        return 0;
    }
}
Beispiel #3
0
function strip_char($original, $char)
{
    $cnt = cut_count($original, $char);
    if ($cnt == 0) {
        return $original;
    }
    $i = 0;
    $strip = "";
    while ($i < $cnt) {
        $strip = $strip . cut($original, $i, $char);
        $i++;
    }
    return $strip;
}
Beispiel #4
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;
}
function read_result()
{
    $result = "fail";
    $return = fread("", "/var/tmp/mydlink_result");
    if (isempty($return) == 1) {
        return "Result of mydlink registration is not exist or NULL";
    }
    $cnt = cut_count($return, "\r\n");
    $t = $cnt - 1;
    $tmp = cut($return, $t, "\r\n");
    $L1 = strlen($tmp);
    $L2 = strstr($tmp, "\n") + strlen("\n");
    $result_str = substr($tmp, $L2, $L1 - $L2);
    $temp = strstr($result_str, "success");
    if (isempty($temp) == 1) {
        $result = $result_str;
    } else {
        $result = "OK";
    }
    return $result;
}
Beispiel #6
0
function LANGPACK_setsealpac()
{
    $lcode = query("/device/features/language");
    if ($lcode == "auto" || $lcode == "") {
        $count = cut_count($_SERVER["HTTP_ACCEPT_LANGUAGE"], ',');
        $i = 0;
        while ($i < $count) {
            $tag = cut($_SERVER["HTTP_ACCEPT_LANGUAGE"], $i, ',');
            $pri = cut($tag, 0, '-');
            $sub = cut($tag, 1, '-');
            if (load_slp(convert_lcode($pri, $sub)) > 0) {
                return;
            }
            $i++;
        }
    } else {
        if (load_slp($lcode) > 0) {
            return;
        }
    }
    sealpac("/etc/sealpac/en.slp");
    // Use system default language, en.
}
Beispiel #7
0
function PHYINF_validmacaddr($macaddr)
{
    if (cut_count($macaddr, ":") == 6) {
        $delimiter = ":";
    } else {
        return 0;
    }
    $i = 0;
    while ($i < 6) {
        $v = cut($macaddr, $i, $delimiter);
        if (strlen($v) != 2 || isxdigit($v) != 1) {
            return 0;
        }
        if ($i == 0) {
            //hendry : check for multicast mac
            $val = strtoul($v, 16);
            $ismulti = $val % 2;
            if ($ismulti == 1) {
                return 0;
            }
        }
        $i++;
    }
    if (toupper($macaddr) == "FF:FF:FF:FF:FF:FF" || $macaddr == "01:11:11:11:11:11" || $macaddr == "00:00:00:00:00:00") {
        return 0;
    }
    return 1;
}
Beispiel #8
0
$blockch_list = fread("", "/proc/dfs_blockch");
//format is : "100,960;122,156;" --> channel 100, remaining time is 960 seconds
//								 --> channel 122, remaining time is 156 seconds
$ttl_block_chn = cut_count($blockch_list, ";") - 1;
$i = 0;
while ($i < $ttl_block_chn) {
    //assume that blocked channel can be more than one channel.
    $ch_field = cut($blockch_list, $i, ';');
    //i mean each "100,960;" represent 1 field
    $ch = cut($ch_field, 0, ',');
    $remaining_time = cut($ch_field, 1, ',');
    setToRuntimeNode($ch, $remaining_time);
    $i++;
}
$clist = WIFI_getchannellist("a");
$count = cut_count($clist, ",");
$i = 0;
while ($i < $count) {
    $ch = cut($clist, $i, ',');
    $str = $ch;
    //for 2.4 Ghz
    if ($ch == "1") {
        $str = "2.412 GHz - CH 1";
    } else {
        if ($ch == "2") {
            $str = "2.417 GHz - CH 2";
        } else {
            if ($ch == "3") {
                $str = "2.422 GHz - CH 3";
            } else {
                if ($ch == "4") {
Beispiel #9
0
function INET_addr_strip0($ip)
{
    $new_ip = "";
    if (cut_count($ip, ".") != 4) {
        return $ip;
    }
    $i = 0;
    while ($i < 4) {
        $part = cut($ip, $i, ".");
        if (isdigit($part) == 0) {
            return $ip;
        }
        $dec = strtoul($part, 10);
        if ($i == 0) {
            $new_ip = $dec;
        } else {
            $new_ip = $new_ip . "." . $dec;
        }
        $i++;
    }
    return $new_ip;
}
Beispiel #10
0
function is_power_user()
{
    if ($_GLOBALS["AUTHORIZED_GROUP"] == "") {
        return 0;
    }
    if ($_GLOBALS["AUTHORIZED_GROUP"] < 0) {
        return 0;
    }
    return 1;
}
if ($_POST["CACHE"] == "true") {
    echo dump(1, "/runtime/session/" . $SESSION_UID . "/postxml");
} else {
    if (is_power_user() == 1) {
        /* cut_count() will return 0 when no or only one token. */
        $SERVICE_COUNT = cut_count($_POST["SERVICES"], ",");
        TRACE_debug("GETCFG: got " . $SERVICE_COUNT . " service(s): " . $_POST["SERVICES"]);
        $SERVICE_INDEX = 0;
        while ($SERVICE_INDEX < $SERVICE_COUNT) {
            $GETCFG_SVC = cut($_POST["SERVICES"], $SERVICE_INDEX, ",");
            TRACE_debug("GETCFG: serivce[" . $SERVICE_INDEX . "] = " . $GETCFG_SVC);
            if ($GETCFG_SVC != "") {
                $file = "/htdocs/webinc/getcfg/" . $GETCFG_SVC . ".xml.php";
                /* GETCFG_SVC will be passed to the child process. */
                if (isfile($file) == "1") {
                    dophp("load", $file);
                }
            }
            $SERVICE_INDEX++;
        }
    } else {
Beispiel #11
0
function check_ppp4($path)
{
    anchor($path);
    $over = query("over");
    if ($over != "eth" && $over != "pptp" && $over != "l2tp" && $over != "tty") {
        /* Internal error, no i18n. */
        set_result("FAILED", $path . "/ipaddr", "Illegal value for over : " . $over);
        return;
    }
    /* IP address */
    $static = query("static");
    if ($static == "1") {
        $ipaddr = query("ipaddr");
        if (INET_validv4addr($ipaddr) == 0) {
            set_result("FAILED", $path . "/ipaddr", i18n("Invalid IP address"));
            return;
        }
    } else {
        /* if static is not 1, it should be 0. */
        set("static", "0");
        del("ipaddr");
    }
    /* DNS */
    $cnt = query("dns/count");
    $i = 0;
    while ($i < $cnt) {
        $i++;
        $value = query("dns/entry:" . $i);
        if (INET_validv4addr($value) == 0) {
            set_result("FAILED", $path . "/dns:" . $i, i18n("Invalid DNS address"));
            return;
        }
        set("dns/entry:" . $i, INET_addr_strip0($value));
    }
    /* MTU/MRU */
    $mtu = query("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 cannot be smaller than 576."));
            return;
        }
        if ($over == "pptp" && $mtu > 1460) {
            set_result("FAILED", $path . "/mtu", i18n("The MTU value is too large, the valid value for pptp is 576 ~ 1460."));
            return;
        } else {
            if ($over == "l2tp" && $mtu > 1460) {
                set_result("FAILED", $path . "/mtu", i18n("The MTU value is too large, the valid value for l2tp is 576 ~ 1460."));
                return;
            } else {
                if ($mtu > 1492) {
                    if ($over == "tty") {
                        if ($mtu > 1500) {
                            set_result("FAILED", $path . "/mtu", i18n("The MTU value is too large, the valid value for 3G is 576 ~ 1500."));
                            return;
                        }
                    } else {
                        set_result("FAILED", $path . "/mtu", i18n("The MTU value is too large, the valid value is 576 ~ 1492."));
                        return;
                    }
                }
            }
        }
        $mtu = $mtu + 1 - 1;
        /* convert to number */
        set("mtu", $mtu);
    }
    $mru = query("mru");
    if ($mru != "") {
        if (isdigit($mru) == "0") {
            set_result("FAILED", $path . "/mtu", i18n("Invalid MRU value."));
            return;
        }
        if ($mru < 576) {
            set_result("FAILED", $path . "/mru", i18n("The MRU value is too small, the valid value is 576 ~ 1492."));
            return;
        }
        if ($mru > 1492) {
            set_result("FAILED", $path . "/mru", i18n("The MRU value is too large, the valid value is 576 ~ 1492."));
            return;
        }
        $mru = $mru + 1 - 1;
        /* convert to number */
        set("mru", $mru);
    }
    /* User Name & Password */
    if (query("username") == "" && $over != "tty") {
        set_result("FAILED", $path . "/username", i18n("The user name cannot be empty"));
        return;
    }
    /* dialup */
    $mode = query("dialup/mode");
    if ($mode != "auto" && $mode != "manual" && $mode != "ondemand") {
        /* no i18n */
        set_result("FAILED", $path . "/dialup/mode", "Invalid value for dial up mode - " . $mode);
        return;
    }
    $tout = query("dialup/idletimeout");
    if ($tout != "") {
        if (isdigit($tout) == "0" || $tout < 0 || $tout >= 10000) {
            set_result("FAILED", $path . "/dialup/mode", i18n("Invalid value for idle timeout."));
            return;
        }
    }
    if ($over == "eth") {
        /* should check service name & ac name here. */
    } else {
        if ($over == "pptp") {
            $server = query("pptp/server");
            if ($server == "") {
                set_result("FAILED", $path . "/pptp/server", i18n("No PPTP server."));
                return;
            }
            if (cut_count($server, ".") == 4 && isdigit(cut($server, 0, ".")) == 1 && isdigit(cut($server, 1, ".")) == 1 && isdigit(cut($server, 2, ".")) == 1 && isdigit(cut($server, 3, ".")) == 1) {
                if (INET_validv4addr($server) == 0) {
                    set_result("FAILED", $path . "/pptp/server", i18n("Invalid server IP address"));
                    return;
                } else {
                    set("pptp/server", INET_addr_strip0($server));
                }
            } else {
                if (isdomain($server) != 1) {
                    set_result("FAILED", $path . "/pptp/server", i18n("Invalid server IP address"));
                    return;
                }
            }
        } else {
            if ($over == "l2tp") {
                $server = query("l2tp/server");
                if ($server == "") {
                    set_result("FAILED", $path . "/l2tp/server", i18n("No L2TP server."));
                    return;
                }
                if (cut_count($server, ".") == 4 && isdigit(cut($server, 0, ".")) == 1 && isdigit(cut($server, 1, ".")) == 1 && isdigit(cut($server, 2, ".")) == 1 && isdigit(cut($server, 3, ".")) == 1) {
                    if (INET_validv4addr($server) == 0) {
                        set_result("FAILED", $path . "/l2tp/server", i18n("Invalid server IP address"));
                        return;
                    } else {
                        set("l2tp/server", INET_addr_strip0($server));
                    }
                } else {
                    if (isdomain($server) != 1) {
                        set_result("FAILED", $path . "/l2tp/server", i18n("Invalid server IP address"));
                        return;
                    }
                }
            }
        }
    }
    set_result("OK", "", "");
}
Beispiel #12
0
<?php 
include "/htdocs/phplib/trace.php";
if ($AUTHORIZED_GROUP < 0) {
    echo "Authenication fail";
} else {
    $get_routing_cmd = "";
    if ($_POST["version"] == "v4") {
        $get_routing_cmd = "echo ==ROUTEN==;route -n;echo ==END1==;echo ==DEFAULT==;ip route show table default;echo ==END2==;echo ==STATIC==;ip route list table STATIC;echo ==END3==;";
    } else {
        if ($_POST["version"] == "v6") {
            $get_routing_cmd = "echo ==ROUTEV6==;ip -6 route show ;echo ==END1==;echo ==STATIC==;ip -6 route show table STATIC;echo ==END2==;";
        }
    }
    if ($get_routing_cmd != "") {
        $count = cut_count($get_routing_cmd, ";");
        function execute($cmd)
        {
            setattr("/runtime/command", "get", $cmd . " >> /var/cmd.result");
            get("x", "/runtime/command");
        }
        $i = 0;
        unlink("/var/cmd.result");
        while ($i < $count) {
            $str = cut($get_routing_cmd, $i, ";");
            execute($str);
            $i++;
        }
        echo fread("", "/var/cmd.result");
        unlink("/var/cmd.result");
    } else {