#--------------------------------------------------------------------- # kernel.org.tcl # Tcl script for IRC bot eggdrop # # On a public !kernel latest Linux info is requested from # www.kernel.org # # v0: 28-Sep-2003 # v1: 09-Oct-2003 # = fixed a bug with nonresponding server #--------------------------------------------------------------------- package require eggdrop 1.6.15 package require Tcl 8.0 bind PUB m !kernel pub:connectkernel bind TIME - * time:kernelsite #--------------------------------------------------------------------- # proc connectkernelsite connects to "www.kernel.org" # # variable kernelinfo is a list containing the following elements: # (IDX) element 0: idx of outgoing connection # (TIME) element 1: time the first request was made # (CHAN) element 2: channels a request was made # (INFO) element 3-: information submitted by the kernel server #--------------------------------------------------------------------- proc pub:connectkernel { nick uhost hand chan text } { global kernelinfo # finger or http (1/0)? set usefinger 0 # only use lowercase channel names set chan [string tolower $chan] # If the variable "kernelinfo" exists a request is pending. if { [info exists kernelinfo] } { putlog "KERNEL: a request is pending!" set channels [lindex $kernelinfo 2] if { [lsearch $channels $chan] == -1 } { lappend channels $chan set kernelinfo [lreplace $kernelinfo 2 2 $channels] } return 1 } # Use finger or use HTTP if { $usefinger == 1 } { set host finger.kernel.org set port 79 } else { set host www.kernel.org set port 80 } # connect to host and catch any errors (DNS failure) if { [catch { set idx [connect $host $port ] } errmsg ] } { set line "No connection to $host ($errmsg)." puthelp "PRIVMSG $chan :(www.kernel.org) $line" return 1 } # in case of http submit url if { $usefinger != 1 } { set httpurl {http://www.kernel.org/kdist/finger_banner} putdcc $idx "GET $httpurl HTTP/0.9" putdcc $idx "\n" } # a new request: timestamp, add channel, make outgoing connection lappend kernelinfo $idx lappend kernelinfo [unixtime] lappend kernelinfo $chan # hand over control to the logging procedure control $idx pub:logkernelinfo return 1 } #--------------------------------------------------------------------- # proc pub:logkernelinfo logs all incoming information #--------------------------------------------------------------------- proc pub:logkernelinfo { idx text } { global kernelinfo # check if a request is pending and if not: kill the connection if { ![info exists kernelinfo] } { putlog "KERNEL: no request pending: terminating." killdcc $idx return 1 } # If the server closed the connection report the information if { $text == "" } { pub:reportkernelinfo return 1 } # HTTP response is ok or not ok? # expected: HTTP/1.1 200 OK if { [scan $text "HTTP/%s %s" version numeric] == 2 } { if { $numeric != 200 } { putlog "KERNEL: http problem (URL changed??)" killdcc $idx pub:reportkernelinfo return 1 } } # paranoid... too many lines received? if { [llength $kernelinfo] > 20 } { killdcc $idx pub:reportkernelinfo return 1 } # Add the HTTP Date header if { [string match "Date: *" $text] } { lappend kernelinfo $text } # Add the HTTP Last-Modified header if { [string match "Last-Modified: *" $text] } { lappend kernelinfo $text } # Add the latest information if { [string match "The latest *" $text] } { lappend kernelinfo $text } return 0 } #--------------------------------------------------------------------- # proc pub:reportkernelinfo logs all incoming information #--------------------------------------------------------------------- proc pub:reportkernelinfo { } { global kernelinfo # paranoid... if { ![info exists kernelinfo] } { return 0 } if { [llength $kernelinfo] < 3 } { unset kernelinfo return 0 } # only timestamp and channels available? if { [llength $kernelinfo] == 3 } { lappend kernelinfo "NO information received!" } # report information on the channels set channels [lindex $kernelinfo 2] set reportinfo [lrange $kernelinfo 3 end] foreach channel $channels { if { ![validchan $channel] } { continue } foreach line $reportinfo { puthelp "PRIVMSG $channel :(www.kernel.org) $line" } } unset kernelinfo } #--------------------------------------------------------------------- # Every minute check status of the requested information #--------------------------------------------------------------------- proc time:kernelsite { args } { global kernelinfo if { ![info exists kernelinfo] } { return 0 } set currenttime [unixtime] set timestamp 0 scan [lindex $kernelinfo 1] %d timestamp if { [expr $currenttime - $timestamp] > 20 } { putlog "KERNEL: no response from server, purging connection." set idx [lindex $kernelinfo 0] killdcc $idx pub:reportkernelinfo } } putlog "Loaded (version 1): Latest Linux info from kernel.org." #--------------------------------------------------------------------- # EXTRA NOTE # # The script filters out the following lines from a HTTP session: # # Date: * # Last-Modified: * # The latest * # # If www.kernel.org decides to change the format (The latest *), this # script should be updated accordingly. # # A typical HTTP session looks like: # # HTTP/1.1 200 OK # Date: Sun, 28 Sep 2003 12:40:16 GMT # Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) # Last-Modified: Sun, 28 Sep 2003 01:56:02 GMT # Accept-Ranges: bytes # Content-Length: 635 # Connection: close # Content-Type: text/plain # The latest stable version of the Linux kernel is: 2.4.22 # The latest prepatch for the stable Linux kernel tree is: 2.4.23-pre5 # The latest snapshot for the stable Linux kernel tree is: 2.4.22-bk25 # The latest beta version of the Linux kernel is: 2.6.0-test6 # The latest 2.2 version of the Linux kernel is: 2.2.25 # The latest 2.0 version of the Linux kernel is: 2.0.39 # The latest prepatch for the 2.0 Linux kernel tree is: 2.0.40-rc6 # The latest -ac patch to the stable Linux kernels is: 2.4.22-ac4 # The latest -ac patch to the beta Linux kernels is: 2.6.0-test1-ac3 # #--------------------------------------------------------------------- # Idea found in Tcl script "kernel.tcl". Original header: # # Script made by CyberBrown # # This simple script fetches infos about the last kernel # with the command "finger @www.kernel.org" and displays # them on the channel. # # A thank to Bakunin because he helped me solving a # little problem. # # If you want you can find me on irc.jnet.it # I hope you'll enjoy this script! ;-) #---------------------------------------------------------------------