############################
### Lusers.tcl           ###
### Version 1.2          ###
### By Wcc               ###
### wcc@techmonkeys.org  ###
### http://dawg.dynu.com ###
### EFnet #|DAWG|Tcl     ###
############################

############################################################################
### Copyright © 2000 - 2001 |DAWG| Scripting Group. All rights reserved. ###
############################################################################

####################################################################################
## This script writes the output of /LUSERS to an HTML web page every X seconds.  ##
####################################################################################

##########################################################
## Just load the script, edit the settings, and rehash. ##
##########################################################

################################################
# Set the filename of the stats web page here. #
################################################

set lusers_setting(page) "./web/lusers.html"

######################################################################
# Set the path to the graphic to place at the top of the page here.  #
# Set to "" to disable.	Remember this is not the path to the actual  #
# file, but the relative path to the web page. E.x: "dawglogo.gif"   #
# would use the file called "dawglogo.gif from the directory the web #
# page is in.                                                        #
######################################################################

set lusers_setting(html_TitleImg) ""

############################################################
# Set the text that appears in the browser title bar here. #
############################################################

set lusers_setting(html_title) "Network Users"

############################
# Set the page title here. #
############################

set lusers_setting(html_heading) "Network Users"

######################################
# Set the page title font size here. #
######################################

set lusers_setting(html_heading_font_size) "6"

########################################
# Set the table header font size here. #
########################################

set lusers_setting(html_tableheader_font_size) "5"

######################################
# Set the table cell font size here. #
######################################

set lusers_setting(html_tablecell_font_size) "4"

#####################################
# Set the table header colors here. #
#####################################

set lusers_setting(color_TableHeader-1) "#8080c0"
set lusers_setting(color_TableHeader-2) "#8080e0"

###################################
# Set the table cell colors here. #
###################################

set lusers_setting(color_TableCell-1) "#c0c0c0"
set lusers_setting(color_TableCell-2) "#e0e0e0"

##################################
# Set the background color here. #
##################################

set lusers_setting(color_Background) "#FFFFFF"

############################
# Set the text color here. #
############################

set lusers_setting(color_Text) "#000000"

##################################
# Set the title text color here. #
##################################

set lusers_setting(color_TitleText) "#000000"

#################################
# Set the link text color here. #
#################################

set lusers_setting(color_Link) "#0000FF"

#########################################
# Set the table header font color here. #
#########################################

set lusers_setting(color_HeaderFont) "#000000"

#######################################
# Set the table cell font color here. #
#######################################

set lusers_setting(color_CellFont) "#000000"

#############################################
# How often should the web page be updated? #
#############################################

set lusers_setting(timer_update) "170"

####################
# Code begins here #
####################

if {![string match 1.6.* $version]} { putlog "\002LUSERS:\002 \002WARNING:\002 This script is intended to run on eggdrop 1.6.x or later." }
if {[info tclversion] < 8.2} { putlog "\002LUSERS:\002 \002WARNING:\002 This script is intended to run on Tcl Version 8.2 or later." }

foreach rb {251 252 254 255 265 266} { bind raw - $rb lusers_write_lusers }

if {![string match "* lusers_update *" [utimers]]} { utimer $lusers_setting(timer_update) lusers_update }
proc lusers_write_lusers {from keyword text} {
	global lusers_setting lusers_lusers_data lusers_localserver
	set lusers_localserver $from
	if {[regexp 252|254 $keyword]} { regsub -all -- ":" $text "" text }
	set lusers_lusers_data($keyword) [string trimleft [join [lrange [split $text] 1 end]] :]
	if {$keyword == 266} { lusers_do_final }
}
proc lusers_do_final {} {
	global lusers_setting server lusers_localserver lusers_lusers_data
	set stats [open $lusers_setting(page) w]	
	puts $stats "<html>"
	puts $stats "<head>"
	puts $stats "<title>$lusers_setting(html_title)</title>"
	puts $stats "<META NAME=\"description\" CONTENT=\"Network Users\">"
	puts $stats "<META NAME=\"keywords\" CONTENT=\"eggdrop, bot, stats, lusers, ircd, link\">"
	puts $stats "</head>"
	puts $stats "<body bgcolor=\"$lusers_setting(color_Background)\" link=\"$lusers_setting(color_Link)\" alink=\"$lusers_setting(color_Link)\" vlink=\"$lusers_setting(color_Link)\">"
	if {$lusers_setting(html_TitleImg) != ""} { puts $stats "<center><img src=\"$lusers_setting(html_TitleImg)\"></img></center>" }
	puts $stats "<center><font size=\"$lusers_setting(html_heading_font_size)\" color=\"$lusers_setting(color_TitleText)\">$lusers_setting(html_heading)</font></center>"
	puts $stats "<br>"
	puts $stats "<center><font size=\"$lusers_setting(html_tablecell_font_size)\" color=\"$lusers_setting(color_Text)\">Connected to $lusers_localserver on port [lindex [split $server :] 1].</font></center>"
	puts $stats "<br>"
	puts $stats "<br>"
	puts $stats "<table align=\"center\">"
	puts $stats "<tr>"
	puts $stats "<td align=\"left\" bgcolor=\"$lusers_setting(color_TableHeader-1)\"><font size=\"$lusers_setting(html_tableheader_font_size)\" color=\"$lusers_setting(color_HeaderFont)\"><center>Network Users</center></font></td>"
	puts $stats "</tr>"
	puts $stats "<tr>"
	puts $stats "<td align=\"left\" bgcolor=\"$lusers_setting(color_TableCell-1)\">"
	puts $stats "<pre>"
	puts $stats ""
	foreach i [array names lusers_lusers_data] { puts $stats "   $lusers_lusers_data($i)   " }
	foreach tag {</pre> </td> </tr> </table> <br> <br>} { puts $stats $tag }
	puts $stats "<center><font color=\"$lusers_setting(color_Text)\">Last Updated: [clock format [clock seconds] -format %D] [clock format [clock seconds] -format "%I:%M %p"]</font></center>"
	puts $stats "</body>"
	puts $stats "</html>"
	close $stats
}
proc lusers_update {} {
	global lusers_setting
	putserv "LUSERS"
	if {![string match "* lusers_update *" [utimers]]} { utimer $lusers_setting(timer_update) lusers_update }
}
putlog "\002LUSERS:\002 Lusers.tcl Version 1.2 by Wcc is loaded."