function Watchdog()
{
    global $NCSIServer, $DialServer, $NetDetectCycle, $isDetectedNoNetwork;
    while (true) {
        $i_c = 0;
        $c_c = 0;
        for ($i = 0; $i < 5; $i++) {
            $c_status = FCurl("http://{$DialServer}");
            $i_status = FCurl($NCSIServer);
            if (strpos($c_status, "portal4HN") > -1) {
                $c_c++;
            }
            if (strpos($i_status, "Microsoft NCSI") > -1) {
                $i_c++;
            }
            // wait
            usleep($NetSleepTime * 1000);
        }
        // not logged in
        if ($i_c == 0 && $c_c >= 1) {
            FLog("You are not logged in, Redialing ...", 3);
            break;
        } else {
            if ($i_c == 0 && $c_c == 0) {
                if ($isDetectedNoNetwork == 0) {
                    FLog("No Network Access! waiting ...", 4);
                    // Set donot log next time
                    $isDetectedNoNetwork = 1;
                }
                // If no network access wait for 5 sec
                // sleep(5);
            } else {
                if ($i_c >= 1) {
                    // Reset Flags
                    $isDetectedNoNetwork = 0;
                }
            }
        }
        // Another Cycle
        usleep($NetDetectCycle * 1000);
    }
}
function netWatchdog()
{
    global $NCSIServer, $DialServer, $NetDetectCycle;
    while (true) {
        $i_c = 0;
        $c_c = 0;
        for ($i = 0; $i < 1; $i++) {
            $c_status = FCurl("http://{$DialServer}", 1);
            $i_status = FCurl($NCSIServer, 5);
            if (strpos($c_status, "portal4HN") > -1) {
                $c_c++;
            }
            if (strpos($i_status, "Microsoft NCSI") > -1) {
                $i_c++;
            }
        }
        // not logged in
        if ($i_c == 0 && $c_c >= 1) {
            $netStatus->img = "warning";
            $netStatus->title = "拨号连接已经丢失";
            $netStatus->msg = "您与网络运营商的链路通讯正常,但是您尚未拨号,所以当前您仅能访问运营商指定的网络资源。若您想访问互联网资源,那么<a href=\"javascript:;\" onclick=\"document.getElementById('app').style.display='block';\">请您拨号上网</a>。";
        } else {
            if ($i_c == 0 && $c_c == 0) {
                $netStatus->img = "error";
                $netStatus->title = "网络出现故障";
                $netStatus->msg = "您无法与网络运营商的服务器取得通信,这可能由于您的线路故障造成,请您仔细检查线路或者您的网络设备,若无法解决请与运营商取得联系。";
            } else {
                if ($i_c >= 1) {
                    $netStatus->img = "ok";
                    $netStatus->title = "当前网络正常";
                    $netStatus->msg = "您的网络一切正常,可以正常访问互联网上的网络资源。";
                }
            }
        }
        return $netStatus;
    }
}