option = {};
handle = {
	["Accept"] = "text/html, application/xhtml+xml, */*",
	["User-Agent"] = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36 LBBROWSER",
	["Accept-Language"] = "zh-CN",
	["Accept-Encoding"] = "deflate",
	["Connection"] = "Keep-Alive"
};
	
function Disconnection(host,wan,user,pass)
	local r = Login(host, wan, user, pass);
	if r == 1 then
		r = Disconn(host, wan, user, pass);
		Sleep(500);
		Logout(host, wan, user, pass);
		return r;
	else
		return r;
	end
end

function Connection(host,wan,user,pass)
	local r = Login(host, wan, user, pass);
	if r == 1 then
		r = Conn(host, wan, user, pass);
		Sleep(500);
		Logout(host, wan, user, pass);
		return r;
	else
		return r;
	end
end

function ChangeIP(host,wan,user,pass)
	local r = Login(host, wan, user, pass);
	if r == 1 then
		r = Disconn(host, wan, user, pass);
		if r == 1 then
			Sleep(5000);
			r = Conn(host, wan, user, pass);
			Sleep(500);
			Logout(host, wan, user, pass);
			return r;
		else
			return r;
		end
	else
		return r;
	end
end

function Login(host, wan, user, pass)
	handle["Authorization"] = "Basic "..hash_Base64(user..":"..pass, "gb2312");
	return 1;
end

function Disconn(host,wan,user,pass)
	local reslut = {};
	net_POST(host.."/wan_connect_disconnect.cgi", "disconnect_connect=+%B6%CF+%BF%AA+&click_value=1&input_value=0&con_dis_stat=1", false, "gb2312", option, handle, reslut);
	if reslut["Status"] == -1 then
		return -1;
	else
		local StatusClass,_ = math.modf(reslut["Status"] / 100.0);
		if StatusClass == 4 or StatusClass == 5 then
			return -2;
		elseif StatusClass == 2 or StatusClass == 3 then
			return 1;
		else
			return 0;
		end
	end
end

function Conn(host,wan,user,pass)
	local reslut = {};
	net_POST(host.."/wan_connect_disconnect.cgi", "disconnect_connect=+%C1%AC+%BD%D3+&click_value=1&input_value=1&con_dis_stat=0", false, "gb2312", option, handle, reslut);
	if reslut["Status"] == -1 then
		return -1;
	else
		local StatusClass,_ = math.modf(reslut["Status"] / 100.0);
		if StatusClass == 4 or StatusClass == 5 then
			return -2;
		elseif StatusClass == 2 or StatusClass == 3 then
			return 1;
		else
			return 0;
		end
	end
end

function Logout(host,wan,user,pass)
	return 1;
end