2016-02-14 04:18:33 +00:00
|
|
|
#!/bin/rc
|
|
|
|
rfork e
|
|
|
|
|
|
|
|
argv0=$0
|
2018-01-07 01:44:53 +00:00
|
|
|
aanto=86400 #one day
|
2016-02-14 04:18:33 +00:00
|
|
|
fn usage {
|
2018-01-07 01:44:53 +00:00
|
|
|
echo 'usage:' $argv0 '[-u user] [-k keypattern] [-p] [-t timeout] host remotescript localcommand arg ...' >[1=2]
|
2016-02-14 04:18:33 +00:00
|
|
|
exit 'usage'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pvar {
|
|
|
|
while(! ~ $#* 0){
|
2018-11-13 10:03:37 +00:00
|
|
|
~ $#$1 0 && echo $1'=()' ||
|
|
|
|
path=/dev/null builtin whatis $1
|
2016-02-14 04:18:33 +00:00
|
|
|
shift
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filter=()
|
|
|
|
keyspec=()
|
|
|
|
while(~ $1 -*){
|
|
|
|
switch($1){
|
|
|
|
case -p; filter=aan
|
|
|
|
case *
|
|
|
|
~ $#* 1 && usage
|
|
|
|
switch($1){
|
|
|
|
case -k; keyspec=($keyspec $2)
|
|
|
|
case -u; keyspec=($keyspec `{user=$2 pvar user})
|
2018-01-07 01:44:53 +00:00
|
|
|
case -t; aanto=$2
|
2016-02-14 04:18:33 +00:00
|
|
|
case *; usage
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
}
|
|
|
|
|
|
|
|
~ $#* 0 1 2 && usage
|
|
|
|
|
|
|
|
host=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
fn sendscript {
|
|
|
|
echo -n $host >/proc/$pid/args
|
|
|
|
cat $1 >/env/v; wc -c </env/v; cat /env/v; rm /env/v
|
|
|
|
shift
|
|
|
|
$*
|
|
|
|
}
|
|
|
|
|
|
|
|
if(~ $filter aan){
|
|
|
|
fn aanserver {
|
|
|
|
~ $#netdir 1 || netdir=/net/tcp/clone
|
|
|
|
netdir=`{basename -d $netdir} || exit
|
|
|
|
<>$netdir/clone {
|
|
|
|
netdir=$netdir/`{read} || exit
|
|
|
|
>[3] $netdir/ctl {
|
|
|
|
echo -n 'announce *!0' >[1=3]
|
|
|
|
echo `{cat $netdir/local} || exit
|
|
|
|
bind '#|' /mnt/aan || exit
|
2018-01-07 01:44:53 +00:00
|
|
|
exec aan -m $aanto $netdir <>/mnt/aan/data1 >[1=0] >[2]/dev/null &
|
2016-02-14 04:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
<>/mnt/aan/data >[1=0] >[2]/dev/null {
|
|
|
|
rfork n
|
|
|
|
fn server {
|
|
|
|
echo -n aanserver $netdir >/proc/$pid/args
|
2018-01-07 01:44:53 +00:00
|
|
|
rm -f /env/^('fn#server' 'fn#aanserver' 'aanto')
|
2016-02-14 04:18:33 +00:00
|
|
|
. <{n=`{read} && ! ~ $#n 0 && read -c $n} >[2=1]
|
|
|
|
}
|
|
|
|
exec tlssrv -A /bin/rc -c server
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn aanclient {
|
|
|
|
host=`{echo $host | sed 's/(.*)!([^!]+)$/\1/'}^!^`{read | sed 's/(.*)!([^!]+)$/\2/'} || exit
|
2018-01-07 01:44:53 +00:00
|
|
|
tlsclient -a -o <>{rfork s; aan -m $aanto -c $host >[1=0]} /bin/rc -c 'sendscript $*' $*
|
2016-02-14 04:18:33 +00:00
|
|
|
}
|
2018-01-07 01:44:53 +00:00
|
|
|
exec $argv0 -k $"keyspec $host <{builtin whatis aanserver; pvar aanto; echo aanserver} aanclient $*
|
2016-02-14 04:18:33 +00:00
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
switch($host){
|
|
|
|
case *!*!*;
|
|
|
|
case *!*; host=$host!rcpu
|
|
|
|
case *; host=net!$host!rcpu
|
|
|
|
}
|
|
|
|
|
|
|
|
exec tlsclient -ak $"keyspec $host /bin/rc -c 'sendscript $*' $*
|