diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-01-28 17:15:08 +0000 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-02-15 14:49:34 +0000 |
commit | 5f1bd5f5c82c8290069f3fa462276a2deb721c17 (patch) | |
tree | fffce172de56639059589a4438fff6c0715f6796 | |
parent | feed6368dd5deb42d605c4ce2381a2c7cac498ae (diff) | |
download | gitano-5f1bd5f5c82c8290069f3fa462276a2deb721c17.tar.gz |
Add gitano-smart-http cgi
-rwxr-xr-x | bin/gitano-smart-http.cgi.in | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/bin/gitano-smart-http.cgi.in b/bin/gitano-smart-http.cgi.in new file mode 100755 index 0000000..b5c02a5 --- /dev/null +++ b/bin/gitano-smart-http.cgi.in @@ -0,0 +1,71 @@ +-- @@SHEBANG +-- -*- Lua -*- +-- gitano-smart-http +-- +-- Git (with) Augmented network operations -- User authentication wrapper +-- +-- Copyright 2014 Codethink Ltd +-- +-- + +-- @@GITANO_LUA_PATH + +local gitano = require "gitano" +local gall = require "gall" +local luxio = require "luxio" +local sio = require "luxio.simple" +local sp = require "luxio.subprocess" + +-- @@GITANO_BIN_PATH +-- @@GITANO_SHARE_PATH + +stream = sio.stderr + +function parse_get_request() + query_string = os.getenv("QUERY_STRING") + + if query_string then + command = string.gsub(query_string, "^service=", "") + repo = string.match(os.getenv("PATH_INFO"), '/(.+)/info/refs') + return command .. " '" .. repo .. "'" + end + + return nil +end + +function parse_post_request() + path_info = os.getenv("PATH_INFO") + + if path_info then + repo, command = string.match(path_info, "/(.+)/(.+)") + return command .. " '" .. repo .. "'" + end + + return nil +end + +function parse_request(request_method) + if request_method == "GET" then + return parse_get_request() + elseif request_method == "POST" then + return parse_post_request() + end +end + +request_method = os.getenv("REQUEST_METHOD") + +if request_method == "GET" or request_method == "POST" then + local user = os.getenv("REMOTE_USER") or "gitano/anonymous" + local cmdline = parse_request(request_method) + + if cmdline and gitano.auth.is_authorized(user, cmdline) then + os.execute("git http-backend") + else + io.write("Status: 403 Forbidden\r\n\r\n") + io.flush() + end +else + io.write("Status: 405 Method Not Allowed\r\n") + io.write("Allow: GET, POST\r\n\r\n") + io.flush() +end |