sub TELNET {
# Display the telnet applet

    use Socket;
    my $html = &Header($Myname,'<a href="'.$nPulseurl.'?a=detail&site='.$in{'host'}.'">Return to Detail View</a>',0);
    $html .= '<center><font color="#ff0000">Warning! This telnet session is <b>not fully</b> encrypted (SSL and SSH are not both enabled).</font></center><br>' if (($ENV{'HTTPS'} eq 'ON') and !$in{'mode'}) or ($in{'mode'} and ($ENV{'HTTPS'} ne 'ON'));
    $html .= '<center><span style="'.$Fss.'">Click in the window to activate.<br>';
    my $addr = $in{'host'} ? &to_ipaddress($in{'host'}) : &to_ipaddress(&get_system_hostname());
    socket(STEST, PF_INET, SOCK_STREAM, getprotobyname("tcp"));
    $SIG{ALRM} = "connect_timeout";
    alarm(10);
    my $port = $in{'port'} ? $in{'port'} : $in{'mode'} ? 22 : 23;
    my $rv = connect(STEST, sockaddr_in($port, inet_aton($addr)));
    close(STEST);
    if (!$rv) {
      $html .= '<p>There is no '.($in{'mode'}?'ssh':'telnet').' server running on '.$addr.' port '.$port.'</p>';
    } else {
      $html .= '<table border=1 cellspacing=0 cellpadding=0><tr><td align="center">';
      my $jars = $in{'mode'} ? "jta20.jar,cryptix.jar" : "jta20.jar";
      $html .= '<applet archive="'.$jars.'" code=de.mud.jta.Applet width='.$Screen_width.' height='.$Screen_height.'>'.
               '<param name=config              value="'.($in{'mode'} ? 'ssh.conf' : 'telnet.conf').'">';
      $html .= '<param name=Socket.port         value="'.$port.'">' if $port;
      $html .= '<param name=Socket.host         value="'.$in{'host'}.'">' if $in{'host'};
      $html .= '<param name=Script.script       value="'.$in{'script'}.'">' if $in{'script'};
      $html .= '<param name=Socket.relay        value="'.$Socket_relay.'">'.
               '<param name=Socket.relayPort    value="'.$Socket_relayPort.'">'.
               '<param name=Terminal.foreground value="'.$Term_foreground.'">'.
               '<param name=Terminal.background value="'.$Term_background.'">'.
               '<param name=Terminal.border     value="'.$Term_border.'">'.
               '<param name=Terminal.scrollBar  value="'.$Term_scrollBar.'">'.
               '<param name=Terminal.id         value="'.$Term_id.'">'.
               '<param name=Terminal.buffer     value="'.$Term_buffer.'">'.
               '<param name=Terminal.size       value="'.$Term_size.'">'.
               '<param name=Terminal.font       value="'.$Term_font.'">'.
               '<param name=Terminal.fontStyle  value="'.$Term_fontStyle.'">'.
               '<param name=Terminal.fontSize   value="'.$Term_fontSize.'">';

      $html .= 'This module requires java to function, but your browser does not support java.<p>';
      $html .= "</applet><br>\n";

      $html .= 'Applet developed under GPL by <a href="http://www.mud.de/se/jta/">Matthias L. Jugel &amp; Marcus Meiner</a>.<br>';
      $html .= 'Includes software developed by the Cryptix Development Team (<a href="http://www.systemics.com/docs/cryptix/">http://www.systemics.com/docs/cryptix/</a>).<br>' if $in{'mode'};
    }
    $html .= "</td></tr></table></center>\n".&Footer();

    print $html;
    exit;
}

sub connect_timeout { }

# to_ipaddress(hostname)
# Converts a hostname to an a.b.c.d format IP address
sub to_ipaddress {
    my @ip = unpack("CCCC", gethostbyname($_[0]));
    if (@ip) { return join("." , @ip); }
    else { return undef; }
}

# get_system_hostname()
# Returns the hostname of this system
sub get_system_hostname {
    if (!$get_system_hostname) {
      chop($get_system_hostname = `hostname 2>/dev/null`);
      if ($?) {
          use Sys::Hostname;
          $get_system_hostname = eval "hostname()";
          if ($@) { $get_system_hostname = "localhost"; }
      }
    }
    return $get_system_hostname;
}

1;
