File: webCns.lua

package info (click to toggle)
eja 9.5.20-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 1,340 kB
  • ctags: 3,142
  • sloc: ansic: 15,010; makefile: 255
file content (29 lines) | stat: -rw-r--r-- 906 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- Copyright (C) 2007-2015 by Ubaldo Porcheddu <ubaldo@eja.it>


eja.help.webCns='cns timeout'


function ejaWebCns(web)
 if web.path == "/library/test/success.html" or (web.headerIn['user-agent'] and web.headerIn['user-agent']:match('CaptiveNetworkSupport')) then
  local cnsData='<HTML><HEAD><TITLE>Success</TITLE></HEAD><BODY>Success</BODY></HTML>'
  if eja.opt.webCns then
   local cnsCheck=0
   local cnsPath=ejaSprintf('%s/eja.cns.log',eja.pathTmp)
   local cnsLog=ejaFileRead(cnsPath) or ''
   for time,ip,url in cnsLog:gmatch('([^ ]-) ([^ ]-) ([^\n]-)\n') do
    if (ip==web.remoteIp or url==web.path) and os.time()-time < ejaNumber(eja.opt.webCns) then cnsCheck=1 end
   end
   if cnsCheck > 0 then
    web.data=cnsData
   else
    ejaFileAppend(cnsPath,os.time()..' '..web.remoteIp..' '..web.path.."\n")
    web.data='CNS'
   end
  else
   web.data=cnsData
  end
  web.cns=1
 end
 return web
end