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
7d286b23
Commit
7d286b23
authored
May 03, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(dashboard, widgets) refactor gateways.widget.php, use callbacks and data from new widget api
parent
9e53bb94
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
81 deletions
+68
-81
gateways.widget.php
src/www/widgets/widgets/gateways.widget.php
+68
-81
No files found.
src/www/widgets/widgets/gateways.widget.php
View file @
7d286b23
...
...
@@ -25,77 +25,64 @@
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once
(
"guiconfig.inc"
);
require_once
(
"pfsense-utils.inc"
);
require_once
(
"widgets/include/gateways.inc"
);
$gateways_status
=
return_gateways_status
(
true
);
?>
<table
class=
"table table-striped table-condensed"
>
<script
type=
"text/javascript"
>
function
gateways_widget_update
(
sender
,
data
)
{
var
tbody
=
sender
.
find
(
'
tbody
'
);
data
.
map
(
function
(
gateway
)
{
var
tr_content
=
[];
var
tr_id
=
"
gateways_widget_gw_
"
+
gateway
[
'
name
'
];
if
(
tbody
.
find
(
"
#
"
+
tr_id
).
length
==
0
)
{
// add new gateway
tr_content
.
push
(
'
<tr id="
'
+
tr_id
+
'
">
'
);
tr_content
.
push
(
'
<td><strong>
'
+
gateway
[
'
name
'
]
+
'
</strong><br/><small>
'
+
gateway
[
'
address
'
]
+
'
<small></td>
'
);
tr_content
.
push
(
'
<td>
'
+
gateway
[
'
delay
'
]
+
'
</td>
'
);
tr_content
.
push
(
'
<td>
'
+
gateway
[
'
loss
'
]
+
'
</td>
'
);
tr_content
.
push
(
'
<td><div class="" style="width:150px;">
'
+
gateway
[
'
status_translated
'
]
+
'
</div></td>
'
);
tr_content
.
push
(
'
</tr>
'
);
tbody
.
append
(
tr_content
.
join
(
''
));
}
else
{
// update existing gateway
$
(
"
#
"
+
tr_id
+
"
> td:eq(2)
"
).
html
(
gateway
[
'
loss
'
]);
$
(
"
#
"
+
tr_id
+
"
> td:eq(1)
"
).
html
(
gateway
[
'
delay
'
]);
}
// set color on status text
switch
(
gateway
[
'
status
'
])
{
case
'
force_down
'
:
status_color
=
'
danger
'
;
break
;
case
'
down
'
:
status_color
=
'
danger
'
;
break
;
case
'
loss
'
:
status_color
=
'
warning
'
;
break
;
case
'
delay
'
:
status_color
=
'
warning
'
;
break
;
case
'
none
'
:
status_color
=
'
success
'
;
break
;
default
:
status_color
=
'
info
'
;
}
$
(
"
#
"
+
tr_id
+
"
> td:eq(3) > div
"
).
removeClass
().
addClass
(
'
bg-
'
+
status_color
);
});
}
</script>
<!-- gateway table -->
<table
class=
"table table-striped table-condensed"
data-plugin=
"gateway"
data-callback=
"gateways_widget_update"
>
<thead>
<tr>
<th>
<?=
gettext
(
'Name'
)
?>
</th>
<th>
<?=
gettext
(
'RTT'
)
?>
</th>
<th>
<?=
gettext
(
'Loss'
)
?>
</th>
<th>
<?=
gettext
(
'Status'
)
?>
</th>
<th
style=
"width:160px;"
>
<?=
gettext
(
'Status'
)
?>
</th>
</tr>
</thead>
<tbody>
<?php
foreach
(
return_gateways_array
()
as
$gname
=>
$gateway
)
:?>
<
tr
>
<
td
>
<
strong
><?=
htmlspecialchars
(
$gateway
[
'name'
]);
?>
</strong><br/>
<?php
$if_gw
=
'~'
;
if
(
is_ipaddr
(
$gateway
[
'gateway'
]))
{
$if_gw
=
htmlspecialchars
(
$gateway
[
'gateway'
]);
}
elseif
(
$gateway
[
'ipprotocol'
]
==
"inet"
)
{
$if_gw
=
htmlspecialchars
(
get_interface_gateway
(
$gateway
[
'friendlyiface'
]));
}
elseif
(
$gateway
[
'ipprotocol'
]
==
"inet6"
)
{
$if_gw
=
htmlspecialchars
(
get_interface_gateway_v6
(
$gateway
[
'friendlyiface'
]));
}
?>
<small>
<?=
$if_gw
;
?>
</small>
</td>
<td>
<?=
!
empty
(
$gateways_status
[
$gname
])
?
htmlspecialchars
(
$gateways_status
[
$gname
][
'delay'
])
:
gettext
(
"Pending"
);
?>
</td>
<td>
<?=
!
empty
(
$gateways_status
[
$gname
])
?
htmlspecialchars
(
$gateways_status
[
$gname
][
'loss'
])
:
gettext
(
"Pending"
);
?>
</td>
<?php
$online
=
gettext
(
"Unknown"
);
$class
=
"info"
;
if
(
!
empty
(
$gateways_status
[
$gname
]))
{
if
(
stristr
(
$gateways_status
[
$gname
][
'status'
],
"force_down"
))
{
$online
=
gettext
(
"Offline (forced)"
);
$class
=
"danger"
;
}
elseif
(
stristr
(
$gateways_status
[
$gname
][
'status'
],
"down"
))
{
$online
=
gettext
(
"Offline"
);
$class
=
"danger"
;
}
elseif
(
stristr
(
$gateways_status
[
$gname
][
'status'
],
"loss"
))
{
$online
=
gettext
(
"Packetloss"
);
$class
=
"warning"
;
}
elseif
(
stristr
(
$gateways_status
[
$gname
][
'status'
],
"delay"
))
{
$online
=
gettext
(
"Latency"
);
$class
=
"warning"
;
}
elseif
(
$gateways_status
[
$gname
][
'status'
]
==
"none"
)
{
$online
=
gettext
(
"Online"
);
$class
=
"success"
;
}
elseif
(
$gateways_status
[
$gname
][
'status'
]
==
""
)
{
$online
=
gettext
(
"Pending"
);
$class
=
"info"
;
}
}
?>
<td
style=
"width:160px;"
>
<div
class=
"bg-
<?=
$class
;
?>
"
style=
"width:150px;"
>
<?=
$online
;
?>
</div>
</td>
</tr>
<?php
endforeach
;
?>
</tbody>
</table>
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