#!/usr/local/bin/perl # index_search.cgi # Allows searching for processes by user or command require './proc-lib.pl'; &ui_print_header(undef, $text{'index_title'}, "", "search", !$no_module_config, 1); &ReadParse(); &index_links("search"); # display search form print "
\n"; if (%in) { # search for processes @procs = &list_processes(); @procs = grep { &can_view_process($_->{'user'}) } @procs; if ($in{mode} == 0) { # search by user @dis = grep { $_->{'user'} eq $in{'user'} } @procs; } elsif ($in{mode} == 1) { # search by regexp @dis = grep { $_->{'args'} =~ /\Q$in{match}\E/i } @procs; } elsif ($in{mode} == 2) { # search by cpu @dis = grep { $_->{'cpu'} > $in{'cpu'} } @procs; @dis = sort { $b->{'cpu'} <=> $a->{'cpu'} } @dis; } elsif ($in{mode} == 3 && $has_fuser_command) { # search by filesystem foreach $p (&find_mount_processes($in{'fs'})) { $using{$p}++; } @dis = grep { defined($using{$_->{'pid'}}) } @procs; } elsif ($in{mode} == 4 && $has_fuser_command) { # search by files foreach $p (&find_file_processes(split(/\s+/, $in{'files'}))) { $using{$p}++; } @dis = grep { defined($using{$_->{'pid'}}) } @procs; } elsif ($in{mode} == 5 && $has_lsof_command) { foreach $p (&find_socket_processes($in{'protocol'},$in{'port'})) { $using{$p}++; } @dis = grep { defined($using{$_->{'pid'}}) } @procs; } elsif ($in{mode} == 6 && $has_lsof_command) { foreach $p (&find_ip_processes($in{'ip'})) { $using{$p}++; } @dis = grep { defined($using{$_->{'pid'}}) } @procs; } if ($in{'ignore'}) { # Ignore this process and any children @dis = grep { $_->{'pid'} != $$ && $_->{'ppid'} != $$ } @dis; } # display matches if (@dis) { print &ui_columns_start([ $text{'pid'}, $text{'owner'}, $text{'cpu'}, $info_arg_map{'_stime'} ? ( $text{'stime'} ) : ( ), $text{'command'} ], 100); foreach $d (@dis) { $p = $d->{'pid'}; push(@pidlist, $p); local @cols; if (&can_edit_process($d->{'user'})) { push(@cols, "$p"); } else { push(@cols, $p); } push(@cols, $d->{user}); push(@cols, $d->{cpu}); if ($info_arg_map{'_stime'}) { push(@cols, $d->{'_stime'}); } push(@cols, &html_escape(cut_string($d->{args}))); print &ui_columns_row(\@cols); } print &ui_columns_end(),"\n"; } else { print "
$text{'search_none'}
\n"; } if (@pidlist && $access{'simple'} && $access{'edit'}) { # display form for mass killing with selected signals print "
\n"; } elsif (@pidlist && $access{'edit'}) { # display form for mass killing with any signal print "\n"; } } &ui_print_footer("/", $text{'index'});