Handle hostnames with upper-case letters
[webmin.git] / software / rhn_check.cgi
1 #!/usr/local/bin/perl
2 # rhn_check.cgi
3 # Save redhat network checking options
4
5 require './software-lib.pl';
6 &ReadParse();
7 &foreign_require("init", "init-lib.pl");
8 &error_setup($text{'rhn_err'});
9 $conf = &read_up2date_config();
10
11 # Validate inputs
12 $in{'interval'} =~ /^\d+$/ || &error($text{'rhn_einterval'});
13 $in{'interval'} >= 120 || &error($text{'rhn_einterval2'});
14 !$in{'proxy_on'} && $in{'proxy'} eq '' ||
15         $in{'proxy'} =~ /^http:\/\/\S+$/ || &error($text{'rhn_eproxy'});
16 @skip = split(/\s+/, $in{'skip'});
17
18 # Save and apply
19 &save_up2date_config($conf, "enableProxy", $in{'proxy_on'});
20 &save_up2date_config($conf, $conf->{'pkgProxy[comment]'} ? "pkgProxy" : "httpProxy", $in{'proxy'});
21 &save_up2date_config($conf, "pkgSkipList", join(";", @skip).";");
22 &flush_file_lines();
23 &read_env_file($rhn_sysconfig, \%rhnsd);
24 $rhnsd{'INTERVAL'} = $in{'interval'};
25 &write_env_file($rhn_sysconfig, \%rhnsd);
26 if ($in{'auto'}) {
27         &init::enable_at_boot("rhnsd");
28         }
29 else {
30         &init::disable_at_boot("rhnsd");
31         }
32 local $init = &init::action_filename("rhnsd");
33 &system_logged("$init stop >/dev/null 2>&1");
34 if ($in{'auto'}) {
35         &system_logged("$init start >/dev/null 2>&1");
36         }
37
38 if ($in{'now'}) {
39         # Run rhn_check now ..
40         &ui_print_unbuffered_header(undef, $text{'rhn_check'}, "");
41
42         print "<b>",&text('rhn_checkdesc', "<tt>up2date -u</tt>"),"</b><p>\n";
43         print "<pre>";
44         &additional_log('exec', undef, "rhn_check");
45         open(CMD, "up2date -u 2>&1 |");
46         while(<CMD>) {
47                 while(s/^[^\015]+\015([^\012])/$1/) { }
48                 if (/\/([^\/\s]+)\-([^\-]+)\-([^\-]+)\.rpm/i) {
49                         push(@packs, $1);
50                         }
51                 print;
52                 }
53         close(CMD);
54         print "</pre>\n";
55
56         @packs || print "<b>$text{'rhn_nocheck'}</b><p>\n";
57         foreach $p (@packs) {
58                 local @pinfo = &show_package_info($p);
59                 }
60         &webmin_log("rhn", "check", undef, { 'packages' => \@packs })
61                 if (@packs);
62
63         &ui_print_footer("", $text{'index_return'});
64         }
65 else {
66         &redirect("");
67         }
68