diff --git a/specs/cwnu-drcom-1.0-2.rockspec b/specs/cwnu-drcom-1.0-2.rockspec index eaaf0ce..c6662bb 100644 --- a/specs/cwnu-drcom-1.0-2.rockspec +++ b/specs/cwnu-drcom-1.0-2.rockspec @@ -3,11 +3,13 @@ version = "1.0-2" source = { url = "git://github.com/leetking/cwnu-drcom.lua", dir = "cwnu-drcom.lua", + tag = "v1.0-2", } description = { summary = "登录西华师范大学校园网", detailed = [[ 通过网页认证登录网络,仅供西华师范大学使用(http://cwnu.edu.cn)。 + v1.0-2 老版本也能继续使用。 ]], homepage = "http://github.com/leetking/cwnu-drcom.lua", maintainer = "leetking ", diff --git a/specs/cwnu-drcom-2.0-0.rockspec b/specs/cwnu-drcom-2.0-0.rockspec new file mode 100644 index 0000000..cec3e4f --- /dev/null +++ b/specs/cwnu-drcom-2.0-0.rockspec @@ -0,0 +1,35 @@ +package = "cwnu-drcom" +version = "2.0-0" +source = { + url = "git://github.com/leetking/cwnu-drcom.lua", + dir = "cwnu-drcom.lua", + tag = "v2.0", +} +description = { + summary = "登录西华师范大学校园网", + detailed = [[ + 通过网页认证登录网络,仅供西华师范大学使用(http://cwnu.edu.cn)。 + v2.0 新版本登录 + ]], + homepage = "http://github.com/leetking/cwnu-drcom.lua", + maintainer = "leetking ", + license = "GNU GPL v3", +} +dependencies = { + "lua >= 5.1", + "luasocket >= 3.0rc1-2", + "md5 >= 1.2-1", +} +build = { + type = "builtin", + modules = { + ["cwnu-drcom.core"] = "src/core.lua", + -- TODO 如何让config模块不导出 + ["cwnu-drcom.config"] = "src/config.lua", + }, + install = { + bin = { + drcom = "drcom.lua", + }, + }, +} diff --git a/src/config.lua b/src/config.lua index 120a36c..dc5af38 100644 --- a/src/config.lua +++ b/src/config.lua @@ -8,9 +8,7 @@ local user = { -- 软件设置 local sys = { ser = "10.255.0.204", - path = "/0.htm", - pid = "2", - calg = "12345678", + path = "/a70.htm", } return { diff --git a/src/core.lua b/src/core.lua index ecd9869..5549d9a 100644 --- a/src/core.lua +++ b/src/core.lua @@ -11,13 +11,13 @@ local encryt_pwd = function(pwd) local calg = syscfg.calg return md5.sumhexa(pid..pwd..calg)..calg..pid end --- 把table转换为url数据string -local table2string = function(tb) +-- 把table转换为key=value形式的string,并由sep隔开 +local table2string = function(tb, sep) local ret = "" local isfirst = true for k, v in pairs(tb) do if not isfirst then - ret = ret.."&" + ret = ret..sep end isfirst = false ret = ret..tostring(k).."="..tostring(v) @@ -25,17 +25,45 @@ local table2string = function(tb) return ret end +-- 获取本机 IP +local get_localip = function() + local socket = require("socket") + local skt = socket.udp() + skt:setpeername("8.8.8.8", 53) -- 随便填写 + local ip, _ = skt:getsockname() + return ip +end + local body = { ["DDDDD"] = (user.net == "SNET") and user.usr or user.usr.."@tel", - ["upass"] = encryt_pwd(user.pwd), + ["upass"] = user.pwd, ["R1"] = 0, - ["R2"] = 1, + ["R2"] = "", + ["R6"] = 0, ["para"] = "00", ["0MKKey"] = "123456", - ["v6ip"] = "", + ["buttonClicked"] = "", + ["redirect_url"] = "", + ["err_flag"] = "", + ["username"] = "", + ["password"] = "", + ["user"] = "", + ["cmd"] = "", + ["Login"] = "", } -local strbody = table2string(body) -local resbody = {} +local cookies = { + ["program"] = "XHSFDX", + ["vlan"] = 0, + ["ip"] = get_localip(), + ["md5_login2"] = body["DDDDD"].."%7C"..body["upass"], -- %7C == | +} +local strbody = table2string(body, "&") +local strcookies = table2string(cookies, "; ") +local resbody = {} + +print("strbody :", strbody) +print("strcookies :", strcookies) +print("localip: ", get_localip()) -- 开始请求 local function login() @@ -44,8 +72,10 @@ local function login() url = "http://"..syscfg.ser..syscfg.path, method = "POST", headers = { - ["Content-Type"] = "application/x-www-form-urlencoded"; - ["Content-Length"] = #strbody + ["Content-Type"] = "application/x-www-form-urlencoded", + ["Content-Length"] = #strbody, + ["Cookie"] = strcookies, + ["Referer"] = "http://"..syscfg.ser..syscfg.path, }, source = ltn12.source.string(strbody), sink = ltn12.sink.table(resbody),