Handle hostnames with upper-case letters
[webmin.git] / webmin / update.pl
1 #!/usr/local/bin/perl
2 # update.pl
3 # Find and install updated modules, and email out the result
4
5 $no_acl_check++;
6 require './webmin-lib.pl';
7
8 # Fetch the updates
9 @urls = $config{'upsource'} ? split(/\t+/, $config{'upsource'})
10                             : ( $update_url );
11 foreach $url (@urls) {
12         # Get updates from this URL, and filter to those for this system
13         $checksig = $config{'upchecksig'} ? 2 : $url eq $update_url ? 2 : 1;
14         ($updates, $host, $port, $page, $ssl) =
15                 &fetch_updates($url, $config{'upuser'}, $config{'uppass'},
16                                $checksig);
17         $updates = &filter_updates($updates, undef, $config{'upthird'},
18                                    $config{'upmissing'});
19
20         # Go through the results
21         foreach $u (@$updates) {
22                 # Get module or theme's details
23                 my %minfo = &get_module_info($u->[0]);
24                 my %tinfo = &get_theme_info($u->[0]);
25                 my %info = %minfo ? %minfo : %tinfo;
26
27                 if ($config{'upshow'}) {
28                         # Just tell the user what would be done
29                         $rv .= &text('update_mshow', $u->[0], $u->[1])."\n".
30                                ($info{'longdesc'} ? "$text{'update_fixes'} : " : "").
31                                $u->[4]."\n\n";
32                         }
33                 else {
34                         # Actually do the update ..
35                         my (@mdescs, @mdirs, @msizes);
36                         $rv .= &text('update_mok', $u->[0], $u->[1])."\n".
37                                ($info{'longdesc'} ? "$text{'update_fixes'} : " : "").
38                                $u->[4]."\n\n";
39                         ($mhost, $mport, $mpage, $mssl) =
40                                 &parse_http_url($u->[2], $host, $port, $page, $ssl);
41                         ($mfile = $mpage) =~ s/^(.*)\///;
42                         $mtemp = &transname($mfile);
43                         &http_download($mhost, $mport, $mpage, $mtemp, \$error,
44                                        undef, $mssl,
45                                        $config{'upuser'}, $config{'uppass'});
46                         if ($error) {
47                                 $rv .= "$error\n\n";
48                                 last;
49                                 }
50                         else {
51                                 $irv = &check_update_signature(
52                                   $mhost, $mport, $mpage,
53                                   $mssl, $config{'upuser'}, $config{'uppass'},
54                                   $mtemp, $checksig);
55                                 $irv ||= &install_webmin_module($mtemp, 1, 0,
56                                                       [ "admin", "root" ]);
57                                 if (!ref($irv)) {
58                                         $irv =~ s/<[^>]*>//g;
59                                         $rv .= &text('update_failed', $irv)."\n\n";
60                                         }
61                                 else {
62                                         $rv .= &text('update_mdesc', $irv->[0]->[0],
63                                                       $irv->[2]->[0])."\n\n";
64                                         }
65                                 }
66                         }
67                 }
68         }
69
70 # Check if a new version of webmin itself is available
71 $version = &get_latest_webmin_version();
72 if ($version > &get_webmin_version()) {
73         $rv .= &text('update_version', $version)."\n";
74         }
75
76 # Send off a results email
77 if ($config{'upemail'} && $rv && &foreign_check("mailboxes")) {
78         # Construct and send the email
79         &foreign_require("mailboxes", "mailboxes-lib.pl");
80         my $data;
81         my $type = $gconfig{'real_os_type'} || $gconfig{'os_type'};
82         my $version = $gconfig{'real_os_version'} || $gconfig{'os_version'};
83         my $myhost = &get_system_hostname();
84         $data .= "$myhost ($type $version)\n\n";
85         $data .= &text('update_rv', "http://$host:$port$page")."\n\n";
86         $data .= $rv;
87         &mailboxes::send_text_mail(&mailboxes::get_from_address(),
88                                    $config{'upemail'},
89                                    undef,
90                                    $text{'update_subject'},
91                                    $data);
92         }
93