Changeset 14374 for misc/runpugs

Show
Ignore:
Timestamp:
10/17/06 08:26:47 (2 years ago)
Author:
andara
svk:copy_cache_prev:
21206
Message:

[runpugs]
Now catches Unicode & apologises :-)

Location:
misc/runpugs
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • misc/runpugs/bin/termserv2.pl

    r14366 r14374  
    11#!/usr/bin/perl 
     2BEGIN { 
     3$ENV{PERLIO}= ":utf8"; 
     4} 
    25use warnings; 
    36use strict; 
    47use utf8; 
     8 
    59use lib '../lib/'; 
    610use Web::Terminal::Server; 
  • misc/runpugs/cgi-bin/runpugs

    r14366 r14374  
    100100    } else { 
    101101    $cmd=~s/^.+?pugs([\>\.])/pugs$1/s; 
    102     if ($cmd=~/clear/) {$cmd=''} else { 
     102    #NO UNICODE! 
     103#    $cmd=tr/\0-\x{10ffff}/\0-\xff_/; 
     104    if ($cmd=~/clear/) {$cmd=''} elsif ($cmd!~/^\p{IsASCII}*$/) { 
     105            $cmd=''; 
     106                $reply = "Sorry, Unicode is not yet supported.\npugs> "; 
     107    } else { 
    103108    $reply = &WebTerminal::Dispatcher::send($sessionid,$ip,$cmd); 
    104109    $reply="\n".$reply; 
  • misc/runpugs/htdocs/index.html

    r14366 r14374  
    2121 
    2222<ul> 
    23 <li><The code>pugs</code> shell runs in <em>safe mode</em>, so system-related calls (including <code>say()</code>!) are disabled.</li> 
     23<li><The code>pugs</code> shell runs in <em>safe mode</em>, so system-related calls are disabled.</li> 
    2424<li>If a call takes too long, the <code>pugs</code> session will time out.</li> 
    2525<li>If left idle for too long, the <code>pugs</code> session will time out.</li> 
  • misc/runpugs/lib/Web/Terminal/Server.pm

    r14366 r14374  
    3232 
    3333our %terminals=(); 
    34 our %lastcalled=(); 
     34#our %lastcalled=(); 
    3535our %sessions_per_ip=(); 
    3636 
     
    3939    my $ip=shift; 
    4040        my $cmd = shift; 
    41 if(scalar(keys %lastcalled)>$Web::Terminal::Settings::nsessions){ # each pugs takes 1% of feather's MEM! 
     41if(scalar(keys %terminals)>$Web::Terminal::Settings::nsessions){ # each pugs takes 1% of feather's MEM! 
    4242    return "Sorry, I can't run any more sessions.\nPlease try again later."; 
    4343} else { 
    44         $lastcalled{$id}=time; 
     44#       $lastcalled{$id}=time; 
    4545        if ( exists $terminals{$id} ) { 
     46    $terminals{$id}->{called}=time; 
    4647                my $term  = $terminals{$id}; 
    4748                my $lines = $term->write($cmd); 
    4849                if ( $cmd eq $Web::Terminal::Settings::quit_command ) { 
    4950                        delete $terminals{$id}; 
    50             delete $lastcalled{$id}; 
    5151            $sessions_per_ip{$ip}--; 
    5252                } 
    5353        if ($lines=~/Aborted/s) { 
    5454             delete $terminals{$id}; 
    55              delete $lastcalled{$id}; 
    5655            $sessions_per_ip{$ip}--; 
    5756        } 
     
    6463        } else { 
    6564            $sessions_per_ip{$ip}++; 
    66                 $terminals{$id} = new Web::Terminal::Server:Session(); 
     65                $terminals{$id} = new Web::Terminal::Server::Session(); 
     66    $terminals{$id}->{called}=time; 
     67    $terminals{$id}->{ip}=$ip; 
    6768                my $term = $terminals{$id}; 
    6869                return $term->{'init'}; 
     
    7879                if ( $len > 0 ) { 
    7980#                       ( my $id, my $ip, my $cmd ) = split( "\n", $msg, 3 ); 
    80 print "MSG:", $msg;                      
     81            print "MSG:", $msg;                  
    8182                        my $mesgref=YAML::Syck::Load($msg); 
    8283                         my $id=$mesgref->{id}; 
    8384             my $ip=$mesgref->{ip}; 
    8485             my $cmd=$mesgref->{cmd}; 
    85             $cmd=pack("U0C*", unpack("C*",$cmd)); 
     86#            $cmd=pack("U0C*", unpack("C*",$cmd)); 
    8687#            print "$id($ip): ",$cmd,"\n"; 
    8788                        my $lines = &termhandler( $id, $ip, $cmd ); 
     
    132133sub timeout() { 
    133134    my $now=time(); 
    134     for my $id (keys %lastcalled) { 
    135         my $then=$lastcalled{$id}; 
     135    for my $id (keys %terminals) { 
     136        my $then=$terminals{$id}; 
    136137        if ($now-$then>$Web::Terminal::Settings::timeout_idle) { 
    137138        if(exists $terminals{$id}) { 
     139            my $ip=$terminals{$id}->{ip}; 
     140            $sessions_per_ip{$ip}--; 
    138141            $terminals{$id}->write(':q'); 
    139142            delete $terminals{$id}; 
    140             } 
    141             if (exists $lastcalled{$id}) { 
    142             delete $lastcalled{$id}; 
    143143            } 
    144144        } 
  • misc/runpugs/lib/Web/Terminal/Server/Session.pm

    r14366 r14374  
    4747        my $obj = shift; 
    4848        my $cmd  = shift; 
    49         chomp $cmd; 
     49#       print "CMD1: $cmd\n"; 
     50#    $cmd=pack("U0C*", unpack("C*",$cmd));     
     51#       print "CMD2: $cmd\n"; 
     52    chomp $cmd; 
    5053        my $ps = ''; 
    5154 
     
    6669#           print "L:",$line,":",$msg; 
    6770            if($msg=~/timed/) { 
    68         $msg=''; 
    69         $pugs->errmsg([]); 
    70         $lline="${Web::Terminal::Settings::prompt} Sorry, that took too long! Aborted.\n"; 
    71         $ps=$Web::Terminal::Settings::prompt; 
    72         last; 
     71            $msg=''; 
     72            $pugs->errmsg([]); 
     73            $lline="${Web::Terminal::Settings::prompt} Sorry, that took too long! Aborted.\n"; 
     74            $ps=$Web::Terminal::Settings::prompt; 
     75            last; 
    7376        } 
    7477        $msg=''; 
     
    8083        } 
    8184 
    82  
    8385        #$lline .= "\n$ps>"; 
     86    chomp $ps; # a hack! 
    8487        $lline .= $ps; 
    8588        return $lline; 
     
    9497        $pty = new IO::Pty 
    9598          or die $!; 
    96     binmode $pty, ':utf8'; 
     99    binmode $pty, ":utf8";  
    97100        ## Execute the program in another process. 
    98101        unless ( $pid = fork ) {    # child process 
     
    106109                ## Associate process with a new controlling terminal. 
    107110                $tty    = $pty->slave; 
    108         binmode $tty, ':utf8'; 
     111        binmode $tty, ":utf8"; 
    109112                $tty_fd = $tty->fileno; 
    110113                close $pty; 
     
    114117                open STDOUT, ">&$tty_fd" or die $!; 
    115118                open STDERR, ">&STDOUT"  or die $!; 
     119        binmode STDIN, ":utf8"; 
     120        binmode STDOUT, ":utf8"; 
     121        binmode STDERR, ":utf8"; 
    116122                close $tty; 
    117123