Handle hostnames with upper-case letters
[webmin.git] / osx-theme / theme.pl
1 # theme.pl
2 # Override functions for the OSX theme
3 # XXX always starts with 'other' category?
4
5 # header(title, image, [help], [config], [nomodule], [nowebmin], [rightside],
6 #        [header], [body], [below])
7 sub theme_header
8 {
9 print "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n";
10 print "<head>\n";
11 print $_[7];
12 print "<title>$_[0]</title>\n";
13 print "<link rel='stylesheet' href='/unauthenticated/style.css' type='text/css'>\n";
14 if ($charset) {
15         print "<meta http-equiv=\"Content-Type\" ",
16               "content=\"text/html; Charset=$charset\">\n";
17         }
18 print "</head>\n";
19 print "<body $_[8]>\n";
20
21 # Get all modules visible to this user
22 @osx_modules = &get_available_module_infos()
23         if (!scalar(@osx_modules));
24
25 # Show table of categories
26 local $one = @osx_modules == 1 && $gconfig{'gotoone'};
27 local $notabs = $gconfig{"notabs_${base_remote_user}"} == 2 ||
28         $gconfig{"notabs_${base_remote_user}"} == 0 && $gconfig{'notabs'};
29 if (@_ > 1 && !$one && $remote_user && !$notabs) {
30         local $logout;
31         if (!$ENV{'ANONYMOUS_USER'} && !$ENV{'SSL_USER'} &&
32             !$ENV{'LOCAL_USER'} && !$ENV{'HTTP_WEBMIN_SERVERS'}) {
33                 if ($main::session_id) {
34                         $logout = "<a href='/session_login.cgi?logout=1'>$text{'main_logout'}</a>";
35                         }
36                 else {
37                         $logout = "<a href='/switch_user.cgi'>$text{'main_switch'}</a>";
38                         }
39                 }
40         &start_osx_table("Module Categories", $logout);
41         local %catnames;
42         &read_file("$config_directory/webmin.catnames", \%catnames);
43         foreach $m (@osx_modules) {
44                 local $c = $m->{'category'};
45                 next if ($cats{$c});
46                 if (defined($catnames{$c})) {
47                     $cats{$c} = $catnames{$c};
48                     }
49                 elsif ($text{"category_$c"}) {
50                     $cats{$c} = $text{"category_$c"};
51                     }
52                 else {
53                     # try to get category name from module ..
54                     local %mtext = &load_language($m->{'dir'});
55                     if ($mtext{"category_$c"}) {
56                         $cats{$c} = $mtext{"category_$c"};
57                         }
58                     else {
59                         $c = $m->{'category'} = "";
60                         $cats{$c} = $text{"category_$c"};
61                         }
62                     }
63                 }
64         @cats = sort { $b cmp $a } keys %cats;
65         $cats = @cats;
66         $per = $cats ? 100.0 / $cats : 100;
67
68         # Actually show category icons
69         # XXX spacing?
70         local (@icons, @titles, @links);
71         foreach $c (@cats) {
72                 local $t = $cats{$c};
73                 push(@titles, $t);
74                 push(@icons, -r "$root_directory/$current_theme/cats/$c.gif" ?
75                         "/$current_theme/cats/$c.gif" :
76                         "/$current_theme/cats/unknown.gif");
77                 push(@links, "/?cat=$c");
78                 }
79         &icons_table(\@links, \@titles, \@icons,
80                      @links > 7 ? scalar(@links) : 7);
81
82         &end_osx_table();
83         }
84
85 if (@_ > 1) {
86         # Open table for main page
87         local @right;
88         if ($ENV{'HTTP_WEBMIN_SERVERS'}) {
89                 push(@right, "<a href='$ENV{'HTTP_WEBMIN_SERVERS'}'>".
90                              "$text{'header_servers'}</a>");
91                 }
92         if (!$_[4]) {
93                 # Module index link
94                 local $idx = $module_info{'index_link'};
95                 local $mi = $module_index_link || "/$module_name/$idx";
96                 push(@right, "<a href=\"$gconfig{'webprefix'}$mi\">".
97                              "$text{'header_module'}</a>");
98                 }
99         if (ref($_[2]) eq "ARRAY" && !$ENV{'ANONYMOUS_USER'}) {
100                 # Help link
101                 push(@right, &hlink($text{'header_help'},
102                                     $_[2]->[0], $_[2]->[1]));
103                 }
104         elsif (defined($_[2]) && !$ENV{'ANONYMOUS_USER'}) {
105                 # Help link
106                 push(@right, &hlink($text{'header_help'}, $_[2]));
107                 }
108         if ($_[3]) {
109                 local %access = &get_module_acl();
110                 if (!$access{'noconfig'} && !$config{'noprefs'}) {
111                         local $cprog = $user_module_config_directory ?
112                                         "uconfig.cgi" : "config.cgi";
113                         push(@right, "<a href=\"$gconfig{'webprefix'}/$cprog?$module_name\">$text{'header_config'}</a>");
114                         }
115                 }
116         push(@right, split(/<br>/, $_[6]));
117         &start_osx_table($_[0], join("&nbsp;|&nbsp;", @right));
118         if ($_[9]) {
119                 print "<table width=100%><tr><td align=center>",
120                       "$_[9]</td></tr></table>\n";
121                 }
122         $started_osx_table++;
123         }
124 }
125
126 sub theme_footer
127 {
128 if ($started_osx_table) {
129         # Close table for main page
130         &end_osx_table();
131         }
132
133 # Show footer links
134
135 print "</body>\n";
136 print "</html>\n";
137 }
138
139 # start_osx_table(title, rightstuff, width)
140 sub start_osx_table
141 {
142 local ($title, $right, $width) = @_;
143 $width ||= 100;
144 print <<EOF;
145 <table align="center" width="$width%" cellspacing="0" cellpadding="0" class="maintablea">
146  <tr>
147   <td>
148    <table width="100%" cellspacing="0" cellpadding="0" class="tableh1a">
149     <tr>
150      <td class="tableh1a"><img src="/unauthenticated/left.gif"></td>
151      <td class="tableh1a" background="/unauthenticated/middle.gif" width="100%"><font class="optionx" color="#ffffff">&#160;&#160;$title</font></td>
152      <td class="tableh1a" background="/unauthenticated/middle.gif" align=right nowrap><font class="optionx" color="#ffffff">$right</font></td>
153      <td class="tableh1a"><img src="/unauthenticated/right.gif"></td>
154     </tr>
155    </table>
156   </td>
157  </tr>
158 </table>
159
160 <table align="center" width="$width%" cellspacing="0" cellpadding="0">
161  <tr>
162   <td background="/unauthenticated/c1b.gif" valign="top"><img name="main_table_r1_c1" src="/unauthenticated/c1.gif" border="0" id="main_table_r1_c1" alt="" /></td>
163    <td width="100%"><table width="100%" cellspacing="0" cellpadding="5" class="maintableb" border="1" bordercolor="7F7F7F">
164     <tr valign="top">
165      <td>
166 EOF
167 }
168
169 sub end_osx_table
170 {
171 print <<EOF;
172      </td>
173     </tr>
174    </table>
175   </td>
176   <td background="/unauthenticated/c3b.gif" valign="top"><img name="main_table_r1_c3" src="/unauthenticated/c3.gif" border="0" id="main_table_r1_c3" alt="" /></td>
177  </tr>
178  <tr>
179   <td><img name="main_table_r2_c1" src="/unauthenticated/2c1.gif" width="10" height="4" border="0" id="main_table_r2_c1" alt="" /></td>
180   <td background="/unauthenticated/c2b.gif"><img name="main_table_r2_c2" src="/unauthenticated/c2.gif" border="0" id="main_table_r2_c2" alt="" /></td>
181   <td><img name="main_table_r2_c3" src="/unauthenticated/c3.gif" width="10" height="4" border="0" id="main_table_r2_c3" alt="" /></td>
182  </tr>
183 </table>
184 EOF
185 }
186
187 sub theme_ui_post_header
188 {
189 local ($text) = @_;
190 local $rv;
191 if (defined($text)) {
192         $rv .= "<center><font size=+1>$text</font></center><br>\n";
193         }
194 return $rv;
195 }
196
197 sub theme_ui_pre_footer
198 {
199 return "";
200 }
201
202 # Hack to prevent the display of <hr> lines
203 #package miniserv;
204 #sub PRINT
205 #{
206 #if ($_[1] !~ /^<hr>(<p>|<br>)?\s*$/) {
207 #       $r = shift;
208 #       $$r++;
209 #       &write_to_sock(@_);
210 #       }
211 #}
212
213
214