1#!/usr/local/bin/perl
2# Show the left-side menu of Webmin modules
3
4use strict;
5use warnings;
6require 'gray-theme/gray-theme-lib.pl';
7&ReadParse();
8our ($current_theme, $remote_user, %gconfig);
9our %text = &load_language($current_theme);
10my %gaccess = &get_module_acl(undef, "");
11
12&popup_header();
13print <<EOF;
14<link rel="stylesheet" type="text/css" href="gray-left.css" />
15<script>
16function toggleview (id1,id2) {
17		var obj1 = document.getElementById(id1);
18		var obj2 = document.getElementById(id2);
19		(obj1.className=="itemshown") ? obj1.className="itemhidden" : obj1.className="itemshown";
20		(obj1.className=="itemshown") ? obj2.innerHTML="<img border='0' src='images/gray-open.gif' alt='[&ndash;]'>" : obj2.innerHTML="<img border='0' src='images/gray-closed.gif' alt='[+]'>";
21	}
22
23// Show the logs for the current module in the right
24function show_logs() {
25  var url = ''+window.parent.frames[1].location;
26  var sl1 = url.indexOf('//');
27  var mod = '';
28  if (sl1 > 0) {
29    var sl2 = url.indexOf('/', sl1+2);
30    if (sl2 > 0) {
31      var sl3 = url.indexOf('/', sl2+1);
32      if (sl3 > 0) {
33        mod = url.substring(sl2+1, sl3);
34      } else {
35        mod = url.substring(sl2+1);
36      }
37    }
38  }
39if (mod && mod.indexOf('.cgi') <= 0) {
40  // Show one module's logs
41  window.parent.frames[1].location = 'webminlog/search.cgi?tall=4&uall=1&fall=1&mall=0&module='+mod;
42  }
43else {
44  // Show all logs
45  window.parent.frames[1].location = 'webminlog/search.cgi?tall=4&uall=1&fall=1&mall=0&mall=1'
46  }
47}
48</script>
49</head>
50<body>
51EOF
52
53# Show login
54my @leftmenu;
55push(@leftmenu, { 'type' => 'text',
56		  'desc' => &text('left_login', $remote_user) });
57push(@leftmenu, { 'type' => 'hr' });
58
59# Webmin modules
60push(@leftmenu, &list_modules_webmin_menu());
61
62# Show module/help search form
63if ($gaccess{'webminsearch'}) {
64	push(@leftmenu, { 'type' => 'input',
65			  'cgi' => $gconfig{'webprefix'}.'/webmin_search.cgi',
66			  'name' => 'search',
67			  'desc' => $text{'left_search'},
68			  'size' => 15 });
69	}
70
71push(@leftmenu, { 'type' => 'hr' });
72
73# Show current module's log search, if logging
74if ($gconfig{'log'} && &foreign_available("webminlog")) {
75	push(@leftmenu, { 'type' => 'item',
76			  'desc' => $text{'left_logs'},
77			  'link' => '/webminlog/',
78			  'icon' => '/images/logs.gif',
79			  'onclick' => 'show_logs(); return false;' });
80	}
81
82# Show info link
83push(@leftmenu, { 'type' => 'item',
84		  'desc' => $text{'left_home'},
85		  'link' => '/right.cgi',
86		  'icon' => '/images/gohome.gif' });
87
88# Show feedback link, but only if a custom email is set
89%gaccess = &get_module_acl(undef, "");
90if (&get_product_name() eq 'webmin' &&		# For Webmin
91      !$ENV{'ANONYMOUS_USER'} &&
92      int($gconfig{'nofeedbackcc'} || 0) != 2 &&
93      $gaccess{'feedback'} &&
94      $gconfig{'feedback_to'} ||
95    &get_product_name() eq 'usermin' &&		# For Usermin
96      !$ENV{'ANONYMOUS_USER'} &&
97      $gconfig{'feedback'}
98    ) {
99	push(@leftmenu, { 'type' => 'item',
100			  'desc' => $text{'left_feedback'},
101			  'link' => '/feedback_form.cgi',
102			  'icon' => '/images/mail-small.gif' });
103	}
104
105# Show refesh modules link, for master admin
106if (&foreign_available("webmin")) {
107	push(@leftmenu, { 'type' => 'item',
108			  'desc' => $text{'main_refreshmods'},
109			  'link' => '/webmin/refresh_modules.cgi',
110			  'icon' => '/images/refresh-small.gif' });
111	}
112
113# Show logout link
114my %miniserv;
115&get_miniserv_config(\%miniserv);
116if ($miniserv{'logout'} && !$ENV{'SSL_USER'} && !$ENV{'LOCAL_USER'} &&
117    $ENV{'HTTP_USER_AGENT'} !~ /webmin/i) {
118	my $logout = { 'type' => 'item',
119		       'icon' => '/images/stock_quit.gif',
120		       'target' => 'window' };
121	if ($main::session_id) {
122		$logout->{'desc'} = $text{'main_logout'};
123		$logout->{'link'} = '/session_login.cgi?logout=1';
124		}
125	else {
126		$logout->{'desc'} = $text{'main_switch'};
127		$logout->{'link'} = '/switch_user.cgi';
128		}
129	push(@leftmenu, $logout);
130	}
131
132# Show link back to original Webmin server
133if ($ENV{'HTTP_WEBMIN_SERVERS'}) {
134	push(@leftmenu, { 'type' => 'item',
135			  'desc' => $text{'header_servers'},
136			  'link' => $ENV{'HTTP_WEBMIN_SERVERS'},
137			  'icon' => '/images/webmin-small.gif',
138			  'target' => 'window' });
139	}
140
141# Actually output the menu
142print "<div class='wrapper'>\n";
143print "<table id='main' width='100%'><tbody><tr><td>\n";
144&show_menu_items_list(\@leftmenu, 0);
145print "</td></tr></tbody></table>\n";
146print "</div>\n";
147&popup_footer();
148
149# show_menu_items_list(&list, indent)
150# Actually prints the HTML for menu items
151sub show_menu_items_list
152{
153my ($items, $indent) = @_;
154foreach my $item (@$items) {
155	if ($item->{'type'} eq 'item') {
156		# Link to some page
157		my $t = !$item->{'target'} ? 'right' :
158			$item->{'target'} eq 'new' ? '_blank' :
159			$item->{'target'} eq 'window' ? '_top' : 'right';
160		if ($item->{'icon'}) {
161			my $icon = add_webprefix($item->{'icon'});
162			print "<div class='linkwithicon'>".
163			      "<img src='$icon' alt=''>\n";
164			}
165		my $cls = $item->{'icon'} ? 'aftericon' :
166		          $indent ? 'linkindented' : 'leftlink';
167		print "<div class='$cls'>";
168		my $link = add_webprefix($item->{'link'});
169		my $tags = $item->{'onclick'} ?
170				"onClick='".$item->{'onclick'}."'" : "";
171		print "<a href='$link' target=$t $tags>".
172		      "$item->{'desc'}</a>";
173		print "</div>";
174		if ($item->{'icon'}) {
175			print "</div>";
176			}
177		print "\n";
178		}
179	elsif ($item->{'type'} eq 'cat') {
180		# Start of a new category
181		my $c = $item->{'id'};
182		print "<div class='linkwithicon'>";
183		print "<a href=\"javascript:toggleview('cat$c','toggle$c')\" ".
184		      "id='toggle$c'><img border='0' src='images/closed.gif' ".
185		      "alt='[+]'></a>\n";
186		print "<div class='aftericon'>".
187		      "<a href=\"javascript:toggleview('cat$c','toggle$c')\" ".
188		      "id='toggletext$c'>".
189		      "<font color='#000000'>$item->{'desc'}</font></a></div>";
190		print "</div>\n";
191		print "<div class='itemhidden' id='cat$c'>\n";
192		&show_menu_items_list($item->{'members'}, $indent+1);
193		print "</div>\n";
194		}
195	elsif ($item->{'type'} eq 'text') {
196		# A line of text
197		print "<div class='leftlink'>",
198		      html_escape($item->{'desc'}),"</div>\n";
199		}
200	elsif ($item->{'type'} eq 'hr') {
201		# Separator line
202		print "<hr>\n";
203		}
204	elsif ($item->{'type'} eq 'input') {
205		# For with an input of some kind
206		my $cgi = add_webprefix($item->{'cgi'});
207		print "<form action='$cgi' target=right>\n";
208		foreach my $h (@{$item->{'hidden'}}) {
209			print ui_hidden(@$h);
210			}
211		print "<div class='leftlink'>";
212		print $item->{'desc'},"\n";
213		print ui_textbox($item->{'name'}, $item->{'value'},
214				 $item->{'size'});
215		if ($item->{'icon'}) {
216			my $icon = add_webprefix($item->{'icon'});
217			print "<input type=image src='$icon' ".
218			      "border=0 class=goArrow>\n";
219			}
220		print "</div>";
221		print "</form>\n";
222		}
223	}
224}
225
226# add_webprefix(link)
227# If a URL starts with a / , add webprefix
228sub add_webprefix
229{
230my ($link) = @_;
231return $link =~ /^\// ? $gconfig{'webprefix'}.$link : $link;
232}
233
234