#!/usr/local/bin/perl
# This file is hereby placed in the public domain. There is no warranty.
# Written 2012 by Moritz Wilhelmy, mw wzff de
# This very ugly perl script transforms an irssi config containing irssiproxy
# options into a copypastable mess of /network add commands. (Exporting to irssi
# config would take longer and be less flexible)
# It is intended to simplify the process of configuring a client irssi for the
# proxy "server".
# In case there are any questions, please send me an email.

use strict;
use warnings;

use Config::Irssi::Parser;

my $conffile = $ENV{HOME} . "/.irssi/config";
chop (my $host = `hostname`);
my $auto = "-auto"; # set to "" to disable
my $prefix = "p"; # "p"roxied

my $p = new Config::Irssi::Parser;
open(my $fh, '<', $conffile);
my $conf = $p->parse($fh);
my %netports = map { split /=/,$_,2 } split/ /, $conf->{settings}->{proxy}->{irssiproxy_ports};
my $pass = $conf->{settings}->{proxy}->{irssiproxy_password};

foreach (keys %netports) {
	print "/network add $prefix$_\n";
	print "/server add $auto -network $prefix$_ $host $netports{$_} $pass\n" ;
}

# $Id: irssiproxy-export.pl,v 1.1 2012/06/29 20:53:10 mw Exp mw $
