123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- local skynet = require "skynet"
- require "skynet.manager"
- local logger = require "logger"
- local stringify = require "stringify"
- local cjson = require "cjson"
- local md5 = require "md5"
- local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
- -- Generate request data
- local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
- content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
- local whitelist = {
- ["47.99.157.83"] = true,
- }
- local function update(path)
- local f = io.popen(string.format("sudo svn up %s", path))
- local text = f:read("*all")
- f:close()
- return text
- end
- local function create_html_page(text)
- return string.format(
- "<!DOCTYPE html><html><head><meta charset='UTF-8'></head> <body>%s</body> </html>",
- string.gsub(text, "[\n]", "<br/>"))
- end
- local function response(header, content)
- header = header or {}
- if header['pokemon-version'] then
- return { content }
- else
- return create_html_page(content)
- end
- end
- -- example:
- -- http://192.168.1.57:9001/svn_update?user=lee&pwd=lee@123&type=1 -- 配置
- -- http://192.168.1.57:9001/svn_update?user=lee&pwd=lee@123&type=2 -- 代码
- local function svn_update(args, ipaddr, header)
- logger.warn("处理来自主机 %s 的SVN更新请求", ipaddr)
- if not whitelist[ipaddr] then
- --return { code=403, msg="Forbidden" }
- -- return cjson.encode({state = 403, msg= "不信任ip"})
- end
- -- 验证gm账号
- local code = string.sub(args.code, 1, 16)
- if code ~= content.sign then
- return cjson.encode({state = 403, msg = "账号或密码错误"})
- end
- logger.trace(" === args = %s", stringify(args))
- -- 先通过 svn 更新配置文件和代码
- local descripe = ""
- if tonumber(args.type) == 1 then
- descripe = update(skynet.getenv "asset")
- end
- if tonumber(args.type) == 2 then
- descripe = descripe .. update(skynet.getenv "src")
- end
- logger.warn("svn_update (%s, %s)\n%s", user, ipaddr, descripe)
- return cjson.encode({state =0, msg = "SVN更新 成功", content = response(header, descripe)})
- -- return response(header, content)
- end
- return svn_update
|