shithub: riscv

Download patch

ref: 31e1c15d441e38a740b8f209f86b8b2d0fc49d79
parent: dc69af5010c1c4860b24d91c7b702ffc199bdf66
author: mischief <mischief@offblast.org>
date: Sat Dec 27 18:38:21 EST 2014

ircrc: use aux/trampoline or tlsclient for connections, add -T flag for tls

previously ircrc dialed through /net itself and resolved ips on its own. this prevented the use of an ip address, and also prevented use of ipv6. now you can use an ip, or a dns name that resolves to ipv6. the -T flag is also added to use tlsclient for encrypted connections.

--- a/rc/bin/ircrc
+++ b/rc/bin/ircrc
@@ -10,6 +10,7 @@
 netdir=()
 nick=$user
 pass=()
+tls=0
 
 fn sighup {
 	exit 'hang up'
@@ -40,11 +41,8 @@
 	}
 	if(~ $target *,*)
 		target = `{echo $target | awk -F',' '{print $NF}'}
-	while () {
-		cmd=`{read}
+	while (cmd=`{read}) {
 		s=$status
-		if(! ~ `{cat $netdir/status} *Established*)
-			exit
 		if(~ $s *eof) {
 			echo  QUIT : Leaving... > $netdir/data
 			exit
@@ -165,12 +163,7 @@
 }
 
 fn pretty {
-	while (~ `{cat $netdir/status} *Established*) {
-		if(! line=`{read}) {
-			echo Connection lost
-			date
-			exit
-		}
+	while (line=`{read}) {
 		switch ($line) {
 		case *PRIVMSG*
 			line = `{echo -n $line | privmsg}
@@ -190,10 +183,6 @@
 	exit
 }
 
-fn getip {
-	echo $1 ip | ndb/dnsquery | sed 1q | awk '{print $NF}'
-}
-
 fn title {
 	if (! ~ $#winid 0) {
 		if (test -f /mnt/acme/$winid/ctl)
@@ -217,8 +206,10 @@
 	case -t
 		target=$2
 		shift
+	case -T
+		tls=1
 	case -*
-		echo 'usage: ircrc  [-p port] [-r realname] [-t target] [-n nick]  [server]' >[1=2]
+		echo 'usage: ircrc  [-p port] [-r realname] [-t target] [-n nick] [-T] [server]' >[1=2]
 		exit 'usage'	
 	}
 	shift
@@ -235,12 +226,6 @@
 	}
 }
 
-ip=`{getip $server}
-if (~ $#ip 0) {
-	echo cant translate $server
-	exit 'unknown host'
-}
-
 title
 userpass=`{auth/userpasswd 'server='^$server^' service=irc user='^$nick >[2]/dev/null}
 if(~ $#userpass 2 && ~ $nick $user) {
@@ -248,10 +233,16 @@
 	pass=$userpass(2)
 }
 
-<[4] $clonefile {
-	netdir=`{basename -d $clonefile} ^ / ^  `{cat /fd/4}
-	echo connect $ip!$port >$netdir/ctl || exit 'cannot connect'
-	echo connected to tcp!$ip!$port on $netdir
-	cat $netdir/data | tr -d '\x2\xd\x1f' | pretty & 
-	work
+p='/n/ircrc'
+bind '#|' $p
+echo connecting to tcp!$server!$port...
+if(~ $tls 0){
+	aux/trampoline tcp!$server!$port <>$p/data1 >[1=0] &
 }
+if not {
+	tlsclient tcp!$server!$port <>$p/data1 >[1=0] &
+}
+netdir=$p
+cat $netdir/data | tr -d '\x2\xd\x1f' | pretty &
+work
+
--- a/sys/man/1/ircrc
+++ b/sys/man/1/ircrc
@@ -20,6 +20,8 @@
 .I nick
 ]
 [
+.B -T
+] [
 .I server
 ]
 .SH DESCRIPTION
@@ -60,6 +62,11 @@
 .BI -n " nick
 Change the default nickname
 .RB ( $user ).
+.TP
+.BI -T
+.br
+Use tls through
+.IR tlsclient(8) .
 .SS Commands
 .I Ircrc
 commands begin with a slash.