Changeset 14366 for misc/runpugs

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

[runpugs]
-clean up sessions/IP on timeout
-first commit of generic Web::Terminal

Location:
misc/runpugs
Files:
12 added
6 modified

Legend:

Unmodified
Added
Removed
  • misc/runpugs/cgi-bin/runpugs

    r14271 r14366  
    5858my $ip=$ENV{'REMOTE_ADDR'}; 
    5959#my $ip="127.0.0.".int(rand(100)); 
    60  
     60#if ($ip eq '86.0.200.34') { 
     61#$ip='127.'.int(rand(100)).'.'.int(rand(100)).'.'.int(rand(100)); 
     62#} 
    6163######### MAIN SITEMANAGER PROGRAM ################### 
    6264 
     
    122124################### PRINTHTTPHEADER ####################### 
    123125sub printhttpheader { 
    124    my $cookie; 
     126#   my $cookie; 
    125127     unless ($headerprinted) { 
    126128 
    127      if ($sessionid) { 
    128          $cookie = $query->cookie( -name    => 'sessionid', 
    129                            -"value" => $sessionid, 
    130                            -path    => '/' ); 
    131        } 
     129#     if ($sessionid) { 
     130#         $cookie = $query->cookie( -name    => 'sessionid', 
     131#                           -"value" => $sessionid, 
     132#                           -path    => '/' ); 
     133#       } 
    132134 
    133135$headerprinted=1; 
    134136 
    135      if ($sessionid) { 
    136          print $query->header(-pragma=>'no-cache', 
    137                       -cookie=>$cookie, 
    138                       -charset=>$lang_charset, 
    139                              ); 
    140        } else { 
     137#        if ($sessionid) { 
     138#         print $query->header(-pragma=>'no-cache', 
     139#                      -cookie=>$cookie, 
     140#                      -charset=>$lang_charset, 
     141#                            ); 
     142#       } else { 
    141143         print $query->header(-pragma=>'no-cache', 
    142144                      -charset=>$lang_charset, 
    143145                              ); 
    144        } 
     146#       } 
    145147   } 
    146148   } 
  • misc/runpugs/data/runpugs.html

    r14299 r14366  
    44<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    55 
    6 <title>Run Perl6 Now!</title> 
     6<title>Run Perl 6 Now -- in your browser!</title> 
    77<link rel="stylesheet" type="text/css" href="/runpugs.css"> 
    88<script language="JavaScript"> 
     
    2626<body> 
    2727<div id="mainwindow"> 
    28 <h1>Run Perl6 now -- in your browser!</h1> 
     28<h1>Run Perl 6 now -- in your browser!</h1> 
    2929<p>This live web terminal runs the latest developement snapshot of 
    3030the <a href="http://www.pugscode.org">pugs</a> interpreter for <a 
    31 href="http://dev.perl.org/perl6/">Perl6</a>. For more information, read <a 
    32 href="http://feather.perl6.nl/~andara/runpugs/">this</a>. 
     31href="http://dev.perl.org/perl 6/">Perl 6</a>. For more details, read the <a 
     32href="http://feather.perl6.nl/~andara/runpugs/">info page</a>. 
    3333</p> 
    3434<form style="text-align: center" id="term" name="terminal" action="/cgi-bin/runpugs" method="POST">                   
  • misc/runpugs/htdocs/index.html

    r14299 r14366  
    33<head> 
    44<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    5 <title>Run Perl6 Now -- in your browser!</title> 
     5<title>Run Perl 6 Now -- in your browser!</title> 
    66<link rel="stylesheet" type="text/css" href="runpugs.css"> 
    77</head> 
     
    99 
    1010<div id="mainwindow"> 
    11 <h1>Run Perl6 now -- in your browser!</h1> 
     11<h1>Run Perl 6 now -- in your browser!</h1> 
    1212 
    13 <p>Welcome to <tt>runpugs</tt>, a web terminal for  <a href="http://www.pugscode.org">pugs</a>. Pugs is an implementation of  <a href="http://dev.perl.org/perl6/">Perl6</a> which aims to implement the full Perl6 specification.</p> 
     13<p>Welcome to <tt>runpugs</tt>, a web terminal for  <a href="http://www.pugscode.org">pugs</a>. Pugs is an implementation of  <a href="http://dev.perl.org/perl6/">Perl 6</a> which aims to implement the full Perl 6 specification.</p> 
    1414<p><tt>runpugs</tt> currently lives <a 
    1515href="http://feather.perl6.nl:8080/cgi-bin/runpugs">here</a>.</p> 
     
    2121 
    2222<ul> 
    23 <li>Pugs 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 (including <code>say()</code>!) 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> 
     
    4141<li>There is no command history.</li> 
    4242</ul> 
    43 <p>You can find the source code for <tt>runpugs</tt> (in Perl5) in the <a href="http://svn.openfoundry.org/pugs/">pugs subversion repository</a> under <code>/misc/runpugs</code>. 
     43<p>You can find the source code for <tt>runpugs</tt> (in Perl 5) in the <a href="http://svn.openfoundry.org/pugs/">pugs subversion repository</a> under <code>/misc/runpugs</code>. 
    4444<p>Thank you for trying <tt>pugs</tt> and <tt>runpugs</tt>!</p> 
    4545<p class="copyright">&copy; Copyright 2006 by Wim Vanderbauwhede</p> 
  • misc/runpugs/lib/WebTerminal/Dispatcher.pm

    r14233 r14366  
    6161    $conn->disconnect(); 
    6262        if ( "$id" ne  "$rid" ) { 
    63                 die "Terminal server returned wrong id: $rid, should be $id"; 
     63#               die "Terminal server returned wrong id: $rid, should be $id"; 
     64        return "Sorry, the pugs session died."; 
    6465        } 
    6566        return $reply; 
  • misc/runpugs/lib/WebTerminal/Server.pm

    r14299 r14366  
    3030 
    3131our %terminals=(); 
    32 our %lastcalled=(); 
    3332our %sessions_per_ip=(); 
    3433 
    3534sub termhandler { 
    3635        my $id  = shift; 
    37     my $ip=shift; 
     36    my $ip = shift; 
    3837        my $cmd = shift; 
    39 if(scalar(keys %lastcalled)>50){ # each pugs takes 1% of feather's MEM! 
    40     return "Sorry, I can't run any more sessions.\nPlease try again later."; 
    41 } else { 
    42         $lastcalled{$id}=time; 
    43         if ( exists $terminals{$id} ) { 
    44                 my $term  = $terminals{$id}; 
    45                 my $lines = $term->write($cmd); 
    46                 if ( $cmd eq ':q' ) { 
    47                         delete $terminals{$id}; 
    48             delete $lastcalled{$id}; 
    49             $sessions_per_ip{$ip}--; 
    50                 } 
    51         if ($lines=~/Aborted/s) { 
    52              delete $terminals{$id}; 
    53              delete $lastcalled{$id}; 
    54             $sessions_per_ip{$ip}--; 
    55         } 
    56                 return $lines; 
    57         } else { 
    58         if ($sessions_per_ip{$ip}>10) { 
    59          return "Sorry, you can't run more than 10 sessions from one IP 
    60          address.\n";    
    61         } else { 
    62             $sessions_per_ip{$ip}++; 
    63                 $terminals{$id} = new WebTerminal::Server::Terminal(); 
    64                 my $term = $terminals{$id}; 
    65                 return $term->{'init'}; 
    66         } 
    67         } 
    68 } 
     38    if(scalar(keys %terminals)>50){ # each pugs takes 1% of feather's MEM! 
     39        return "Sorry, I can't run any more sessions.\nPlease try again later."; 
     40    } else { 
     41        if ( exists $terminals{$id} ) { 
     42                $terminals{$id}->{called}=time; 
     43                    my $term  = $terminals{$id}; 
     44                my $lines = $term->write($cmd); 
     45                if ( $cmd eq ':q' ) { 
     46                        delete $terminals{$id}; 
     47                $sessions_per_ip{$ip}--; 
     48                } 
     49            if ($lines=~/Aborted/s) { 
     50                 delete $terminals{$id}; 
     51                $sessions_per_ip{$ip}--; 
     52            } 
     53                return $lines; 
     54        } else { 
     55            if ($sessions_per_ip{$ip}>10) { 
     56                 return "Sorry, you can't run more than 10 sessions from one IP address.\n";    
     57            } else { 
     58                $sessions_per_ip{$ip}++; 
     59                        $terminals{$id} = new WebTerminal::Server::Terminal(); 
     60                    $terminals{$id}->{called}=time; 
     61                    $terminals{$id}->{ip}=$ip; 
     62                        my $term = $terminals{$id}; 
     63                return $term->{'init'}; 
     64            } 
     65            } 
     66    }    
    6967} 
    7068 
     
    9088 
    9189sub run { 
    92 my $host=shift; 
    93 my $port=shift; 
    94 $SIG{USR1}=\&timeout; 
    95 Proc::Daemon::Init; 
    96 # fork/exec by the book: 
    97 use Errno qw(EAGAIN); 
    98 my $pid; 
    99 FORK: { 
    100 if ($pid=fork) { 
    101     #parent here 
    102     WebTerminal::Msg->new_server( $host, $port, \&login_proc ); 
    103     WebTerminal::Msg->event_loop(); 
    104 } elsif (defined $pid) { 
    105    # child here 
    106    while (getppid()>10) { # a bit ad-hoc. 
    107        sleep 300; 
    108         #print getppid(),"\n"; 
    109         kill 'USR1',getppid(); 
    110     } 
    111 } elsif ($! == EAGAIN) { 
    112     sleep 5; 
    113     redo FORK; 
    114 } else { 
    115     die "Can't fork: $!\n"; 
    116 }  
    117 } # FORK 
     90    my $host=shift; 
     91    my $port=shift; 
     92    $SIG{USR1}=\&timeout; 
     93    Proc::Daemon::Init; 
     94    # fork/exec by the book: 
     95    use Errno qw(EAGAIN); 
     96    my $pid; 
     97    FORK: { 
     98        if ($pid=fork) { 
     99            #parent here 
     100            WebTerminal::Msg->new_server( $host, $port, \&login_proc ); 
     101            WebTerminal::Msg->event_loop(); 
     102        } elsif (defined $pid) { 
     103           # child here 
     104           while (getppid()>10) { # a bit ad-hoc. 
     105               sleep 300; 
     106                #print getppid(),"\n"; 
     107                kill 'USR1',getppid(); 
     108            } 
     109        } elsif ($! == EAGAIN) { 
     110            sleep 5; 
     111            redo FORK; 
     112        } else { 
     113            die "Can't fork: $!\n"; 
     114        }  
     115    } # FORK 
    118116} 
    119117 
    120118sub timeout() { 
    121119    my $now=time(); 
    122     for my $id (keys %lastcalled) { 
    123         my $then=$lastcalled{$id}; 
     120    for my $id (keys %terminals) { 
     121        my $then=$terminals{$id}->{called}; 
    124122        if ($now-$then>600) { 
    125123        if(exists $terminals{$id}) { 
     124            my $ip=$terminals{$id}->{ip}; 
     125            $sessions_per_ip{$ip}--; 
    126126            $terminals{$id}->write(':q'); 
    127127            delete $terminals{$id}; 
    128             } 
    129             if (exists $lastcalled{$id}) { 
    130             delete $lastcalled{$id}; 
    131128            } 
    132129        } 
  • misc/runpugs/lib/WebTerminal/Server/Terminal.pm

    r14266 r14366  
    1515        my $class    = ref($invocant) || $invocant; 
    1616        my $self     = {@_}; 
    17         my $prompt = '/\>\ /'; 
     17        #my $prompt = '/\>\ /'; 
     18        my $prompt = '/>\ /'; 
    1819        ## Start pugs 
    1920#    $ENV{PUGS_SAFEMODE}=1;# Must be in CGI script! 
     
    2425        $self->{'pugs'} = new Net::Telnet( 
    2526                -fhopen => $self->{'pty'}, 
     27        -timeout => 20, 
    2628                -prompt => $prompt, 
    2729                -telnetmode      => 0,