Handle hostnames with upper-case letters
[webmin.git] / index.cgi
1 #!/usr/local/bin/perl
2 # Display all Webmin modules visible to the current user
3
4 BEGIN { push(@INC, ".."); };
5 use WebminCore;
6
7 &init_config();
8 &ReadParse();
9 $hostname = &get_display_hostname();
10 $ver = &get_webmin_version();
11 &get_miniserv_config(\%miniserv);
12 if ($gconfig{'real_os_type'}) {
13         if ($gconfig{'os_version'} eq "*") {
14                 $ostr = $gconfig{'real_os_type'};
15                 }
16         else {
17                 $ostr = "$gconfig{'real_os_type'} $gconfig{'real_os_version'}";
18                 }
19         }
20 else {
21         $ostr = "$gconfig{'os_type'} $gconfig{'os_version'}";
22         }
23 %access = &get_module_acl();
24
25 # Build a list of all modules
26 @modules = &get_visible_module_infos();
27
28 if (!defined($in{'cat'})) {
29         # Maybe redirect to some module after login
30         local $goto = &get_goto_module(\@modules);
31         if ($goto) {
32                 &redirect($goto->{'dir'}.'/');
33                 exit;
34                 }
35         }
36
37 $gconfig{'sysinfo'} = 0 if ($gconfig{'sysinfo'} == 1);
38 if ($gconfig{'alt_startpage'}) {
39         # Tim's webmin header
40         &header(&text('main_title', $ver, $hostname, $ostr));
41         print "<TABLE class='header' id='alt_startpage' BORDER=0 WIDTH=100%>\n";
42         print "<TR><TD WIDTH=20% ALIGN=left>\n";
43         print "Version $ver<BR>$hostname<BR>$ostr</TD>";
44         print "<TD WIDTH=60% ALIGN=center>\n";
45         print "<IMG SRC=\"images/newlogo.gif\" BORDER=0>";
46         print "</TD><TD WIDTH=20% ALIGN=right>";
47         print "<a href=http://www.webmin.com/>$text{'main_homepage'}</a><br>";
48         print "<a href=feedback_form.cgi>$text{'main_feedback'}</a>"
49                 if ($gconfig{'nofeedbackcc'} != 2 && $access{'feedback'});
50         if ($miniserv{'logout'} && !$ENV{'SSL_USER'} && !$ENV{'LOCAL_USER'} &&
51             $ENV{'HTTP_USER_AGENT'} !~ /webmin/i) {
52                 print "<br><br>\n";
53                 if ($main::session_id) {
54                         print "<a href='session_login.cgi?logout=1'>",
55                               "$text{'main_logout'}</a>";
56                         }
57                 else {
58                         print "<a href=switch_user.cgi>$text{'main_switch'}</a>";
59                         }
60                 }
61         print "</TD></TR></TABLE><HR id='header_hr'><P>\n\n";
62         }
63 else {
64         # Standard webmin header
65         if ($gconfig{'texttitles'}) {
66                 @args = ( $text{'main_title2'}, undef );
67                 }
68         else {
69                 @args = ( $gconfig{'nohostname'} ? $text{'main_title2'} :
70                             &text('main_title', $ver, $hostname, $ostr),
71                           "images/webmin-blue.png" );
72                 if ($gconfig{'showlogin'}) {
73                         $args[0] = $remote_user." : ".$args[0];
74                         }
75                 }
76         &header(@args, undef, undef, 1, 1,
77                 $tconfig{'brand'} ? 
78                 "<a href=$tconfig{'brand_url'}>$tconfig{'brand'}</a>" :
79                 $gconfig{'brand'} ? 
80                 "<a href=$gconfig{'brand_url'}>$gconfig{'brand'}</a>" :
81                 "<a href=http://www.webmin.com/>$text{'main_homepage'}</a>".
82                 ($gconfig{'nofeedbackcc'} == 2 || !$access{'feedback'} ? "" :
83                   "<br><a href=feedback_form.cgi>$text{'main_feedback'}</a>")
84                 );
85         print "<center><font size=+1>",
86             &text('main_version', $ver, $hostname, $ostr),"</font></center>\n"
87                 if (!$gconfig{'nohostname'});
88         print "<hr id='header_hr'><p>\n";
89         }
90 print $text{'main_header'};
91
92 if (!@modules) {
93         # use has no modules!
94         print "<p class='main_none'><b>$text{'main_none'}</b><p>\n";
95         }
96 elsif ($gconfig{"notabs_${base_remote_user}"} == 2 ||
97     $gconfig{"notabs_${base_remote_user}"} == 0 && $gconfig{'notabs'}) {
98         # Generate main menu with all modules on one page
99         print "<center><table id='mods' cellpadding=5 cellspacing=0 width=100%>\n";
100         $pos = 0;
101         $cols = $gconfig{'nocols'} ? $gconfig{'nocols'} : 4;
102         $per = 100.0 / $cols;
103         foreach $m (@modules) {
104                 if ($pos % $cols == 0) { print "<tr $cb>\n"; }
105                 print "<td valign=top align=center width=$per\%>\n";
106                 local $idx = $m->{'index_link'};
107                 print "<table border><tr><td><a href=$gconfig{'webprefix'}/$m->{'dir'}/$idx>",
108                       "<img src=$m->{'dir'}/images/icon.gif border=0 ",
109                       "width=48 height=48></a></td></tr></table>\n";
110                 print "<a href=$gconfig{'webprefix'}/$m->{'dir'}/$idx>$m->{'desc'}</a></td>\n";
111                 if ($pos % $cols == $cols - 1) { print "</tr>\n"; }
112                 $pos++;
113                 }
114         print "</table></center><p><hr id='mods_hr'>\n";
115         }
116 else {
117         # Display under categorised tabs
118         &ReadParse();
119         %cats = &list_categories(\@modules);
120         @cats = sort { $b cmp $a } keys %cats;
121         $cats = @cats;
122         $per = $cats ? 100.0 / $cats : 100;
123         if (!defined($in{'cat'})) {
124                 # Use default category
125                 if (defined($gconfig{'deftab'}) &&
126                     &indexof($gconfig{'deftab'}, @cats) >= 0) {
127                         $in{'cat'} = $gconfig{'deftab'};
128                         }
129                 else {
130                         $in{'cat'} = $cats[0];
131                         }
132                 }
133         elsif (!$cats{$in{'cat'}}) {
134                 $in{'cat'} = "";
135                 }
136         print "<table id='cattabs' border=0 cellpadding=0 cellspacing=0 height=20><tr>\n";
137         $usercol = defined($gconfig{'cs_header'}) ||
138                    defined($gconfig{'cs_table'}) ||
139                    defined($gconfig{'cs_page'});
140         foreach $c (@cats) {
141                 $t = $cats{$c};
142                 if ($in{'cat'} eq $c) {
143                         print "<td class='usercoll' valign=top $cb>", $usercol ? "<br>" :
144                           "<img src=images/lc2.gif alt=\"\">","</td>\n";
145                         print "<td class='usercolc' id='selectedcat' $cb>&nbsp;<b>$t</b>&nbsp;</td>\n";
146                         print "<td class='usercolr' valign=top $cb>", $usercol ? "<br>" :
147                           "<img src=images/rc2.gif alt=\"\">","</td>\n";
148                         }
149                 else {
150                         print "<td class='usercoll' valign=top $tb>", $usercol ? "<br>" :
151                           "<img src=images/lc1.gif alt=\"\">","</td>\n";
152                         print "<td class='usercolc' $tb>&nbsp;",
153                               "<a href=$gconfig{'webprefix'}/?cat=$c><b>$t</b></a>&nbsp;</td>\n";
154                         print "<td class='usercolr' valign=top $tb>", $usercol ? "<br>" :
155                           "<img src=images/rc1.gif alt=\"\">","</td>\n";
156                         }
157                 print "<td width=10></td>\n";
158                 }
159         print "</tr></table> <table id='mods' border=0 cellpadding=0 cellspacing=0 ",
160               "width=100% $cb>\n";
161         print "<tr><td><table width=100% cellpadding=5>\n";
162
163         # Display the modules in this category
164         $pos = 0;
165         $cols = $gconfig{'nocols'} ? $gconfig{'nocols'} : 4;
166         $per = 100.0 / $cols;
167         foreach $m (@modules) {
168                 next if ($m->{'category'} ne $in{'cat'});
169
170                 if ($pos % $cols == 0) { print "<tr>\n"; }
171                 local $idx = $m->{'index_link'};
172                 print "<td valign=top align=center width=$per\%>\n";
173                 print "<table border bgcolor=#ffffff><tr><td><a href=$gconfig{'webprefix'}/$m->{'dir'}/$idx>",
174                       "<img src=$m->{'dir'}/images/icon.gif alt=\"\" border=0></a>",
175                       "</td></tr></table>\n";
176                 print "<a href=$gconfig{'webprefix'}/$m->{'dir'}/$idx>$m->{'desc'}</a></td>\n";
177                 if ($pos++ % $cols == $cols - 1) { print "</tr>\n"; }
178                 }
179         while($pos++ % $cols) {
180                 print "<td width=$per\%></td>\n";
181                 }
182         print "</table></td></tr></table><p><hr id='mods_hr'>\n";
183         }
184
185 # Check for incorrect OS
186 if (&foreign_check("webmin")) {
187         &foreign_require("webmin", "webmin-lib.pl");
188         &webmin::show_webmin_notifications();
189         }
190
191 if ($miniserv{'logout'} && !$gconfig{'alt_startpage'} &&
192     !$ENV{'SSL_USER'} && !$ENV{'LOCAL_USER'} && !$ENV{'ANONYMOUS_USER'} &&
193     $ENV{'HTTP_USER_AGENT'} !~ /webmin/i) {
194         print "<table id='altlogout' width=100% cellpadding=0 cellspacing=0><tr>\n";
195         if ($main::session_id) {
196                 print "<td align=right><a href='session_login.cgi?logout=1'>",
197                       "$text{'main_logout'}</a></td>\n";
198                 }
199         else {
200                 print "<td align=right><a href=switch_user.cgi>",
201                       "$text{'main_switch'}</a></td>\n";
202                 }
203         print "</tr></table>\n";
204         }
205
206 print $text{'main_footer'};
207 &footer();
208