Handle hostnames with upper-case letters
[webmin.git] / package-updates / index.cgi
1 #!/usr/local/bin/perl
2 # Show installed packages, and flag those for which an update is needed
3
4 require './package-updates-lib.pl';
5 &ui_print_header(undef, $module_info{'desc'}, "", undef, 1, 1);
6 &error_setup($text{'index_err'});
7 &ReadParse();
8 if ($in{'clear'}) {
9         $in{'search'} = '';
10         }
11
12 # See if any security updates exist
13 $in{'mode'} ||= 'updates';
14 @avail = &list_for_mode($in{'mode'}, 0);
15 ($sec) = grep { $_->{'security'} } @avail;
16
17 # Show mode selector (all, updates only, updates and new)
18 @grid = ( );
19 foreach $m ('current', 'updates', 'new',
20             $sec ? ( 'security' ) : ( )) {
21         $mmsg = $text{'index_mode_'.$m};
22         if ($in{'mode'} eq $m) {
23                 push(@mlinks, "<b>$mmsg</b>");
24                 }
25         else {
26                 push(@mlinks, "<a href='index.cgi?mode=$m&all=".
27                               &urlize($in{'all'})."&search=".
28                               &urlize($in{'search'})."'>$mmsg</a>");
29                 }
30         }
31 push(@grid, $text{'index_mode'}, &ui_links_row(\@mlinks));
32
33 # Show search box
34 push(@grid, $text{'index_search'}, &ui_textbox("search", $in{'search'}, 30)." ".
35                                    &ui_submit($text{'index_searchok'})." ".
36                                    &ui_submit($text{'index_clear'}, 'clear'));
37
38 print &ui_form_start("index.cgi");
39 print &ui_hidden("mode", $in{'mode'});
40 print &ui_grid_table(\@grid, 2),"<p>\n";
41 print &ui_form_end();
42
43 # Work out what packages to show
44 @current = &list_current(1);
45
46 # Make lookup hashes
47 %current = map { $_->{'name'}."/".$_->{'system'}, $_ } @current;
48 %avail = map { $_->{'name'}."/".$_->{'system'}, $_ } @avail;
49
50 # Build table
51 $anysource = 0;
52 foreach $p (sort { $a->{'name'} cmp $b->{'name'} } (@current, @avail)) {
53         next if ($done{$p->{'name'},$p->{'system'}}++); # May be in both lists
54
55         # Work out the status
56         $c = $current{$p->{'name'}."/".$p->{'system'}};
57         $a = $avail{$p->{'name'}."/".$p->{'system'}};
58
59         if ($a && $c && &compare_versions($a, $c) > 0) {
60                 # An update is available
61                 $msg = "<b><font color=#00aa00>".
62                        &text('index_new', $a->{'version'})."</font></b>";
63                 $need = 1;
64                 next if ($in{'mode'} eq 'security' && !$a->{'security'});
65                 next if ($in{'mode'} ne 'updates' &&
66                          $in{'mode'} ne 'current' &&
67                          $in{'mode'} ne 'security');
68                 }
69         elsif ($a && !$c) {
70                 # Could be installed, but isn't currently
71                 next if (!&installation_candiate($a));
72                 $msg = "<font color=#00aa00>$text{'index_caninstall'}</font>";
73                 $need = 0;
74                 next if ($in{'mode'} ne 'new');
75                 }
76         elsif (!$a->{'version'} && $c->{'updateonly'}) {
77                 # No update exists, and we don't care unless there is one
78                 next;
79                 }
80         elsif (!$a->{'version'}) {
81                 # No update exists
82                 $msg = "<font color=#ffaa00><b>".
83                         &text('index_noupdate', $c->{'version'})."</b></font>";
84                 $need = 0;
85                 next if ($in{'mode'} ne 'current');
86                 }
87         else {
88                 # We have the latest
89                 $msg = &text('index_ok', $c->{'version'});
90                 $need = 0;
91                 next if ($in{'mode'} ne 'current');
92                 }
93         $source = ucfirst($a->{'source'});
94         if ($a->{'security'}) {
95                 $source = "<font color=#ff0000>$source</font>";
96                 }
97
98         # If searching, limit to search
99         if ($in{'search'}) {
100                 $re = $in{'search'};
101                 $found = $p->{'desc'} =~ /\Q$re\E/i ||
102                          $p->{'name'} =~ /\Q$re\E/i ||
103                          $p->{'version'} =~ /\Q$re\E/i;
104                 next if (!$found);
105                 }
106
107         # Add to table
108         push(@rows, [
109                 { 'type' => 'checkbox', 'name' => 'u',
110                   'value' => $p->{'update'}."/".$p->{'system'},
111                   'checked' => $need },
112                 "<a href='view.cgi?mode=$in{'mode'}&name=".
113                   &urlize($p->{'name'})."&system=".
114                   &urlize($p->{'system'})."&search=".
115                   &urlize($in{'search'})."'>$p->{'name'}</a>",
116                 $p->{'desc'},
117                 $msg,
118                 $source ? ( $source ) : $anysource ? ( "") : ( ),
119                 ]);
120         $anysource++ if ($source);
121         }
122
123 # Show the packages, if any
124 if (@rows) {
125         print &text('index_count', scalar(@rows)),"<br>\n";
126         }
127 print &ui_form_columns_table(
128         "update.cgi",
129         [ [ "ok", $in{'mode'} eq 'new' ? $text{'index_install'}
130                                        : $text{'index_update'} ],
131           undef,
132           [ "refresh", $text{'index_refresh'} ] ],
133         1,
134         undef,
135         [ [ "mode", $in{'mode'} ],
136           [ "search", $in{'search'} ] ],
137         [ "", $text{'index_name'}, $text{'index_desc'}, $text{'index_status'},
138           $anysource ? ( $text{'index_source'} ) : ( ), ],
139         100,
140         \@rows,
141         undef,
142         0,
143         undef,
144         $text{'index_none_'.$in{'mode'}},
145         1
146         );
147 if (!@rows) {
148         print &ui_form_start("update.cgi");
149         print &ui_hidden("mode", $in{'mode'});
150         print &ui_hidden("search", $in{'search'});
151         print &ui_form_end([ [ "refresh", $text{'index_refresh'} ] ]);
152         }
153
154 # Show scheduled report form
155 print "<hr>\n";
156 print &ui_form_start("save_sched.cgi");
157 print &ui_hidden("mode", $in{'mode'});
158 print &ui_hidden("search", $in{'search'});
159 print &ui_table_start($text{'index_header'}, undef, 2);
160
161 $job = &find_cron_job();
162 if ($job) {
163         $sched = $job->{'hours'} eq '*' ? 'h' :
164                  $job->{'days'} eq '*' && $job->{'weekdays'} eq '*' ? 'd' :
165                  $job->{'days'} eq '*' && $job->{'months'} eq '*' ? 'w' :
166                                                                     undef;
167         }
168 else {
169         $sched = "d";
170         }
171
172 # When to run
173 print &ui_table_row($text{'index_sched'},
174                     &ui_radio("sched_def", $job ? 0 : 1,
175                               [ [ 1, $text{'index_sched1'} ],
176                                 [ 0, $text{'index_sched0'} ] ])."\n".
177                     &ui_select("sched", $sched,
178                                [ [ 'h', $text{'index_schedh'} ],
179                                  [ 'd', $text{'index_schedd'} ],
180                                  [ 'w', $text{'index_schedw'} ] ]));
181
182 # Send email to
183 print &ui_table_row($text{'index_email'},
184                     &ui_textbox("email", $config{'sched_email'}, 40));
185
186 # Install or just notify?
187 print &ui_table_row($text{'index_action'},
188                     &ui_radio("action", int($config{'sched_action'}),
189                                [ [ 0, $text{'index_action0'} ],
190                                  [ 1, $text{'index_action1'} ],
191                                  [ 2, $text{'index_action2'} ] ]));
192
193 print &ui_table_end();
194 print &ui_form_end([ [ "save", $text{'save'} ] ]);
195
196 &ui_print_footer("/", $text{'index'});
197