3 # Run a command, and maybe display it's output
5 require './proc-lib.pl';
7 $access{'run'} || &error($text{'run_ecannot'});
9 # Force run as user from ACL. This is done instead of calling
10 # switch_acl_uid, so that commands can be run with su
11 if (!$module_info{'usermin'}) {
12 if ($access{'uid'} < 0) {
13 $in{'user'} = $remote_user;
15 elsif ($access{'uid'}) {
16 $in{'user'} = getpwuid($access{'uid'});
20 $in{'input'} =~ s/\r//g;
22 if (&supports_users()) {
23 defined(getpwnam($in{'user'})) || &error($text{'run_euser'});
24 &can_edit_process($in{'user'}) || &error($text{'run_euser2'});
25 if ($in{'user'} ne getpwuid($<)) {
26 $cmd = &command_as_user($in{'user'}, 0, $cmd);
32 if (!($pid = fork())) {
33 close(STDIN); close(STDOUT); close(STDERR);
34 &open_execute_command(PROC, "($cmd)", 0);
35 print PROC $in{'input'};
39 &redirect("index_tree.cgi");
42 # run and display output..
43 &ui_print_unbuffered_header(undef, $text{'run_title'}, "");
45 print &text('run_output', "<tt>$in{'cmd'}</tt>"),"<p>\n";
47 $got = &safe_process_exec_logged($cmd, 0, 0,
48 STDOUT, $in{'input'}, 1);
49 if (!$got) { print "<i>$text{'run_none'}</i>\n"; }
51 &ui_print_footer("", $text{'index'});
53 &webmin_log("run", undef, undef, \%in);