3 # Run some command with the given parameters
5 require './custom-lib.pl';
7 if ($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data/i) {
8 &ReadParse(\%getin, "GET");
9 &ReadParseMime(undef, \&read_parse_mime_callback, [ $getin{'id'} ]);
15 &error_setup($text{'run_err'});
16 $cmd = &get_command($in{'id'}, $in{'idx'});
17 &can_run_command($cmd) || &error($text{'run_ecannot'});
18 if (&supports_users()) {
19 $user = $cmd->{'user'} eq '*' ? $remote_user : $cmd->{'user'};
20 @user_info = getpwnam($user);
21 @user_info || &error(&text('run_ecmduser', $user));
24 @user_info = ( "root", undef, 0, 0 );
27 # substitute parameters into command
28 ($env, $export, $str, $displaystr) = &set_parameter_envs(
29 $cmd, $cmd->{'cmd'}, \@user_info);
32 @hosts = @{$cmd->{'hosts'}};
33 @hosts = ( 0 ) if (!@hosts);
34 @servers = &list_servers();
36 # Run and display output
37 if ($cmd->{'format'} ne 'redirect') {
38 if ($cmd->{'format'}) {
39 print "Content-type: ",$cmd->{'format'},"\n";
43 &ui_print_unbuffered_header($cmd->{'desc'}, $text{'run_title'},
44 "", -d "help" ? "run" : undef);
48 &remote_error_setup(\&remote_custom_handler);
51 ($server) = grep { $_->{'id'} eq $h } @servers;
53 $txt = $cmd->{'noshow'} ? 'run_out2' : 'run_out';
54 if (@{$cmd->{'hosts'}}) {
57 if (!$cmd->{'format'}) {
58 print &text($txt, "<tt>".&html_escape($displaystr)."</tt>",
59 $server->{'desc'} || "<tt>$server->{'host'}</tt>"),"\n";
60 print "<pre>" if (!$cmd->{'raw'});
62 $remote_custom_error = undef;
65 ($got, $out, $timeout) = &execute_custom_command(
66 $cmd, $env, $export, $str,
67 $cmd->{'format'} ne 'redirect');
71 &remote_foreign_require($server->{'host'}, "custom",
73 &remote_foreign_call($server->{'host'}, "custom",
74 "set_parameter_envs", $cmd, $cmd->{'cmd'},
75 \@user_info, \%in, 1);
76 ($got, $out, $timeout) = &remote_foreign_call(
77 $server->{'host'}, "custom", "execute_custom_command",
78 $cmd, $env, $export, $str);
81 &additional_log('exec', undef, $displaystr);
83 if (!$remote_custom_error) {
84 print $out if ($h != 0 && $cmd->{'format'} ne 'redirect');
85 if (!$got && !$cmd->{'format'}) {
86 print "<i>$text{'run_noout'}</i>\n";
90 if (!$cmd->{'format'}) {
91 print "</pre>\n" if (!$cmd->{'raw'});
92 if ($remote_custom_error) {
93 print "<b>$remote_custom_error</b><p>\n";
96 print "<b>",&text('run_timeout',
97 $cmd->{'timeout'}),"</b><p>\n";
101 # Only log non-upload inputs
103 foreach $i (keys %in) {
104 ($arg) = grep { $_->{'name'} eq $i } @{$cmd->{'args'}};
105 if ($arg->{'type'} != 10) {
106 $cmdin{$i} = $in{$i};
110 &webmin_log("exec", "command", $cmd->{'id'}, \%cmdin);
111 unlink(@unlink) if (@unlink);
112 if (!$cmd->{'format'}) {
113 &ui_print_footer("", $text{'index_return'});
115 elsif ($cmd->{'format'} eq 'redirect') {
119 sub remote_custom_handler
121 $remote_custom_error = join("", @_);