Changeset 16595 for misc/runpugs
- Timestamp:
- 06/01/07 18:08:37 (18 months ago)
- Location:
- misc/runpugs
- Files:
-
- 1 added
- 9 modified
-
README (modified) (4 diffs)
-
bin/perl_repl.pl (modified) (1 diff)
-
bin/test_session.pl (modified) (1 diff)
-
bin/test_session_dispatcher.pl (modified) (2 diffs)
-
lib/Repl.pm (modified) (1 diff)
-
lib/Web/Terminal/Dispatcher.pm (modified) (1 diff)
-
lib/Web/Terminal/Server.pm (modified) (4 diffs)
-
lib/Web/Terminal/Server/Session.pm (modified) (10 diffs)
-
lib/Web/Terminal/Settings.pm (modified) (2 diffs)
-
webtermrc (added)
Legend:
- Unmodified
- Added
- Removed
-
misc/runpugs/README
r16564 r16595 1 1 ============================================================================== 2 2007/0 5/07Release of version 0.4.0 of runpugs/Web::Terminal2 2007/06/01 Release of version 0.4.0 of runpugs/Web::Terminal 3 3 ============================================================================== 4 4 5 5 NAME 6 runpugs: a web te minal for interactive pugs6 runpugs: a web terminal for interactive pugs 7 7 Web::Terminal: library for building a web terminal for interactive shells 8 8 … … 20 20 Net::Telnet 21 21 IO::Pty 22 Config::General 22 23 23 * make sure that you change the following settings in lib/Web/Terminal/Settings.pm 24 $rel_root (Release pugs) 25 $dev_root (Development pugs) 26 $root (web root) 27 $port (usually should be 2059) 28 $server (bin/termserv4.pl) 24 * create a $HOME/.webtermrc configuration file (start from the webtermrc file in the repository) 25 * make sure that you change the following settings 26 rel_root (Release pugs) 27 dev_root (Development pugs) 28 root (web root) 29 port (default 2059; any free TCP port is OK) 30 server (bin/termserv.pl) 29 31 30 * Start the terminal server script (bin/termserv 4.pl)32 * Start the terminal server script (bin/termserv.pl) 31 33 32 34 * To run, simply point your browser to /runpugs/ … … 34 36 DESCRIPTION 35 37 runpugs has two main components: 36 -a mod_perl script (/perl/runpugs 3.pl) which uses an html template37 (/data/runpugs_async 3.html). The latter calls the runpugs.css stylesheet from38 -a mod_perl script (/perl/runpugs.pl) which uses an html template 39 (/data/runpugs_async.html). The latter calls the runpugs.css stylesheet from 38 40 /htdocs/runpugs.css. The script is called from /htdocs/runpugs/index.html 39 -a server (/bin/termserv 3.pl) which handles the interactive pugs sessions and communicates with41 -a server (/bin/termserv.pl) which handles the interactive pugs sessions and communicates with 40 42 the mod_perl script. The pugs sessions stay alive for some time (currently 10') if 41 43 left inactive. 42 44 43 45 This version has some AJAX goodness and runs under mod_perl. 44 The entrypoint is /htdocs/runpugs/index.html, which calls /perl/runpugs 3.pl46 The entrypoint is /htdocs/runpugs/index.html, which calls /perl/runpugs.pl 45 47 46 48 The underlying library, Web/Terminal, can in principle be used for any … … 62 64 -Better session management 63 65 -use Moose for Session objects 64 -More generic (Settings.pm )66 -More generic (Settings.pm uses Config::General) 65 67 66 68 CHANGES IN VERSION 0.3.0 -
misc/runpugs/bin/perl_repl.pl
r16228 r16595 4 4 #use lib '../lib','/home/andara/lib/perl/5.8.8'; 5 5 use Repl; 6 6 my $prompt ='pugs> '; 7 my $motd ='Simple Perl REPL'; 7 8 my $subref = sub { 8 9 my $cmd = shift; 9 10 my $res = eval($cmd); 10 return $res;11 return ($res,$prompt); 11 12 }; 12 my $prompt ='pugs> '; 13 my $motd ='Simple Perl REPL'; 13 14 14 15 15 my $repl = new Repl {subref=>$subref,prompt=>$prompt,motd=>$motd}; -
misc/runpugs/bin/test_session.pl
r16218 r16595 13 13 my $session=create_session($app); 14 14 15 my $subref = sub {my $cmd=shift;my $res=$session->write($cmd);chomp $res; return $res;};15 my $subref = sub {my $cmd=shift;my $res=$session->write($cmd);chomp $res; return ($res,$session->{'prompt'});}; 16 16 17 17 my $prompt =$session->prompt; -
misc/runpugs/bin/test_session_dispatcher.pl
r16218 r16595 7 7 use Web::Terminal::Dispatcher; 8 8 $Web::Terminal::Settings::port=2059; 9 10 my $app=(defined $ARGV[0])?$ARGV[0]:2; 9 my $app; 10 if (defined $ARGV[0]){ 11 $app=$ARGV[0]; 12 } else { 13 die "Usage: $0 app (0|1|2) [id (default 42)].\n"; 14 } 11 15 my $id=(defined $ARGV[1])?$ARGV[1]:42; 12 16 $id='testsession'.$id; … … 17 21 (my $reply,my $prompt,my $histref) = 18 22 &Web::Terminal::Dispatcher::send($id,$ip,$app,1,$cmd); 19 return $reply;23 return ($reply,$prompt); 20 24 }; 21 25 -
misc/runpugs/lib/Repl.pm
r16218 r16595 18 18 /\:q(uit)*$/i && exit(); 19 19 chomp $_; 20 my $res=$s->subref->($_);21 print $res,"\n",$ s->prompt;20 (my $res,my $prompt)=$s->subref->($_); 21 print $res,"\n",$prompt; 22 22 } 23 23 } -
misc/runpugs/lib/Web/Terminal/Dispatcher.pm
r15833 r16595 21 21 DEFAULT => [], 22 22 ); 23 my $v = (1 - $Web::Terminal::Settings::daemon)*(1-$Web::Terminal::Settings::test);23 my $v = 1;#(1 - $Web::Terminal::Settings::daemon)*(1-$Web::Terminal::Settings::test); 24 24 25 25 sub send { -
misc/runpugs/lib/Web/Terminal/Server.pm
r16218 r16595 43 43 44 44 # verbose 45 my $v = (1 - $Web::Terminal::Settings::daemon)*(1-$Web::Terminal::Settings::test);45 my $v = 1;#(1 - $Web::Terminal::Settings::daemon)*(1-$Web::Terminal::Settings::test); 46 46 47 47 # Datastructures per app, so $session{$app}{...}, $inactive[$app][...] or @{$inactive[$app]} … … 387 387 } 388 388 } else { 389 print " Session $id ($app,$cmd) is not active:", exists( $active_sessions[$app]{$id}),"\n" if $v;389 print " Session $id ($app,$cmd) is not active:", (defined $active_sessions[$app])?exists( $active_sessions[$app]{$id}):'(empty)',"\n" if $v; 390 390 # new session 391 391 assert($n_inactive_sessions[$app]==scalar( @{ $inactive_sessions[$app] })); … … 421 421 # asynchronously create new sessions 422 422 &async_init_create(); 423 return $ret; 423 my $term = $sessions[$app]{$ret}; 424 my $motd=$term->{'motd'}; 425 return $motd; 424 426 } else { 425 427 print … … 696 698 return 1; 697 699 } else { 700 print "PUGS_SAFEMODE=1 $cmd -e \"print 42\" 2>/dev/null\n"; 698 701 my $reply=`PUGS_SAFEMODE=1 $cmd -e \"print 42\" 2>/dev/null`; 699 702 if ($reply==42) { -
misc/runpugs/lib/Web/Terminal/Server/Session.pm
r16219 r16595 15 15 $SIG{CHLD}='IGNORE'; 16 16 17 my $v= (1-$Web::Terminal::Settings::daemon)*(1-$Web::Terminal::Settings::test);17 my $v=1;#(1-$Web::Terminal::Settings::daemon)*(1-$Web::Terminal::Settings::test); 18 18 19 19 my $prompt ='/'.$Web::Terminal::Settings::prompt.'/'; … … 30 30 has 'pty' => (is=>'rw',isa=>'Any'); 31 31 has 'pid' => (is=>'rw',isa=>'Int'); 32 has 'motd' => (is=>'rw',isa=>'Str'); 32 33 33 34 sub BUILD { … … 37 38 my $app=$self->app; 38 39 my $command=$Web::Terminal::Settings::commands[$app]; 39 if ( not $Web::Terminal::Settings::test) {40 if ($Web::Terminal::Settings::test!=1) { 40 41 if ($self->ia==0) { 41 42 #1. Create a file with the content of $cmd using $id.p6 for name, store in data … … 68 69 -telnetmode => 0, 69 70 -cmd_remove_mode => 0, 71 -input_record_separator => "\n", 70 72 ); 71 73 } … … 76 78 print "Reading Pugs startup message...\n" if $v; 77 79 my $m=$self->readlines(); 80 $self->{'motd'}=$m; 78 81 if ($self->{'error'}==1 and not $Web::Terminal::Settings::test) { 79 82 # should close the TTY … … 170 173 sub DESTROY { 171 174 my $obj = shift; 172 if ( not $Web::Terminal::Settings::test) {175 if ( $Web::Terminal::Settings::test!=1) { 173 176 if (defined $obj->{'pty'}) { 174 177 $obj->{'pty'}->close(); … … 193 196 my $i = 1; 194 197 my $lline = ''; 195 if ( not $Web::Terminal::Settings::test) {198 if ( $Web::Terminal::Settings::test!=1) { 196 199 if ( $cmd eq $Web::Terminal::Settings::quit_command ) { 197 200 $obj->{pugs}->close(); … … 206 209 while ($i<$Web::Terminal::Settings::nlines) { 207 210 my $line = $pugs->getline; 208 my $msg=$pugs->errmsg; 209 print "L:",$line,":",$msg if $v; 210 if($msg=~/timed/) { 211 $msg=''; 212 $pugs->errmsg([]); 213 $lline="${Web::Terminal::Settings::prompt} Sorry, that took too long! Aborted.\n"; 214 $pugs->close(); 215 $ps=$Web::Terminal::Settings::prompt; 216 $obj->{'error'}=1; 217 last; 218 } 219 $msg=''; 220 if ( ($line =~ /$Web::Terminal::Settings::prompt_pattern/ or 221 ($line=~/$Web::Terminal::Settings::quit_pattern/)) and $i > 1 ) { $ps = $1; last } 211 my $msg=$pugs->errmsg; 212 print "L:{",$line,"}\n",$msg if $v; 213 if($msg=~/timed/) { 214 $msg=''; 215 $pugs->errmsg([]); 216 $lline="${Web::Terminal::Settings::prompt} Sorry, that took too long! Aborted.\n"; 217 $pugs->close(); 218 $ps=$Web::Terminal::Settings::prompt; 219 $obj->{'error'}=1; 220 last; 221 } 222 $msg=''; 223 # print "\nTEST",$Web::Terminal::Settings::prompt_pattern,"\n"; 224 #print ('(^(pugs|\.\.\.\.)>\s+)' eq $Web::Terminal::Settings::prompt_pattern); 225 #if ($line=~/pugs/) { 226 #print "OK!\n"; 227 #} 228 if ( ($line =~ /$Web::Terminal::Settings::prompt_pattern/ or 229 ($line=~/$Web::Terminal::Settings::quit_pattern/)) and $i > 1 ) { 230 $ps = $1; 231 my $ps1=$ps; 232 my $charnum=ord(chop $ps1); 233 if ($charnum<32) { 234 $ps=$ps1; 235 } 236 last; 237 } 222 238 $lline .= $line unless $line =~ 223 /$Web::Terminal::Settings::prompt_pattern/;239 /$Web::Terminal::Settings::prompt_pattern/; 224 240 $i++; 225 241 } … … 252 268 # my $i = 1; 253 269 my $lline = ''; 254 if ( not $Web::Terminal::Settings::test) {270 if ( $Web::Terminal::Settings::test!=1) { 255 271 my $pugs=$obj->{'pugs'}; 256 272 $pugs->errmode(sub {kill 9,$obj->{'pid'}; }); … … 275 291 # #} else {die;$prev=1;} 276 292 # } 277 293 # print "TEST",$Web::Terminal::Settings::prompt,"\n"; 278 294 ($line, $ps)=$pugs->waitfor(String=>$Web::Terminal::Settings::prompt); 279 295 $pugs->buffer_empty(); # maybe redundant, but play safe -
misc/runpugs/lib/Web/Terminal/Settings.pm
r16228 r16595 5 5 use vars qw( $VERSION ); 6 6 $VERSION = '0.4.0'; 7 use utf8; 7 #use utf8 8 8 use strict; 9 10 use Config::General; 9 11 10 12 use Exporter; … … 51 53 ); 52 54 53 #ghci 54 ##GHCi 55 #our $command='/usr/local/bin/ghci'; 56 #our $prompt='Prelude> '; 57 #our $prompt_pattern='(^(Prelude)>\s+)'; 58 #our $quit_pattern='^Leaving\ GHCi\.'; 59 #our $quit_message='Leaving GHCi.'; 60 #cut 55 #my %config = Config::General::ParseConfig("./wtrc"); 56 my $conf = new Config::General( 57 -ConfigFile => $ENV{'HOME'}.'/.webtermrc', 58 -InterPolateVars=>1, 59 -InterPolateEnv=>1 60 ); 61 my %config=$conf->getall(); 61 62 62 #Pugs 63 my $ulimit='ulimit -m 64000; ulimit -v 64000;'; 64 my $nice='/usr/bin/nice'; 65 my $pugs='/usr/bin/pugs'; 66 my $rel_root='/home/andara/pugs-rel'; 67 my $dev_root='/home/andara/pugs-dev'; 68 my $rel_lib="-I$rel_root/blib6/lib"; 69 my $dev_lib="-I$dev_root/blib6/lib"; 63 no strict 'refs'; 70 64 71 #$ulimit=''; 72 #$nice='';#/bin/nice'; 73 #$pugs='/usr/bin/pugs'; 74 #$rel_root='/usr/bin'; 75 #$dev_root='/usr/bin'; 76 #$rel_lib=''; 77 #$dev_lib=''; 65 for my $key (keys %config) { 66 my $fkey="Web::Terminal::Settings::$key"; 67 if ($config{$key}=~/^\(\d+(,\d+)*\)/) { 68 my $vals=$config{$key}; 69 $vals=~s/[\(\)]//g; 70 @{$fkey}=split(/,/,$vals); 71 } else { 72 ${$fkey}=$config{$key}; 73 } 74 } 78 75 79 76 our @commands=( 80 "$ulimit $nice $rel_root/pugs $rel_lib", 81 "$ulimit $nice $dev_root/pugs $dev_lib", 82 #"perl ./perl_repl.pl" 77 "$Web::Terminal::Settings::ulimit $Web::Terminal::Settings::nice $Web::Terminal::Settings::rel_root/pugs $Web::Terminal::Settings::rel_lib", 78 "$Web::Terminal::Settings::ulimit $Web::Terminal::Settings::nice $Web::Terminal::Settings::dev_root/pugs $Web::Terminal::Settings::dev_lib", 83 79 ); 84 80 85 our $test=0; 86 our $appname='runpugs'; 87 our $prompt='pugs> '; 88 #$prompt='perl> '; 89 our $prompt_pattern='(^(pugs|\.\.\.\.)>\s+)'; 90 our $quit_pattern='^Leaving\ pugs\.'; 91 our $quit_message='Leaving pugs.'; 81 if ($Web::Terminal::Settings::test==2) { 82 push @commands,"perl ./perl_repl.pl"; 83 push @Web::Terminal::Settings::n_max,1; 84 push @Web::Terminal::Settings::npreloaded_sessions,1; 85 push @Web::Terminal::Settings::n_inactive_min,1; 86 } 92 87 93 our $init_pattern='(\>\s+)'; 94 our $quit_command=':q'; 95 our $reset_command=':r'; 96 our $abort_command=':A'; # To simulate abort in test mode 88 our @n_inactive_max=@Web::Terminal::Settings::npreloaded_sessions; 97 89 98 our $filter=0; 99 our $filter_pattern=''; 100 my $root='/home/andara/apache'; 101 102 our $cgi_path="$root/cgi-bin/"; 103 our $lib_path="$root/lib/"; 104 our $bin_path="$root/bin/"; 105 our $data_path="$root/data/"; 106 our $tmp_path="$root/data/tmp/"; 107 our $log_path="$root/data/log"; 108 our $daemon=1; 109 our $port=2057; 110 our $host='localhost'; 111 112 our $restart_parent=0; # restart parent server from child if 1 113 our $server="$bin_path/termserv.pl"; # used to restart parent server from child 114 115 our $nsessions=50; # obsolete 116 our @n_max=(20,50);#,5); 117 our $nsessions_ip=10; 118 our @npreloaded_sessions=(5,10);#,2); 119 our @n_inactive_max=@npreloaded_sessions; 120 our @n_inactive_min=(2,5);#,0); 121 122 our $timeout_idle=90; # was 600 123 our $timeout_call=30; # was 30 124 our $check_interval=60; 125 our $create_interval=5; # should be 30 I guess 126 our $nlines=250; 127 our $nchars=250; 128 our $nrecent=10; 129 our $perl='/usr/bin/perl'; 90 1; 130 91 131 92 __END__
