From 6069dcfdb022edbd4b862e70696f7d12667ac230 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Sat, 30 Dec 2023 10:35:11 -0500 Subject: [PATCH 1/3] added holes.pl, lists all open sockets, only meaningful if running in an application container of course --- scripts/holes.pl | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 scripts/holes.pl diff --git a/scripts/holes.pl b/scripts/holes.pl new file mode 100644 index 000000000..6f6799f1b --- /dev/null +++ b/scripts/holes.pl @@ -0,0 +1,53 @@ +use Irssi; +use strict; +use warnings; + +our $VERSION = "1.0.0"; +our %IRSSI = ( + authors => 'terminaldweller', + contact => 'https://terminaldweller.com', + name => 'holes', + description => 'gives a list of of the open sockets as an expando(this makes sense only if irssi is in a container)', + license => 'GPL3 or newer', + url => 'https://github.com/irssi/scripts.irssi.org', +); + +Irssi::settings_add_int('misc', 'holes_frequency', 30000); +Irssi::settings_add_str('misc', 'holes_separator', ''); +my $holes = ""; +my $timeout; +my $holes_cmd = << 'HOLES_CMD'; +lsof | grep socket | awk '{print $4}' | awk 'BEGIN{FS=":"}{print $2}' | tr -d [] | uniq +HOLES_CMD + +sub uniq { + my %seen; + grep !$seen{$_}++, @_; +} + +sub holes_sub { + my $result; + Irssi::timeout_remove($timeout); + my $output = `$holes_cmd`; + my $sep = Irssi::parse_special(Irssi::settings_get_str('holes_separator')); + my @lines = split /\n/, $output; + my @lines = uniq(@lines); + $holes = ''; + $result = @lines; + foreach my $line (@lines) { + if ($result == "") { + $result = $line + } + $result = $result.$sep.$line + } + # $result =~ s/^\s+//; + $holes= $result; + $timeout = Irssi::timeout_add_once(Irssi::settings_get_int('holes_frequency'), 'holes_sub' , undef); +} + +Irssi::expando_create('holes', sub { + return $holes; +}, {}); + +$timeout = Irssi::timeout_add(Irssi::settings_get_int('holes_frequency'), 'holes_sub' , undef); +holes_sub(); From 052f2b22c6a66b9f070f4034503888434e280878 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Wed, 31 Jan 2024 12:45:27 -0500 Subject: [PATCH 2/3] fixed the warnings. showing ports instead of socket fid --- scripts/holes.pl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/holes.pl b/scripts/holes.pl index 6f6799f1b..61d823cf9 100644 --- a/scripts/holes.pl +++ b/scripts/holes.pl @@ -2,12 +2,12 @@ use strict; use warnings; -our $VERSION = "1.0.0"; +our $VERSION = "1.0.1"; our %IRSSI = ( authors => 'terminaldweller', contact => 'https://terminaldweller.com', name => 'holes', - description => 'gives a list of of the open sockets as an expando(this makes sense only if irssi is in a container)', + description => 'gives a list of of the open sockets as an expando(this makes sense only if irssi is in an application container)', license => 'GPL3 or newer', url => 'https://github.com/irssi/scripts.irssi.org', ); @@ -17,7 +17,7 @@ my $holes = ""; my $timeout; my $holes_cmd = << 'HOLES_CMD'; -lsof | grep socket | awk '{print $4}' | awk 'BEGIN{FS=":"}{print $2}' | tr -d [] | uniq +netstat -ntap 2>/dev/null | awk '{print $4}' | awk 'BEGIN{FS=":"}{print $2}' | sed '/^$/d' HOLES_CMD sub uniq { @@ -31,16 +31,15 @@ sub holes_sub { my $output = `$holes_cmd`; my $sep = Irssi::parse_special(Irssi::settings_get_str('holes_separator')); my @lines = split /\n/, $output; - my @lines = uniq(@lines); + @lines = uniq(@lines); $holes = ''; $result = @lines; foreach my $line (@lines) { - if ($result == "") { + if ($result eq "") { $result = $line } $result = $result.$sep.$line } - # $result =~ s/^\s+//; $holes= $result; $timeout = Irssi::timeout_add_once(Irssi::settings_get_int('holes_frequency'), 'holes_sub' , undef); } From 0c8802b99ceef88142f90d5339aa201390d6e4c9 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Thu, 1 Feb 2024 19:56:47 -0500 Subject: [PATCH 3/3] Nei's right. My brain does not work --- scripts/holes.pl | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/holes.pl b/scripts/holes.pl index 61d823cf9..ca8857ac7 100644 --- a/scripts/holes.pl +++ b/scripts/holes.pl @@ -35,9 +35,6 @@ sub holes_sub { $holes = ''; $result = @lines; foreach my $line (@lines) { - if ($result eq "") { - $result = $line - } $result = $result.$sep.$line } $holes= $result;