forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_leases.cgi
executable file
·38 lines (32 loc) · 1.08 KB
/
delete_leases.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
#!/usr/local/bin/perl
# Delete multiple leases
require './dhcpd-lib.pl';
&ReadParse();
%access = &get_module_acl();
&error_setup($text{'listl_err'});
if( !($access{'w_leases'} && $access{'r_leases'}) ) {
&error("$text{'eacl_np'} $text{'eacl_pdl'}");
}
@d = split(/\0/, $in{'d'});
@d || &error($text{'listl_enone'});
# Find the leases to remove
&tokenize_file($config{'lease_file'}, \@tok);
$i = $j = 0;
while($i < @tok) {
$lease = &parse_struct(\@tok, \$i, $j++, $config{'lease_file'});
if (&indexof($lease->{'index'}, @d) >= 0) {
push(@todelete, $lease);
}
}
# Delete them, in reverse order so that line numbers aren't messed up
&lock_file($config{'lease_file'});
$lref = &read_file_lines($config{'lease_file'});
foreach $lease (reverse(@todelete)) {
splice(@$lref, $lease->{'line'},
$lease->{'eline'} - $lease->{'line'} + 1);
}
&flush_file_lines($config{'lease_file'});
&unlock_file($config{'lease_file'});
&restart_dhcpd();
&webmin_log("delete", "lease", $lease->{'values'}->[0]);
&redirect("list_leases.cgi?all=$in{'all'}&network=$in{'network'}&netmask=$in{'netmask'}");