diff options
Diffstat (limited to 'cgi-bin/provisioning.cgi')
-rwxr-xr-x | cgi-bin/provisioning.cgi | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cgi-bin/provisioning.cgi b/cgi-bin/provisioning.cgi index e8af6be..ba8f9a6 100755 --- a/cgi-bin/provisioning.cgi +++ b/cgi-bin/provisioning.cgi @@ -8,6 +8,7 @@ local root = ENV["DOCUMENT_ROOT"] or "" local request_method = ENV["REQUEST_METHOD"] or "" local user_agent = ENV["HTTP_USER_AGENT"] or "" local ip_address = ENV["REMOTE_ADDR"] or "" +local server = ENV["SERVER_NAME"] or "" local log = io.open("/var/log/provisioning.log", "a+") log:write("Running provisioning.cgi ".. os.date() .. "\n") @@ -79,6 +80,19 @@ local basename = posix.basename(path_info) local mac = string.match(basename, "%x%x%x%x%x%x%x%x%x%x%x%x") if ( request_method == "GET" ) then + -- If it's a Linksys and corresponding file exists in /Linksys/ then serve it up, replacing $SERV with SERVER_NAME + if string.match(user_agent, "Linksys") and posix.stat(root.."/Linksys/"..basename) then + local f = io.open(root.."/Linksys/"..basename, "r") + if f then + log:write("Translating local file\n") + io.stdout:write("Content-Type: \n\n") + io.stdout:write((string.gsub(f:read("*a"), "%$SERV", server))) + f:close() + log:close() + os.exit() + end + end + -- don't even bother for files that don't contain a MAC if mac == nil then http_code(404) |