Changeset 14403 for misc/runpugs
- Timestamp:
- 10/18/06 01:01:34 (2 years ago)
- Location:
- misc/runpugs
- Files:
-
- 3 modified
-
cgi-bin/runpugs (modified) (1 diff)
-
lib/WebTerminal/Server.pm (modified) (7 diffs)
-
lib/WebTerminal/Server/Terminal.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
misc/runpugs/cgi-bin/runpugs
r14374 r14403 65 65 if ( $query->param()) { # an action has been chosen 66 66 my $cmd=$query->param("cmd"); 67 my $action = $query->param("action")||'runpugs';67 my $action = $query->param("action")||'runpugs'; 68 68 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); 77 80 } 78 } else { # no action has been taken, display login page79 &runpugs($query,'',$sessionid,$ip);80 }81 81 } else { 82 82 &runpugs($query,'',$sessionid,$ip); -
misc/runpugs/lib/WebTerminal/Server.pm
r14366 r14403 40 40 } else { 41 41 if ( exists $terminals{$id} ) { 42 if ($terminals{$id}->{pid}) { 42 43 $terminals{$id}->{called}=time; 43 44 my $term = $terminals{$id}; … … 45 46 if ( $cmd eq ':q' ) { 46 47 delete $terminals{$id}; 48 my $pid= $terminals{$id}->{pid}; 49 if ($pid) { 50 kill 9,$pid; 51 } 47 52 $sessions_per_ip{$ip}--; 48 53 } 49 54 if ($lines=~/Aborted/s) { 50 55 delete $terminals{$id}; 56 my $pid= $terminals{$id}->{pid}; 57 if ($pid) { 58 kill 9,$pid; 59 } 51 60 $sessions_per_ip{$ip}--; 52 61 } 53 62 return $lines; 63 } else { 64 return "pugs> "; 65 } 54 66 } else { 55 67 if ($sessions_per_ip{$ip}>10) { … … 74 86 ( my $id, my $ip, my $cmd ) = split( "\n", $msg, 3 ); 75 87 $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"; 77 95 my $lines = &termhandler( $id, $ip, $cmd ); 78 96 $conn->send_now("$id\n$lines"); … … 91 109 my $port=shift; 92 110 $SIG{USR1}=\&timeout; 111 my $daemon=0; 112 if ($daemon) { 93 113 Proc::Daemon::Init; 114 } 94 115 # fork/exec by the book: 95 116 use Errno qw(EAGAIN); … … 98 119 if ($pid=fork) { 99 120 #parent here 121 use Cwd; 122 print cwd(); 123 open(LOG,">/home/andara/apache/data/runpugs.log"); 100 124 WebTerminal::Msg->new_server( $host, $port, \&login_proc ); 101 125 WebTerminal::Msg->event_loop(); … … 103 127 # child here 104 128 while (getppid()>10) { # a bit ad-hoc. 105 sleep 300;129 sleep 60; 106 130 #print getppid(),"\n"; 107 131 kill 'USR1',getppid(); 108 132 } 133 sleep 5; 134 system("killall /usr/bin/pugs"); 135 chdir "/home/andara/apache/cgi-bin/"; 136 exec('/usr/bin/perl ../bin/termserv.pl'); 109 137 } elsif ($! == EAGAIN) { 110 138 sleep 5; … … 122 150 if ($now-$then>600) { 123 151 if(exists $terminals{$id}) { 152 my $pid= $terminals{$id}->{pid}; 124 153 my $ip=$terminals{$id}->{ip}; 125 154 $sessions_per_ip{$ip}--; 126 $terminals{$id}->write(':q'); 155 if ($pid) { 156 kill 9,$pid; 157 } 158 # $terminals{$id}->write(':q'); 127 159 delete $terminals{$id}; 128 160 } 129 161 } 130 162 } 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 131 172 } 132 173 -
misc/runpugs/lib/WebTerminal/Server/Terminal.pm
r14366 r14403 9 9 write() sends commands to it. 10 10 =cut 11 11 $SIG{CHLD}='IGNORE'; 12 12 ## Constructor 13 13 sub new { … … 25 25 $self->{'pugs'} = new Net::Telnet( 26 26 -fhopen => $self->{'pty'}, 27 -timeout => 20,27 -timeout => 10, 28 28 -prompt => $prompt, 29 29 -telnetmode => 0, … … 57 57 58 58 $pugs->print($cmd); 59 while ( 1) {59 while ($i<256) { 60 60 my $line = $pugs->getline; 61 61 my $msg=$pugs->errmsg; … … 73 73 $i++; 74 74 } 75 75 if ($i>=255) { 76 kill 9, $obj->{'pid'}; 77 $lline.="Generated output is limited to 100 lines. Aborted.\npugs"; 78 } 76 79 77 80 #$lline .= "\n$ps>";
