html/kernel.pl


   1 # Fetches the version(s) of the latest Linux kernel(s).
   2 
   3 # /kernel
   4 
   5 use strict;
   6 use Irssi;
   7 use IO::Socket;
   8 
   9 use vars qw($VERSION %IRSSI);
  10 
  11 $VERSION = '0.9';
  12 %IRSSI = (
  13     authors     => 'Johan "Ion" Kiviniemi',
  14     contact     => 'ion at hassers.org',
  15     name        => 'Kernel',
  16     description => 'Fetches the version(s) of the latest Linux kernel(s).',
  17     license     => 'Public Domain',
  18     url         => 'http://ion.amigafin.org/irssi/',
  19     changed     => 'Tue Mar 12 22:20 EET 2002',
  20 );
  21 
  22 sub finger($$) {
  23     # Yes, Net::Finger is already done and i'm reinventing the wheel.
  24     my ($user, $host) = @_;
  25     my $buffer;
  26     if (my $socket = IO::Socket::INET->new(
  27             PeerHost => $host,
  28             PeerPort => 'finger(79)',
  29             Proto    => 'tcp',
  30         ))
  31     {
  32         if (syswrite $socket, "$user\n") {
  33             unless (sysread $socket, $buffer, 1024) {
  34                 # Should i use $! here?
  35                 Irssi::print(
  36                     "Unable to read from the socket: $!",
  37                     Irssi::MSGLEVEL_CLIENTERROR
  38                 );
  39             }
  40         } else {
  41             # ..and here?
  42             Irssi::print(
  43                 "Unable to write to the socket: $!",
  44                 Irssi::MSGLEVEL_CLIENTERROR
  45             );
  46         }
  47     } else {
  48         Irssi::print("Connection to $host failed: $!",
  49             Irssi::MSGLEVEL_CLIENTERROR);
  50     }
  51     return $buffer;
  52 }
  53 
  54 sub get_version {
  55     my @version;
  56     if (my $finger = finger("", "finger.kernel.org")) {
  57         # The magic of the regexps :)
  58         @version = $finger =~ /:\s*(\S+)\s*$/gm;
  59         # Modify this to do whatever you want.
  60         Irssi::print("@version");
  61     }
  62 }
  63 
  64 Irssi::command_bind('kernel_version', 'get_version');