Changeset 14374 for misc/runpugs
- Timestamp:
- 10/17/06 08:26:47 (2 years ago)
- svk:copy_cache_prev:
- 21206
- Location:
- misc/runpugs
- Files:
-
- 5 modified
-
bin/termserv2.pl (modified) (1 diff)
-
cgi-bin/runpugs (modified) (1 diff)
-
htdocs/index.html (modified) (1 diff)
-
lib/Web/Terminal/Server.pm (modified) (5 diffs)
-
lib/Web/Terminal/Server/Session.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
misc/runpugs/bin/termserv2.pl
r14366 r14374 1 1 #!/usr/bin/perl 2 BEGIN { 3 $ENV{PERLIO}= ":utf8"; 4 } 2 5 use warnings; 3 6 use strict; 4 7 use utf8; 8 5 9 use lib '../lib/'; 6 10 use Web::Terminal::Server; -
misc/runpugs/cgi-bin/runpugs
r14366 r14374 100 100 } else { 101 101 $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 { 103 108 $reply = &WebTerminal::Dispatcher::send($sessionid,$ip,$cmd); 104 109 $reply="\n".$reply; -
misc/runpugs/htdocs/index.html
r14366 r14374 21 21 22 22 <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> 24 24 <li>If a call takes too long, the <code>pugs</code> session will time out.</li> 25 25 <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 32 32 33 33 our %terminals=(); 34 our %lastcalled=();34 #our %lastcalled=(); 35 35 our %sessions_per_ip=(); 36 36 … … 39 39 my $ip=shift; 40 40 my $cmd = shift; 41 if(scalar(keys % lastcalled)>$Web::Terminal::Settings::nsessions){ # each pugs takes 1% of feather's MEM!41 if(scalar(keys %terminals)>$Web::Terminal::Settings::nsessions){ # each pugs takes 1% of feather's MEM! 42 42 return "Sorry, I can't run any more sessions.\nPlease try again later."; 43 43 } else { 44 $lastcalled{$id}=time;44 # $lastcalled{$id}=time; 45 45 if ( exists $terminals{$id} ) { 46 $terminals{$id}->{called}=time; 46 47 my $term = $terminals{$id}; 47 48 my $lines = $term->write($cmd); 48 49 if ( $cmd eq $Web::Terminal::Settings::quit_command ) { 49 50 delete $terminals{$id}; 50 delete $lastcalled{$id};51 51 $sessions_per_ip{$ip}--; 52 52 } 53 53 if ($lines=~/Aborted/s) { 54 54 delete $terminals{$id}; 55 delete $lastcalled{$id};56 55 $sessions_per_ip{$ip}--; 57 56 } … … 64 63 } else { 65 64 $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; 67 68 my $term = $terminals{$id}; 68 69 return $term->{'init'}; … … 78 79 if ( $len > 0 ) { 79 80 # ( my $id, my $ip, my $cmd ) = split( "\n", $msg, 3 ); 80 print "MSG:", $msg;81 print "MSG:", $msg; 81 82 my $mesgref=YAML::Syck::Load($msg); 82 83 my $id=$mesgref->{id}; 83 84 my $ip=$mesgref->{ip}; 84 85 my $cmd=$mesgref->{cmd}; 85 $cmd=pack("U0C*", unpack("C*",$cmd));86 # $cmd=pack("U0C*", unpack("C*",$cmd)); 86 87 # print "$id($ip): ",$cmd,"\n"; 87 88 my $lines = &termhandler( $id, $ip, $cmd ); … … 132 133 sub timeout() { 133 134 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}; 136 137 if ($now-$then>$Web::Terminal::Settings::timeout_idle) { 137 138 if(exists $terminals{$id}) { 139 my $ip=$terminals{$id}->{ip}; 140 $sessions_per_ip{$ip}--; 138 141 $terminals{$id}->write(':q'); 139 142 delete $terminals{$id}; 140 }141 if (exists $lastcalled{$id}) {142 delete $lastcalled{$id};143 143 } 144 144 } -
misc/runpugs/lib/Web/Terminal/Server/Session.pm
r14366 r14374 47 47 my $obj = shift; 48 48 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; 50 53 my $ps = ''; 51 54 … … 66 69 # print "L:",$line,":",$msg; 67 70 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; 73 76 } 74 77 $msg=''; … … 80 83 } 81 84 82 83 85 #$lline .= "\n$ps>"; 86 chomp $ps; # a hack! 84 87 $lline .= $ps; 85 88 return $lline; … … 94 97 $pty = new IO::Pty 95 98 or die $!; 96 binmode $pty, ':utf8';99 binmode $pty, ":utf8"; 97 100 ## Execute the program in another process. 98 101 unless ( $pid = fork ) { # child process … … 106 109 ## Associate process with a new controlling terminal. 107 110 $tty = $pty->slave; 108 binmode $tty, ':utf8';111 binmode $tty, ":utf8"; 109 112 $tty_fd = $tty->fileno; 110 113 close $pty; … … 114 117 open STDOUT, ">&$tty_fd" or die $!; 115 118 open STDERR, ">&STDOUT" or die $!; 119 binmode STDIN, ":utf8"; 120 binmode STDOUT, ":utf8"; 121 binmode STDERR, ":utf8"; 116 122 close $tty; 117 123
