Handle hostnames with upper-case letters
[webmin.git] / mscstyle_mini / theme.pl
1 #!/usr/local/bin/perl
2
3 #theme_prebody - called just before the main body of every page, so it can print any HTML it likes.
4 #theme_postbody - called just after the main body of every page.
5 #theme_header - called instead of the normal header function, with the same parameters. You could use this to re-write the header function in your own style with help and index links whereever you want them.
6 #theme_footer - called instead of the footer function with the same parameters.
7 #theme_error - called instead of the error function, with the same parameters.
8
9
10 sub theme_header {
11
12 local @available = ("webmin", "system", "servers", "cluster", "hardware", "", "net", "kororaweb");
13
14 local($ll, %access);
15 print "<!doctype html public \"-//W3C//DTD HTML 3.2 Final//EN\">\n";
16 print "<html>\n";
17 if ($charset) {
18     print "<meta http-equiv=\"Content-Type\" ",
19           "content=\"text/html; Charset=$charset\">\n";
20     }
21 local $os_type = $gconfig{'real_os_type'} ? $gconfig{'real_os_type'}
22                       : $gconfig{'os_type'};
23 local $os_version = $gconfig{'real_os_version'} ? $gconfig{'real_os_version'}
24                             : $gconfig{'os_version'};
25 print "<head>\n";
26 if (@_ > 0) {
27     if ($gconfig{'sysinfo'} == 1) {
28         printf "<title>%s : %s on %s (%s %s)</title>\n",
29             $_[0], $remote_user, &get_display_hostname(),
30             $os_type, $os_version;
31         }
32     elsif ($gconfig{'sysinfo'} == 4) {
33         printf "<title>%s on %s (%s %s)</title>\n",
34             $remote_user, &get_display_hostname(),
35             $os_type, $os_version;
36         }
37     else {
38         print "<title>$_[0]</title>\n";
39         }
40     print $_[7] if ($_[7]);
41     if ($gconfig{'sysinfo'} == 0 && $remote_user) {
42         print "<SCRIPT LANGUAGE=\"JavaScript\">\n";
43         printf
44         "defaultStatus=\"%s%s logged into Webmin %s on %s (%s %s)\";\n",
45             $remote_user,
46             $ENV{'SSL_USER'} ? " (SSL certified)" :
47             $ENV{'LOCAL_USER'} ? " (Local user)" : "",
48             &get_webmin_version(), &get_display_hostname(),
49             $os_type, $os_version;
50         print "</SCRIPT>\n";
51         }
52     }
53
54 @msc_modules = &get_visible_module_infos()
55         if (!scalar(@msc_modules));
56
57 print '<body bgcolor=#424242 link=#000000 vlink=#000000 text=#000000 leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" '.$_[8].'>';
58
59 if ($remote_user && @_ > 1) {
60         # Show basic header with webmin.com link and logout button
61         local $logout = $main::session_id ? "/session_login.cgi?logout=1"
62                                           : "/switch_user.cgi";
63         print qq~<table width="100%" border="0" cellspacing="0" cellpadding="0" background="/images/top_bar.jpg">
64           <tr>
65             <td width="100%" nowrap><a href="http://www.webmin.com"><img src="/images/webmin_top.jpg" border="0" alt="Webmin home page"></a></td>
66             <td nowrap><a href='$logout'><img src="/images/logout.jpg" border="0" alt="$text{'main_logout'}"></a></td>
67           </tr>
68         </table>~;
69         }
70
71 local $one = @msc_modules == 1 && $gconfig{'gotoone'};
72 if (@_ > 1 && !$one && $remote_user) {
73     # Display module categories
74     print qq~<table width="100%" border="0" cellspacing="0" cellpadding="0">
75   <tr>
76     <td background="/images/shadow.jpg" nowrap><img src="/images/shadow.jpg"></td>
77   </tr>
78 </table>~;
79
80     &read_file("$config_directory/webmin.catnames", \%catnames);
81     foreach $m (@msc_modules) {
82         $c = $m->{'category'};
83         next if ($cats{$c});
84         if (defined($catnames{$c})) {
85             $cats{$c} = $catnames{$c};
86             }
87         elsif ($text{"category_$c"}) {
88             $cats{$c} = $text{"category_$c"};
89             }
90         else {
91             # try to get category name from module ..
92             local %mtext = &load_language($m->{'dir'});
93             if ($mtext{"category_$c"}) {
94                 $cats{$c} = $mtext{"category_$c"};
95                 }
96             else {
97                 $c = $m->{'category'} = "";
98                 $cats{$c} = $text{"category_$c"};
99                 }
100             }
101         }
102     @cats = sort { $b cmp $a } keys %cats;
103     $cats = @cats;
104     $per = $cats ? 100.0 / $cats : 100;
105
106     if (!defined($in{'cat'})) {
107        
108         # Use default category
109         if (defined($gconfig{'deftab'}) &&
110             &indexof($gconfig{'deftab'}, @cats) >= 0) {
111             $in{'cat'} = $gconfig{'deftab'};
112             }
113         else {
114             $in{'cat'} = $cats[0];
115             }
116         }
117     elsif (!$cats{$in{'cat'}}) {
118         $in{'cat'} = "";
119         }
120
121 #####Navigation Bar START#####
122     print qq~<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#848484">
123   <tr><td><center>~;
124
125     foreach $c (@cats) {
126         $t = $cats{$c};
127            $inlist    = "false";
128            foreach $testet (@available) {
129                if ($testet eq $c) {
130                 $inlist = "true";
131                } 
132             }
133         if ($in{'cat'} eq $c) {
134            if ($inlist eq "true") {
135
136               if ($c eq "") {
137                 print qq~<img src="/images/cats_over/others.jpg">~;
138
139               } elsif ($c eq "webmin") {
140                if (@_ > 1) {
141                print qq~<a href=/?cat=$c><img src="/images/cats_over/$c.jpg" border=0></a>~;
142                 } else {
143                print qq~<img src="/images/cats_over/$c.jpg" border=0>~;
144                 }
145                } else {
146                print qq~<img src="/images/cats_over/$c.jpg">~;
147
148
149               }
150
151         } else {
152             print qq~<img src="/images/cats_over/unknown.jpg">~;
153
154
155            }
156         }
157         else {
158             if ($inlist eq "true") {
159               if ($c eq "") {
160                 print qq~<a href=/?cat=$c><img src="/images/cats/others.jpg" border=0 alt=$c></a>~;
161
162
163               } else {
164                print qq~<a href=/?cat=$c><img src="/images/cats/$c.jpg" border=0 alt=$c></a>~;
165
166
167               }
168         } else {
169             print qq~<a href=/?cat=$c><img src="/images/cats/unknown.jpg" border=0 alt=$c></a>~;
170
171
172         }
173            
174             }
175         }
176
177     print qq~
178     </center></td>
179   </tr>
180 </table>~;
181     print qq~<table width="100%" border="0" cellspacing="0" cellpadding="0" background="/images/shadow2.jpg" height="4">
182   <tr>
183     <td width="100%"><img src="/images/shadow2.jpg"></td>
184   </tr>
185 </table>~;
186
187
188    }
189
190 if (@_ > 1 && (!$_[5] || $ENV{'HTTP_WEBMIN_SERVERS'})) {
191    # Show tabs under module categories
192 print '<table width=100% border="0" cellspacing="0" cellpadding="0" background="/images/tabs/bgimage.jpg"><tr><td>';
193    
194      if ($ENV{'HTTP_WEBMIN_SERVERS'}) {
195         &tab_start();
196         print "<a href='$ENV{'HTTP_WEBMIN_SERVERS'}'>",
197               "$text{'header_servers'}</a><br>\n";
198         &tab_end();
199         }
200         if (!$_[4]) { &tab_start; print "<a href=\"/$module_name/\">",
201                             "$text{'header_module'}</a>"; &tab_end;}
202         if (ref($_[2]) eq "ARRAY") {
203                 &tab_start; print &hlink($text{'header_help'}, $_[2]->[0], $_[2]->[1]); &tab_end;
204                 }
205         elsif (defined($_[2])) {
206                 &tab_start; 
207 print &hlink($text{'header_help'}, $_[2]); 
208 &tab_end;
209                 }
210         if ($_[3]) {
211                 local %access = &get_module_acl();
212                 if (!$access{'noconfig'}) {
213                         &tab_start; print "<a href=\"/config.cgi?$module_name\">",
214                               $text{'header_config'},"</a>"; &tab_end;
215                         }
216                 }
217
218     foreach $t (split(/<br>/, $_[6])) {
219       if ($t =~ /\S/) {
220               &tab_start; print $t; &tab_end;
221       }
222     }
223
224 print "</td></tr></table>";
225
226     if (!$_[5]) {
227             # Show page title in tab
228             local $title = $_[0];
229             $title =~ s/&auml;/ä/g;
230             $title =~ s/&ouml;/ö/g;
231             $title =~ s/&uuml;/ü/g;
232             $title =~ s/&nbsp;/ /g;
233
234 #           print "<p><table border=0 cellpadding=0 cellspacing=0 width=95% align=center><tr><td><table border=0 cellpadding=0 cellspacing=0 height=20><tr>\n";
235             $usercol = defined($gconfig{'cs_header'}) ||
236                    defined($gconfig{'cs_table'}) ||
237                    defined($gconfig{'cs_page'});
238 #           print "<td bgcolor=#bae3ff>",
239 #             "<img src=/images/tabs/blue_left.jpg alt=\"\">","</td>\n";
240 #           print "<td bgcolor=#bae3ff>&nbsp;<b>$title</b>&nbsp;</td>\n";
241 #           print "<td bgcolor=#bae3ff>",
242 #             "<img src=/images/tabs/blue_right.jpg alt=\"\">","</td>\n";
243 #           print "</tr></table></td></tr></table>"; 
244
245 print "<center><font color=#FFFFFF><b>$title</b></font></center>";
246 &make_sep;
247              &theme_prebody;
248         }
249     } 
250 @header_arguments = @_;
251 }
252
253 sub theme_prebody
254 {
255 print "<table border=0 width=100% align=center cellspacing=0 cellpadding=0><tr><td background=/images/msctile.jpg>\n";
256 }
257
258 sub theme_postbody
259 {
260 print "</table>\n" if (@header_arguments > 1 && !$header_arguments[5]);
261 }
262
263 sub theme_footer {
264 local $i;
265
266 print "</table></table><br>\n"
267         if (@header_arguments > 1 && !$header_arguments[5]);
268
269 print "<table border=0 width=100% align=center cellspacing=0 cellpadding=0><tr><td>\n";
270
271 for($i=0; $i+1<@_; $i+=2) {
272     local $url = $_[$i];
273     if ($url eq '/') {
274         $url = "/?cat=$module_info{'category'}";
275         }
276     elsif ($url eq '' && $module_name) {
277         $url = "/$module_name/";
278         }
279     elsif ($url =~ /^\?/ && $module_name) {
280         $url = "/$module_name/$url";
281         }
282     if ($i == 0) {
283         print "&nbsp;<a href=\"$url\"><img alt=\"<-\" align=middle border=0 src=/images/arrow.jpg></a>\n";
284         }
285     else {
286         print "&nbsp;|\n";
287         }
288     print "&nbsp;<a href=\"$url\"><font color=#FFFFFF>",&text('main_return', $_[$i+1]),"</font></a>\n";
289     }
290 print "</td></tr></table>\n";
291
292 print "<br>\n";
293 if (!$_[$i]) {
294     local $postbody = $tconfig{'postbody'};
295     if ($postbody) {
296         local $hostname = &get_display_hostname();
297         local $version = &get_webmin_version();
298         local $os_type = $gconfig{'real_os_type'} ?
299                 $gconfig{'real_os_type'} : $gconfig{'os_type'};
300         local $os_version = $gconfig{'real_os_version'} ?
301                 $gconfig{'real_os_version'} : $gconfig{'os_version'};
302         $postbody =~ s/%HOSTNAME%/$hostname/g;
303         $postbody =~ s/%VERSION%/$version/g;
304         $postbody =~ s/%USER%/$remote_user/g;
305         $postbody =~ s/%OS%/$os_type $os_version/g;
306         print "$postbody\n";
307         }
308     if ($tconfig{'postbodyinclude'}) {
309         open(INC, $module_name ?
310             "../$gconfig{'theme'}/$tconfig{'postbodyinclude'}" :
311             "$gconfig{'theme'}/$tconfig{'postbodyinclude'}");
312         while(<INC>) {
313             print;
314             }
315         close(INC);
316         }
317     if (defined(&theme_postbody)) {
318         &theme_postbody(@_);
319         }
320     print "</body></html>\n";
321     }
322
323 }
324
325 #sub theme_error {
326
327 #print "error";
328
329 #}
330
331
332 sub chop_font {
333
334 if (!$lang->{'titles'} || $gconfig{'texttitles'}) {
335         print $t;
336 } else {
337         foreach $l (split(//, $t)) {
338             $ll = ord($l);
339             if ($ll > 127 && $lang->{'charset'}) {
340                 print "<img src=/images/letters2/$ll.$lang->{'charset'}.gif alt=\"$l\" align=bottom border=0>";
341                 }
342             elsif ($l eq " ") {
343                 print "<img src=/images/letters2/$ll.gif alt=\"\&nbsp;\" align=bottom border=0>";
344                 }
345             else {
346                 print "<img src=/images/letters2/$ll.gif alt=\"$l\" align=bottom border=0>";
347                 }
348             }
349         }
350 }
351
352 sub tab_start {
353     print qq~    <td nowrap>
354       <table border="0" cellspacing="0" cellpadding="0">
355         <tr>
356           <td background="/images/tabs/bg.jpg"><img src="/images/tabs/left.jpg" nowrap></td>
357           <td background="/images/tabs/bg.jpg" nowrap>
358           ~;
359 }
360
361
362 sub tab_end {
363      print qq~</td>
364           <td background="/images/tabs/bg.jpg" nowrap><img src="/images/tabs/right.jpg"></td>
365         </tr>
366       </table>
367
368     </td>~;
369 }
370
371 1;
372
373 sub make_sep {
374
375 print qq~
376 <table cellpadding="0" cellspacing="0" border="0" width="100%" background="/images/cat_sep.jpg">
377     <tr>
378     <td valign="Top" width="100%"><img src="/images/left_cat_sep.jpg" alt=" ">
379     </td>
380     <td valign="Top"><img src="/images/right_cat_sep.jpg" alt=" "></td>
381     </tr>
382 </table>
383 ~;
384
385 }