-- foureightysix.go-beyond.org -- Copyright 2008 by Teran McKinney (sega01). Released under the GPLv3. -- Nah, copyright 2009 by Teran McKinney (sega01). Released to the public -- domain now, but credit is appreciated. -- Thanks to Madhat, Freenode={"#css","#html","#lua"}, Google, and the countless -- others that have lead up to this :-). -- Yes, I know the formatting is painful and ugly. -- For saving to disk every 250 hits (and reading initially) wl_load_module("tabledb") wl_send_headers() 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") -- Inefficent. if file then file:close() vars=(table.load (dbfile)) vars.hits = vars.hits + 1 else vars={hits=1, ipv6hits=0, refs={}, b30r={}} end end --if not vars.ipv6hits then -- vars.ipv6hits=0 --end -- Yes, there is a typo in the HTTP spec :-). -- Definitely a better way to do this. referrer=os.getenv("HTTP_REFERER") or nil --referrer="http://google.com" --if (referrer=os.getenv("HTTP_REFERER") or false) then if (referrer) then if (referrer:match("://([^/]+)")) then referringhost=referrer:match("://([^/]+)"):sub(1,32) local cleanhost=wl_html_encode(referringhost) -- Someone is being bad. We could let them through, but this is just simpler. if (referringhost ~= cleanhost) then referringhost=nil end end end --end -- Really missing Heather <3. -- Your rank of referring hosts would be nice, eg: 4/50 for fourth most hits. -- Would be nice to have this a bit smaller. HTML5 anyone? 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

I'm quietly getting the counter started again on 2009-07-14. Have fun :-). Here is the source, if you are interested.
]] -- Helps with debugging in the Lua console <- Eh? if referringhost then write ([[Referrer: ]]..referrer..[[
Referring host: ]]..referringhost) for key,entry in pairs(vars.refs) do if (entry[1] == referringhost) then refhostkey=key break end end if refhostkey then vars.refs[refhostkey][2]=vars.refs[refhostkey][2] + 1 -- Redundancy here with the bottom 30 code. write ([[
Your referring 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 --- -- No need to sort if it's the first. if (refhostkey ~= 1) then table.sort(vars.refs, function(lhs, rhs) return lhs[2] > rhs[2] end) end else for key,entry in pairs(vars.b30r) do if (entry[1] == referringhost) 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 referring host's hit count: ]]..vars.b30r[refhostkey][2]) -- Crossing the border. 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 referrer!]] -- 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] = {referringhost,1} else vars.refs[20] = {referringhost,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 ([[

Referring 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 Icadyptes.

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


]] end write [[
]] -- "Save" the changes -- Thanks to lanthas for this bit -- Keeping it to how it looks weird. Some funny loss at times. 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