Handle hostnames with upper-case letters
[webmin.git] / blue-theme / left.cgi
1 #!/usr/bin/perl
2 # Show the left-side menu of Virtualmin domains, plus modules
3
4 BEGIN { push(@INC, ".."); };
5 use WebminCore;
6 &init_config();
7 &ReadParse();
8 %text = &load_language($current_theme);
9 %gaccess = &get_module_acl(undef, "");
10
11 # Work out what modules and categories we have
12 @cats = &get_visible_modules_categories();
13 @modules = map { @{$_->{'modules'}} } @cats;
14
15 &popup_header();
16 print <<EOF;
17 <link rel="stylesheet" type="text/css" href="left.css" />
18 <script>
19 function toggleview (id1,id2) {
20                 var obj1 = document.getElementById(id1);
21                 var obj2 = document.getElementById(id2);
22                 (obj1.className=="itemshown") ? obj1.className="itemhidden" : obj1.className="itemshown"; 
23                 (obj1.className=="itemshown") ? obj2.innerHTML="<img border='0' src='images/open.gif' alt='[&ndash;]'>" : obj2.innerHTML="<img border='0' src='images/closed.gif' alt='[+]'>"; 
24         }
25
26 // Show the logs for the current module in the right
27 function show_logs() {
28   var url = ''+window.parent.frames[1].location;
29   var sl1 = url.indexOf('//');
30   var mod = '';
31   if (sl1 > 0) {
32     var sl2 = url.indexOf('/', sl1+2);
33     if (sl2 > 0) {
34       var sl3 = url.indexOf('/', sl2+1);
35       if (sl3 > 0) {
36         mod = url.substring(sl2+1, sl3);
37       } else {
38         mod = url.substring(sl2+1);
39       }
40     }
41   }
42 if (mod && mod.indexOf('.cgi') <= 0) {
43   // Show one module's logs
44   window.parent.frames[1].location = 'webminlog/search.cgi?tall=4&uall=1&fall=1&mall=0&module='+mod;
45   }
46 else {
47   // Show all logs
48   window.parent.frames[1].location = 'webminlog/search.cgi?tall=4&uall=1&fall=1&mall=0&mall=1'
49   }
50 }
51 </script>
52 </head>
53 <body>
54 EOF
55
56 # Show login
57 print &text('left_login', $remote_user),"<br>\n";
58
59 if ($gconfig{"notabs_${base_remote_user}"} == 2 ||
60     $gconfig{"notabs_${base_remote_user}"} == 0 && $gconfig{'notabs'} ||
61     @modules <= 1) {
62         # Show all modules in one list
63         foreach $minfo (@modules) {
64                 $target = $minfo->{'noframe'} ? "_top" : "right";
65                 print "<a target=$target href=$minfo->{'dir'}/>$minfo->{'desc'}</a><br>\n";
66                 }
67         }
68 else {
69         # Show all modules under categories
70         foreach $c (@cats) {
71                 # Show category opener, plus modules under it
72                 &print_category_opener(
73                         $c->{'code'},
74                         $in{$c->{'code'}} ? 1 : 0,
75                         $c->{'unused'} ?
76                                 "<font color=#888888>$c->{'desc'}</font>" :
77                                 $c->{'desc'});
78                 $cls = $in{$c->{'code'}} ? "itemshown" : "itemhidden";
79                 print "<div class='$cls' id='$c->{'code'}'>";
80                 foreach my $minfo (@{$c->{'modules'}}) {
81                         &print_category_link("$minfo->{'dir'}/",
82                                              $minfo->{'desc'},
83                                              undef,
84                                              undef,
85                                              $minfo->{'noframe'} ? "_top" : "",
86                                         );
87                         }
88                 print "</div>\n";
89                 }
90         }
91
92 # Show module/help search form
93 if (-r "$root_directory/webmin_search.cgi" &&
94     $gaccess{'webminsearch'}) {
95         print "<form action=webmin_search.cgi target=right>\n";
96         print $text{'left_search'},"&nbsp;";
97         print &ui_textbox("search", undef, 15);
98         }
99
100 print "<div class='leftlink'><hr></div>\n";
101
102 # Show current module's log search, if logging
103 if ($gconfig{'log'} && &foreign_available("webminlog")) {
104         print "<div class='linkwithicon'><img src=images/logs.gif>\n";
105         print "<div class='aftericon'><a target=right href='webminlog/' onClick='show_logs(); return false;'>$text{'left_logs'}</a></div></div>\n";
106         }
107
108 # Show info link
109 print "<div class='linkwithicon'><img src=images/gohome.gif>\n";
110 print "<div class='aftericon'><a target=right href='right.cgi?open=system&open=status'>$text{'left_home'}</a></div></div>\n";
111
112 # Show feedback link, but only if a custom email is set
113 %gaccess = &get_module_acl(undef, "");
114 if (&get_product_name() eq 'webmin' &&          # For Webmin
115       !$ENV{'ANONYMOUS_USER'} &&
116       $gconfig{'nofeedbackcc'} != 2 &&
117       $gaccess{'feedback'} &&
118       $gconfig{'feedback_to'} ||
119     &get_product_name() eq 'usermin' &&         # For Usermin
120       !$ENV{'ANONYMOUS_USER'} &&
121       $gconfig{'feedback'}
122     ) {
123         print "<div class='linkwithicon'><img src=images/mail-small.gif>\n";
124         print "<div class='aftericon'><a target=right href='feedback_form.cgi'>$text{'left_feedback'}</a></div></div>\n";
125         }
126
127 # Show refesh modules link, for master admin
128 if (&foreign_available("webmin")) {
129         print "<div class='linkwithicon'><img src=images/refresh-small.gif>\n";
130         print "<div class='aftericon'><a target=right href='webmin/refresh_modules.cgi'>$text{'main_refreshmods'}</a></div></div>\n";
131         }
132
133 # Show logout link
134 &get_miniserv_config(\%miniserv);
135 if ($miniserv{'logout'} && !$ENV{'SSL_USER'} && !$ENV{'LOCAL_USER'} &&
136     $ENV{'HTTP_USER_AGENT'} !~ /webmin/i) {
137         print "<div class='linkwithicon'><img src=images/stock_quit.gif>\n";
138         if ($main::session_id) {
139                 print "<div class='aftericon'><a target=_top href='session_login.cgi?logout=1'>$text{'main_logout'}</a></div>";
140                 }
141         else {
142                 print "<div class='aftericon'><a target=_top href='switch_user.cgi'>$text{'main_switch'}</a></div>";
143                 }
144         print "</div>\n";
145         }
146
147 # Show link back to original Webmin server
148 if ($ENV{'HTTP_WEBMIN_SERVERS'}) {
149         print "<div class='linkwithicon'><img src=images/webmin-small.gif>\n";
150         print "<div class='aftericon'><a target=_top href='$ENV{'HTTP_WEBMIN_SERVERS'}'>$text{'header_servers'}</a></div>";
151         }
152
153 &popup_footer();
154
155 # print_category_opener(name, &allcats, label)
156 # Prints out an open/close twistie for some category
157 sub print_category_opener
158 {
159 local ($c, $status, $label) = @_;
160 $label = $c eq "others" ? $text{'left_others'} : $label;
161 local $img = $status ? "open.gif" : "closed.gif";
162
163 # Show link to close or open catgory
164 print "<div class='linkwithicon'>";
165 print "<a href=\"javascript:toggleview('$c','toggle$c')\" id='toggle$c'><img border='0' src='images/$img' alt='[+]'></a>\n";
166 print "<div class='aftericon'><a href=\"javascript:toggleview('$c','toggle$c')\" id='toggle$c'><font color=#000000>$label</font></a></div></div>\n";
167 }
168
169
170 sub print_category_link
171 {
172 local ($link, $label, $image, $noimage, $target) = @_;
173 $target ||= "right";
174 print "<div class='linkindented'><a target=$target href=$link>$label</a></div>\n";
175 }
176