#!/usr/local/bin/perl # index.cgi # Display the telnet applet BEGIN { push(@INC, ".."); }; use WebminCore; use Socket; &init_config(); $theme_no_table = 1 if ($config{'sizemode'} == 1); &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1); if ($ENV{'HTTPS'} eq 'ON' && !$config{'mode'}) { print "
",&text( $config{'mode'} ? 'index_esocket2' : 'index_esocket', $addr, $port),"
\n"; } else { print "
",&text('index_elookup', $addr),"
\n"; } } else { # If the host is not local, start up a proxy sub-process if ($config{'proxy'}) { # Allocate a free port &get_miniserv_config(\%miniserv); $proxyport = $miniserv{'port'} + 1; $err = &allocate_socket(MAIN, \$proxyport); &error($err) if ($err); # Connect to the destination &open_socket($addr, $port, CONN); # Forward traffic in sub-process if (!($pid = fork())) { # Accept the connection (for up to 60 secs) $rmask = undef; vec($rmask, fileno(MAIN), 1) = 1; $sel = select($rmask, undef, undef, 60); $sel >= 0 || die "no connection after 60 seconds"; $acptaddr = accept(SOCK, MAIN); $acptaddr || die "accept failed?!"; close(MAIN); untie(*STDIN); untie(*STDOUT); #untie(*STDERR); close(STDIN); close(STDOUT); #close(STDERR); # Forward traffic in and out select(CONN); $| = 1; select(SOCK); $| = 1; while(1) { $rmask = undef; vec($rmask, fileno(SOCK), 1) = 1; vec($rmask, fileno(CONN), 1) = 1; $sel = select($rmask, undef, undef, undef); if (vec($rmask, fileno(SOCK), 1)) { # Read from applet, send to server $got = sysread(SOCK, $buf, 1024); $got > 0 || last; syswrite(CONN, $buf, $got); } if (vec($rmask, fileno(CONN), 1)) { # Read from applet, send to server $got = sysread(CONN, $buf, 1024); $got > 0 || last; syswrite(SOCK, $buf, $got); } } print STDERR "exited read loop\n"; exit(0); } $SIG{'CHLD'} = \&child_reaper; close(CONN); close(MAIN); # Force applet to connect to proxy $config{'port'} = $proxyport; delete($config{'host'}); } # Output the applet print "