Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .\proxy2ch.exe --api a6kwZ1FHfwlxIKJWCq4XQQnUTqiA1P:ZDzsNQ7PcOOGE2mXo145X6bt39WMz6 --api-auth-xua "JaneStyle/4.23" --api-auth-ua "Monazilla/1.00 JaneStyle/4.23 Windows/10.0.22000" --api-dat-ua "Monazilla/1.00 JaneStyle/4.23 Windows/10.0.22000" -c --verbose --bbscgi-lua sample.lua
- ----------------------------
- sample.lua
- ----------------------------
- function createTableFromBody(str)
- local t = {}
- for s in string.gmatch(str, "([^&]+)") do
- local idx = string.find(s, "=")
- local name = string.sub(s, 1, idx-1)
- local value = string.sub(s, idx+1)
- t[name] = value
- end
- return t
- end
- function createBodyFromTableWithOrder(tBody, order)
- order = order or {}
- local ret = ""
- for i, name in ipairs(order) do
- if tBody[name] ~= nil then
- if ret ~= "" then
- ret = ret .. "&"
- end
- ret = ret .. name .. "=" .. tBody[name]
- tBody[name] = nil
- end
- end
- for name, value in pairs(tBody) do
- if ret ~= "" then
- ret = ret .. "&"
- end
- ret = ret .. name .. "=" .. value
- end
- return ret
- end
- function generatePostSignatureFromTable(tBody, userAgent, hmacKey)
- local bbs = tBody["bbs"] or ""
- local key = tBody["key"] or ""
- local time = tBody["time"] or ""
- local from = tBody["FROM"] or ""
- local mail = tBody["mail"] or ""
- local message = tBody["MESSAGE"] or ""
- local subject = tBody["subject"] or ""
- local userAgent = userAgent or ""
- local monaKey = proxy2ch.monaKey
- local unused = ""
- local nonce = os.time()
- local data = table.concat({bbs, key, time, from, mail, message, subject, userAgent, monaKey, unused, nonce}, "<>")
- return proxy2ch.hmacSHA256(hmacKey, data), nonce
- end
- function willSendRequestToBbsCgi(request, host, board, thread)
- if string.sub(host, -#".5ch.net") ~= ".5ch.net" then
- return request
- end
- local apiKey = "a6kwZ1FHfwlxIKJWCq4XQQnUTqiA1P"
- local hmacKey = "ZDzsNQ7PcOOGE2mXo145X6bt39WMz6"
- local userAgent = "Monazilla/1.00 JaneStyle/4.23 Windows/10.0.22000"
- --リクエストボディをtableに変換する
- --"name1=value1&name=value2"形式のstringが{"name1" = "value1", "name2" = "value2"}形式のtableに変換される
- local tBody = createTableFromBody(request.body)
- --既にリクエストボディがUTF-8になっていると思われる場合はUTF-8への変換を無効にする
- --submitフィールドの値がUTF-8で解釈可能かどうかで判定する
- local shouldConvertToUTF8 = not proxy2ch.isValidAsUTF8(proxy2ch.decodeURIComponent(tBody["submit"]))
- --リクエストボディの各フィールドのURLエンコードを解除し、必要ならUTF-8に変換する
- --リクエストボディのUTF-8化が必須かどうかはUser-Agentにより異なる
- for name, value in pairs(tBody) do
- local decoded = proxy2ch.decodeURIComponent(value)
- tBody[name] = shouldConvertToUTF8 and proxy2ch.convertShiftJISToUTF8(decoded) or decoded
- end
- --リクエストボディとUser-Agentからリクエストのsignatureを生成する
- --signatureの生成元となるリクエストボディはURLエンコードを解除しておく必要がある
- local postSig, postNonce = generatePostSignatureFromTable(tBody, userAgent, hmacKey)
- --リクエストボディの各フィールドを再度URLエンコードする
- for name, value in pairs(tBody) do
- tBody[name] = proxy2ch.encodeURIComponent(value)
- end
- --tableからフィールドの順序を指定して新しいリクエストボディを生成する
- request.body = createBodyFromTableWithOrder(tBody, {"submit", "FROM", "mail", "MESSAGE", "bbs", "key", "time"})
- request.headers = HttpHeaders.new()
- request.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"
- request.headers["X-PostSig"] = postSig
- request.headers["X-APIKey"] = apiKey
- request.headers["X-PostNonce"] = postNonce
- request.headers["X-MonaKey"] = proxy2ch.monaKey
- request.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
- request.headers["Accept-Encoding"] = "gzip, identity"
- request.headers["Referer"] = "https://" .. host .. "/" .. board .. "/"
- request.headers["User-Agent"] = userAgent
- return request
- end
Add Comment
Please, Sign In to add comment