#!/usr/bin/perl -w # # # This script is totally experimental and thus -- not supported! # # # USE AT YOUR OWN RISK # use strict; use vars qw($VERSION %IRSSI); $VERSION = "1.0"; %IRSSI = ( authors => 'Jakub Jankowski', contact => 'shasta@toxcorp.com', name => 'topiclogger', description => 'Logs topic changes. Written for #linuxnews@IRCNet', license => 'GNU GPLv2 or later', url => 'http://toxcorp.com/irc/irssi/', changed => 'Fri Dec 12 17:12:43 2003' ); use Irssi; use Irssi::Irc; use POSIX; my $scp = "/usr/bin/scp"; sub strip_html_codes { my ($str) = @_; $str =~ s/[\x01\x02\x03\x04\x05\x06\x07\x08]//g; $str =~ s/\&/\&/g; $str =~ s/\"/\"/g; $str =~ s/\/\>/g; return $str; } sub event_topic { my ($server, $data, $nick, $address) = @_; my ($channel, $topic) = split(/ :/, $data, 2); my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); local *F; my $tag = $server->{'tag'}; # log topic changes only for that channel my $desired_channel = Irssi::settings_get_str("topiclogger_channel"); # log topic changes only on that ircnet my $desired_tag = Irssi::settings_get_str("topiclogger_tag"); # log to this file my $desired_file = Irssi::settings_get_str("topiclogger_file"); my $tmpfile = $desired_file . ".tmp"; $year += 1900; $mon++; $sec = "0".$sec if ($sec < 10); $min = "0".$min if ($min < 10); $hour = "0".$hour if ($hour < 10); $mday = "0".$mday if ($mday < 10); $mon = "0".$mon if ($mon < 10); return unless (Irssi::settings_get_bool("topiclogger")); return unless (defined $desired_channel && lc($channel) eq lc($desired_channel)); return unless (defined $desired_tag && lc($tag) eq lc($desired_tag)); return unless (defined $desired_file && $desired_file ne ''); if (!defined open(F, ">$tmpfile")) { Irssi::print("Couldn't open $tmpfile for writing"); return; } print(F "Current topic: ". strip_html_codes($topic) ."
\n"); print(F "Set on: $mday.$mon.$year, $hour:$min:$sec by: ". strip_html_codes($nick) . "!" . strip_html_codes($address) . "
\n"); close(F); if (!rename($tmpfile, $desired_file)) { Irssi::print("Couldn't rename $tmpfile to $desired_file"); return; } my $pid = fork(); unless (defined $pid) { Irssi::print("Fork failed."); return; } elsif ($pid) { # parent Irssi::pidwait_add($pid); return; } else { # child my $remoteuser = Irssi::settings_get_str("topiclogger_remote_user"); my $remotehost = Irssi::settings_get_str("topiclogger_remote_host"); my $remotepath = Irssi::settings_get_str("topiclogger_remote_path"); POSIX::_exit(1) unless (defined $remoteuser && defined $remotehost && defined $remotepath); my @cmd = ($scp, '-q', '-o', 'BatchMode=yes', $desired_file, $remoteuser.'@'.$remotehost.':'.$remotepath); system(@cmd); POSIX::_exit(1); } } Irssi::settings_add_bool('misc', 'topiclogger', 1); Irssi::settings_add_str('misc', 'topiclogger_channel', "#test"); Irssi::settings_add_str('misc', 'topiclogger_tag', "ircnet"); Irssi::settings_add_str('misc', 'topiclogger_file', "ircnet-test-topics.html"); Irssi::settings_add_str('misc', 'topiclogger_remote_user', "username"); Irssi::settings_add_str('misc', 'topiclogger_remote_host', "127.0.0.1"); Irssi::settings_add_str('misc', 'topiclogger_remote_path', "/home/username/public_html/foo.html"); Irssi::signal_add('event topic', 'event_topic');