3 # Edit or create a shared network
5 require './dhcpd-lib.pl';
6 require './params-lib.pl';
9 ($par, $sha) = &get_branch('sha');
10 $sconf = $sha->{'members'};
13 %access = &get_module_acl();
14 &error_setup($text{'eacl_aviol'});
16 &error("$text{'eacl_np'} $text{'eacl_pin'}")
17 unless &can('c', \%access, $sha) && &can('rw', \%access, $par);
20 &error("$text{'eacl_np'} $text{'eacl_psn'}")
21 if !&can('r', \%access, $sha);
25 &ui_print_header(undef, $in{'new'} ? $text{'esh_crheader'} : $text{'esh_eheader'}, "");
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";
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'}) : "";
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] : "";
40 &display_params($sconf, "shared-network");
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);
46 foreach $g (&find("group", $conf)) {
47 push(@group, $g) if &can('r', \%access, $g);
49 foreach $s (&find("subnet", $conf)) {
50 push(@subn, $s) if &can('r', \%access, $s);
52 foreach $sh (&find("shared-network", $conf)) {
53 foreach $h (&find("host", $sh->{'members'})) {
55 # if &can('r', \%access, $h);
56 $inshar{$h} = $sh->{'index'};
58 foreach $g (&find("group", $sh->{'members'})) {
60 # if &can('r', \%access, $g);
61 $inshar{$g} = $sh->{'index'};
63 foreach $s (&find("subnet", $sh->{'members'})) {
65 # if &can('r', \%access, $s);
66 $inshar{$s} = $sh->{'index'};
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;
73 print "<td valign=top align=right><b>$text{'esh_hosts'}</b></td>\n";
74 print "<td><select name=hosts size=3 multiple>\n";
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" : "",
82 print "</select></td>\n";
84 print "<td valign=top align=right><b>$text{'esh_groups'}</b></td>\n";
85 print "<td><select name=groups size=3 multiple>\n";
88 next if !&can('r', \%access, $g);
89 foreach $h (@{$g->{'members'}}) {
90 if ($h->{'name'} eq "host") { $gm++; }
92 printf "<option value=\"%s,%s\" %s>%s\n",
93 $g->{'index'}, $inshar{$g},
94 (!$in{'new'}) && $inshar{$g} eq $sha->{'index'} ? "selected" : "",
97 print "</select></td>\n";
99 print "<td valign=top align=right><b>$text{'esh_subn'}</b></td>\n";
100 print "<td><select name=subnets size=3 multiple>\n";
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" : "",
108 print "</select></td>\n";
111 # inaccessible hosts in this shared network
113 if (!&can('r', \%access, $h) && $inshar{$h} eq $sha->{'index'}) {
114 print "<input name=hosts value=\"$h->{'index'},$sha->{'index'}\" type=hidden>\n";
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";
123 # inaccessible subnets in this shared network
125 if (!&can('r', \%access, $s) && $inshar{$s} eq $sha->{'index'}) {
126 print "<input name=subnets value=\"$s->{'index'},$sha->{'index'}\" type=hidden>\n";
130 print "</table></td></tr>\n";
132 print "</table></td></tr></table>\n";
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'},
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> \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> \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);
156 print "<input type=hidden name=new value=1>\n";
157 print "<input type=submit value=\"$text{'create'}\">\n";
160 if ($config{'dhcpd_version'} >= 3 && !$in{'new'}) {
161 # Display address pools
163 print &ui_subheading($text{'esh_pools'});
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");
172 print "$text{'esub_poolnone'}<p>\n";
175 &icons_table(\@links, \@titles, \@icons, 5);
177 print "<a href='edit_pool.cgi?uidx=$in{'idx'}&new=1'>",
178 "$text{'esub_pooladd'}</a><br>\n";
182 &ui_print_footer("", $text{'esh_return'});