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