local skynet = require "skynet"
require "skynet.manager"
local logger = require "logger"
local stringify = require "stringify"
local watchdog = skynet.localname(".watchdog")
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,
["14.29.136.211"] = true,
["192.168.1.41"] = true,
["222.212.88.4"] = true,
}
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/console?user=lee&pwd=lee@123&cmd=gc
-- http://192.168.1.57:9001/console?user=lee&pwd=lee@123&cmd=mem
-- http://192.168.1.57:9001/console?user=lee&pwd=lee@123&cmd=stat
-- http://192.168.1.57:9001/console?user=lee&pwd=lee@123&cmd=info#address=.watchdog
local function service_inquire(args, ipaddr, header)
logger.warn("处理来自主机 %s 的控制台请求", ipaddr)
if not whitelist[ipaddr] then
--return { "403 - Forbidden" }
-- return cjson.encode({errno = 403, host = header.host, info = "不信任ip"})
end
-- 验证gm账号
local code = string.sub(args.code, 1, 16)
if code ~= content.sign then
return cjson.encode({state = 403, msg = "账号或密码错误"})
end
if args.cmd~="info" then
return cjson.encode({state = 400, msg = "错误的请求类型"})
end
local context
local service_name=skynet.localname(args.address)
logger.trace("===========service_name=%s",service_name)
if not service_name then
return cjson.encode({state = 400, msg = "查询的服务不存在"})
else
context = skynet.call(args.address,"debug","INFO")
end
-- return { "400 - Bad Request" }
logger.trace(" context = %s",context)
if not context then
return cjson.encode({state = 400,msg = "参数错误"})
else
return cjson.encode({state =0,msg = "成功",context = context})
end
end
return service_inquire