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
f9333ee4
Commit
f9333ee4
authored
Aug 05, 2015
by
jschellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update lagacy Firewall Log Summary page, better coding and fancy layout
parent
627858d3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
135 deletions
+117
-135
diag_logs_filter_summary.php
src/www/diag_logs_filter_summary.php
+117
-135
No files found.
src/www/diag_logs_filter_summary.php
View file @
f9333ee4
<?php
error_reporting
(
E_ALL
);
/*
Copyright (C) 2014
Deciso B.V.
Copyright (C) 2014
-2015 Deciso B.V. - J. Schellevis
Copyright (C) 2009 Jim Pingle (jpingle@gmail.com)
All rights reserved.
...
...
@@ -34,11 +34,14 @@ require_once("filter_log.inc");
require_once
(
"interfaces.inc"
);
$filter_logfile
=
'/var/log/filter.log'
;
$lines
=
5000
;
$entriesperblock
=
5
;
$lines
=
5000
;
// Maximum number of log entries to fetch
$entriesperblock
=
10
;
// Maximum elements to show individually
// Retrieve filter log data
$filterlog
=
conv_log_filter
(
$filter_logfile
,
$lines
,
$lines
);
// Set total retrieved line counter
$gotlines
=
count
(
$filterlog
);
// Set readable fieldnames
$fields
=
array
(
'act'
=>
gettext
(
"Actions"
),
'interface'
=>
gettext
(
"Interfaces"
),
...
...
@@ -49,100 +52,12 @@ $fields = array(
'dstport'
=>
gettext
(
"Destination Ports"
));
$summary
=
array
();
foreach
(
array_keys
(
$fields
)
as
$f
)
{
$summary
[
$f
]
=
array
();
}
$totals
=
array
();
function
cmp
(
$a
,
$b
)
{
if
(
$a
==
$b
)
{
return
0
;
}
return
(
$a
<
$b
)
?
1
:
-
1
;
}
function
stat_block
(
$summary
,
$stat
,
$num
)
{
global
$g
,
$gotlines
,
$fields
;
uasort
(
$summary
[
$stat
]
,
'cmp'
);
print
"<table width=
\"
200
\"
cellpadding=
\"
3
\"
cellspacing=
\"
0
\"
border=
\"
1
\"
summary=
\"
source destination ip
\"
>"
;
print
"<tr><th colspan=
\"
2
\"
>
{
$fields
[
$stat
]
}
"
.
gettext
(
"data"
)
.
"</th></tr>"
;
$k
=
array_keys
(
$summary
[
$stat
]);
$total
=
0
;
$numentries
=
0
;
for
(
$i
=
0
;
$i
<
$num
;
$i
++
)
{
if
(
isset
(
$k
[
$i
]))
{
$total
+=
$summary
[
$stat
][
$k
[
$i
]];
$numentries
++
;
$outstr
=
$k
[
$i
];
if
(
is_ipaddr
(
$outstr
))
{
$outstr
=
"<a href=
\"
diag_dns.php?host=
{
$outstr
}
\"
title=
\"
"
.
gettext
(
"Reverse Resolve with DNS"
)
.
"
\"
><img border=
\"
0
\"
src=
\"
/themes/
{
$g
[
'theme'
]
}
/images/icons/icon_log.gif
\"
alt=
\"
log
\"
/></a>
{
$outstr
}
"
;
}
elseif
(
substr_count
(
$outstr
,
'/'
)
==
1
)
{
list
(
$proto
,
$port
)
=
explode
(
'/'
,
$outstr
);
$service
=
getservbyport
(
$port
,
strtolower
(
$proto
));
if
(
$service
)
$outstr
.=
":
{
$service
}
"
;
}
print
"<tr><td>
{
$outstr
}
</td><td width=
\"
50
\"
align=
\"
right
\"
>
{
$summary
[
$stat
][
$k
[
$i
]]
}
</td></tr>"
;
}
}
$leftover
=
$gotlines
-
$total
;
if
(
$leftover
>
0
)
{
print
"<tr><td>Other</td><td width=
\"
50
\"
align=
\"
right
\"
>
{
$leftover
}
</td></tr>"
;
}
print
"</table>"
;
}
function
pie_block
(
$summary
,
$stat
,
$num
)
{
global
$gotlines
,
$fields
;
uasort
(
$summary
[
$stat
]
,
'cmp'
);
$k
=
array_keys
(
$summary
[
$stat
]);
$total
=
0
;
$numentries
=
0
;
print
"
\n
<script type=
\"
text/javascript
\"
>
\n
"
;
print
"//<![CDATA[
\n
"
;
for
(
$i
=
0
;
$i
<
$num
;
$i
++
)
{
if
(
isset
(
$k
[
$i
]))
{
$total
+=
$summary
[
$stat
][
$k
[
$i
]];
$numentries
++
;
print
"var d
{
$stat
}{
$i
}
= [];
\n
"
;
print
"d
{
$stat
}{
$i
}
.push([1,
{
$summary
[
$stat
][
$k
[
$i
]]
}
]);
\n
"
;
}
}
$leftover
=
$gotlines
-
$total
;
if
(
$leftover
>
0
)
{
print
"var d
{
$stat
}{
$num
}
= [];
\n
"
;
print
"d
{
$stat
}{
$num
}
.push([1,
{
$leftover
}
]);
\n
"
;
}
print
"Event.observe(window, 'load', function() {\n"
;
print
" new Proto.Chart($('piechart
{
$stat
}
'),
\n
"
;
print
" [
\n
"
;
for
(
$i
=
0
;
$i
<
$num
;
$i
++
)
{
if
(
isset
(
$k
[
$i
]))
{
print
" { data: d
{
$stat
}{
$i
}
, label:
\"
{
$k
[
$i
]
}
\"
}"
;
if
(
!
((
$i
==
(
$numentries
-
1
))
&&
(
$leftover
<=
0
)))
print
",
\n
"
;
else
print
"
\n
"
;
}
}
if
(
$leftover
>
0
)
print
" { data: d
{
$stat
}{
$i
}
, label:
\"
Other
\"
}
\n
"
;
print
" ],
\n
"
;
print
" {\n"
;
print
" pies: {show: true, autoScale: true},
\n
"
;
print
" legend: {show: true, labelFormatter: lblfmt}
\n
"
;
print
" });
\n
"
;
print
"});
\n
"
;
print
"//]]>
\n
"
;
print
"</script>
\n
"
;
print
"<table cellpadding=
\"
3
\"
cellspacing=
\"
0
\"
border=
\"
0
\"
summary=
\"
pie chart
\"
>"
;
print
"<tr><th><font size=
\"
+1
\"
>
{
$fields
[
$stat
]
}
</font></th></tr>"
;
print
"<tr><td><div id=
\"
piechart
{
$stat
}
\"
style=
\"
width:450px;height:300px
\"
></div></td></tr>"
;
print
"</table>
\n
"
;
}
// Fill summary array with filterlog data
foreach
(
$filterlog
as
$fe
)
{
foreach
(
array_keys
(
$fields
)
as
$field
)
{
if
(
isset
(
$fe
[
$field
]))
{
...
...
@@ -157,58 +72,125 @@ foreach ($filterlog as $fe) {
}
}
// Custom sorting function
function
cmp
(
$a
,
$b
)
{
if
(
$a
==
$b
)
{
return
0
;
}
return
(
$a
<
$b
)
?
1
:
-
1
;
}
// Setup full data array for pie and table
function
d3pie_data
(
$summary
,
$num
)
{
$data
=
array
();
foreach
(
array_keys
(
$summary
)
as
$stat
)
{
uasort
(
$summary
[
$stat
]
,
'cmp'
);
$other
=
0
;
foreach
(
array_keys
(
$summary
[
$stat
])
as
$key
)
{
if
(
!
isset
(
$data
[
$stat
]))
{
$data
[
$stat
]
=
array
();
}
if
(
count
(
$data
[
$stat
])
<
$num
)
{
$data
[
$stat
][]
=
array
(
'label'
=>
$key
,
'value'
=>
$summary
[
$stat
][
$key
]);
}
else
{
$other
+=
$summary
[
$stat
][
$key
];
}
}
if
(
$other
>
0
)
{
$data
[
$stat
][]
=
array
(
'label'
=>
"other"
,
'value'
=>
$other
);
}
}
return
$data
;
}
include
(
"head.inc"
);
?>
<body>
<script
src=
"/javascript/filter_log.js"
type=
"text/javascript"
></script>
<script
type=
"text/javascript"
src=
"/protochart/prototype.js"
></script>
<script
type=
"text/javascript"
src=
"/protochart/ProtoChart.js"
></script>
<!--[if IE]>
<script type="text/javascript" src="/protochart/excanvas.js">
</script>
<![endif]-->
<script
type=
"text/javascript"
>
//
<!
[
CDATA
[
function
lblfmt
(
lbl
)
{
return
'
<font size=
\
"-2
\
">
'
+
lbl
+
'
<
\
/font>
'
}
//]]>
</script>
<?php
include
(
"fbegin.inc"
);
?>
<section
class=
"page-content-main"
>
<div
class=
"container-fluid"
>
<div
class=
"row"
>
<?php
if
(
isset
(
$input_errors
)
&&
count
(
$input_errors
)
>
0
)
print_input_errors
(
$input_errors
);
?>
<section
class=
"col-xs-12"
>
<?
$active_tab
=
"/diag_logs_filter.php"
;
include
(
'diag_logs_tabs.inc'
);
?>
<div
class=
"tab-content content-box col-xs-12"
>
<div
class=
"container-fluid"
>
<?
$tab_group
=
'firewall'
;
include
(
'diag_logs_pills.php'
);
?>
<p>
<?php
printf
(
gettext
(
'This is a firewall log summary, of the last %1$s lines of the firewall log (Max %2$s).'
),
$gotlines
,
$lines
)
?>
<br
/></p>
</div>
</div>
</section>
<section
class=
"col-xs-12"
>
<!-- retrieve full dataset for pie and table -->
<?php
$data
=
d3pie_data
(
$summary
,
$entriesperblock
)
?>
<!-- iterate items and create pie placeholder + tabledata -->
<?php
foreach
(
array_keys
(
$fields
)
as
$field
)
:
?>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
><h3
class=
"panel-title"
>
<?=
$fields
[
$field
]
?>
</h3></div>
<div
class=
"panel-body"
>
<div
class=
"piechart"
id=
"
<?=
$field
?>
"
>
<svg></svg>
</div>
<table
class=
"table table-striped table-bordered"
>
<th
colspan=
"2"
>
<?=
$fields
[
$field
]
?>
<?=
gettext
(
"data"
);
?>
</th>
<?php
foreach
(
array_keys
(
$data
[
$field
])
as
$row
)
:
?>
<tr>
<td>
<?php
if
(
is_ipaddr
(
$data
[
$field
][
$row
][
"label"
]))
:
?>
<a
href=
"diag_dns.php?host=
<?=
$data
[
$field
][
$row
][
"label"
]
?>
"
title=
""
.
gettext
("
Reverse
Resolve
with
DNS
").""
><span
class=
"glyphicon glyphicon-search"
></span></a>
<?php
endif
?>
<?=
$data
[
$field
][
$row
][
"label"
]
?>
</td>
<td>
<?=
$data
[
$field
][
$row
][
"value"
]
?>
</td>
</tr>
<?php
endforeach
?>
</table>
</div>
</div>
<?php
endforeach
?>
</section>
</div>
</div>
</section>
<script
type=
"text/javascript"
>
// Generate Donut charts
nv
.
addGraph
(
function
()
{
// Find all piechart classes to insert the chart
$
(
'
div[class="piechart"]
'
).
each
(
function
(){
var
selected_id
=
$
(
this
).
prop
(
"
id
"
);
var
chart
=
nv
.
models
.
pieChart
()
.
x
(
function
(
d
)
{
return
d
.
label
})
.
y
(
function
(
d
)
{
return
d
.
value
})
.
showLabels
(
true
)
//Display pie labels
.
labelThreshold
(.
05
)
//Configure the minimum slice size for labels to show up
.
labelType
(
"
percent
"
)
//Configure what type of data to show in the label. Can be "key", "value" or "percent"
.
donut
(
true
)
//Turn on Donut mode. Makes pie chart look tasty!
.
donutRatio
(
0.2
)
//Configure how big you want the donut hole size to be.
;
d3
.
select
(
"
[id='
"
+
selected_id
+
"
'].piechart svg
"
)
.
datum
(
<?
echo
json_encode
(
$data
);
?>
[
selected_id
])
.
transition
().
duration
(
350
)
.
call
(
chart
);
// Update Chart after window resize
nv
.
utils
.
windowResize
(
function
(){
chart
.
update
();
});
return
chart
;
});
});
<?
$active_tab
=
"/diag_logs_filter.php"
;
include
(
'diag_logs_tabs.inc'
);
?>
<div
class=
"tab-content content-box col-xs-12"
>
<div
class=
"container-fluid"
>
<?
$tab_group
=
'firewall'
;
include
(
'diag_logs_pills.php'
);
?>
</script>
<p>
<?php
printf
(
gettext
(
'This is a firewall log summary, of the last %1$s lines of the firewall log (Max %2$s).'
),
$gotlines
,
$lines
)
?>
<br
/>
<?=
gettext
(
"NOTE: IE8 users must enable compatibility view."
)
?>
</p>
<style>
.piechart
svg
{
height
:
400px
;
}
</style>
<pre>
<?php
foreach
(
array_keys
(
$fields
)
as
$field
)
{
pie_block
(
$summary
,
$field
,
$entriesperblock
);
echo
"<br /><br />"
;
stat_block
(
$summary
,
$field
,
$entriesperblock
);
echo
"<br /><br />"
;
}
?>
</pre>
</div>
</div>
</section>
</div>
</div>
</section>
<?php
include
(
"foot.inc"
);
?>
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