#!/usr/bin/perl # Handles xml-rpc requests from arbitrary clients. Each is a call to a # function in a Webmin module. if (!$ENV{'GATEWAY_INTERFACE'}) { # Command-line mode $no_acl_check++; $ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin"; $ENV{'WEBMIN_VAR'} ||= "/var/webmin"; if ($0 =~ /^(.*\/)[^\/]+$/) { chdir($1); } chop($pwd = `pwd`); $0 = "$pwd/xmlrpc.pl"; $command_line = 1; $> == 0 || die "xmlrpc.cgi must be run as root"; } BEGIN { push(@INC, "."); }; use WebminCore; use POSIX; use Socket; $force_lang = $default_lang; $trust_unknown_referers = 2; # Only trust if referer was not set &init_config(); $main::error_must_die = 1; # Can this user make remote calls? if (!$command_line) { %access = &get_module_acl(); if ($access{'rpc'} == 0 || $access{'rpc'} == 2 && $base_remote_user ne 'admin' && $base_remote_user ne 'root' && $base_remote_user ne 'sysadm') { &error_exit(1, "Invalid user for RPC"); } } # Load the XML parser module eval "use XML::Parser"; if ($@) { &error_exit(2, "XML::Parser Perl module is not installed"); } # Read in the XML my $rawxml; if ($command_line) { # From STDIN while(<STDIN>) { $rawxml .= $_; } } else { # From web client my $clen = $ENV{'CONTENT_LENGTH'}; while(length($rawxml) < $clen) { my $buf; my $got = read(STDIN, $buf, $clen - length($rawxml)); if ($got <= 0) { &error_exit(3, "Failed to read $clen bytes"); } $rawxml .= $buf; } } # Parse the XML my $parser = new XML::Parser('Style' => 'Tree'); my $xml; eval { $xml = $parser->parse($rawxml); }; if ($@) { &error_exit(4, "Invalid XML : $@"); } # Look for the method calls, and invoke each one my $xmlrv = "<?xml version=\"1.0\" encoding=\"$default_charset\"?>\n"; foreach my $mc (&find_xmls("methodCall", $xml)) { # Find the method name and module my ($mn) = &find_xmls("methodName", $mc); $h = $mn->[1]->[0]; my ($mod, $func) = $mn->[1]->[2] =~ /::/ ? split(/::/, $mn->[1]->[2]) : $mn->[1]->[2] =~ /\./ ? split(/\./, $mn->[1]->[2]) : (undef, $mn->[1]->[2]); # Find the parameters my ($params) = &find_xmls("params", $mc); my @params = &find_xmls("param", $params); my @args; foreach my $p (@params) { my ($value) = &find_xmls("value", $p, 1); my $perlv = &parse_xml_value($value); push(@args, $perlv); } # Require the module, if needed if ($mod) { if (!$done_require_module{$mod}) { if (!&foreign_check($mod)) { &error_exit(5, "Webmin module $mod does not exist"); } eval { &foreign_require($mod, $lib); }; if ($@) { $xmlrv .= &make_error_xml(6, "Failed to load module $mod : $@"); last; } } } # Call the function my @rv; if ($func eq "eval") { # Execute some Perl code @rv = eval "$args[0]"; if ($@) { $xmlrv .= &make_error_xml(8, "Eval failed : $@"); } } else { # A real function call eval { @rv = &foreign_call($mod, $func, @args); }; if ($@) { $xmlrv .= &make_error_xml(7, "Function call $func failed : $@"); last; } } # Encode the results $xmlrv .= "<methodResponse>\n"; $xmlrv .= "<params>\n"; $xmlrv .= "<param><value>\n"; if (@rv == 1) { $xmlrv .= &encode_xml_value($rv[0]); } else { $xmlrv .= &encode_xml_value(\@rv); } $xmlrv .= "</value></param>\n"; $xmlrv .= "</params>\n"; $xmlrv .= "</methodResponse>\n"; } # Flush all modified files, as some APIs require a call to this function &flush_file_lines(); # Return results to caller if (!$command_line) { print "Content-type: text/xml\n"; print "Content-length: ",length($xmlrv),"\n"; print "\n"; } print $xmlrv; # parse_xml_value(&value) # Given a <value> object, returns a Perl scalar, hash ref or array ref for # the contents sub parse_xml_value { my ($value) = @_; my ($scalar) = &find_xmls([ "int", "i4", "boolean", "string", "double" ], $value, 1); my ($date) = &find_xmls([ "dateTime.iso8601" ], $value, 1); my ($base64) = &find_xmls("base64", $value, 1); my ($struct) = &find_xmls("struct", $value, 1); my ($array) = &find_xmls("array", $value, 1); if ($scalar) { return $scalar->[1]->[2]; } elsif ($date) { # Need to decode date # XXX format? } elsif ($base64) { # Convert to binary return &decode_base64($base64->[1]->[2]); } elsif ($struct) { # Parse member names and values my %rv; foreach my $member (&find_xmls("member", $struct, 1)) { my ($name) = &find_xmls("name", $member, 1); my ($value) = &find_xmls("value", $member, 1); my $perlv = &parse_xml_value($value); $rv{$name->[1]->[2]} = $perlv; } return \%rv; } elsif ($array) { # Parse data values my @rv; my ($data) = &find_xmls("data", $array, 1); foreach my $value (&find_xmls("value", $data, 1)) { my $perlv = &parse_xml_value($value); push(@rv, $perlv); } return \@rv; } else { # Fallback - just a string directly in the value return $value->[1]->[2]; } } # encode_xml_value(string|int|&hash|&array) # Given a Perl object, returns XML lines representing it for return to a caller sub encode_xml_value { local ($perlv) = @_; if (ref($perlv) eq "ARRAY") { # Convert to array XML format my $xmlrv = "<array>\n<data>\n"; foreach my $v (@$perlv) { $xmlrv .= "<value>\n"; $xmlrv .= &encode_xml_value($v); $xmlrv .= "</value>\n"; } $xmlrv .= "</data>\n</array>\n"; return $xmlrv; } elsif (ref($perlv) eq "HASH") { # Convert to struct XML format my $xmlrv = "<struct>\n"; foreach my $k (keys %$perlv) { $xmlrv .= "<member>\n"; $xmlrv .= "<name>".&html_escape($k)."</name>\n"; $xmlrv .= "<value>\n"; $xmlrv .= &encode_xml_value($perlv->{$k}); $xmlrv .= "</value>\n"; $xmlrv .= "</member>\n"; } $xmlrv .= "</struct>\n"; return $xmlrv; } elsif ($perlv =~ /^\-?\d+$/) { # Return an integer return "<int>$perlv</int>\n"; } elsif ($perlv =~ /^\-?\d*\.\d+$/) { # Return a double return "<double>$perlv</double>\n"; } elsif ($perlv =~ /^[\40-\377]*$/) { # Return a scalar return "<string>".&html_escape($perlv)."</string>\n"; } else { # Contains non-printable characters, so return as base64 return "<base64>".&encode_base64($perlv)."</base64>\n"; } } # find_xmls(name|&names, &config, [depth]) # Returns the XMLs object with some name, by recursively searching the XML sub find_xmls { local ($name, $conf, $depth) = @_; local @m = ref($name) ? @$name : ( $name ); if (&indexoflc($conf->[0], @m) >= 0) { # Found it! return ( $conf ); } else { # Need to recursively scan all sub-elements, except for the first # which is just the tags of this element if (defined($depth) && !$depth) { # Gone too far .. stop return ( ); } local $i; local $list = $conf->[1]; local @rv; for($i=1; $i<@$list; $i+=2) { local @srv = &find_xmls($name, [ $list->[$i], $list->[$i+1] ], defined($depth) ? $depth-1 : undef); push(@rv, @srv); } return @rv; } return ( ); } # error_exit(code, message) # Output an XML error message sub error_exit { my ($code, $msg) = @_; $msg =~ s/\r|\n$//; $msg =~ s/\r|\n/ /g; # Construct error XML my $xmlerr = "<?xml version=\"1.0\"?>\n"; $xmlerr .= &make_error_xml($code, $msg); # Send the error XML if (!$command_line) { print "Content-type: text/xml\n"; print "Content-length: ",length($xmlerr),"\n"; print "\n"; } print $xmlerr; exit($command_line ? $code : 0); } sub make_error_xml { my ($code, $msg) = @_; $xmlerr .= "<methodResponse>\n"; $xmlerr .= "<fault>\n"; $xmlerr .= "<value>\n"; $xmlerr .= &encode_xml_value( { 'faultCode' => $code, 'faultString' => $msg }); $xmlerr .= "</value>\n"; $xmlerr .= "</fault>\n"; $xmlerr .= "</methodResponse>\n"; return $xmlerr; }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
acl | Folder | 0755 |
|
|
adsl-client | Folder | 0755 |
|
|
apache | Folder | 0755 |
|
|
at | Folder | 0755 |
|
|
authentic-theme | Folder | 0755 |
|
|
backup-config | Folder | 0755 |
|
|
bacula-backup | Folder | 0755 |
|
|
bandwidth | Folder | 0755 |
|
|
bin | Folder | 0755 |
|
|
bind8 | Folder | 0755 |
|
|
blue-theme | Folder | 0755 |
|
|
change-user | Folder | 0755 |
|
|
cluster-copy | Folder | 0755 |
|
|
cluster-cron | Folder | 0755 |
|
|
cluster-passwd | Folder | 0755 |
|
|
cluster-shell | Folder | 0755 |
|
|
cluster-software | Folder | 0755 |
|
|
cluster-useradmin | Folder | 0755 |
|
|
cluster-usermin | Folder | 0755 |
|
|
cluster-webmin | Folder | 0755 |
|
|
cpan | Folder | 0755 |
|
|
cron | Folder | 0755 |
|
|
custom | Folder | 0755 |
|
|
dfsadmin | Folder | 0755 |
|
|
dhcpd | Folder | 0755 |
|
|
dovecot | Folder | 0755 |
|
|
exim | Folder | 0755 |
|
|
exports | Folder | 0755 |
|
|
fail2ban | Folder | 0755 |
|
|
fdisk | Folder | 0755 |
|
|
fetchmail | Folder | 0755 |
|
|
filemin | Folder | 0755 |
|
|
filter | Folder | 0755 |
|
|
firewall | Folder | 0755 |
|
|
firewall6 | Folder | 0755 |
|
|
firewalld | Folder | 0755 |
|
|
fsdump | Folder | 0755 |
|
|
gray-theme | Folder | 0755 |
|
|
grub | Folder | 0755 |
|
|
heartbeat | Folder | 0755 |
|
|
htaccess-htpasswd | Folder | 0755 |
|
|
idmapd | Folder | 0755 |
|
|
images | Folder | 0755 |
|
|
inetd | Folder | 0755 |
|
|
init | Folder | 0755 |
|
|
inittab | Folder | 0755 |
|
|
ipfilter | Folder | 0755 |
|
|
ipfw | Folder | 0755 |
|
|
ipsec | Folder | 0755 |
|
|
iscsi-client | Folder | 0755 |
|
|
iscsi-server | Folder | 0755 |
|
|
iscsi-target | Folder | 0755 |
|
|
iscsi-tgtd | Folder | 0755 |
|
|
jabber | Folder | 0755 |
|
|
krb5 | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
ldap-client | Folder | 0755 |
|
|
ldap-server | Folder | 0755 |
|
|
ldap-useradmin | Folder | 0755 |
|
|
logrotate | Folder | 0755 |
|
|
logviewer | Folder | 0755 |
|
|
lpadmin | Folder | 0755 |
|
|
lvm | Folder | 0755 |
|
|
mailboxes | Folder | 0755 |
|
|
mailcap | Folder | 0755 |
|
|
man | Folder | 0755 |
|
|
mon | Folder | 0755 |
|
|
mount | Folder | 0755 |
|
|
mysql | Folder | 0755 |
|
|
net | Folder | 0755 |
|
|
nis | Folder | 0755 |
|
|
openslp | Folder | 0755 |
|
|
package-updates | Folder | 0755 |
|
|
pam | Folder | 0755 |
|
|
pap | Folder | 0755 |
|
|
passwd | Folder | 0755 |
|
|
phpini | Folder | 0755 |
|
|
postfix | Folder | 0755 |
|
|
postgresql | Folder | 0755 |
|
|
ppp-client | Folder | 0755 |
|
|
pptp-client | Folder | 0755 |
|
|
pptp-server | Folder | 0755 |
|
|
proc | Folder | 0755 |
|
|
procmail | Folder | 0755 |
|
|
proftpd | Folder | 0755 |
|
|
qmailadmin | Folder | 0755 |
|
|
quota | Folder | 0755 |
|
|
raid | Folder | 0755 |
|
|
samba | Folder | 0755 |
|
|
sarg | Folder | 0755 |
|
|
sendmail | Folder | 0755 |
|
|
servers | Folder | 0755 |
|
|
shell | Folder | 0755 |
|
|
shorewall | Folder | 0755 |
|
|
shorewall6 | Folder | 0755 |
|
|
smart-status | Folder | 0755 |
|
|
smf | Folder | 0755 |
|
|
software | Folder | 0755 |
|
|
spam | Folder | 0755 |
|
|
squid | Folder | 0755 |
|
|
sshd | Folder | 0755 |
|
|
status | Folder | 0755 |
|
|
stunnel | Folder | 0755 |
|
|
syslog | Folder | 0755 |
|
|
syslog-ng | Folder | 0755 |
|
|
system-status | Folder | 0755 |
|
|
tcpwrappers | Folder | 0755 |
|
|
time | Folder | 0755 |
|
|
tunnel | Folder | 0755 |
|
|
unauthenticated | Folder | 0755 |
|
|
updown | Folder | 0755 |
|
|
useradmin | Folder | 0755 |
|
|
usermin | Folder | 0755 |
|
|
vendor_perl | Folder | 0755 |
|
|
vgetty | Folder | 0755 |
|
|
webalizer | Folder | 0755 |
|
|
webmin | Folder | 0755 |
|
|
webmincron | Folder | 0755 |
|
|
webminlog | Folder | 0755 |
|
|
wuftpd | Folder | 0755 |
|
|
xinetd | Folder | 0755 |
|
|
xterm | Folder | 0755 |
|
|
LICENCE | File | 1.48 KB | 0644 |
|
LICENCE.ja | File | 1.62 KB | 0644 |
|
README.md | File | 4.25 KB | 0644 |
|
WebminCore.pm | File | 7.85 KB | 0644 |
|
acl_security.pl | File | 4.51 KB | 0755 |
|
changepass.pl | File | 868 B | 0755 |
|
chooser.cgi | File | 7.21 KB | 0755 |
|
config-aix | File | 227 B | 0644 |
|
config-cobalt-linux | File | 264 B | 0644 |
|
config-coherent-linux | File | 264 B | 0644 |
|
config-corel-linux | File | 264 B | 0644 |
|
config-debian-linux | File | 264 B | 0644 |
|
config-freebsd | File | 256 B | 0644 |
|
config-generic-linux | File | 264 B | 0644 |
|
config-gentoo-linux | File | 264 B | 0644 |
|
config-hpux | File | 243 B | 0644 |
|
config-irix | File | 284 B | 0644 |
|
config-lib.pl | File | 10.82 KB | 0755 |
|
config-macos | File | 260 B | 0644 |
|
config-mandrake-linux | File | 278 B | 0644 |
|
config-msc-linux | File | 264 B | 0644 |
|
config-netbsd | File | 283 B | 0644 |
|
config-open-linux | File | 264 B | 0644 |
|
config-openbsd | File | 241 B | 0644 |
|
config-openmamba-linux | File | 264 B | 0644 |
|
config-openserver | File | 236 B | 0644 |
|
config-osf1 | File | 266 B | 0644 |
|
config-pardus-linux | File | 264 B | 0644 |
|
config-redhat-linux | File | 264 B | 0644 |
|
config-slackware-linux | File | 280 B | 0644 |
|
config-sol-linux | File | 264 B | 0644 |
|
config-solaris | File | 417 B | 0644 |
|
config-suse-linux | File | 264 B | 0644 |
|
config-syno-linux | File | 364 B | 0644 |
|
config-trustix-linux | File | 264 B | 0644 |
|
config-turbo-linux | File | 264 B | 0644 |
|
config-united-linux | File | 264 B | 0644 |
|
config-unixware | File | 286 B | 0644 |
|
config-windows | File | 88 B | 0644 |
|
config.cgi | File | 1.55 KB | 0755 |
|
config_save.cgi | File | 1.64 KB | 0755 |
|
copyconfig.pl | File | 4.33 KB | 0755 |
|
create-module.pl | File | 3.82 KB | 0755 |
|
date_chooser.cgi | File | 2.19 KB | 0755 |
|
deb-name | File | 7 B | 0644 |
|
defaultacl | File | 98 B | 0644 |
|
defaulttheme | File | 16 B | 0644 |
|
entities_map.txt | File | 1.47 KB | 0644 |
|
fastrpc.cgi | File | 10.18 KB | 0755 |
|
favicon.ico | File | 14.73 KB | 0644 |
|
feedback.cgi | File | 6.37 KB | 0755 |
|
feedback_form.cgi | File | 3.45 KB | 0755 |
|
group_chooser.cgi | File | 7.36 KB | 0755 |
|
help.cgi | File | 2.94 KB | 0755 |
|
index.cgi | File | 5.61 KB | 0755 |
|
install-module.pl | File | 1.54 KB | 0755 |
|
install-type | File | 4 B | 0644 |
|
javascript-lib.pl | File | 14.69 KB | 0755 |
|
lang_list.txt | File | 3.41 KB | 0644 |
|
maketemp.pl | File | 424 B | 0755 |
|
mime.types | File | 12.42 KB | 0644 |
|
miniserv.pem | File | 2.9 KB | 0644 |
|
miniserv.pl | File | 179.71 KB | 0755 |
|
module_chooser.cgi | File | 4.14 KB | 0755 |
|
newmods.pl | File | 1.25 KB | 0755 |
|
os_list.txt | File | 34.18 KB | 0644 |
|
oschooser.pl | File | 4.55 KB | 0755 |
|
pam_login.cgi | File | 2.83 KB | 0755 |
|
password_change.cgi | File | 7 KB | 0755 |
|
password_form.cgi | File | 1.3 KB | 0755 |
|
perlpath.pl | File | 571 B | 0755 |
|
record-failed.pl | File | 503 B | 0755 |
|
record-login.pl | File | 513 B | 0755 |
|
record-logout.pl | File | 516 B | 0755 |
|
robots.txt | File | 26 B | 0644 |
|
rpc.cgi | File | 4 KB | 0755 |
|
run-postinstalls.pl | File | 1 KB | 0755 |
|
run-uninstalls.pl | File | 1004 B | 0755 |
|
safeacl | File | 44 B | 0644 |
|
session_login.cgi | File | 3.55 KB | 0755 |
|
setup-repos.sh | File | 4.66 KB | 0755 |
|
setup.bat | File | 3.09 KB | 0644 |
|
setup.pl | File | 30.33 KB | 0755 |
|
setup.sh | File | 32.06 KB | 0755 |
|
switch_skill.cgi | File | 293 B | 0755 |
|
switch_user.cgi | File | 404 B | 0755 |
|
thirdparty.pl | File | 1.73 KB | 0755 |
|
ui-lib.pl | File | 82.8 KB | 0755 |
|
update-from-repo.sh | File | 14.8 KB | 0755 |
|
uptracker.cgi | File | 2.88 KB | 0755 |
|
user_chooser.cgi | File | 7.29 KB | 0755 |
|
version | File | 6 B | 0644 |
|
web-lib-funcs.pl | File | 356.13 KB | 0755 |
|
web-lib.pl | File | 907 B | 0755 |
|
webmin-daemon | File | 80 B | 0644 |
|
webmin-init | File | 1.93 KB | 0755 |
|
webmin-pam | File | 101 B | 0644 |
|
webmin-search-lib.pl | File | 9.42 KB | 0755 |
|
webmin-systemd | File | 371 B | 0644 |
|
webmin_search.cgi | File | 2.63 KB | 0755 |
|
xmlrpc.cgi | File | 7.53 KB | 0755 |
|