3 # Edit or create a subnet
5 require './dhcpd-lib.pl';
6 require './params-lib.pl';
9 ($par, $sub) = &get_branch('sub');
10 $mems = $par->{'members'};
11 $sconf = $sub->{'members'};
14 %access = &get_module_acl();
15 &error_setup($text{'eacl_aviol'});
17 &error("$text{'eacl_np'} $text{'eacl_pis'}")
18 unless &can('c', \%access, $sub) && &can('rw', \%access, $par);
21 &error("$text{'eacl_np'} $text{'eacl_pss'}")
22 if !&can('r', \%access, $sub);
26 if ($in{'sidx'} ne "") {
27 local $s = $conf->[$in{'sidx'}];
28 $desc = &text('ehost_shared', $s->{'values'}->[0]);
30 &ui_print_header($desc, $in{'new'} ? $text{'esub_crheader'} : $text{'esub_edheader'}, "");
32 foreach $s (&find("shared-network", $conf)) {
33 if ($in{'sidx'} eq $s->{'index'}) {
38 print "<form action=save_subnet.cgi method=post>\n";
39 print "<input name=ret value=\"$in{'ret'}\" type=hidden>\n";
40 print "<table border width=100%>\n";
41 print "<tr $tb> <td><b>$text{'esub_tabhdr'}</b></td> </tr>\n";
42 print "<tr $cb> <td><table width=100%>\n";
44 print "<tr> <td><b>$text{'esub_desc'}</b></td>\n";
45 printf "<td colspan=3><input name=desc size=60 value='%s'></td> </tr>\n",
46 $sub ? &html_escape($sub->{'comment'}) : "";
48 print "<tr> <td><b>$text{'esub_naddr'}</b></td>\n";
49 printf "<td><input name=network size=25 value=\"%s\"></td>\n",
50 $sub ? $sub->{'values'}->[0] : "";
52 print "<td><b>$text{'esub_nmask'}</b></td>\n";
53 printf "<td><input name=netmask size=15 value=\"%s\"></td> </tr>\n",
54 $sub ? $sub->{'values'}->[2] : "";
56 @range = $sub ? &find("range", $sub->{'members'}) : ();
57 print "<tr> <td valign=top><b>$text{'esub_arange'}</b></td> <td colspan=3>\n";
58 for($i=0; $i<=@range; $i++) {
60 local $dyn = ($r->{'values'}->[0] eq "dynamic-bootp");
61 printf "<input name=range_low_$i size=15 value=\"%s\"> - \n",
62 $r->{'values'}->[$dyn];
63 printf "<input name=range_hi_$i size=15 value=\"%s\"> \n",
64 $r->{'values'}->[$dyn+1];
65 printf "<input type=checkbox name=range_dyn_$i value=1 %s>\n",
66 $dyn ? "checked" : "";
67 print "$text{'esub_dbooptpq'}<br>\n";
69 print "</td> </tr>\n";
71 if (!defined($in{'ret'})) {
72 print "<tr> <td><b>$text{'esub_shnet'}</b></td>\n";
73 print "<td><select name=parent>\n";
74 printf "<option value=\"\" '%s'><%s>\n",
75 $s_parent ? "" : "checked", $text{'esub_none'};
76 foreach $s (&find("shared-network", $conf)) {
77 printf "<option value=\"%s\" %s>%s\n",
79 $s eq $s_parent ? "selected" : "",
81 if &can('rw', \%access, $s);
83 print "</select></td>\n";
86 print "<input name=parent type=hidden value=$s_parent->{'index'}>\n";
87 print "<tr> <td> </td> <td> </td>\n";
90 &display_params($sconf, "subnet");
92 foreach $h (&find("host", $mems)) {
94 # if &can('r', \%access, $h);
96 foreach $g (&find("group", $mems)) {
98 # if &can('r', \%access, $g);
100 foreach $s (&find("subnet", $mems)) {
101 foreach $h (&find("host", $s->{'members'})) {
103 # if &can('r', \%access, $h);
104 $insubn{$h} = $s->{'index'};
106 foreach $g (&find("group", $s->{'members'})) {
108 # if &can('r', \%access, $g);
109 $insubn{$g} = $s->{'index'};
112 @host = sort { $a->{'values'}->[0] cmp $b->{'values'}->[0] } @host;
113 # @group = sort { @{$a->{'members'}} <=> @{$b->{'members'}} } @group;
115 print "<tr> <td valign=top><b>$text{'esub_hosts'}</b></td>\n";
116 print "<td><select name=hosts size=3 multiple>\n";
118 next if !&can('r', \%access, $h);
119 printf "<option value=\"%s,%s\" %s>%s\n",
120 $h->{'index'}, $insubn{$h},
121 (!$in{'new'}) && $insubn{$h} eq $sub->{'index'} ? "selected" : "",
124 print "</select></td>\n";
126 print "<td valign=top><b>$text{'esub_groups'}</b></td>\n";
127 print "<td><select name=groups size=3 multiple>\n";
128 foreach $g (@group) {
130 next if !&can('r', \%access, $g);
131 foreach $h (@{$g->{'members'}}) {
132 if ($h->{'name'} eq "host") { $gm++; }
134 printf "<option value=\"%s,%s\" %s>%s\n",
135 $g->{'index'}, $insubn{$g},
136 (!$in{'new'}) && $insubn{$g} eq $sub->{'index'} ? "selected" : "",
137 &group_name($gm, $g);
139 print "</select></td>\n";
142 # inaccessible hosts in this subnet
144 if (!&can('r', \%access, $h) && $insubn{$h} eq $sub->{'index'}) {
145 print "<input name=hosts value=\"$h->{'index'},$sub->{'index'}\" type=hidden>\n";
148 # inaccessible groups in this subnet
149 foreach $g (@group) {
150 if (!&can('r', \%access, $g) && $insubn{$g} eq $sub->{'index'}) {
151 print "<input name=groups value=\"$g->{'index'},$sub->{'index'}\" type=hidden>\n";
156 print "</table></td></tr></table>\n";
157 print "<input type=hidden name=sidx value=\"$in{'sidx'}\">\n";
159 # Show buttons for existing subnet
160 print "<input type=hidden name=idx value=\"$in{'idx'}\">\n";
161 print "<table width=100%><tr>\n";
162 print "<td><input type=submit value=\"$text{'save'}\"></td>\n"
163 if &can('rw', \%access, $sub);
164 print "<td align=center><input type=submit name=options value=\"",
165 &can('rw', \%access, $sub) ? $text{'butt_eco'} : $text{'butt_vco'},
167 if ($access{'r_leases'}) {
168 print "<td align=center><input type=submit name=leases ",
169 "value=\"$text{'butt_leases'}\"></td>\n";
171 print "<td align=right><input type=submit name=delete ",
172 "value=\"$text{'delete'}\"></td>\n" if &can('rw', \%access, $sub, 1);
173 print "</tr></table>\n";
174 print "<a href=\"edit_host.cgi?new=1&sidx=$in{'sidx'}&uidx=$in{'idx'}"
175 ."&ret=subnet\">$text{'index_addhst'}</a> \n"
176 if &can('rw', \%access, $sub);
177 print "<a href=\"edit_group.cgi?new=1&sidx=$in{'sidx'}&uidx=$in{'idx'}"
178 ."&ret=subnet\">$text{'index_addhstg'}</a><p>\n"
179 if &can('rw', \%access, $sub);
182 # Show create button for new subnet
183 print "<input type=hidden name=new value=1>\n";
184 print "<input type=submit value=\"$text{'create'}\">\n";
187 if ($config{'dhcpd_version'} >= 3 && !$in{'new'}) {
188 # Display address pools
190 print &ui_subheading($text{'esub_pools'});
192 foreach $p (&find('pool', $sconf)) {
193 push(@links, "edit_pool.cgi?uidx=$in{'idx'}&sidx=$in{'sidx'}&idx=$p->{'index'}");
194 push(@titles, &text('esub_pool', $pn));
195 push(@icons, "images/pool.gif");
199 print "$text{'esub_poolnone'}<p>\n";
202 &icons_table(\@links, \@titles, \@icons, 5);
204 print "<a href='edit_pool.cgi?uidx=$in{'idx'}&sidx=$in{'sidx'}&new=1'>",
205 "$text{'esub_pooladd'}</a><br>\n";
209 if ($in{'ret'} eq "shared") {
210 &ui_print_footer("edit_shared.cgi?idx=$in{'sidx'}", $text{'esub_retshar'});
213 &ui_print_footer("", $text{'esub_return'});