<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w

use IO::Socket;

my ($localport,$sslserver,$sslport,$ircserver,$ircport);

#MAIN SECTION

print STDERR "tunnel.pl           simple SSH tunnel\n";
init();
bindserver();
waitforconnect();

#END SECTION

sub init {
    if ( @ARGV &lt; 5 ) {
        die "Insufficient parameters\n";
    }
    ($localport,$sslserver,$sslport,$ircserver,$ircport) = @ARGV;
}    

sub bindserver {
    $server = IO::Socket::INET-&gt;new( Proto        =&gt; "tcp",
	    		             LocalPort    =&gt; $localport,
			             Listen	  =&gt; SOMAXCONN,
			             Reuse        =&gt; 1);
    die "Can not start server on $localport \n" unless $server;
    print STDERR "Server connected to $localport \n";
}			        

sub waitforconnect {
    print STDERR "waiting for connection on $localport \n";
    if (defined($client=$server-&gt;accept())) {
	print STDERR "Connection on $localport \n";
        connectssl();
	startconn();
    }
}

sub connectssl {
    $errflag=0;
    $handle = IO::Socket::INET-&gt;new( Proto	=&gt; "tcp",
                                     PeerAddr   =&gt; $sslserver,
				     PeerPort   =&gt; $sslport);
    $errflag=1 unless $handle;
    if ($errflag==1) {
        print STDERR "Error connecting SSL server $sslserver on port $sslport \n";
    } else {	
        print STDERR "Connected to SSL server $sslserver on port $sslport\n";
	print $handle "CONNECT $ircserver:$ircport HTTP/1.0 \r\n\r\n";
	$flag=0;
	while (defined($_=&lt;$handle&gt;) &amp;&amp; $flag==0) {
	    if (/AUTH/) {
	        $line=&lt;$client&gt;;
		print $handle $line;
		print STDERR "CLIENT: $line \n";
		print STDERR "Connected to IRCserver $ircserver on port $ircport \n";
		$flag=1;
	    }
	}    
    }	
}     				     

sub startconn {
    $kidpid=fork();
    if ($kidpid) {
	while (defined($line=&lt;$client&gt;)) {
	    print $handle $line;
	}
    }
    else {	    
	while (defined($line=&lt;$handle&gt;)) {
	    print $client $line;
	}
    }
}    				         </pre></body></html>