Changeset 14403 for misc/runpugs

Show
Ignore:
Timestamp:
10/18/06 01:01:34 (2 years ago)
Author:
andara
Message:

[runpugs]
-now limits generated output (to 256 lines)
-runpugs is now a semi-self(re)starter
-added some minimal logging

Location:
misc/runpugs
Files:
3 modified

Legend:

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

    r14374 r14403  
    6565if ( $query->param()) {      # an action has been chosen 
    6666    my $cmd=$query->param("cmd"); 
    67      my $action =  $query->param("action")||'runpugs'; 
     67    my $action =  $query->param("action")||'runpugs'; 
    6868    if ($action =~ /^(\w+)$/) { 
    69         $action = $1; 
    70         if ($access_OK) { 
    71             if ($action eq "runpugs") { 
    72                 &runpugs($query,$cmd,$sessionid,$ip); 
    73             }  
    74     } else { 
    75         my $warning_message="Action has illegal chars: $action"; 
    76     &runpugs($query,'',$sessionid,$ip); 
     69        $action = $1; 
     70        if ($access_OK) { 
     71                if ($action eq "runpugs") { 
     72                        &runpugs($query,$cmd,$sessionid,$ip); 
     73                }  
     74        } else { 
     75            &runpugs($query,'init',$sessionid,$ip); 
     76        } 
     77    } else {            # no action has been taken, display login page 
     78       my $warning_message="Action has illegal chars: $action"; 
     79       &runpugs($query,'init',$sessionid,$ip); 
    7780    } 
    78 } else {            # no action has been taken, display login page 
    79     &runpugs($query,'',$sessionid,$ip); 
    80 } 
    8181} else { 
    8282         &runpugs($query,'',$sessionid,$ip); 
  • misc/runpugs/lib/WebTerminal/Server.pm

    r14366 r14403  
    4040    } else { 
    4141        if ( exists $terminals{$id} ) { 
     42        if ($terminals{$id}->{pid}) { 
    4243                $terminals{$id}->{called}=time; 
    4344                    my $term  = $terminals{$id}; 
     
    4546                if ( $cmd eq ':q' ) { 
    4647                        delete $terminals{$id}; 
     48                 my $pid= $terminals{$id}->{pid}; 
     49                 if ($pid) { 
     50                     kill 9,$pid; 
     51                 } 
    4752                $sessions_per_ip{$ip}--; 
    4853                } 
    4954            if ($lines=~/Aborted/s) { 
    5055                 delete $terminals{$id}; 
     56                 my $pid= $terminals{$id}->{pid}; 
     57                 if ($pid) { 
     58                     kill 9,$pid; 
     59                 } 
    5160                $sessions_per_ip{$ip}--; 
    5261            } 
    5362                return $lines; 
     63           } else { 
     64           return "pugs> "; 
     65           } 
    5466        } else { 
    5567            if ($sessions_per_ip{$ip}>10) { 
     
    7486                        ( my $id, my $ip, my $cmd ) = split( "\n", $msg, 3 ); 
    7587            $cmd=pack("U0C*", unpack("C*",$cmd)); 
    76 #            print "$id($ip): ",$cmd,"\n"; 
     88            my $pid=0; 
     89            if(exists $terminals{$id}) { 
     90            $pid=$terminals{$id}->{pid}; 
     91            } 
     92            my $nsess=scalar keys %terminals; 
     93            print scalar(localtime)," : $nsess : $ip : $id : $pid > ",$cmd,"\n"; 
     94            print LOG scalar(localtime)," : $nsess : $ip : $id : $pid > ",$cmd,"\n"; 
    7795                        my $lines = &termhandler( $id, $ip, $cmd ); 
    7896                        $conn->send_now("$id\n$lines"); 
     
    91109    my $port=shift; 
    92110    $SIG{USR1}=\&timeout; 
     111my $daemon=0; 
     112if ($daemon) { 
    93113    Proc::Daemon::Init; 
     114} 
    94115    # fork/exec by the book: 
    95116    use Errno qw(EAGAIN); 
     
    98119        if ($pid=fork) { 
    99120            #parent here 
     121            use Cwd; 
     122            print cwd(); 
     123            open(LOG,">/home/andara/apache/data/runpugs.log"); 
    100124            WebTerminal::Msg->new_server( $host, $port, \&login_proc ); 
    101125            WebTerminal::Msg->event_loop(); 
     
    103127           # child here 
    104128           while (getppid()>10) { # a bit ad-hoc. 
    105                sleep 300; 
     129               sleep 60; 
    106130                #print getppid(),"\n"; 
    107131                kill 'USR1',getppid(); 
    108132            } 
     133            sleep 5; 
     134            system("killall /usr/bin/pugs"); 
     135            chdir "/home/andara/apache/cgi-bin/"; 
     136            exec('/usr/bin/perl ../bin/termserv.pl'); 
    109137        } elsif ($! == EAGAIN) { 
    110138            sleep 5; 
     
    122150        if ($now-$then>600) { 
    123151        if(exists $terminals{$id}) { 
     152            my $pid= $terminals{$id}->{pid}; 
    124153            my $ip=$terminals{$id}->{ip}; 
    125154            $sessions_per_ip{$ip}--; 
    126             $terminals{$id}->write(':q'); 
     155            if ($pid) { 
     156                kill 9,$pid; 
     157            } 
     158#            $terminals{$id}->write(':q'); 
    127159            delete $terminals{$id}; 
    128160            } 
    129161        } 
    130162    } 
     163=reaper 
     164    # as a hack, we can reap "lost" sessions here 
     165     my @sessions=`ps x | grep pugs | grep -v runpugs | grep -v grep`; 
     166     for my $session (@sessions) { 
     167     chomp $session; 
     168       my $pid=$session; 
     169       $pid=~s/\s+.*$//; 
     170     } 
     171=cut 
    131172} 
    132173 
  • misc/runpugs/lib/WebTerminal/Server/Terminal.pm

    r14366 r14403  
    99write() sends commands to it. 
    1010=cut 
    11  
     11$SIG{CHLD}='IGNORE'; 
    1212## Constructor 
    1313sub new { 
     
    2525        $self->{'pugs'} = new Net::Telnet( 
    2626                -fhopen => $self->{'pty'}, 
    27         -timeout => 20, 
     27        -timeout => 10, 
    2828                -prompt => $prompt, 
    2929                -telnetmode      => 0, 
     
    5757 
    5858        $pugs->print($cmd); 
    59         while (1) { 
     59        while ($i<256) { 
    6060                my $line = $pugs->getline; 
    6161        my $msg=$pugs->errmsg; 
     
    7373                $i++; 
    7474        } 
    75  
     75    if ($i>=255) { 
     76     kill 9, $obj->{'pid'}; 
     77     $lline.="Generated output is limited to 100 lines. Aborted.\npugs"; 
     78    } 
    7679 
    7780        #$lline .= "\n$ps>";