Skip to content

Commit

Permalink
LCDproc: Add a link status screen for each interface. Issue #8198
Browse files Browse the repository at this point in the history
  • Loading branch information
vktg committed Feb 28, 2020
1 parent d41f8e1 commit 259aa1c
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sysutils/pfSense-pkg-LCDproc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PORTNAME= pfSense-pkg-LCDproc
PORTVERSION= 0.10.8
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
101 changes: 101 additions & 0 deletions sysutils/pfSense-pkg-LCDproc/files/usr/local/pkg/lcdproc_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,51 @@ function outputled_gateway() {
return 1;
}

function build_interface_link_list() {
// Returns a dictionary of all the interfaces along with their
// link and address information, keyed on the interface description.
global $config;

$result = array();
$ifList = get_configured_interface_with_descr();

foreach($ifList as $ifdescr => $ifname) {

// get the interface link infos
$ifinfo = get_interface_info($ifdescr);

$entry = array();
$entry['name'] = $ifname;
$entry['mac'] = $ifinfo['macaddr'];

if ($ifinfo['status'] == "up" ||
$ifinfo['status'] == "associated") {

$entry['status'] = "up";
} else {
$entry['status'] = "down";
}

if ($ifinfo['pppoelink'] == "up" ||
$ifinfo['pptplink'] == "up" ||
$ifinfo['l2tplink'] == "up") {

$entry['link'] = sprintf(gettext("Uptime %s"), $ifinfo['ppp_uptime']);
} else {
$entry['link'] = $ifinfo['media'];
}

$entry['v4addr'] = (empty($ifinfo['ipaddr'])) ?
"n/a" : $ifinfo['ipaddr'];

$entry['v6addr'] = (empty($ifinfo['ipaddrv6'])) ?
"n/a" : $ifinfo['ipaddrv6'];

$result[$ifdescr] = $entry;
}
return $result;
}

function build_interface_traffic_stats_list() {
// Returns a dictionary of all the interfaces along with their in/out
// traffic stats, keyed on the interface name.
Expand Down Expand Up @@ -966,6 +1011,30 @@ function build_interface($lcd) {
}
$includeSummary = false; // this screen needs all the lines
break;
case "scr_interfaces_link":
$ifLinkList = build_interface_link_list();
foreach ($ifLinkList as $ifdescr => $iflink) {
$s_name = $name . $ifdescr;
$ifname = $iflink['name'] . ":";
$lcd_cmds[] = "screen_add $s_name";
$lcd_cmds[] = "screen_set $s_name heartbeat off";
$lcd_cmds[] = "screen_set $s_name name \"$name.$ifdescr\"";
$lcd_cmds[] = "screen_set $s_name duration $refresh_frequency";
$lcd_cmds[] = "widget_add $s_name ifname_wdgt string";
$lcd_cmds[] = "widget_set $s_name ifname_wdgt 1 1 \"$ifname\"";
$lcd_cmds[] = "widget_add $s_name link_wdgt scroller";
$lcd_cmds[] = "widget_add $s_name v4l_wdgt string";
$lcd_cmds[] = "widget_set $s_name v4l_wdgt 1 2 \"v4:\"";
$lcd_cmds[] = "widget_add $s_name v4a_wdgt scroller";
$lcd_cmds[] = "widget_add $s_name v6l_wdgt string";
$lcd_cmds[] = "widget_set $s_name v6l_wdgt 1 3 \"v6:\"";
$lcd_cmds[] = "widget_add $s_name v6a_wdgt scroller";
$lcd_cmds[] = "widget_add $s_name macl_wdgt string";
$lcd_cmds[] = "widget_set $s_name macl_wdgt 1 4 \"m:\"";
$lcd_cmds[] = "widget_add $s_name maca_wdgt scroller";
$includeSummary = false; // this screen needs all the lines
}
break;
case "scr_traffic_by_address":
$lcd_cmds[] = "screen_add $name";
$lcd_cmds[] = "screen_set $name heartbeat off";
Expand Down Expand Up @@ -1024,6 +1093,7 @@ function loop_status($lcd) {

$lcd_cmds = array();
$interfaceTrafficList = null;
$ifLinkList = null;

/* initializes the widget counter */
$widget_counter = 0;
Expand Down Expand Up @@ -1181,6 +1251,37 @@ function loop_status($lcd) {
}
$updateSummary = false;
break;
case "scr_interfaces_link":
// We only want build_interface_link_list() to be
// called once per loop, and only if it's needed
if ($ifLinkList == null)
$ifLinkList = build_interface_link_list();

foreach ($ifLinkList as $ifdescr => $iflink) {
$s_name = $name . $ifdescr;
$ifname = $iflink['name'] . ":";
$l_str = ($iflink['status'] == "down") ? "down" : $iflink['link'];

$lcd_cmds[] = "widget_set $s_name ifname_wdgt 1 1 \"$ifname\"";

$lcd_cmds[] = "widget_set $s_name link_wdgt " .
(strlen($iflink['name']) + 3) . " 1 " .
$lcdpanel_width . " 1 h 4 \"" . $l_str . "\"";

$lcd_cmds[] = "widget_set $s_name v4a_wdgt 5 2 " .
$lcdpanel_width . " 2 h 4 \"" .
$iflink['v4addr'] . "\"";

$lcd_cmds[] = "widget_set $s_name v6a_wdgt 5 3 " .
$lcdpanel_width . " 3 h 4 \"" .
$iflink['v6addr'] . "\"";

$lcd_cmds[] = "widget_set $s_name maca_wdgt 4 4 " .
$lcdpanel_width . " 4 h 4 \"" .
$iflink['mac'] . "\"";
}
$updateSummary = false;
break;
case "scr_traffic_by_address":
$title = ($lcdpanel_width >= 20) ? "Host IN / OUT" : "Host IN / OUT";
$lcd_cmds[] = "widget_set $name title_wdgt 2 1 \"{$title}\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
if (!isset($pconfig['scr_top_interfaces_by_bps'])) $pconfig['scr_top_interfaces_by_bps'] = false;
if (!isset($pconfig['scr_top_interfaces_by_total_bytes'])) $pconfig['scr_top_interfaces_by_total_bytes'] = false;
if (!isset($pconfig['scr_top_interfaces_by_bytes_today'])) $pconfig['scr_top_interfaces_by_bytes_today'] = false;
if (!isset($pconfig['scr_interfaces_link'])) $pconfig['scr_interfaces_link'] = false;
if (!isset($pconfig['scr_traffic_by_address'])) $pconfig['scr_traffic_by_address'] = false;
if (!isset($pconfig['scr_traffic_by_address_if'])) $pconfig['scr_traffic_by_address_if'] = '';
if (!isset($pconfig['scr_traffic_by_address_sort'])) $pconfig['scr_traffic_by_address_sort'] = 'in';
Expand Down Expand Up @@ -83,6 +84,7 @@
$lcdproc_screens_config['scr_top_interfaces_by_bps'] = $pconfig['scr_top_interfaces_by_bps'];
$lcdproc_screens_config['scr_top_interfaces_by_total_bytes'] = $pconfig['scr_top_interfaces_by_total_bytes'];
$lcdproc_screens_config['scr_top_interfaces_by_bytes_today'] = $pconfig['scr_top_interfaces_by_bytes_today'];
$lcdproc_screens_config['scr_interfaces_link'] = $pconfig['scr_interfaces_link'];
$lcdproc_screens_config['scr_traffic_by_address'] = $pconfig['scr_traffic_by_address'];
$lcdproc_screens_config['scr_traffic_by_address_if'] = $pconfig['scr_traffic_by_address_if'];
$lcdproc_screens_config['scr_traffic_by_address_sort'] = $pconfig['scr_traffic_by_address_sort'];
Expand Down Expand Up @@ -218,8 +220,8 @@
)
);


$group = new Form_Group('Traffic of interface');

$group->add(
new Form_Checkbox(
'scr_traffic', // checkbox name (id)
Expand All @@ -245,28 +247,43 @@
'Interfaces listed with current bits-per-second (in & out)', // checkbox text
$pconfig['scr_top_interfaces_by_bps'] // checkbox initial value
)
)->setHelp('A 4‐row 20‐column display size, or higher, is recommended for this screen.');

)->setHelp('A 4-row 20-column display size, or higher, is recommended for this screen.');
$section->addInput(
new Form_Checkbox(
'scr_top_interfaces_by_total_bytes', // checkbox name (id)
'Interfaces by volume', // checkbox label
'Interfaces listed with total bytes since last boot (in & out)', // checkbox text
$pconfig['scr_top_interfaces_by_total_bytes'] // checkbox initial value
)
)->setHelp('A 4‐row 20‐column display size, or higher, is recommended for this screen.');

)->setHelp('A 4-row 20-column display size, or higher, is recommended for this screen.');
$section->addInput(
new Form_Checkbox(
'scr_top_interfaces_by_bytes_today', // checkbox name (id)
'Interfaces by volume today', // checkbox label
'Interfaces listed with total bytes since the start of the day, or since LCDproc reset (in & out)', // checkbox text
$pconfig['scr_top_interfaces_by_bytes_today'] // checkbox initial value
)
)->setHelp('A 4‐row 20‐column display size, or higher, is recommended for this screen.');
)->setHelp('A 4-row 20-column display size, or higher, is recommended for this screen.');

$section->addInput(
new Form_Checkbox(
'scr_interfaces_link', // checkbox name (id)
'Interfaces link status', // checkbox label
'Display the interfaces current link status', // checkbox text
$pconfig['scr_interfaces_link'] // checkbox initial value
)
)->setHelp(
'This will create a seperate status screen for each inferface with four lines each:%1$s' .
'%2$sIFNAME%3$s: %2$slink status%3$s%1$s' .
'v4: %2$sip v4 address%3$s%1$s' .
'v6: %2$sip v6 address%3$s%1$s' .
'm: %2$smac address%3$s%1$s' .
'A 4-row 20-column display size, or higher, is recommended for this screen.',
'<br/>', '&lt;', '&gt;', '&hyphen;'
);

$group = new Form_Group('Addresses by traffic');

$group->add(new Form_Checkbox(
'scr_traffic_by_address',
'',
Expand Down Expand Up @@ -303,18 +320,18 @@
null,
$pconfig['scr_traffic_by_address_hostipformat'],
array (
'' => gettext('IP Address'),
'' => gettext('IP Address'),
'hostname' => gettext('Host Name'),
'descr' => gettext('Description'),
'fqdn' => gettext('FQDN')
)
))->setHelp('Display');
$group->setHelp('A 4&hyphen;row 20&hyphen;column display size, or higher, is recommended for this screen.');
$section->add($group);

$group->setHelp('A 4-row 20-column display size, or higher, is recommended for this screen.');
$section->add($group);

$form->add($section); // Add the section to our form
print($form); // Finally . . We can display our new form
$form->add($section);
print($form);

?>

Expand Down

0 comments on commit 259aa1c

Please sign in to comment.