3 # console <host>/<machine> -- interactive client interface
5 # The main interactive client interace to conmux. Allows direct
6 # interaction with the payload, as well as allowing break out
7 # to the conmux menu to envoke defined commands; for example
10 # (C) Copyright IBM Corp. 2004, 2005, 2006
11 # Author: Andy Whitcroft <andyw@uk.ibm.com>
13 # The Console Multiplexor is released under the GNU Public License V2
20 use POSIX
qw(errno_h BUFSIZ);
22 use Getopt
::Long
qw(:config no_auto_abbrev);
24 my $CONMUX = $FindBin::Bin
;
25 my $CONMUX = $ENV{'CONMUX_ROOT'} if ($ENV{'CONMUX_ROOT'});
27 # Find our internal libraries.
28 use lib
$FindBin::Bin
;
29 use lib
"$FindBin::Bin/../lib/";
30 use lib
"$FindBin::Bin/lib/";
33 # Basic terminal handling.
35 $termSettings = `stty -g`;
36 system "stty raw -echo opost onlret";
39 system "stty $termSettings";
48 's|status' => \
$status,
51 warn "Usage: $P <service>\n";
52 warn " $P <registry>/<service>\n";
53 warn " $P <host>:<port>\n";
54 warn " $P --status <service>\n";
55 die " $P --list [<registry>]\n";
62 $id = 'user:' . $ENV{'LOGNAME'};
66 # MODE: registry list.
70 print Conmux
::Registry
::list
('-');
72 } elsif ($#ARGV == 0) {
73 print Conmux
::Registry
::list
($ARGV[0]);
82 # COMMAND: payload status command
85 usage
() if ($#ARGV != 0);
89 $sock = Conmux
::connect($ARGV[0]);
92 print "unavailable\n";
95 my %r = Conmux
::sendCmd
($sock, 'CONNECT', { 'id' => $id,
96 'to' => 'console', 'hide' => 1 });
97 if ($r{'status'} ne 'OK') {
98 print "unavailable\n";
100 } elsif ($r{'state'}) {
101 print "$r{'state'}\n";
111 # COMMAND: general payload connect.
117 # Connect to the host/port specified on the command line,
119 my $sock = Conmux
::connect($ARGV[0]);
121 my %r = Conmux
::sendCmd
($sock, 'CONNECT', { 'id' => $id, 'to' => 'console' });
122 die "$P: $ARGV[0]: connect failed - $r{'status'}\n" if ($r{'status'} ne 'OK');
124 print "Connected to $r{'title'} (~\$quit to exit)\n";
125 #display message of the day passed by the server e.g. who is already connected
128 my $rin = $win = $ein = '';
129 vec($rin, fileno(STDIN
), 1) = 1;
130 vec($rin, fileno($sock), 1) = 1;
131 my $ein = $rin | $win;
133 # We want to buffer output to the terminal. This prevents the program
134 # from blocking if the user hits CTRL-S for example.
139 # Loop waiting for input from the user, or from the server.
141 $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
143 if ($! == EINTR
|| $! == EAGAIN
) {
146 die "$P: select failed - $!\n";
149 if (vec($rout, fileno(STDIN
), 1)) {
150 $len = sysread(STDIN
, $data, 4096);
153 if ($! == EINTR
|| $! == EAGAIN
) {
156 die "$P: STDIN: read failed - $!\n";
158 print STDERR
"Connection Closed (client)\n";
163 if (vec($rout, fileno($sock), 1)) {
164 $len = sysread($sock, $data, 4096);
167 if ($! == EINTR
|| $! == EAGAIN
) {
170 die "$P: server: read failed - $!\n";
172 print STDERR
"Connection Closed (server)\n";