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
f0631f9b
Commit
f0631f9b
authored
Feb 25, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) spaces and curly braces in filter_log.inc
parent
880980a7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
293 additions
and
280 deletions
+293
-280
filter_log.inc
src/etc/inc/filter_log.inc
+293
-280
No files found.
src/etc/inc/filter_log.inc
View file @
f0631f9b
<?php
/*
Copyright (C) 2014
Deciso B.V.
Copyright (C) 2014-2016
Deciso B.V.
Copyright (C) Scott Ullrich
Copyright (C) 2009 Jim Pingle
All rights reserved.
...
...
@@ -38,8 +38,9 @@ function conv_log_filter($logfile, $nentries, $tail = 50, $filtertext = '', $fil
global
$config
;
/* Make sure this is a number before using it in a system call */
if
(
!
(
is_numeric
(
$tail
)))
if
(
!
(
is_numeric
(
$tail
)))
{
return
;
}
if
(
$filtertext
!=
""
){
$tail
=
5000
;
...
...
@@ -54,8 +55,9 @@ function conv_log_filter($logfile, $nentries, $tail = 50, $filtertext = '', $fil
$counter
=
0
;
foreach
(
$logarr
as
$logent
)
{
if
(
$counter
>=
$nentries
)
if
(
$counter
>=
$nentries
)
{
break
;
}
$flent
=
parse_filter_line
(
$logent
);
if
(
isset
(
$flent
)
&&
is_array
(
$flent
))
{
...
...
@@ -68,55 +70,63 @@ function conv_log_filter($logfile, $nentries, $tail = 50, $filtertext = '', $fil
}
}
}
}
/* Since the lines are in reverse order, flip them around if needed based on the user's preference */
return
isset
(
$config
[
'syslog'
][
'reverse'
])
?
$filterlog
:
array_reverse
(
$filterlog
);
}
function
escape_filter_regex
(
$filtertext
)
{
function
escape_filter_regex
(
$filtertext
)
{
/* If the caller (user) has not already put a backslash before a slash, to escape it in the regex, */
/* then this will do it. Take out any "\/" already there, then turn all ordinary "/" into "\/". */
return
str_replace
(
'/'
,
'\/'
,
str_replace
(
'\/'
,
'/'
,
$filtertext
));
}
function
match_filter_line
(
$flent
,
$filtertext
=
""
)
{
if
(
!
$filtertext
)
function
match_filter_line
(
$flent
,
$filtertext
=
""
)
{
if
(
!
$filtertext
)
{
return
true
;
}
$filtertext
=
escape_filter_regex
(
str_replace
(
' '
,
'\s+'
,
$filtertext
));
return
@
preg_match
(
"/
{
$filtertext
}
/i"
,
implode
(
" "
,
array_values
(
$flent
)));
}
function
match_filter_field
(
$flent
,
$fields
)
{
foreach
(
$fields
as
$key
=>
$field
)
{
if
(
$field
==
"All"
)
if
(
$field
==
"All"
)
{
continue
;
}
if
((
strpos
(
$field
,
'!'
)
===
0
))
{
$field
=
substr
(
$field
,
1
);
if
(
strtolower
(
$key
)
==
'act'
)
{
if
(
in_arrayi
(
$flent
[
$key
],
explode
(
" "
,
$field
)))
if
(
in_arrayi
(
$flent
[
$key
],
explode
(
" "
,
$field
)))
{
return
false
;
}
}
else
{
$field_regex
=
escape_filter_regex
(
$field
);
if
(
@
preg_match
(
"/
{
$field_regex
}
/i"
,
$flent
[
$key
]))
if
(
@
preg_match
(
"/
{
$field_regex
}
/i"
,
$flent
[
$key
]))
{
return
false
;
}
}
}
else
{
if
(
strtolower
(
$key
)
==
'act'
)
{
if
(
!
in_arrayi
(
$flent
[
$key
],
explode
(
" "
,
$field
)))
if
(
!
in_arrayi
(
$flent
[
$key
],
explode
(
" "
,
$field
)))
{
return
false
;
}
}
else
{
$field_regex
=
escape_filter_regex
(
$field
);
if
(
!@
preg_match
(
"/
{
$field_regex
}
/i"
,
$flent
[
$key
]))
if
(
!@
preg_match
(
"/
{
$field_regex
}
/i"
,
$flent
[
$key
]))
{
return
false
;
}
}
}
}
return
true
;
}
}
// Case Insensitive in_array function
function
in_arrayi
(
$needle
,
$haystack
)
{
function
in_arrayi
(
$needle
,
$haystack
)
{
return
in_array
(
strtolower
(
$needle
),
array_map
(
'strtolower'
,
$haystack
));
}
...
...
@@ -270,14 +280,17 @@ function parse_filter_line($line)
}
/* AJAX specific handlers */
function
handle_ajax
(
$nentries
,
$tail
=
50
)
{
function
handle_ajax
(
$nentries
,
$tail
=
50
)
{
global
$config
;
if
(
isset
(
$_GET
[
'lastsawtime'
])
||
isset
(
$_POST
[
'lastsawtime'
]))
{
global
$filter_logfile
,
$filterent
;
if
(
isset
(
$_GET
[
'lastsawtime'
]))
if
(
isset
(
$_GET
[
'lastsawtime'
])
||
isset
(
$_POST
[
'lastsawtime'
]))
{
if
(
isset
(
$_GET
[
'lastsawtime'
]))
{
$lastsawtime
=
$_GET
[
'lastsawtime'
];
if
(
isset
(
$_POST
[
'lastsawtime'
]))
}
if
(
isset
(
$_POST
[
'lastsawtime'
]))
{
$lastsawtime
=
$_POST
[
'lastsawtime'
];
}
/* compare lastsawrule's time stamp to filter logs.
* afterwards return the newer records so that client
* can update AJAX interface screen.
...
...
@@ -295,10 +308,10 @@ function handle_ajax($nentries, $tail = 50) {
}
elseif
(
$log_row
[
'act'
]
==
"reject"
)
{
$img
=
"<span class='glyphicon glyphicon-remove text-warning' alt=
{
$log_row
[
'act'
]
}
></span>"
;
}
if
(
$row_time
>
$lastsawtime
)
{
if
(
$log_row
[
'proto'
]
==
"TCP"
)
if
(
$row_time
>
$lastsawtime
)
{
if
(
$log_row
[
'proto'
]
==
"TCP"
)
{
$log_row
[
'proto'
]
.=
":
{
$log_row
[
'tcpflags'
]
}
"
;
}
$img
=
"<a href=
\"
#
\"
onClick=
\"
javascript:getURL('diag_logs_filter.php?getrulenum=
{
$log_row
[
'rulenum'
]
}
,
{
$log_row
[
'rulenum'
]
}
', outputrule);
\"
>
{
$img
}
</a>"
;
$new_rules
.=
"
{
$img
}
||
{
$log_row
[
'time'
]
}
||
{
$log_row
[
'interface'
]
}
||
{
$log_row
[
'srcip'
]
}
||
{
$log_row
[
'dst'
]
}
||
{
$log_row
[
'proto'
]
}
||"
.
time
()
.
"||
\n
"
;
}
...
...
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