summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2014-01-28 17:15:08 +0000
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-02-12 14:53:06 +0000
commit6219f402060dacc262bc1530652ab3d84f7d784a (patch)
tree1043af1012dcc273584a874bfcd5c8134ad177d1
parent89c362f4906895f422bfd5b4794804a6cb2f5091 (diff)
downloadgitano-6219f402060dacc262bc1530652ab3d84f7d784a.tar.gz
Add gitano-smart-http cgi
-rwxr-xr-xbin/gitano-smart-http.cgi.in71
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