forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_pool.cgi
executable file
·94 lines (87 loc) · 2.54 KB
/
save_pool.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/local/bin/perl
# save_pool.cgi
# Create, update or delete an address pool
require './dhcpd-lib.pl';
require './params-lib.pl';
&ReadParse();
&lock_file($config{'dhcpd_conf'});
$conf = &get_config();
if ($in{'sidx'} ne "") {
$sha = $conf->[$in{'sidx'}];
$sub = $sha->{'members'}->[$in{'uidx'}];
$indent = 2;
}
else {
$sub = $conf->[$in{'uidx'}];
$indent = 1;
}
if ($in{'new'}) {
$pool = { 'name' => 'pool',
'type' => 1,
'members' => [ ] };
}
else {
$pool = $sub->{'members'}->[$in{'idx'}];
}
# check acls
%access = &get_module_acl();
&error_setup($text{'eacl_aviol'});
&error("$text{'eacl_np'} $text{'eacl_pus'}") if !&can('rw', \%access, $sub);
# save
if ($in{'delete'}) {
# Delete this pool from it's subnet
&save_directive($sub, [ $pool ], [ ], 0);
}
else {
# Validate inputs
for($i=0; defined($low = $in{"range_low_$i"}); $i++) {
next if (!$low);
$hi = $in{"range_hi_$i"}; $dyn = $in{"range_dyn_$i"};
&check_ipaddress($low) ||
&error("'$low' $text{'ssub_invalidipr'}");
!$hi || &check_ipaddress($hi) ||
&error("'$hi' $text{'ssub_invalidipr'}");
$rng = { 'name' => 'range',
'values' => [ ($dyn ? "dynamic-bootp" : ()),
$low, ($hi ? $hi : ()) ] };
push(@rng, $rng);
}
&save_directive($pool, "range", \@rng, 1);
if($in{'failover_peer'}) {
!&check_domain($in{'failover_peer'}) ||
&error("'$in{'failover_peer'}' $text{'ssub_invalidfopeer'}");
$in{'failover_peer'} = "\"$in{'failover_peer'}\"";
push(@failover_peer, { 'name' => 'failover peer',
'values' => [ $in{'failover_peer'} ] });
}
&save_directive($pool, "failover", \@failover_peer, 1);
$in{'allow'} =~ s/\r//g;
foreach $a (split(/\n/, $in{'allow'})) {
push(@allow, { 'name' => 'allow', 'values' => [ $a ] });
}
&save_directive($pool, "allow", \@allow, 1);
$in{'deny'} =~ s/\r//g;
foreach $a (split(/\n/, $in{'deny'})) {
push(@deny, { 'name' => 'deny', 'values' => [ $a ] });
}
&save_directive($pool, "deny", \@deny, 1);
&parse_params($pool, 0);
# Save or create the pool
if ($in{'new'}) {
&save_directive($sub, [ ], [ $pool ], $indent);
}
else {
&save_directive($sub, [ $pool ], [ $pool ], $indent);
}
}
&flush_file_lines();
&unlock_file($config{'dhcpd_conf'});
if ($sub->{'name'} eq 'subnet') {
&webmin_log('modify', 'subnet',
"$sub->{'values'}->[0]/$sub->{'values'}->[2]", \%in);
&redirect("edit_subnet.cgi?sidx=$in{'sidx'}&idx=$in{'uidx'}");
}
else {
&webmin_log('modify', 'shared', $sub->{'values'}->[0], \%in);
&redirect("edit_shared.cgi?idx=$in{'uidx'}");
}