diff --git a/resources/tokenisation/minter/token_gen.lua b/resources/tokenisation/minter/token_gen.lua
--- a/resources/tokenisation/minter/token_gen.lua
+++ b/resources/tokenisation/minter/token_gen.lua
#
@@ -26,10 +26,6 @@ local json = require "lib.json"
#
-- How long should a token be valid for (seconds)
#
--- Get the secret from Nginx config
#
---local secret = ngx.var.secret
#
-local secret = '1234' -- for offline testing only
#
-- What IPs should be excluded from checks?
#
local excluded_ips = {"127.0.0.1"}
#
@@ -99,13 +95,17 @@ end
#
local function sendFailed(reason)
#
local r = {status = false, token = 'failed', exp = '-1', msg = reason}
#
- ngx.say(json.encode(r))
#
- -- print(json.encode(r))
#
+ ngx.say(json.encode(r))
#
+ print(json.encode(r))
#
@@ -132,7 +132,7 @@ local function check_referrer(referrer,httpref,permitted)
#
-- Next, check whether the domain exists in permitted_referrers
#
for key,allowed in pairs(permitted_referrers)
#
- print("Test " .. allowed)
#
-- Check whether the whitelist uses a wild card
#
first = string.sub(allowed, 1, 1)
#
@@ -140,7 +140,6 @@ local function check_referrer(referrer,httpref,permitted)
#
-- remove the first label from the referring domain, and then do a comparison
#
splitd = strSplit(".",refdomain)
#
- print("Checking against " .. table.concat(splitd,"."))
#
if table.concat(splitd,".") == allowed
#
-- print("Matched wildcard")
#
@@ -161,22 +160,33 @@ end
#
+local enable_debug = nil
#
--- get some details from the request
#
-local referer = unescape(ngx.var.arg_ref)
#
--- local referer = 'https://snippets.bentasker.co.uk/foobar' -- for offline testing only
#
-local vidpath = ngx.var.arg_vidpath
#
--- local vidpath = '2019/08/16.m3u8' -- for offline testing only
#
-local ip = ngx.var.remote_addr
#
--- local ip = '127.0.1.1' -- for offline testing only
#
--- Grab the HTTP referrer header if present
#
-local httpref = ngx.var.http_referer
#
--- local httpref = 'https://snippets.bentasker.co.uk/foobar' -- for offline testing only
#
+-- Set various config items
#
+ -- We're running in OpenResty, run for real
#
+ referer = unescape(ngx.var.arg_ref)
#
+ vidpath = ngx.var.arg_vidpath
#
+ ip = ngx.var.remote_addr
#
+ secret = ngx.var.secret
#
+ httpref = ngx.var.http_referer
#
+ if ngx.var.arg_debug ~= nil
#
+ print("CLI detected, using preset values")
#
+ -- Testing from CLI, use static values
#
+ referer = 'https://snippets.bentasker.co.uk/foobar'
#
+ vidpath = '2019/08/16.m3u8'
#
+ httpref = 'https://snippets.bentasker.co.uk/foobar'
#
@@ -199,14 +209,15 @@ local expires = os.time() + tokenlife
#
local tok = mint_token(vidpath,expires,ip,secret)
#
-if ngx.var.arg_debug ~= nil
#
+if enable_debug ~= nil
#
debug = {vidpath = vidpath, IP = ip, Expires = expires}
#
-ngx.print(sendSuccessful(tok,expires,debug))
#
--- print(sendSuccessful(tok,expires,{vidpath,ip,expires})) -- offline testing only
#
+ ngx.print(sendSuccessful(tok,expires,debug))
#
+ print(sendSuccessful(tok,expires,debug))