Skip to content

Commit

Permalink
New version.
Browse files Browse the repository at this point in the history
  • Loading branch information
leetking authored and leetking committed Aug 26, 2017
1 parent edd03a0 commit 6c535c0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
2 changes: 2 additions & 0 deletions specs/cwnu-drcom-1.0-2.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>",
Expand Down
35 changes: 35 additions & 0 deletions specs/cwnu-drcom-2.0-0.rockspec
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
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",
},
},
}
4 changes: 1 addition & 3 deletions src/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ local user = {
-- 软件设置
local sys = {
ser = "10.255.0.204",
path = "/0.htm",
pid = "2",
calg = "12345678",
path = "/a70.htm",
}

return {
Expand Down
50 changes: 40 additions & 10 deletions src/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,59 @@ 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)
end
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()
Expand All @@ -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),
Expand Down

0 comments on commit 6c535c0

Please sign in to comment.