Handle hostnames with upper-case letters
[webmin.git] / proc / run.cgi
1 #!/usr/local/bin/perl
2 # run.cgi
3 # Run a command, and maybe display it's output
4
5 require './proc-lib.pl';
6 &ReadParse();
7 $access{'run'} || &error($text{'run_ecannot'});
8
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;
14                 }
15         elsif ($access{'uid'}) {
16                 $in{'user'} = getpwuid($access{'uid'});
17                 }
18         }
19
20 $in{'input'} =~ s/\r//g;
21 $cmd = $in{'cmd'};
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);
27                 }
28         }
29
30 if ($in{'mode'}) {
31         # fork and run..
32         if (!($pid = fork())) {
33                 close(STDIN); close(STDOUT); close(STDERR);
34                 &open_execute_command(PROC, "($cmd)", 0);
35                 print PROC $in{'input'};
36                 close(PROC);
37                 exit;
38                 }
39         &redirect("index_tree.cgi");
40         }
41 else {
42         # run and display output..
43         &ui_print_unbuffered_header(undef, $text{'run_title'}, "");
44         print "<p>\n";
45         print &text('run_output', "<tt>$in{'cmd'}</tt>"),"<p>\n";
46         print "<pre>";
47         $got = &safe_process_exec_logged($cmd, 0, 0,
48                                          STDOUT, $in{'input'}, 1);
49         if (!$got) { print "<i>$text{'run_none'}</i>\n"; }
50         print "</pre>\n";
51         &ui_print_footer("", $text{'index'});
52         }
53 &webmin_log("run", undef, undef, \%in);
54