project Websites / videos.bentasker.co.uk avatar

Websites / videos.bentasker.co.uk: 6e124f8e




VID-11 Adjust so that can be run from the CLI for build/debug purposes

VID-11 Adjust so that can be run from the CLI for build/debug purposes

Commit 6e124f8e.

Authored 2019-04-18T14:41:33.000+01:00 by B Tasker in project Websites / videos.bentasker.co.uk

+44 lines -33 lines

Changes

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)
# local tokenlife = 3600
#
# --- 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.status = 403
# - ngx.say(json.encode(r))
# - ngx.exit(403)
# -
# - -- Offline only
# - -- print(json.encode(r))
#
# + if ngx ~= nil
# + then
# + ngx.status = 403
# + ngx.say(json.encode(r))
# + ngx.exit(403)
# + else
# + print("Denying")
# + print(json.encode(r))
# + end
# +
# end
#
#
# @@ -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)
# do
# - print("Test " .. allowed)
# +
# -- Check whether the whitelist uses a wild card
# first = string.sub(allowed, 1, 1)
# if first == "*"
# @@ -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)
# splitd[1] = '*'
# - print("Checking against " .. table.concat(splitd,"."))
# if table.concat(splitd,".") == allowed
# then
# -- print("Matched wildcard")
# @@ -161,22 +160,33 @@ end
#
# -- Function main
# local debug = nil
# +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
# -
# --- Get the user's IP
# -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
# +if ngx ~= nil
# +then
# + -- 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
# + then
# + enable_debug = 1
# + end
# +
# +else
# + print("CLI detected, using preset values")
# + -- Testing from CLI, use static values
# + referer = 'https://snippets.bentasker.co.uk/foobar'
# + vidpath = '2019/08/16.m3u8'
# + ip = '127.0.1.1'
# + secret = '1234abcd'
# + httpref = 'https://snippets.bentasker.co.uk/foobar'
# +
# +end
#
#
#
# @@ -199,14 +209,15 @@ local expires = os.time() + tokenlife
#
# local tok = mint_token(vidpath,expires,ip,secret)
#
# --- print(os.time())
# --- print(expires)
# --- print(tok)
#
# -if ngx.var.arg_debug ~= nil
# +if enable_debug ~= nil
# then
# debug = {vidpath = vidpath, IP = ip, Expires = expires}
# end
#
# -ngx.print(sendSuccessful(tok,expires,debug))
# --- print(sendSuccessful(tok,expires,{vidpath,ip,expires})) -- offline testing only
# +if ngx ~= nil
# +then
# + ngx.print(sendSuccessful(tok,expires,debug))
# +else
# + print(sendSuccessful(tok,expires,debug))
# +end
#