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-10 15:05:31 +0000 |
commit | ebce7a41db962e6e78f98a73cc51598d3e0229e8 (patch) | |
tree | 5968757cf7607c322df4b06c8db810e09d616a83 | |
parent | a0502774b11a280cff1bb9297455160b86358ba9 (diff) | |
download | gitano-ebce7a41db962e6e78f98a73cc51598d3e0229e8.tar.gz |
Add gitano-smart-http cgi
-rwxr-xr-x | bin/gitano-smart-http.cgi.in | 69 |
1 files changed, 69 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..2cfaa17 --- /dev/null +++ b/bin/gitano-smart-http.cgi.in @@ -0,0 +1,69 @@ +-- @@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("/usr/lib/git-core/git-http-backend") + else + io.write("Status: 403 Forbidden\r\n\r\n") + end +else + -- 405 Method not allowed might be more appropriate + io.write("Status: 403 Forbidden\r\n\r\n") +end |