Webmin-RPC 改造可行性证明

<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog01.html" frameborder="0" width="728" scrolling="no" height="90"></iframe>
测试基本上和我想得一样。方法是修改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";<br>foreach $pr (@procs) {<br>$p = $pr-&gt;{'pid'};<br> $x .= "<proc>\n";<br>$x .= "<pid>$p</pid>\n";<br>$x .= "<user>$pr-&gt;{'user'}</user>\n";<br>$x .= "<cpu>$pr-&gt;{'cpu'}</cpu>\n";<br> $x .= "</proc>\n";<br>}<br>$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>;<br>for($i=0; $line=<ps>; $i++) {<br>chop($line);<br>$line =~ s/^\s+//g;<br>eval { @w = split(/\s+/, $line, -1); };<br>if ($@) {<br># Hit a split loop<br>$i--; next;<br>}<br>if ($line =~ /ps -o user,ruser/) {<br># Skip process ID 0 or ps command<br>$i--; next;<br>}<br>if (@_ &amp;&amp; &amp;indexof($w[4], @_) # Not interested in this PID<br>$i--; next;<br>}<br>$plist[$i]-&gt;{"pid"} = $w[4];<br>$plist[$i]-&gt;{"ppid"} = $w[5];<br>$plist[$i]-&gt;{"user"} = $w[0];<br>$plist[$i]-&gt;{"cpu"} = "$w[7] %";<br>$plist[$i]-&gt;{"size"} = "$w[8] kB";<br>$plist[$i]-&gt;{"time"} = $w[11];<br>$plist[$i]-&gt;{"_stime"} = $w[12];<br>$plist[$i]-&gt;{"nice"} = $w[9];<br>$plist[$i]-&gt;{"args"} = @w$plist[$i]-&gt;{"_group"} = $w[2];<br>$plist[$i]-&gt;{"_ruser"} = $w[1];<br>$plist[$i]-&gt;{"_rgroup"} = $w[3];<br>$plist[$i]-&gt;{"_pgid"} = $w[6];<br>$plist[$i]-&gt;{"_tty"} = $w[13] =~ /\?/ ? $text{'edit_none'} : "/dev/$w[12]";<br>}<br>close(PS);<br>}<br>return @plist;<br>}</ps></ps>


Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=477952


你可能感兴趣的:(xml,.net,redhat,cgi,perl)