Handle hostnames with upper-case letters
[webmin.git] / fetchmail / check.cgi
1 #!/usr/local/bin/perl
2 # check.cgi
3 # Run a fetchmail config file
4
5 require './fetchmail-lib.pl';
6 &ReadParse();
7
8 if ($config{'config_file'}) {
9         $file = $config{'config_file'};
10         }
11 else {
12         &can_edit_user($in{'user'}) || &error($text{'poll_ecannot'});
13         @uinfo = getpwnam($in{'user'});
14         $file = "$uinfo[7]/.fetchmailrc";
15         $uheader = &text('poll_foruser', "<tt>$in{'user'}</tt>");
16         }
17
18 &ui_print_unbuffered_header($uheader, $text{'check_title'}, "");
19
20 $cmd = "$config{'fetchmail_path'} -v -f '$file'";
21 if ($config{'mda_command'}) {
22         $cmd .= " -m '$config{'mda_command'}'";
23         }
24 if (defined($in{'idx'})) {
25         @conf = &parse_config_file($file);
26         $poll = $conf[$in{'idx'}];
27         $cmd .= " $poll->{'poll'}";
28         }
29
30 print &text('check_exec', "<tt>$cmd</tt>"),"<p>\n";
31 print "<pre>";
32 if ($< == 0) {
33         # For webmin, switch to the user
34         if ($in{'user'} ne 'root') {
35                 $cmd = &command_as_user($in{'user'}, 0, $cmd)
36                 }
37         open(CMD, "$cmd 2>&1 |");
38         &additional_log("exec", undef, "su '$in{'user'}' -c '$cmd'");
39         }
40 else {
41         # For usermin, which has already switched
42         open(CMD, "$cmd 2>&1 |");
43         }
44 while(<CMD>) {
45         print &html_escape($_);
46         }
47 close(CMD);
48 print "</pre>\n";
49
50 if ($? > 256) { print "<b>$text{'check_failed'}</b> <p>\n"; }
51 else { print "$text{'check_ok'} <p>\n"; }
52
53 &webmin_log("check", defined($in{'idx'}) ? "server" : "file",
54             $config{'config_file'} ? $file : $in{'user'}, $poll);
55
56 if (!$fetchmail_config && $config{'view_mode'}) {
57         &ui_print_footer("edit_user.cgi?user=$in{'user'}", $text{'user_return'},
58                          "", $text{'index_return'});
59         }
60 else {
61         &ui_print_footer("", $text{'index_return'});
62         }
63