FluidMotion » NaibsPages » News » irssi notify popup via ssh

irssi notify popup via ssh

22 November 2009 15:32

Quite a few people run irssi within screen sessions on remote machines (and ssh into said machine to carry on with their irc session)

There have been a few solutions posted around (with irssi plugins) that will, via the libnotify package, provide a GUI popup but these are all to-do with irssi running locally.




Others have taken this concept and have enabled it to operate remotely




This is just a further enhancement of this to simplify it further and minimise additional dependencies.






This irssi => notify setup is split into a couple of parts

#1 serverside (where irssi is running

#2 clientside (where you ssh from to re-connect to ssh)



All that is needed is

1) ssh server

2) irssi

3) either bash with tcp support, nc or sock (to pipe the data back to the main client

If such requirements are met then all that is needed is to add this irssi script to:

~/.irssi/scripts (and possibly symlink to ~/.irssi/scripts/autorun)


## Put me in ~/.irssi/scripts, and then execute the following in irssi:
##       /load perl
##       /script load notify

use strict;
use Irssi;
use vars qw($VERSION %IRSSI);

$VERSION = "0.01a";
%IRSSI = (
authors => 'Luke Macken, Paul W. Frields, Naib',
contact => 'lewk@csh.rit.edu, stickster@gmail.com',
name => 'notify.pl',
description => 'Pipe highlighted messages over tcp to a waiting daemon for popup     notification',
license => 'GNU General Public License',
url => 'http://lewk.org/log/code/irssi-notify',

Irssi::settings_add_str("notify", "notify_port", '6666');
Irssi::settings_add_str("notify", "notify_ip", '');

my ($server, $summary, $message) = @_;

# Make the message entity-safe
$message =~ s/&/&/g; # That could have been done better.
$message =~ s/</&lt;/g;
$message =~ s/>/&gt;/g;
$message =~ s/'/&apos;/g;
$message =~ s/"/&quot;/g;
$message =~ s/`/&apos;/g;

$message = substr($message, 0, 50) if(length($message) > 50);
my $port =  Irssi::settings_get_str('notify_port');
my $ip =  Irssi::settings_get_str('notify_ip');
#system("echo \"$summary---$message\" | nc -n $ip $port &");
#system("echo \"$summary---$message\" | sock :$port 2>/dev/null &");
system("(echo '$summary---$message' > /dev/tcp/$ip/$port) 2>/dev/null &");
##issue found when connecting from a non-notify box

my ($dest, $text, $stripped) = @_;
my $server = $dest->{server};

return if (!$server || !($dest->{level} & MSGLEVEL_HILIGHT));
my $sender = $stripped;
$sender =~ s/^\<.([^\>]+)\>.+/\1/ ;
$stripped =~ s/^\<.[^\>]+\>.// ;
my $summary = $dest->{target} . ": " . $sender;
notify($server, $summary, $stripped);

my ($server, $msg, $nick, $address) = @_;

return if (!$server);
notify($server, "Private message from ".$nick, $msg);

Irssi::signal_add('print text', 'print_text_notify');
Irssi::signal_add('message private', 'message_private_notify');

This has been further improved over other implementations flying around. additional character substituions have been made (it is a amazing what people will put into their nickname) as well as providing 3 examples for transmitting the data across a network socket

1) via netcat

2) via sock command

3) via bash (prefered)

With this loaded server-side all that is needed is client-side setup



The clientSide setup is split into 3 parts and is dependant on a couple of things

#1 xinetd configuration

#2 ssh connection setting (to enable portForwarding)

#3 libnotify ( for notification popup script )


xinetd configuration

edit /etc/services and add a new entry

irssi       6666/tcp

Where the portnumber is to match that as in the irssi plugin (pick a port that isn't exposed to the WAN).

Now you can make an /etc/xinetd.d/irssi file to act as the port listener


service irssi
flags = REUSE
disable = no
socket_type = stream
wait = no
user = YOUR_USER
protocol = tcp
server = /home/bin/irssi_notify

Set "YOUR_USER" to the login name you runas and set the "server = ..."  to the location of the notify script (to come)


ssh configuration

To simplify connecting and enabling the needed portForwarding you can add an ~/.ssh/config entry

Host irssi_ssh
Hostname 111.222.333.444
User foo
RemoteForward localhost:6666 localhost:6666

Now instead of connecting like:  ssh foo@111.222.333.444 you can issue the command:  ssh irssi_ssh and it will connect and enable portForwarding.


notify script

With the networking side of things configured all that is needed is the notify bash-wrapper script (which is spawned via xinetd)


read line
export DISPLAY=":0"
[[ $(echo'$msg'|egrep -i "ping$|pong$") ]] && urgency="critical"

notify-send -u "$urgency" -i gtk-dialog-info -t 5000 "$nick" "$msg"


This will read in the data piped to it via xinetd, split up the nick and the message as well as change the priority of the popup if it is a ping/pong response




Xinetd entry link

irssi script link

client popup script link

Rating 5.0 (2 votes)