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
25485266
Commit
25485266
authored
Apr 22, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(filter, alias) validate / transform url content before save
parent
7e239603
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
2 deletions
+42
-2
pfsense-utils.inc
src/etc/inc/pfsense-utils.inc
+42
-2
No files found.
src/etc/inc/pfsense-utils.inc
View file @
25485266
...
@@ -461,12 +461,52 @@ function process_alias_urltable($name, $url, $freq, $forceupdate=false) {
...
@@ -461,12 +461,52 @@ function process_alias_urltable($name, $url, $freq, $forceupdate=false) {
// If the file doesn't exist or is older than update_freq days, fetch a new copy.
// If the file doesn't exist or is older than update_freq days, fetch a new copy.
if
(
!
file_exists
(
$urltable_filename
)
||
((
time
()
-
filemtime
(
$urltable_filename
))
>
(
$freq
*
86400
-
90
))
||
$forceupdate
)
{
if
(
!
file_exists
(
$urltable_filename
)
||
((
time
()
-
filemtime
(
$urltable_filename
))
>
(
$freq
*
86400
-
90
))
||
$forceupdate
)
{
// open file handle to output file, in case the process takes a lot of time, make sure there's a file before
// filter starts to load. Also helps for tracking progress.
//
// todo: rethink alias_expand_urltable in filter.inc , its probably not a very good idea to download and
// process files during boot.
$output_file_handle
=
fopen
(
$urltable_filename
,
'w'
);
$alias_type
=
alias_get_type
(
$name
);
// Try to fetch the URL supplied
// Try to fetch the URL supplied
@
unlink
(
"
{
$urltable_filename
}
.tmp"
);
@
unlink
(
"
{
$urltable_filename
}
.tmp"
);
$verify_ssl
=
isset
(
$config
[
'system'
][
'checkaliasesurlcert'
]);
$verify_ssl
=
isset
(
$config
[
'system'
][
'checkaliasesurlcert'
]);
if
(
download_file
(
$url
,
"
{
$urltable_filename
}
.tmp"
,
$verify_ssl
))
{
if
(
download_file
(
$url
,
"
{
$urltable_filename
}
.tmp"
,
$verify_ssl
))
{
mwexec
(
"/usr/bin/sed -E 's/\;.*//g; /^[[:space:]]*($|#)/d' "
.
escapeshellarg
(
$urltable_filename
.
".tmp"
)
.
" > "
.
escapeshellarg
(
$urltable_filename
));
foreach
(
preg_split
(
'/[\n\r]+/'
,
file_get_contents
(
"
{
$urltable_filename
}
.tmp"
),
-
1
,
PREG_SPLIT_NO_EMPTY
)
as
$line
)
{
if
(
alias_get_type
(
$name
)
==
"urltable_ports"
)
{
$line
=
trim
(
$line
);
// remove leading spaces
if
(
$line
[
0
]
!=
'#'
)
{
// cleanse line item
$line
=
preg_split
(
'/\s+/'
,
$line
)[
0
];
if
(
$alias_type
==
"urltable_ports"
)
{
// todo: add proper validation for ports here
fwrite
(
$output_file_handle
,
"
{
$line
}
\n
"
);
}
else
{
// validate or resolve line items, skip unparseable content
if
(
is_subnet
(
$line
)
||
is_ipaddr
(
$line
))
{
fwrite
(
$output_file_handle
,
"
{
$line
}
\n
"
);
}
elseif
(
is_hostname
(
$line
))
{
foreach
(
array
(
DNS_AAAA
,
DNS_A
)
as
$dns_type
)
{
// normally dns_get_record should be able to use DNS_A + DNS_AAAA
// but for some strange reason not on our platform...
$dns_records
=
@
dns_get_record
(
$line
,
$dns_type
);
if
(
$dns_records
)
{
foreach
(
$dns_records
as
$dns_record
)
{
if
(
!
empty
(
$dns_record
[
'ipv6'
]))
{
fwrite
(
$output_file_handle
,
$dns_record
[
'ipv6'
]
.
"
\n
"
);
}
elseif
(
!
empty
(
$dns_record
[
'ip'
]))
{
fwrite
(
$output_file_handle
,
$dns_record
[
'ip'
]
.
"
\n
"
);
}
}
}
}
}
fflush
(
$output_file_handle
);
}
}
}
fclose
(
$output_file_handle
);
if
(
$alias_type
==
"urltable_ports"
)
{
$ports
=
explode
(
"
\n
"
,
file_get_contents
(
$urltable_filename
));
$ports
=
explode
(
"
\n
"
,
file_get_contents
(
$urltable_filename
));
$ports
=
group_ports
(
$ports
);
$ports
=
group_ports
(
$ports
);
file_put_contents
(
$urltable_filename
,
implode
(
"
\n
"
,
$ports
));
file_put_contents
(
$urltable_filename
,
implode
(
"
\n
"
,
$ports
));
...
...
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