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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| local headers = ngx.req.get_headers() local reqUri = ngx.var.request_uri local uri = ngx.var.uri local userAgent = headers["user-agent"] local codePath = "/data/fiche/code"
if uri == "/" then ngx.say("Welcome to p.qiyuos.cn") ngx.exit(200) end
if uri == "/favicon.ico" then ngx.exit(200) end
local function file_exists(path) local file = io.open(path, "rb") if file then file:close() end return file ~= nil end
local function readFile2Mem(file) local fp = io.open(file,"r") if fp then return fp:read("*all") end end
local codeBeauty1 = [[ <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="https://cdn.bootcss.com/prettify/r298/run_prettify.min.js?autoload=true&lang=html"></script> <style type="text/css"> body { background: #fff; } pre.prettyprint { background-color: #eee; } .prettyprint ol.linenums > li { list-style-type: decimal; } .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.clo,.opn,.pun{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.kwd,.tag,.typ{font-weight:700}.str{color:#060}.kwd{color:#006}.com{color:#600;font-style:italic}.typ{color:#404}.lit{color:#044}.clo,.opn,.pun{color:#440}.tag{color:#006}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} </style> </head> <body> <pre class="prettyprint linenums" id="quine"> ]] local codeBeauty2 = [[ </pre> <script type="text/javascript">//<![CDATA[ (function () { function htmlEscape(s) { return s; // .replace(/&/g, '&') // .replace(/</g, '<') // .replace(/>/g, '>'); } // this page's own source code var quineHtml = htmlEscape( document.getElementById("quine").innerHTML ); // Highlight the operative parts: quineHtml = quineHtml.replace( /<script src[\s\S]*?><\/script>|<!--\?[\s\S]*?-->|<pre\b[\s\S]*?<\/pre>/g, '<span class="operative">$&<\/span>'); // insert into PRE document.getElementById("quine").innerHTML = quineHtml; })(); //\]\]> </script> </body> </html> ]]
if not file_exists(codePath .. uri .. "/index.txt") then ngx.exit(404) end
local paste = readFile2Mem(codePath .. uri .. "/index.txt") if not userAgent or string.len(userAgent) < 20 or not string.match(userAgent, "Mozilla") then ngx.say(paste) ngx.exit(200) else ngx.say(codeBeauty1 .. paste .. codeBeauty2) ngx.exit(200) end
|