Skip to content

Commit 071bd13

Browse files
authored
Removed license handling
1 parent 0d51cb2 commit 071bd13

File tree

1 file changed

+1
-79
lines changed

1 file changed

+1
-79
lines changed

htaccess.lua

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-- Compilation: luajit -b htaccess.lua htaccess-bytecode.lua
44
-- Version: 1.2.1
55

6-
-- TODO: Sometimes code is executed 4 (!) times for each request. Investigate and SOLVE THIS SHIT.
6+
-- TODO: Sometimes code is executed 4 times for each request due to the way nginx handles requests. Make sure it is cached accordingly.
77

88
-- Error function, returns HTTP 500 and logs an error message
99
local fail = function(msg)
@@ -13,45 +13,6 @@ local fail = function(msg)
1313
ngx.exit(500)
1414
end
1515

16-
-- local log = function(msg) -- TODO: Remove this function!
17-
-- if type(msg) == 'nil' then
18-
-- ngx.log(ngx.ERR, '(nil)')
19-
-- elseif type(msg) == 'string' then
20-
-- ngx.log(ngx.ERR, msg)
21-
-- elseif type(msg) == 'number' then
22-
-- msg = tostring(msg)
23-
-- elseif type(msg) == 'table' then
24-
-- ngx.log(ngx.ERR, '(table)')
25-
-- for key, val in pairs(msg) do
26-
-- if type(val) == 'nil' then
27-
-- val = '(nil)'
28-
-- elseif type(val) == 'boolean' then
29-
-- if val then
30-
-- val = 'true'
31-
-- else
32-
-- val = 'false'
33-
-- end
34-
-- elseif type(val) == 'table' then
35-
-- val = '(table)'
36-
-- end
37-
-- ngx.log(ngx.ERR, '> ['..key..'] > '..val)
38-
-- end
39-
-- return
40-
-- elseif type(msg) == 'boolean' then
41-
-- if msg then
42-
-- msg = '(true)'
43-
-- else
44-
-- msg = '(false)'
45-
-- end
46-
-- else
47-
-- msg = type(msg)
48-
-- end
49-
-- ngx.log(ngx.ERR, msg)
50-
-- end
51-
52-
-- Define error string used for security violation errors
53-
local C_SECURITY_VIOLATION_ERROR = 'Security violation'
54-
5516
-- Halts the script execution
5617
local die = function()
5718
ngx.exit(0) -- os.exit(0) leads to timeouts in nginx
@@ -88,44 +49,6 @@ local cache_set = function(key, value, expiry_sec)
8849
return cache_dict:set(key, value, expiry_sec)
8950
end
9051

91-
local cached_nreq = cache_get('__NREQ__') -- number of requests in total since server start
92-
if not cached_nreq then
93-
cached_nreq = 0
94-
end
95-
96-
local lc_cache_name = decode_base64('X19MSUNFTlNFX18=')
97-
local lc_ok_header = decode_base64('WC1MaWNlbnNlOiBPSw==')
98-
99-
-- Check license
100-
local check_lc = function()
101-
local cached_lc = cache_dict:get_stale(lc_cache_name) -- cached license check results
102-
if cached_lc == 1 then
103-
return true
104-
elseif cached_lc == 9 then
105-
return false
106-
end
107-
-- ask license server for valid license
108-
local curl = io.popen(decode_base64('Y3VybCAtcyAtSSBodHRwczovL2h0YWNjZXNzLWZvci1uZ2lueC5jb20vbGljZW5zZS1jaGVjay8='))
109-
-- -s ... silent (no stdout output)
110-
-- -I ... fetch headers only
111-
if curl == nil then
112-
fail(decode_base64('TElDRU5TRSBFUlJPUjogQ291bGQgbm90IHBlcmZvcm0gY1VSTCByZXF1ZXN0'))
113-
end
114-
local curl_headers = curl:read('*all')
115-
curl:close()
116-
if string.find(curl_headers, lc_ok_header) then
117-
cache_dict:set(lc_cache_name, 1, 0)
118-
return true
119-
end
120-
cache_dict:set(lc_cache_name, 9, 0)
121-
return false
122-
end
123-
124-
-- check number of requests. if more than n requests (free) check license
125-
if cached_nreq > 100 and not check_lc() then
126-
fail(decode_base64('TElDRU5TRSBFUlJPUjogTm8gdmFsaWQgbGljZW5zZSBmb3VuZA=='))
127-
end
128-
12952
-- Define request status values
13053
local C_STATUS_SUBREQUEST = 1
13154
local C_STATUS_VOID = 9
@@ -148,7 +71,6 @@ if request_status then
14871
else
14972
is_subrequest = false
15073
cache_set(trace_id, C_STATUS_SUBREQUEST) -- Write subrequest status to cache for any following subrequest
151-
cache_dict:set('__NREQ__', cached_nreq+1, 0)
15274
end
15375

15476
-- The original requested URI including query string

0 commit comments

Comments
 (0)