测试基本上和我想得一样。方法是修改webmin里面的lib一类的文件,把html相关的地方修改成xml,然后返回。也就是说,基本上还是webmin的代码,修改一下print里面的东西。我想找个本科生一个个改就OK的。以下是测试代码,有兴趣的朋友,可以联系我,我们一起把这个项目放到sourceforge上。
#!/usr/bin/perl
use XMLRPC::Transport::HTTP;
use Time::Local;
XMLRPC::Transport::HTTP::CGI
-> dispatch_to('Process')
-> handle;
package Process;
sub ListProcesses {
my ($self) = @_;
@procs = sort { $b->{'cpu'} <=> $a->{'cpu'} } &list_processes();
@procs = grep { !$hide{$_->{'user'}} } @procs;
@procs = grep { $_->{'user'} eq $remote_user } @procs if ($user_processes_only);
$x = "<processes>\n";
foreach $pr (@procs) {
$p = $pr->{'pid'};
$x .= "<proc>\n";
$x .= "<pid>$p</pid>\n";
$x .= "<user>$pr->{'user'}</user>\n";
$x .= "<cpu>$pr->{'cpu'}</cpu>\n";
$x .= "</proc>\n";
}
$x .= "</processes>\n";
return $x ;
};
sub list_processes
{
local($pcmd, $line, $i, %pidmap, @plist, $dummy, @w, $_);
local $out = `ps V`;
if ($out =~ /version\s+(\d+)\./ && $1 >= 2 || $out =~ /version\s+\./) {
# New version of ps, as found in redhat 6
open(PS, "ps --cols 500 -eo user,ruser,group,rgroup,pid,ppid,pgid,pcpu,vsz,nice,etime,time,stime,tty,args 2>/dev/null |");
$dummy = <PS>;
for($i=0; $line=<PS>; $i++) {
chop($line);
$line =~ s/^\s+//g;
eval { @w = split(/\s+/, $line, -1); };
if ($@) {
# Hit a split loop
$i--; next;
}
if ($line =~ /ps -o user,ruser/) {
# Skip process ID 0 or ps command
$i--; next;
}
if (@_ && &indexof($w[4], @_) < 0) {
# Not interested in this PID
$i--; next;
}
$plist[$i]->{"pid"} = $w[4];
$plist[$i]->{"ppid"} = $w[5];
$plist[$i]->{"user"} = $w[0];
$plist[$i]->{"cpu"} = "$w[7] %";
$plist[$i]->{"size"} = "$w[8] kB";
$plist[$i]->{"time"} = $w[11];
$plist[$i]->{"_stime"} = $w[12];
$plist[$i]->{"nice"} = $w[9];
$plist[$i]->{"args"} = @w<15 ? "defunct" : join(' ', @w[14..$#w]);
$plist[$i]->{"_group"} = $w[2];
$plist[$i]->{"_ruser"} = $w[1];
$plist[$i]->{"_rgroup"} = $w[3];
$plist[$i]->{"_pgid"} = $w[6];
$plist[$i]->{"_tty"} = $w[13] =~ /\?/ ? $text{'edit_none'} : "/dev/$w[12]";
}
close(PS);
}
return @plist;
}