1#!/usr/local/bin/perl
2# edit_mod.cgi
3# Display details of a module or theme
4
5require './cluster-webmin-lib.pl';
6&ReadParse();
7$type = $in{'tedit'} || !$in{'mod'} ? 'theme' : 'mod';
8$name = $in{$type};
9&ui_print_header(undef, $text{"edit_title_$type"}, "");
10
11# Find all hosts with the module or theme
12@hosts = &list_webmin_hosts();
13@servers = &list_servers();
14foreach $h (@hosts) {
15	local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
16	foreach $m ($type eq 'theme' ? @{$h->{'themes'}}
17				     : @{$h->{'modules'}}) {
18		if ($m->{'dir'} eq $name) {
19			$s->{'module'} = $m;
20			push(@got, $s);
21			push(@goth, $h);
22			$mod = $m if (!$mod);
23			if (!$checkon && ($s->{'id'} == $in{'host'} ||
24				  !$s->{'id'} && !defined($in{'host'}))) {
25				$checkon = $s;
26				$checkonh = $h;
27				}
28			}
29		}
30	}
31
32# Get the details from this host, or the first in the list
33if (!$checkon) {
34	$checkonh = $goth[0];
35	$checkon = $got[0];
36	}
37#&remote_foreign_require($checkon->{'host'}, "software", "software-lib.pl");
38#@pinfo = &remote_foreign_call($checkon->{'host'}, "software", "package_info",
39#			      $in{'package'});
40
41# Show module/theme details
42print "<table border width=100%>\n";
43print "<tr $tb> <td><b>",&text("edit_header_$type", &server_name($checkon)),
44      "</b></td> </tr>\n";
45print "<tr $cb> <td><table width=100%>\n";
46
47print "<tr> <td><b>$text{'edit_desc'}</b></td>\n";
48print "<td>",$mod->{'desc'},"</td>\n";
49
50print "<td><b>$text{'edit_ver'}</b></td>\n";
51print "<td>",$mod->{'version'} ? $mod->{'version'}
52			       : $text{'edit_nover'},"</td> </tr>\n";
53
54if ($type eq 'mod') {
55	# Show details of module
56	foreach $m (@{$checkonh->{'modules'}}) {
57		$modmap{$m->{'dir'}} = $m;
58		foreach $d (split(/\s+/, $m->{'depends'})) {
59			push(@{$ondeps{$d}}, $m);
60			}
61		}
62
63	&read_file("$config_directory/webmin.catnames", \%catnames);
64	print "<tr> <td><b>$text{'edit_cat'}</b></td>\n";
65	$c = $mod->{'category'};
66	print "<td>",$catname{$c} ? $catname{$c} :
67		     $text{"category_$c"} ? $text{"category_$c"} :
68					    $text{"category_"},"</td>\n";
69
70	print "<td><b>$text{'edit_dir'}</b></td>\n";
71	if ($checkon->{'id'}) {
72		print "<td><tt><a href='/servers/link.cgi/$checkon->{'id'}/",
73		      "$mod->{'dir'}/'>$mod->{'dir'}</a></tt></td> </tr>\n";
74		}
75	else {
76		print "<td><tt><a href='/$mod->{'dir'}/'>$mod->{'dir'}</a>",
77		      "</tt></td> </tr>\n";
78		}
79
80	# Show operating systems
81	print "<tr> <td valign=top><b>$text{'edit_os'}</b></td>\n";
82	print "<td colspan=3>\n";
83	$oss = $mod->{'os_support'};
84	if (!$oss) {
85		print $text{'edit_osall'};
86		}
87	else {
88		open(OSLIST, "<$root_directory/os_list.txt");
89		while(<OSLIST>) {
90			chop;
91			if (/^([^\t]+)\t+([^\t]+)\t+(\S+)\t+(\S+)\t*(.*)$/) {
92				$osname{$3} ||= $1;
93				}
94			}
95		close(OSLIST);
96		$osname{"*-linux"} = "Linux";
97		while(1) {
98			local ($os, $ver, $codes);
99			if ($oss =~ /^([^\/\s]+)\/([^\{\s]+)\{([^\}]*)\}\s*(.*)$/) {
100				$os = $1; $ver = $2; $codes = $3; $oss = $4;
101				}
102			elsif ($oss =~ /^([^\/\s]+)\/([^\/\s]+)\s*(.*)$/) {
103				$os = $1; $ver = $2; $oss = $3;
104				}
105			elsif ($oss =~ /^([^\{\s]+)\{([^\}]*)\}\s*(.*)$/) {
106				$os = $1; $codes = $2; $oss = $3;
107				}
108			elsif ($oss =~ /^\{([^\}]*)\}\s*(.*)$/) {
109				$codes = $1; $oss = $2;
110				}
111			elsif ($oss =~ /^(\S+)\s*(.*)$/) {
112				$os = $1; $oss = $2;
113				}
114			else { last; }
115			print "&nbsp;,&nbsp;\n" if ($doneone++);
116			$osn = $osname{$os} ? $osname{$os} : $os;
117			$osn =~ s/\s/&nbsp;/g;
118			if ($ver) {
119				print "$osn&nbsp;$ver";
120				}
121			elsif ($os) {
122				print "$osn";
123				}
124			if ($codes) {
125				$codes =~ s/\s/&nbsp;/g;
126				if ($os) {
127					print " (",&text('edit_codes',
128							"<tt>$codes</tt>"),")";
129					}
130				else {
131					print &text('edit_codes',
132						    "<tt>$codes</tt>");
133					}
134				}
135			}
136		}
137	print "</td> </tr>\n";
138
139	# Show which modules this module depends upon
140	local @deps = grep { !/^[0-9\.]+$/ } split(/\s+/, $mod->{'depends'});
141	local @pdeps = split(/\s+/, $mod->{'perldepends'});
142	print "<tr> <td valign=top><b>$text{'edit_deps'}</b></td>\n";
143	print "<td valign=top>\n";
144	if (@deps || @pdeps) {
145		foreach $d (@deps) {
146			local $mm = $modmap{$d};
147			print $mm->{'desc'}," (<tt>$mm->{'dir'}</tt>)<br>\n";
148			}
149		foreach $d (@pdeps) {
150			print &text('edit_pdep', "<tt>$d</tt>"),"<br>\n";
151			}
152		}
153	else {
154		print "$text{'edit_nodeps'}\n";
155		}
156	print "</td>\n";
157
158	# Show which other modules depend on this one
159	print "<td valign=top><b>$text{'edit_ondeps'}</b></td>\n";
160	print "<td valign=top>\n";
161	if ($ondeps{$mod->{'dir'}}) {
162		foreach $d (@{$ondeps{$mod->{'dir'}}}) {
163			print $d->{'desc'}," (<tt>$d->{'dir'}</tt>)<br>\n";
164			}
165		}
166	else {
167		print "$text{'edit_nodeps'}\n";
168		}
169	print "</td> </tr>\n";
170	}
171else {
172	# Show details of theme
173	}
174
175print "</table></td></tr></table><p>\n";
176
177print "<table width=100%><tr>\n";
178
179# Show button to delete module
180print "<td><form action=delete_mod.cgi>\n";
181print "<input type=hidden name=type value=\"$type\">\n";
182print "<input type=hidden name=mod value=\"$name\">\n";
183print "<input type=submit value='",$text{"edit_uninst_$type"},"'>\n";
184print "<select name=server>\n";
185print "<option value=-1>$text{'edit_all'}</option>\n";
186foreach $s (@got) {
187	print "<option value='$s->{'id'}'>",&server_name($s),"</option>\n";
188	}
189print "</select></form></td>\n";
190
191if ($type eq 'mod') {
192	# Show button to edit config
193	print "<td><form action=edit_config.cgi>\n";
194	print "<input type=hidden name=type value=\"$type\">\n";
195	print "<input type=hidden name=mod value=\"$name\">\n";
196	print "<input type=submit value='$text{'edit_config'}'>\n";
197	&create_on_input(undef, 1, 0, 0);
198	print "</form></td>\n";
199	}
200
201if ($type eq 'mod') {
202	# Show user/group ACL selector
203	print "<td align=right><form action=edit_acl.cgi>\n";
204	print "<input type=hidden name=mod value=\"$name\">\n";
205	print "<input type=hidden name=host value=\"$checkonh->{'id'}\">\n";
206	print "<input type=submit value='$text{'edit_acl'}'>\n";
207	print "<select name=whohost>\n";
208	for($i=0; $i<@goth; $i++) {
209		$h = $goth[$i];
210		local %ingroup;
211		foreach $g (@{$h->{'groups'}}) {
212			map { $ingroup{$_}++ } @{$g->{'members'}};
213			}
214		local $d = &server_name($got[$i]);
215		foreach $u (@{$h->{'users'}}) {
216			local @m = $ingroup{$u->{'name'}} ? @{$u->{'ownmods'}}
217							  : @{$u->{'modules'}};
218			print "<option value='$h->{'id'},$u->{'name'}'>",
219			      &text('edit_uacl', $u->{'name'}, $d),"</option>\n"
220				if (&indexof($name, @m) >= 0);
221			}
222		foreach $g (@{$h->{'groups'}}) {
223			local @m = $ingroup{$g->{'name'}} ? @{$g->{'ownmods'}}
224							  : @{$g->{'modules'}};
225			print "<option value='$h->{'id'},$g->{'name'}'>",
226			      &text('edit_gacl', $g->{'name'}, $d),"</option>\n"
227				if (&indexof($name, @m) >= 0);
228			}
229		}
230	print "</select></form></td>\n";
231	}
232
233print "</tr></table>\n";
234
235# Show hosts with the module or theme
236print &ui_hr();
237print &ui_subheading($text{'edit_hosts'});
238@icons = map { "/servers/images/$_->{'type'}.gif" } @got;
239@links = map { "edit_host.cgi?id=$_->{'id'}" } @got;
240@titles = map { &server_name($_).
241	        ($_->{'module'}->{'version'} ? " ($text{'host_version2'} $_->{'module'}->{'version'})" : "") } @got;
242&icons_table(\@links, \@titles, \@icons);
243print "<br>";
244
245&remote_finished();
246&ui_print_footer("", $text{'index_return'});
247
248
249