From: <jam...@te...> - 2002-09-10 18:00:12
|
> When you go to view some of the sub modules in the net module, though they > are listed as > just list CGI's ( list_routes.cgi for instance), they default to allowing > you to edit them (they are in > a form). How opposed would you be to me patching them such that instead > you seem them > in text (not in a form) and there is an edit button there if you are > allowed to edit them? > Of course I am asking because that is how I wish it to work in order to > minimize the risk of > a customer doing the wrong thing (granted you still have to click save). > Still, if I do this I want it to work in a way that is acceptable to you. > Cheers...james Well, unfortunately I could not wait for a reply, because of dead lines, at any rate, I have created a patch for the DNS sub module of the Net module that does this very thing. When you go into the DNS module now it will simply list the information. If you have permision an edit button will be at the bottom. If you don't, then it won't. If you click edit, the same form as before will appear. In this implementation, I simply copied list_dns.cgi to a new file edit_dns.cgi, and altered list_dns.cgi to only show the information, and have the edit button if appropriate. I did add a new entry to /usr/libexec/webmin/lang/en for "Edit". Also, I added a new funciton to net/net-lib.pl called convert_host_order() which takes a dns object (that dns hash you pass around), and returns a comma delimted string of the nice pretty host order you display on the edit screen (well it used to be the list screen). I tried to make it work for all platforms, but there is no way for me to test that. Cheers...james diff -urN .delta/lang/en current/lang/en --- .delta/lang/en Mon Sep 9 16:25:53 2002 +++ current/lang/en Tue Sep 10 10:57:37 2002 @@ -29,6 +29,7 @@ yes=Yes no=No save=Save +edit=Edit create=Create delete=Delete find=Find diff -urN .delta/net/edit_dns.cgi current/net/edit_dns.cgi --- .delta/net/edit_dns.cgi Wed Dec 31 19:00:00 1969 +++ current/net/edit_dns.cgi Tue Sep 10 13:08:24 2002 @@ -0,0 +1,45 @@ +#!/usr/local/bin/perl +# list_dns.cgi +# Display the DNS client configuration + +require './net-lib.pl'; +$access{'dns'} == 2 || &error($text{'dns_ecannot'}); +&header($text{'dns_title'}, ""); +print "<hr>\n"; + +$dns = &get_dns_config(); +print "<form action=save_dns.cgi>\n"; +print "<table border width=100%>\n"; +print "<tr $tb> <td><b>$text{'dns_options'}</b></td> </tr>\n"; +print "<tr $cb> <td><table width=100%>\n"; + +print "<tr> <td><b>$text{'dns_hostname'}</b></td>\n"; +printf "<td><input name=hostname size=20 value=\"%s\"></td>\n", + &get_hostname(); + +print "<td><b>$text{'dns_order'}</b></td>\n"; +print "<td>",&order_input($dns),"</td> </tr>\n"; + +print "<tr> <td valign=top><b>$text{'dns_servers'}</b></td> <td>\n"; +for($i=0; $i<$max_dns_servers; $i++) { + printf "<input name=nameserver_$i size=15 value=\"%s\"><br>\n", + $dns->{'nameserver'}->[$i]; + } +print "</td>\n"; + +print "<td valign=top><b>$text{'dns_search'}</b></td> <td valign=top>\n"; +printf "<input type=radio name=domain_def value=1 %s> $text{'dns_none'}\n", + $dns->{'domain'} ? "" : "checked"; +printf "<input type=radio name=domain_def value=0 %s> $text{'dns_listed'}\n", + $dns->{'domain'} ? "checked" : ""; +print "<br><textarea name=domain rows=3 cols=30>", + join("\n", @{$dns->{'domain'}}),"</textarea></td> </tr>\n"; + +print "</table></td></tr></table>\n"; +print "<input type=submit value=\"$text{'save'}\">\n" + if ($access{'dns'} == 2); +print "</form>\n"; + +print "<hr>\n"; +&footer("", $text{'index_return'}); + diff -urN .delta/net/lang/en current/net/lang/en --- .delta/net/lang/en Mon Sep 9 16:25:54 2002 +++ current/net/lang/en Tue Sep 10 13:13:50 2002 @@ -87,6 +87,7 @@ routes_local=Local routes routes_err=Failed to save routing routes_ecannot=You are not allowed to edit routing and gateways +routes_vcannot=You are not allowed to view routing and gateways routes_script=Additional routing commands routes_etype='$1' is not a valid route type @@ -100,6 +101,7 @@ dns_listed=Listed .. dns_eorder=Missing resolution order dns_ecannot=You are not allowed to edit DNS client settings +dns_vcannot=You are not allowed to view DNS client settings dns_err=Failed to save DNS configuration dns_ehost='$1' is not a valid hostname dns_ens='$1' is not a valid nameserver IP address diff -urN .delta/net/list_dns.cgi current/net/list_dns.cgi --- .delta/net/list_dns.cgi Mon Sep 9 16:25:53 2002 +++ current/net/list_dns.cgi Tue Sep 10 13:30:55 2002 @@ -3,42 +3,42 @@ # Display the DNS client configuration require './net-lib.pl'; -$access{'dns'} || &error($text{'dns_ecannot'}); +$access{'dns'} || &error($text{'dns_vcannot'}); &header($text{'dns_title'}, ""); print "<hr>\n"; $dns = &get_dns_config(); -print "<form action=save_dns.cgi>\n"; print "<table border width=100%>\n"; print "<tr $tb> <td><b>$text{'dns_options'}</b></td> </tr>\n"; print "<tr $cb> <td><table width=100%>\n"; -print "<tr> <td><b>$text{'dns_hostname'}</b></td>\n"; -printf "<td><input name=hostname size=20 value=\"%s\"></td>\n", - &get_hostname(); +print "<tr> <td align=right><b>$text{'dns_hostname'}:</b></td>\n"; +printf "<td>%s</td>\n", &get_hostname(); -print "<td><b>$text{'dns_order'}</b></td>\n"; -print "<td>",&order_input($dns),"</td> </tr>\n"; +print "<td align=right><b>$text{'dns_order'}:</b></td>\n"; +printf "<td>%s</td> </tr>\n", convert_host_order($dns); -print "<tr> <td valign=top><b>$text{'dns_servers'}</b></td> <td>\n"; +print "<tr> <td valign=top align=right><b>$text{'dns_servers'}:</b></td> <td>\n"; for($i=0; $i<$max_dns_servers; $i++) { - printf "<input name=nameserver_$i size=15 value=\"%s\"><br>\n", + printf "%s<br>\n", $dns->{'nameserver'}->[$i]; } print "</td>\n"; -print "<td valign=top><b>$text{'dns_search'}</b></td> <td valign=top>\n"; -printf "<input type=radio name=domain_def value=1 %s> $text{'dns_none'}\n", - $dns->{'domain'} ? "" : "checked"; -printf "<input type=radio name=domain_def value=0 %s> $text{'dns_listed'}\n", - $dns->{'domain'} ? "checked" : ""; -print "<br><textarea name=domain rows=3 cols=30>", - join("\n", @{$dns->{'domain'}}),"</textarea></td> </tr>\n"; +print "<td valign=top align=right><b>$text{'dns_search'}:</b></td> <td valign=top>\n"; +foreach my $domain (@{$dns->{'domain'}}) { + print "${domain}<br></td> </tr>\n"; + } print "</table></td></tr></table>\n"; -print "<input type=submit value=\"$text{'save'}\">\n" - if ($access{'dns'} == 2); -print "</form>\n"; + +# +# If they can edit display the edit button +if ($access{'dns'} == 2) { + print "<form action=edit_dns.cgi>\n"; + print "<input type=submit value=\"$text{'edit'}\">\n"; + print "</form>\n"; + } print "<hr>\n"; &footer("", $text{'index_return'}); diff -urN .delta/net/net-lib.pl current/net/net-lib.pl --- .delta/net/net-lib.pl Mon Sep 9 16:25:53 2002 +++ current/net/net-lib.pl Tue Sep 10 13:04:13 2002 @@ -68,5 +68,27 @@ return join(".", (hex($1), hex($2), hex($3), hex($4))); } +# +# Convert nsswitch entries to user viewable text. +sub convert_host_order { +my $dns = shift; +my @order = split(/\s+/, $dns->{'order'}); +my %conversion = ( + 'files' => 'Hosts', + 'hosts' => 'Hosts', + 'dns' => 'DNS', + 'bind' => 'DNS', + 'nis' => 'NIS', + 'yp' => 'YP', + 'nisplus' => 'NIS+', + 'db' => 'DB'); + +foreach my $element (@order) { + $element = $conversion{$element}; +} +return join(', ', @order); +} + + 1; |