Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
9f883fd7
Commit
9f883fd7
authored
Dec 29, 2016
by
Senol Korkmaz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use regular expressions to optimize dhcp_clean_leases()
parent
5b4acfac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
31 deletions
+11
-31
services_dhcp.php
src/www/services_dhcp.php
+11
-31
No files found.
src/www/services_dhcp.php
View file @
9f883fd7
...
...
@@ -47,45 +47,25 @@ function dhcp_clean_leases()
return
;
}
/* Build l
ist of
static MACs */
$
staticmac
s
=
array
();
/* Build l
ease patterns for
static MACs */
$
lease_pattern
s
=
array
();
foreach
(
legacy_config_get_interfaces
(
array
(
"virtual"
=>
false
))
as
$ifname
=>
$ifarr
)
{
if
(
isset
(
$config
[
'dhcpd'
][
$ifname
][
'staticmap'
]))
{
foreach
(
$config
[
'dhcpd'
][
$ifname
][
'staticmap'
]
as
$static
)
{
$
staticmacs
[]
=
$static
[
'mac'
]
;
$
lease_patterns
[]
=
'(\h*lease\s*[0-9\.]+\s*\{[^\{\}]*hardware\h*ethernet\h*'
.
$static
[
'mac'
]
.
'[^\{\}]*(.*"[^\{\}]*\}|\})\s?)'
;
}
}
}
/* Read existing leases */
$leases_contents
=
explode
(
"
\n
"
,
file_get_contents
(
$leasesfile
));
$newleases_contents
=
array
();
$i
=
0
;
while
(
$i
<
count
(
$leases_contents
))
{
/* Find a lease definition */
if
(
substr
(
$leases_contents
[
$i
],
0
,
6
)
==
"lease "
)
{
$templease
=
array
();
$thismac
=
""
;
/* Read to the end of the lease declaration */
do
{
if
(
substr
(
$leases_contents
[
$i
],
0
,
20
)
==
" hardware ethernet "
)
{
$thismac
=
substr
(
$leases_contents
[
$i
],
20
,
17
);
}
$templease
[]
=
$leases_contents
[
$i
];
$i
++
;
}
while
(
$leases_contents
[
$i
-
1
]
!=
"}"
);
/* Check for a matching MAC address and if not present, keep it. */
if
(
!
in_array
(
$thismac
,
$staticmacs
))
{
$newleases_contents
=
array_merge
(
$newleases_contents
,
$templease
);
}
}
else
{
/* It's a line we want to keep, copy it over. */
$newleases_contents
[]
=
$leases_contents
[
$i
];
$i
++
;
}
}
/* Read existing leases file */
$leases_contents
=
file_get_contents
(
$leasesfile
);
/* Remove existing leases for static MACs */
$leases_contents
=
preg_replace
(
$lease_patterns
,
''
,
$leases_contents
);
/* Write out the new leases file */
$fd
=
fopen
(
$leasesfile
,
'w'
);
fwrite
(
$fd
,
implode
(
"
\n
"
,
$newleases_contents
)
);
fwrite
(
$fd
,
$leases_contents
);
fclose
(
$fd
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment