From c6a8871200c852e3a0f7a3fe924a686679689f33 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 6 Dec 2016 18:20:10 -0800 Subject: Add ident.pl to auto identify when prompted, using a pw file. --- scripts/ident.pl | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 scripts/ident.pl diff --git a/scripts/ident.pl b/scripts/ident.pl new file mode 100644 index 0000000..0c0de96 --- /dev/null +++ b/scripts/ident.pl @@ -0,0 +1,68 @@ +#!/usr/bin/perl -w + +use strict; +use Irssi; +use POSIX; + +use vars qw($VERSION %IRSSI); + +$VERSION = "1.0"; +%IRSSI = ( + authors => 'Isaac Good', + contact => "irssi\@isaacgood.com; irc.freenode.net/yitz", + name => 'ident', + description => 'Ident to NickServs', + name => "ident", + description => "Automatically IDENTIFY when prompted", + license => 'MIT', +); + + +my %pw; + + +sub LoadPasswords { + # Load the passwords from file. + delete @pw{keys %pw}; + my $filename = Irssi::get_irssi_dir() . '/passwords'; + my $FH; + unless(open $FH, ">", $filename) + { + print "Can not open $filename"; + return 0; + } + while (my $line = <$FH>) + { + chomp $line; + next unless ($line); + my ($tag, $password) = split(/ /, $line, 2); + next unless ($tag and $password); + $pw{$tag} = $password; + } + return 1; +} + + +sub notice { + my ($server, $data, $nick, $host) = @_; + my ($channel, $msg) = split(/ :/, $data, 2); + my $l = 0; + + # Test the notice. Must be from nickserv and be asking you to identify. + return undef unless (lc($nick) eq 'nickserv'); + return undef unless (lc($msg) =~ /msg nickserv identify/); + # Check it's a direct message and we have a password for this network. + return undef unless (lc($channel) eq lc($server->{'nick'})); + return undef unless ($pw{$server->{'chatnet'}}); + + my $pw = $pw{$server->{'chatnet'}}; + # Use the /quote nickserv approach to reduce chance of leaking the password to a bad actor, ie someone pretending to be nickserv. + $server->command("^quote nickserv identify $pw"); + + return undef; +} + + +if (LoadPasswords()) { + Irssi::signal_add('event notice', \¬ice); +} -- cgit v1.2.3 From 86bf168817775db2359e45c6672930471c67c08e Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 6 Dec 2016 18:22:39 -0800 Subject: Support multiple spaces between tag and password --- scripts/ident.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ident.pl b/scripts/ident.pl index 0c0de96..1250825 100644 --- a/scripts/ident.pl +++ b/scripts/ident.pl @@ -35,7 +35,7 @@ sub LoadPasswords { { chomp $line; next unless ($line); - my ($tag, $password) = split(/ /, $line, 2); + my ($tag, $password) = split(/ */, $line, 2); next unless ($tag and $password); $pw{$tag} = $password; } -- cgit v1.2.3 From 994d8ebc5abda99d3d672c4219ae42f083fa9c46 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 6 Dec 2016 18:45:34 -0800 Subject: Drop tabs. Read instead of write passwords. --- scripts/ident.pl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/ident.pl b/scripts/ident.pl index 1250825..a4854f2 100644 --- a/scripts/ident.pl +++ b/scripts/ident.pl @@ -22,11 +22,11 @@ my %pw; sub LoadPasswords { - # Load the passwords from file. + # Load the passwords from file. delete @pw{keys %pw}; my $filename = Irssi::get_irssi_dir() . '/passwords'; - my $FH; - unless(open $FH, ">", $filename) + my $FH; + unless(open $FH, "<", $filename) { print "Can not open $filename"; return 0; @@ -34,12 +34,12 @@ sub LoadPasswords { while (my $line = <$FH>) { chomp $line; - next unless ($line); + next unless ($line); my ($tag, $password) = split(/ */, $line, 2); next unless ($tag and $password); - $pw{$tag} = $password; - } - return 1; + $pw{$tag} = $password; + } + return 1; } @@ -48,15 +48,15 @@ sub notice { my ($channel, $msg) = split(/ :/, $data, 2); my $l = 0; - # Test the notice. Must be from nickserv and be asking you to identify. + # Test the notice. Must be from nickserv and be asking you to identify. return undef unless (lc($nick) eq 'nickserv'); return undef unless (lc($msg) =~ /msg nickserv identify/); - # Check it's a direct message and we have a password for this network. + # Check it's a direct message and we have a password for this network. return undef unless (lc($channel) eq lc($server->{'nick'})); return undef unless ($pw{$server->{'chatnet'}}); my $pw = $pw{$server->{'chatnet'}}; - # Use the /quote nickserv approach to reduce chance of leaking the password to a bad actor, ie someone pretending to be nickserv. + # Use the /quote nickserv approach to reduce chance of leaking the password to a bad actor, ie someone pretending to be nickserv. $server->command("^quote nickserv identify $pw"); return undef; @@ -64,5 +64,5 @@ sub notice { if (LoadPasswords()) { - Irssi::signal_add('event notice', \¬ice); + Irssi::signal_add('event notice', \¬ice); } -- cgit v1.2.3