-- foureightysix.go-beyond.org -- Copyright 2008 by Teran McKinney (sega01). Released under the GPLv3. -- Thanks to Madhat, Freenode={"#css,"#html","#lua}, Google, and the countless -- others that have lead up to this :-). -- For saving to disk every 250 hits (and reading initially) wl_load_module("tabledb") wl_send_headers() -- This is more proper, but makes FF2 not complete the background (looks like a -- picture frame). --wl_send_headers(nil, "application/xhtml+xml") --wl={pwd="/srv/www/htdocs/486/"} local dbfile=(wl.pwd.."vars.db") if wl.persistent then vars=wl.persistent wl.persistent=nil vars.hits = vars.hits + 1 else file = io.open(dbfile, "r") if file then file:close() vars=(table.load (dbfile)) vars.hits = vars.hits + 1 else vars={hits=1, refs={}, b30r={}} end end if not vars.ipv6hits then vars.ipv6hits=0 end referer=os.getenv("HTTP_REFERER") or nil --referer="http://google.com" if referer then if (referer:match("://([^/]+)")) then referinghost=referer:match("://([^/]+)"):sub(1,32) end end write [[ foureightysix.go-beyond.org
11         2358132   1345589 
14    42  33     37 76     10
98    71  59     72 58       
44    18   1676510  94617711 
28657463  68     75 02     51
      21  39     31 96     41
      83   1781151   4229832 
.go-beyond.org

The 486 got bored, apparently 1,164,250 hits wasn't enough for it. Anyways, I'm quietly getting the counter started again, but from a fresh start. Have fun :-). Here is the source, if you are interested.
]] -- Helps with debugging in the Lua console if referinghost then write ([[Referer: ]]..referer..[[
Refering host: ]]..referinghost) refhostkey=nil for key,entry in pairs(vars.refs) do if (entry[1] == referinghost) then refhostkey=key break end end if refhostkey then vars.refs[refhostkey][2]=vars.refs[refhostkey][2] + 1 write ([[
Your refering host's hit count: ]]..vars.refs[refhostkey][2]) --- Don't think that we need this bit --local sorted={} --for k,v in pairs(vars.refs) do --sorted[k] = v --end --vars.refs=sorted --sorted=nil --- table.sort(vars.refs, function(lhs, rhs) return lhs[2] > rhs[2] end) else for key,entry in pairs(vars.b30r) do if (entry[1] == referinghost) then refhostkey=key break end end -- Swapping FIFO with #20. -- Note that this will probably only work properly on -- a clean "database". However, it may clean itself out with the right series of -- hits. if refhostkey then vars.b30r[refhostkey][2]=vars.b30r[refhostkey][2] + 1 write ([[
Your refering host's hit count: ]]..vars.b30r[refhostkey][2]) if (vars.b30r[refhostkey][2] > vars.refs[20][2]) then -- Backup #20 local temp=vars.refs[20] vars.refs[20]=vars.b30r[refhostkey] vars.b30r[refhostkey]=temp temp=nil end else write [[
You are the first user from your referer!]] -- Try to keep XSS out, but I'm not 100% sure of why it simply doesn't log them. -- I guess I can call it a feature for now :-). clean_referinghost=wl_html_encode(referinghost) --vars.refs[50] = {clean_referinghost,1} -- Many thanks to ToxicFrog for all of the help on this code if vars.refs[20] then local sorted={} start=1 max=30 for k,v in pairs(vars.b30r) do if (start==max) then break else start = start + 1 end -- v should already be a table sorted[k+1] = v end vars.b30r=sorted sorted=nil vars.b30r[1] = {clean_referinghost,1} else vars.refs[20] = {clean_referinghost,1} local sorted={} local count=0 for k,v in pairs(vars.refs) do count=count+1 -- v should already be a table sorted[count] = v end vars.refs=sorted sorted=nil table.sort(vars.refs, function(lhs, rhs) return lhs[2] > rhs[2] end) end end end end local useragent = os.getenv"HTTP_USER_AGENT" if useragent then write ([[
Your user agent is: ]]..useragent) end local remoteaddr = os.getenv"REMOTE_ADDR" -- omnisource will be proxying the IPv4 requests and IPv4 is disabled on the -- box, so requests from its IP will 99.99% of the time be IPv4 requests. if (remoteaddr == "2001:470:8:29::2" ) then write [[
You are connecting from IPv4, please consider using IPv6.]] else write ([[
Thank you for using IPv6! Your IPv6 address is: ]]..remoteaddr) vars.ipv6hits=vars.ipv6hits+1 end local ipv6percent=(vars.ipv6hits/vars.hits*100) ipv6percent=ipv6percent - ipv6percent %0.01 write ([[
Percentage of total hits from IPv6: ]]..ipv6percent..[[%]]) write ([[

Refering host
Hits
]]) max=20 start=0 for _,entry in pairs(vars.refs) do if (start==max) then break else start = start + 1 end local server=entry[1] local hits=entry[2] local percentage=(hits/vars.hits*100) percentage=percentage - percentage %0.01 write ([[
]]..server..[[
]]..hits..[[ (]]..percentage..[[%)
]]) end write ([[

Total hits: ]]..vars.hits) write [[

This page is scripted with the WebLua API, which uses Lua. It uses Lighttpd as a webserver, on top of my Arch Linux fork.

Donate | Blog | Contact ]] if (remoteaddr == "2001:470:8:29::2" ) then write [[


]] end write [[
]] -- "Save" the changes -- Thanks to lanthas for this bit if (vars.hits % 250 == 0) then table.save(vars, dbfile) wl.persistent=vars -- Think that we need this here too. else wl.persistent=vars end