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_1 = { ["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, } -- example: -- http://192.168.1.57:9001/whitelist?user=lee&pwd=lee@123&account=xxx -- http://192.168.1.57:9001/whitelist?user=lee&pwd=lee@123&ipaddr=xxx -- http://192.168.1.57:9001/whitelist?user=lee&pwd=lee@123 local function whitelist(args, ipaddr, header) logger.warn("处理来自主机 %s 的新增白名单请求", ipaddr) if not whitelist_1[ipaddr] then --return { code=403, msg="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.account then local account=cjson.decode(args.account) for k,v in pairs(account) do skynet.call(watchdog, "lua", "addnew_account_whitelist", v) logger.warn("account-whitelist-addnew: %s", v) end return cjson.encode({state = 0, msg = "新增白名单 成功",account=account}) elseif args.ipaddr then local ipaddress=cjson.decode(args.ipaddr) for k,v in pairs(ipaddress) do skynet.call(watchdog, "lua", "addnew_ipaddr_whitelist",v) logger.warn("ipaddr-whitelist-addnew: %s",v) end return cjson.encode({state = 0, msg = "新增白名单 成功",ipaddr=ipaddress}) else return cjson.encode({state=400,msg="参数错误"}) end end return whitelist