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
9e00c0ac
Commit
9e00c0ac
authored
Jul 10, 2015
by
Ad Schellevis
Committed by
Franco Fichtner
Jul 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) cleanups related to filter_log.inc
parent
fbc56cbf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
113 deletions
+118
-113
filter_log.inc
src/etc/inc/filter_log.inc
+0
-113
diag_logs_filter.php
src/www/diag_logs_filter.php
+104
-0
log.widget.php
src/www/widgets/widgets/log.widget.php
+14
-0
No files found.
src/etc/inc/filter_log.inc
View file @
9e00c0ac
...
...
@@ -268,118 +268,6 @@ function parse_filter_line($line)
return
$flent
;
}
function
get_port_with_service
(
$port
,
$proto
)
{
if
(
!
$port
)
return
''
;
$service
=
getservbyport
(
$port
,
$proto
);
$portstr
=
""
;
if
(
$service
)
{
$portstr
=
sprintf
(
'<span title="'
.
gettext
(
'Service %1$s/%2$s: %3$s'
)
.
'">'
.
htmlspecialchars
(
$port
)
.
'</span>'
,
$port
,
$proto
,
$service
);
}
else
{
$portstr
=
htmlspecialchars
(
$port
);
}
return
':'
.
$portstr
;
}
function
find_rule_by_number
(
$rulenum
,
$type
=
'block'
)
{
/* Passing arbitrary input to grep could be a Very Bad Thing(tm) */
if
(
!
is_numeric
(
$rulenum
)
||
!
in_array
(
$type
,
array
(
'pass'
,
'block'
,
'match'
,
'rdr'
)))
return
;
$lookup_pattern
=
"^@
{
$rulenum
}
[[:space:]]
{
$type
}
[[:space:]].*[[:space:]]log[[:space:]]"
;
/* At the moment, miniupnpd is the only thing I know of that
generates logging rdr rules */
unset
(
$buffer
);
if
(
$type
==
"rdr"
)
$_gb
=
exec
(
"/sbin/pfctl -vvPsn -a
\"
miniupnpd
\"
| /usr/bin/egrep "
.
escapeshellarg
(
"^@
{
$rulenum
}
"
),
$buffer
);
else
{
if
(
file_exists
(
'/tmp/rules.debug'
))
{
$_gb
=
exec
(
'/sbin/pfctl -vvPnf /tmp/rules.debug 2>/dev/null | /usr/bin/egrep '
.
escapeshellarg
(
$lookup_pattern
),
$buffer
);
}
else
{
$_gb
=
exec
(
'/sbin/pfctl -vvPsr | /usr/bin/egrep '
.
escapeshellarg
(
$lookup_pattern
),
$buffer
);
}
}
if
(
is_array
(
$buffer
))
return
$buffer
[
0
];
return
""
;
}
function
buffer_rules_load
()
{
global
$buffer_rules_rdr
,
$buffer_rules_normal
;
unset
(
$buffer
,
$buffer_rules_rdr
,
$buffer_rules_normal
);
/* Redeclare globals after unset to work around PHP */
global
$buffer_rules_rdr
,
$buffer_rules_normal
;
$buffer_rules_rdr
=
array
();
$buffer_rules_normal
=
array
();
$_gb
=
exec
(
"/sbin/pfctl -vvPsn -a
\"
miniupnpd
\"
| grep '^@'"
,
$buffer
);
if
(
is_array
(
$buffer
))
{
foreach
(
$buffer
as
$line
)
{
list
(
$key
,
$value
)
=
explode
(
" "
,
$line
,
2
);
$buffer_rules_rdr
[
$key
]
=
$value
;
}
}
unset
(
$buffer
,
$_gb
);
if
(
file_exists
(
'/tmp/rules.debug'
))
{
$_gb
=
exec
(
"/sbin/pfctl -vvPnf /tmp/rules.debug 2>/dev/null | /usr/bin/egrep '^@[0-9]+\([0-9]+\)[[:space:]].*[[:space:]]log[[:space:]]' | /usr/bin/egrep -v '^@[0-9]+\([0-9]+\)[[:space:]](nat|rdr|binat|no|scrub)'"
,
$buffer
);
}
else
{
$_gb
=
exec
(
"/sbin/pfctl -vvPsr | /usr/bin/egrep '^@[0-9]+\([0-9]+\)[[:space:]].*[[:space:]]log[[:space:]]'"
,
$buffer
);
}
if
(
is_array
(
$buffer
))
{
foreach
(
$buffer
as
$line
)
{
list
(
$key
,
$value
)
=
explode
(
" "
,
$line
,
2
);
$matches
=
array
();
if
(
preg_match
(
'/\@(?P<rulenum>\d+)\)/'
,
$key
,
$matches
)
==
1
)
{
$key
=
"@
{
$matches
[
'rulenum'
]
}
"
;
}
$buffer_rules_normal
[
$key
]
=
$value
;
}
}
unset
(
$_gb
,
$buffer
);
}
function
buffer_rules_clear
()
{
unset
(
$GLOBALS
[
'buffer_rules_normal'
]);
unset
(
$GLOBALS
[
'buffer_rules_rdr'
]);
}
function
find_rule_by_number_buffer
(
$rulenum
,
$type
)
{
global
$buffer_rules_rdr
,
$buffer_rules_normal
;
$lookup_key
=
"@
{
$rulenum
}
"
;
if
(
$type
==
"rdr"
)
{
$ruleString
=
$buffer_rules_rdr
[
$lookup_key
];
//TODO: get the correct 'description' part of a RDR log line. currently just first 30 characters..
$rulename
=
substr
(
$ruleString
,
0
,
30
);
}
else
{
$ruleString
=
$buffer_rules_normal
[
$lookup_key
];
list
(,
$rulename
,)
=
explode
(
"
\"
"
,
$ruleString
);
$rulename
=
str_replace
(
"USER_RULE: "
,
'<span class="glyphicon glyphicon-user" title="USER_RULE" alt="USER_RULE"></span>'
,
$rulename
);
}
return
"
{
$rulename
}
(
{
$lookup_key
}
)"
;
}
function
find_action_image
(
$action
)
{
if
((
strstr
(
strtolower
(
$action
),
'p'
))
||
(
strtolower
(
$action
)
==
'rdr'
))
{
return
'glyphicon glyphicon-play text-success'
;
}
if
(
strstr
(
strtolower
(
$action
),
'r'
))
{
return
'glyphicon glyphicon-remove text-warning'
;
}
return
'glyphicon glyphicon-remove text-danger'
;
}
/* AJAX specific handlers */
function
handle_ajax
(
$nentries
,
$tail
=
50
)
{
global
$config
;
...
...
@@ -399,7 +287,6 @@ function handle_ajax($nentries, $tail = 50) {
$filterlog
=
isset
(
$config
[
'syslog'
][
'reverse'
])
?
array_reverse
(
$filterlog
)
:
$filterlog
;
foreach
(
$filterlog
as
$log_row
)
{
$row_time
=
strtotime
(
$log_row
[
'time'
]);
//$img = "<img border='0' src='" . find_action_image($log_row['act']) . "' alt={$log_row['act']} title={$log_row['act']} />";
if
(
$log_row
[
'act'
]
==
"pass"
)
{
$img
=
"<span class='glyphicon glyphicon-play text-success' alt=
{
$log_row
[
'act'
]
}
></span>"
;
}
elseif
(
$log_row
[
'act'
]
==
"block"
)
{
...
...
src/www/diag_logs_filter.php
View file @
9e00c0ac
...
...
@@ -372,6 +372,110 @@ function easyrule_parse_pass($int, $proto, $src, $dst, $dstport = 0, $ipproto =
return
gettext
(
"Unknown pass error."
);
}
/********************************************************************************************************************
* other imported
********************************************************************************************************************/
function
get_port_with_service
(
$port
,
$proto
)
{
if
(
!
$port
)
return
''
;
$service
=
getservbyport
(
$port
,
$proto
);
$portstr
=
""
;
if
(
$service
)
{
$portstr
=
sprintf
(
'<span title="'
.
gettext
(
'Service %1$s/%2$s: %3$s'
)
.
'">'
.
htmlspecialchars
(
$port
)
.
'</span>'
,
$port
,
$proto
,
$service
);
}
else
{
$portstr
=
htmlspecialchars
(
$port
);
}
return
':'
.
$portstr
;
}
function
find_rule_by_number
(
$rulenum
,
$type
=
'block'
)
{
/* Passing arbitrary input to grep could be a Very Bad Thing(tm) */
if
(
!
is_numeric
(
$rulenum
)
||
!
in_array
(
$type
,
array
(
'pass'
,
'block'
,
'match'
,
'rdr'
)))
return
;
$lookup_pattern
=
"^@
{
$rulenum
}
[[:space:]]
{
$type
}
[[:space:]].*[[:space:]]log[[:space:]]"
;
/* At the moment, miniupnpd is the only thing I know of that
generates logging rdr rules */
unset
(
$buffer
);
if
(
$type
==
"rdr"
)
$_gb
=
exec
(
"/sbin/pfctl -vvPsn -a
\"
miniupnpd
\"
| /usr/bin/egrep "
.
escapeshellarg
(
"^@
{
$rulenum
}
"
),
$buffer
);
else
{
if
(
file_exists
(
'/tmp/rules.debug'
))
{
$_gb
=
exec
(
'/sbin/pfctl -vvPnf /tmp/rules.debug 2>/dev/null | /usr/bin/egrep '
.
escapeshellarg
(
$lookup_pattern
),
$buffer
);
}
else
{
$_gb
=
exec
(
'/sbin/pfctl -vvPsr | /usr/bin/egrep '
.
escapeshellarg
(
$lookup_pattern
),
$buffer
);
}
}
if
(
is_array
(
$buffer
))
return
$buffer
[
0
];
return
""
;
}
function
buffer_rules_load
()
{
global
$buffer_rules_rdr
,
$buffer_rules_normal
;
unset
(
$buffer
,
$buffer_rules_rdr
,
$buffer_rules_normal
);
/* Redeclare globals after unset to work around PHP */
global
$buffer_rules_rdr
,
$buffer_rules_normal
;
$buffer_rules_rdr
=
array
();
$buffer_rules_normal
=
array
();
$_gb
=
exec
(
"/sbin/pfctl -vvPsn -a
\"
miniupnpd
\"
| grep '^@'"
,
$buffer
);
if
(
is_array
(
$buffer
))
{
foreach
(
$buffer
as
$line
)
{
list
(
$key
,
$value
)
=
explode
(
" "
,
$line
,
2
);
$buffer_rules_rdr
[
$key
]
=
$value
;
}
}
unset
(
$buffer
,
$_gb
);
if
(
file_exists
(
'/tmp/rules.debug'
))
{
$_gb
=
exec
(
"/sbin/pfctl -vvPnf /tmp/rules.debug 2>/dev/null | /usr/bin/egrep '^@[0-9]+\([0-9]+\)[[:space:]].*[[:space:]]log[[:space:]]' | /usr/bin/egrep -v '^@[0-9]+\([0-9]+\)[[:space:]](nat|rdr|binat|no|scrub)'"
,
$buffer
);
}
else
{
$_gb
=
exec
(
"/sbin/pfctl -vvPsr | /usr/bin/egrep '^@[0-9]+\([0-9]+\)[[:space:]].*[[:space:]]log[[:space:]]'"
,
$buffer
);
}
if
(
is_array
(
$buffer
))
{
foreach
(
$buffer
as
$line
)
{
list
(
$key
,
$value
)
=
explode
(
" "
,
$line
,
2
);
$matches
=
array
();
if
(
preg_match
(
'/\@(?P<rulenum>\d+)\)/'
,
$key
,
$matches
)
==
1
)
{
$key
=
"@
{
$matches
[
'rulenum'
]
}
"
;
}
$buffer_rules_normal
[
$key
]
=
$value
;
}
}
unset
(
$_gb
,
$buffer
);
}
function
buffer_rules_clear
()
{
unset
(
$GLOBALS
[
'buffer_rules_normal'
]);
unset
(
$GLOBALS
[
'buffer_rules_rdr'
]);
}
function
find_rule_by_number_buffer
(
$rulenum
,
$type
)
{
global
$buffer_rules_rdr
,
$buffer_rules_normal
;
$lookup_key
=
"@
{
$rulenum
}
"
;
if
(
$type
==
"rdr"
)
{
$ruleString
=
$buffer_rules_rdr
[
$lookup_key
];
//TODO: get the correct 'description' part of a RDR log line. currently just first 30 characters..
$rulename
=
substr
(
$ruleString
,
0
,
30
);
}
else
{
$ruleString
=
$buffer_rules_normal
[
$lookup_key
];
list
(,
$rulename
,)
=
explode
(
"
\"
"
,
$ruleString
);
$rulename
=
str_replace
(
"USER_RULE: "
,
'<span class="glyphicon glyphicon-user" title="USER_RULE" alt="USER_RULE"></span>'
,
$rulename
);
}
return
"
{
$rulename
}
(
{
$lookup_key
}
)"
;
}
/**********************************************************************************************************************************
* End of imported code
*********************************************************************************************************************************/
...
...
src/www/widgets/widgets/log.widget.php
View file @
9e00c0ac
...
...
@@ -36,6 +36,20 @@ require_once("pfsense-utils.inc");
require_once
(
"functions.inc"
);
require_once
(
"filter_log.inc"
);
function
find_action_image
(
$action
)
{
if
((
strstr
(
strtolower
(
$action
),
'p'
))
||
(
strtolower
(
$action
)
==
'rdr'
))
{
return
'glyphicon glyphicon-play text-success'
;
}
if
(
strstr
(
strtolower
(
$action
),
'r'
))
{
return
'glyphicon glyphicon-remove text-warning'
;
}
return
'glyphicon glyphicon-remove text-danger'
;
}
if
(
is_numeric
(
$_POST
[
'filterlogentries'
]))
{
$config
[
'widgets'
][
'filterlogentries'
]
=
$_POST
[
'filterlogentries'
];
...
...
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