Created
July 9, 2018 14:40
-
-
Save mozhu1024/4edbfa8b22638b8fa1da50c8d91efed7 to your computer and use it in GitHub Desktop.
[Github Webhook with LuaJit]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ffi = nil | |
local token = 'xxx' | |
ffi = require("ffi") | |
ffi.load("z") | |
ffi.cdef[[int system(const char * string);]] | |
if "POST" == ngx.var.request_method then | |
ngx.req.read_body() | |
local args, err = ngx.req.get_post_args() | |
if args ~= nil then | |
local _token = nil | |
for key, val in pairs(args) do | |
if key == "token" then | |
if val ~= nil then | |
_token = val | |
end | |
end | |
end | |
if _token == token then | |
ffi.C.system("cd /var/www/blog && git pull >> /var/log/updatelua.log") | |
ngx.say("ok") | |
ngx.exit(0) | |
end | |
end | |
end | |
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR | |
ngx.say("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment