Handle hostnames with upper-case letters
[webmin.git] / dhcpd / edit_shared.cgi
1 #!/usr/local/bin/perl
2 # edit_shared.cgi
3 # Edit or create a shared network
4
5 require './dhcpd-lib.pl';
6 require './params-lib.pl';
7 &ReadParse();
8 $conf = &get_config();
9 ($par, $sha) = &get_branch('sha');
10 $sconf = $sha->{'members'};
11
12 # check acls
13 %access = &get_module_acl();
14 &error_setup($text{'eacl_aviol'});
15 if ($in{'new'}  ) {
16         &error("$text{'eacl_np'} $text{'eacl_pin'}")
17                 unless &can('c', \%access, $sha) && &can('rw', \%access, $par);
18         }
19 else {
20         &error("$text{'eacl_np'} $text{'eacl_psn'}")
21                 if !&can('r', \%access, $sha);
22         }
23
24 # display
25 &ui_print_header(undef, $in{'new'} ? $text{'esh_crheader'} : $text{'esh_eheader'}, "");
26
27 print "<form action=save_shared.cgi method=post>\n";
28 print "<table border width=100%>\n";
29 print "<tr $tb> <td><b>$text{'esh_tabhdr'}</b></td> </tr>\n";
30 print "<tr $cb> <td><table width=100%>\n";
31
32 print "<tr> <td><b>$text{'esh_desc'}</b></td>\n";
33 printf "<td colspan=3><input name=desc size=60 value='%s'></td> </tr>\n",
34         $sha ? &html_escape($sha->{'comment'}) : "";
35
36 print "<tr> <td><b>$text{'esh_netname'}</b></td>\n";
37 printf "<td><input name=name size=15 value=\"%s\"></td>\n",
38         $sha ? $sha->{'values'}->[0] : "";
39
40 &display_params($sconf, "shared-network");
41
42 print "<tr> <td colspan=4> <table border=0 width=100%>\n";
43 foreach $h (&find("host", $conf)) {
44         push(@host, $h) if &can('r', \%access, $h);
45         }
46 foreach $g (&find("group", $conf)) {
47         push(@group, $g) if &can('r', \%access, $g);
48         }
49 foreach $s (&find("subnet", $conf)) {
50         push(@subn, $s) if &can('r', \%access, $s);
51         }
52 foreach $sh (&find("shared-network", $conf)) {
53         foreach $h (&find("host", $sh->{'members'})) {
54                 push(@host, $h);
55 # if &can('r', \%access, $h);
56                 $inshar{$h} = $sh->{'index'};
57                 }
58         foreach $g (&find("group", $sh->{'members'})) {
59                 push(@group, $g);
60 # if &can('r', \%access, $g);
61                 $inshar{$g} = $sh->{'index'};
62                 }
63         foreach $s (&find("subnet", $sh->{'members'})) {
64                 push(@subn, $s);
65 # if &can('r', \%access, $s);
66                 $inshar{$s} = $sh->{'index'};
67                 }
68         }
69 @host = sort { $a->{'values'}->[0] cmp $b->{'values'}->[0] } @host;
70 # @group = sort { @{$a->{'members'}} <=> @{$b->{'members'}} } @group;
71 @subn = sort { $a->{'values'}->[0] cmp $b->{'values'}->[0] } @subn;
72
73 print "<td valign=top align=right><b>$text{'esh_hosts'}</b></td>\n";
74 print "<td><select name=hosts size=3 multiple>\n";
75 foreach $h (@host) {
76         next if !&can('r', \%access, $h);
77         printf "<option value=\"%s,%s\" %s>%s\n",
78                 $h->{'index'}, $inshar{$h},
79                 (!$in{'new'}) && $inshar{$h} eq $sha->{'index'} ? "selected" : "",
80                 $h->{'values'}->[0];
81         }
82 print "</select></td>\n";
83
84 print "<td valign=top align=right><b>$text{'esh_groups'}</b></td>\n";
85 print "<td><select name=groups size=3 multiple>\n";
86 foreach $g (@group) {
87         local $gm = 0;
88         next if !&can('r', \%access, $g);
89         foreach $h (@{$g->{'members'}}) {
90                 if ($h->{'name'} eq "host") { $gm++; }
91                 }
92         printf "<option value=\"%s,%s\" %s>%s\n",
93                 $g->{'index'}, $inshar{$g},
94                 (!$in{'new'}) && $inshar{$g} eq $sha->{'index'} ? "selected" : "",
95                 &group_name($gm, $g);
96         }
97 print "</select></td>\n";
98
99 print "<td valign=top align=right><b>$text{'esh_subn'}</b></td>\n";
100 print "<td><select name=subnets size=3 multiple>\n";
101 foreach $s (@subn) {
102         next if !&can('r', \%access, $s);
103         printf "<option value=\"%s,%s\" %s>%s\n",
104                 $s->{'index'}, $inshar{$s},
105                 (!$in{'new'}) && $inshar{$s} eq $sha->{'index'} ? "selected" : "",
106                 $s->{'values'}->[0];
107         }
108 print "</select></td>\n";
109
110 if (!$in{'new'}) {
111         # inaccessible hosts in this shared network
112         foreach $h (@host) {
113                 if (!&can('r', \%access, $h) && $inshar{$h} eq $sha->{'index'}) {
114                         print "<input name=hosts value=\"$h->{'index'},$sha->{'index'}\" type=hidden>\n";
115                         }
116                 }
117         # inaccessible groups in this shared network
118         foreach $g (@group) {
119                 if (!&can('r', \%access, $g) && $inshar{$g} eq $sha->{'index'}) {
120                         print "<input name=groups value=\"$g->{'index'},$sha->{'index'}\" type=hidden>\n";
121                         }
122                 }
123         # inaccessible subnets in this shared network
124         foreach $s (@subn) {
125                 if (!&can('r', \%access, $s) && $inshar{$s} eq $sha->{'index'}) {
126                         print "<input name=subnets value=\"$s->{'index'},$sha->{'index'}\" type=hidden>\n";
127                         }
128                 }
129         }
130 print "</table></td></tr>\n";
131
132 print "</table></td></tr></table>\n";
133 if (!$in{'new'}) {
134         print "<input type=hidden name=idx value=\"$in{'idx'}\">\n";
135         print "<table width=100%><tr>\n";
136         print "<td><input type=submit value=\"$text{'save'}\"></td>\n"
137                 if &can('rw', \%access, $sha);
138         print "<td align=center><input type=submit name=options value=\"",
139           &can('rw', \%access, $sha) ? $text{'butt_eco'} : $text{'butt_vco'},
140               "\"></td>\n";               
141         print "<td align=right><input type=submit name=delete ",
142               "value=\"$text{'delete'}\"></td>\n" 
143                   if &can('rw', \%access, $sha, 1);
144         print "</tr></table>\n";
145         print "<a href=\"edit_host.cgi?new=1&sidx=$in{'idx'}"
146                 ."&ret=shared\">$text{'index_addhst'}</a>&nbsp;&nbsp;\n"
147                         if &can('rw', \%access, $sha);
148         print "<a href=\"edit_group.cgi?new=1&sidx=$in{'idx'}"
149                 ."&ret=shared\">$text{'index_addhstg'}</a>&nbsp;&nbsp;\n"
150                         if &can('rw', \%access, $sha);
151         print "<a href=\"edit_subnet.cgi?new=1&sidx=$in{'idx'}"
152                 ."&ret=shared\">$text{'index_addsub'}</a><p>\n"
153                         if &can('rw', \%access, $sha);
154         }
155 else {
156         print "<input type=hidden name=new value=1>\n";
157         print "<input type=submit value=\"$text{'create'}\">\n";
158         }
159
160 if ($config{'dhcpd_version'} >= 3 && !$in{'new'}) {
161         # Display address pools
162         print &ui_hr();
163         print &ui_subheading($text{'esh_pools'});
164         local $pn = 1;
165         foreach $p (&find('pool', $sconf)) {
166                 push(@links, "edit_pool.cgi?uidx=$in{'idx'}&idx=$p->{'index'}");
167                 push(@titles, &text('esub_pool', $pn));
168                 push(@icons, "images/pool.gif");
169                 $pn++;
170                 }
171         if ($pn == 1) {
172                 print "$text{'esub_poolnone'}<p>\n";
173                 }
174         else {
175                 &icons_table(\@links, \@titles, \@icons, 5);
176                 }
177         print "<a href='edit_pool.cgi?uidx=$in{'idx'}&new=1'>",
178               "$text{'esub_pooladd'}</a><br>\n";
179         }
180
181 print "</form>\n";
182 &ui_print_footer("", $text{'esh_return'});
183