#!/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"; print "
\n"; printf "\n", $in{mode}==0 ? "checked" : ""; print &hlink("$text{'search_user'}","suser"),"\n"; printf " %s
\n", $in{mode}==0 ? $in{user} : "", &user_chooser_button("user", 0); printf "\n", $in{mode}==1 ? "checked" : ""; print &hlink("$text{'search_match'}","smatch"),"\n"; printf "
\n", $in{mode}==1 ? $in{match} : ""; printf "\n", $in{mode}==2 ? "checked" : ""; $cpu = sprintf "\n", $in{mode}==2 ? $in{cpu} : ""; print &hlink("".&text('search_cpupc', $cpu)."", "scpu"),"
\n"; print "
\n"; if ($has_fuser_command) { printf "\n", $in{mode}==3 ? "checked" : ""; print &hlink("$text{'search_fs'}","sfs"),"\n"; if (&foreign_check("mount")) { &foreign_require("mount", "mount-lib.pl"); print "
\n"; } else { printf "
\n", $in{'mode'}==3 ? $in{'fs'} : ""; } printf "\n", $in{mode}==4 ? "checked" : ""; print &hlink("$text{'search_files'}","sfiles"),"\n"; printf "\n", $in{mode}==4 ? $in{'files'} : ""; print &file_chooser_button("files", 0); print "
\n"; } if ($has_lsof_command) { # Show input for file in use printf "\n", $in{mode}==5 ? "checked" : ""; print &hlink("$text{'search_port'}","ssocket"),"\n"; printf "\n", $in{mode}==5 ? $in{port} : ""; # Show input for protocol and port print &hlink("$text{'search_protocol'}","ssocket"),"\n"; print "\n"; print "
\n"; # Show input for IP address printf "\n", $in{mode}==6 ? "checked" : ""; print &hlink("$text{'search_ip'}","sip"),"\n"; printf "\n", $in{mode}==6 ? $in{ip} : ""; } print "
\n"; print "\n"; print " " x 5; printf " %s
\n", $in{'ignore'} || !defined($in{'mode'}) ? 'checked' : '', &hlink("$text{'search_ignore'}","signore"); 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"; print "\n"; printf "\n", join(" ", @pidlist); print "\n"; foreach $s ('KILL', 'TERM', 'HUP', 'STOP', 'CONT') { printf "\n", $text{"kill_".lc($s)}, $s; } print "
\n"; } elsif (@pidlist && $access{'edit'}) { # display form for mass killing with any signal print "
\n"; print "\n"; print "\n"; printf "\n", join(" ", @pidlist); print "\n"; print " " x 2; print "\n"; print " " x 2; print "\n"; print "
\n"; } } &ui_print_footer("/", $text{'index'});