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 = {
["192.168.1.23"] = true,
["192.168.1.127"] = true,
["192.168.1.50"] = true,
["192.168.1.41"] = true,
["14.29.136.211"] = true,
["222.212.88.4"] = 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(
"
%s ",
string.gsub(text, "[\n]", "
"))
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