Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCDproc: add a shutdown/reboot control menu. Issue #8196 #784

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require_once("functions.inc");
require_once("interfaces.inc");
require_once("/usr/local/pkg/lcdproc.inc");
require_once("system.inc");

function get_pfstate() {
global $config;
Expand Down Expand Up @@ -360,11 +361,7 @@ function send_lcd_commands($lcd, $lcd_cmds) {
lcdproc_warn("Failed to interpret lcd commands");
return;
}
while (($cmd_output = fgets($lcd, 8000)) !== false) {
if (preg_match("/^huh?/", $cmd_output)) {
lcdproc_notice("LCDd output: \"$cmd_output\". Executed \"$lcd_cmd\"");
}
}
get_lcd_messages($lcd);
foreach ($lcd_cmds as $lcd_cmd) {
if (! fwrite($lcd, "$lcd_cmd\n")) {
lcdproc_warn("Connection to LCDd process lost $errstr ($errno)");
Expand All @@ -375,6 +372,24 @@ function send_lcd_commands($lcd, $lcd_cmds) {
return true;
}

function get_lcd_messages($lcd) {
while (($cmd_output = fgets($lcd, 8000)) !== false) {
if (preg_match("/^huh?/", $cmd_output)) {
lcdproc_notice("LCDd output: \"$cmd_output\". Executed \"$lcd_cmd\"");
}
if (cmenu_enabled()) {
if (preg_match("/^menuevent select r_ask_yes/", $cmd_output)) {
lcdproc_notice("init REBOOT!");
system_reboot();
}
if (preg_match("/^menuevent select s_ask_yes/", $cmd_output)) {
lcdproc_notice("init SHUTDOWN!");
system_halt();
}
}
}
}

function get_lcdpanel_width() {
global $config;
$lcdproc_size_config = $config['installedpackages']['lcdproc']['config'][0];
Expand Down Expand Up @@ -425,6 +440,15 @@ function outputled_enabled_CFontz633() {
}
}

function cmenu_enabled() {
global $config;
$lcdproc_config = $config['installedpackages']['lcdproc']['config'][0];
if (!isset($lcdproc_config['controlmenu'])) {
return false;
}
return true;
}

function outputled_carp() {
/* Returns the status of CARP for the box.
Assumes ALL CARP status are the same for all the intefaces.
Expand Down Expand Up @@ -818,6 +842,17 @@ function build_interface($lcd) {
$lcd_cmds[] = "hello";
$lcd_cmds[] = "client_set name pfSense";

/* setup pfsense control menu */
if (cmenu_enabled()) {
$lcd_cmds[] = 'menu_add_item "" reboot_menu menu "Reboot"';
$lcd_cmds[] = 'menu_add_item "reboot_menu" r_ask_no action "No" -next _close_';
$lcd_cmds[] = 'menu_add_item "reboot_menu" r_ask_yes action "Yes" -next _quit_';

$lcd_cmds[] = 'menu_add_item "" shutdown_menu menu "Shutdown"';
$lcd_cmds[] = 'menu_add_item "shutdown_menu" s_ask_no action "No" -next _close_';
$lcd_cmds[] = 'menu_add_item "shutdown_menu" s_ask_yes action "Yes" -next _quit_';
}

/* process screens to display */
if (is_array($lcdproc_screens_config)) {
foreach ($lcdproc_screens_config as $name => $screen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
if (!isset($pconfig['contrast'])) $pconfig['contrast'] = '-1';
if (!isset($pconfig['backlight'])) $pconfig['backlight'] = 'default';
if (!isset($pconfig['outputleds'])) $pconfig['outputleds'] = 'no';
if (!isset($pconfig['controlmenu'])) $pconfig['controlmenu'] = 'no';
if (!isset($pconfig['mtxorb_type'])) $pconfig['mtxorb_type'] = 'lcd'; // specific to Matrix Orbital driver
if (!isset($pconfig['mtxorb_adjustable_backlight'])) $pconfig['mtxorb_adjustable_backlight'] = true; // specific to Matrix Orbital driver

Expand All @@ -66,6 +67,7 @@
$lcdproc_config['contrast'] = $pconfig['contrast'];
$lcdproc_config['backlight'] = $pconfig['backlight'];
$lcdproc_config['outputleds'] = $pconfig['outputleds'];
$lcdproc_config['controlmenu'] = $pconfig['controlmenu'];
$lcdproc_config['mtxorb_type'] = $pconfig['mtxorb_type'];
$lcdproc_config['mtxorb_adjustable_backlight'] = $pconfig['mtxorb_adjustable_backlight'];

Expand Down Expand Up @@ -248,7 +250,12 @@
$pconfig['mtxorb_adjustable_backlight'] // initial value
)
);
$subsection->setHelp('Select the Matrix Orbital display type.<br />Some old firmware versions of Matrix Orbital modules do not support an adjustable backlight but only can switch the backlight on/off. If you own such a module and experience randomly appearing block characters and backlight cannot be switched on or off, uncheck the adjustable backlight option.');
$subsection->setHelp(
'Select the Matrix Orbital display type.%1$s' .
'Some old firmware versions of Matrix Orbital modules do not support an adjustable backlight' .
'but only can switch the backlight on/off. If you own such a module and experience randomly' .
'appearing block characters and backlight cannot be switched on or off, uncheck the adjustable backlight option.'
);
$section->add($subsection);
?>

Expand Down Expand Up @@ -298,7 +305,11 @@ function updateInputVisibility() {
'115200' => '115200 bps'
]
)
)->setHelp('Set the port speed.<br />Caution: not all the driver or panels support all the speeds, leave "default" if unsure.');
)->setHelp(
'Set the port speed.%1$s' .
'Caution: not all the driver or panels support all the speeds, leave "default" if unsure.',
'<br />'
);

/********* New section *********/
$form->add($section);
Expand Down Expand Up @@ -331,14 +342,27 @@ function updateInputVisibility() {
$pconfig['outputleds'] // checkbox initial value
)
)->setHelp(
'This feature is currently supported by the CFontz633 driver only.<br />' .
'Each LED can be off or show two colors: RED (alarm) or GREEN (everything ok) and shows:<br />' .
'LED1: NICs status (green: ok, red: at least one nic down)<br />' .
'LED2: CARP status (green: master, red: backup, off: CARP not implemented)<br />' .
'LED3: CPU status (green &lt; 50%, red &gt; 50%)<br />' .
'LED4: Gateway status (green: ok, red: at least one gateway not responding, off: no gateway configured).'
'This feature is currently supported by the CFontz633 driver only.%1$s' .
'Each LED can be off or show two colors: RED (alarm) or GREEN (everything ok) and shows:%1$s' .
'LED1: NICs status (green: ok, red: at least one nic down)%1$s' .
'LED2: CARP status (green: master, red: backup, off: CARP not implemented)%1$s' .
'LED3: CPU status (green %2$s 50%, red %3$s 50%)%1$s' .
'LED4: Gateway status (green: ok, red: at least one gateway not responding, off: no gateway configured).',
'<br />', '&lt;', '&gt;'
);

$section->addInput(
new Form_Checkbox(
'controlmenu', // checkbox name (id)
'pfSense control menu', // checkbox label
'Enable the pfSense control menu next to LCDproc\'s Options menu.', // checkbox text
$pconfig['controlmenu'] // checkbox initial value
)
)->setHelp(
'This will only be usefull on display with buttons.%1$s' .
'Currently you can REBOOT and HALT the system from there.',
'<br />'
);

$section->addInput(
new Form_Select(
Expand All @@ -360,7 +384,11 @@ function updateInputVisibility() {
'100' => '100%'
]
)
)->setHelp('Set the brightness of the LCD panel.<br />This option is not supported by all the LCD panels, leave "default" if unsure.');
)->setHelp(
'Set the brightness of the LCD panel.%1$s' . '
This option is not supported by all the LCD panels, leave "default" if unsure.',
'<br />'
);

$section->addInput(
new Form_Select(
Expand All @@ -383,8 +411,9 @@ function updateInputVisibility() {
]
)
)->setHelp(
'Set the contrast of the LCD panel.<br />' .
'This option is not supported by all the LCD panels, leave "default" if unsure.'
'Set the contrast of the LCD panel.%1$s' .
'This option is not supported by all the LCD panels, leave "default" if unsure.',
'<br />'
);

$section->addInput(
Expand All @@ -399,8 +428,9 @@ function updateInputVisibility() {
]
)
)->setHelp(
'Set the backlight setting. If set to the default value, then the backlight setting of the display can be influenced by the clients.<br />' .
'This option is not supported by all the LCD panels, leave "default" if unsure.'
'Set the backlight setting. If set to the default value, then the backlight setting of the display can be influenced by the clients.%1$s' .
'This option is not supported by all the LCD panels, leave "default" if unsure.',
'<br />'
);

$section->addInput(
Expand All @@ -424,8 +454,9 @@ function updateInputVisibility() {
]
)
)->setHelp(
'Set the off-brightness of the LCD panel. This value is used when the display is normally switched off in case LCDd is inactive.<br />' .
'This option is not supported by all the LCD panels, leave "default" if unsure.'
'Set the off-brightness of the LCD panel. This value is used when the display is normally switched off in case LCDd is inactive.%1$s' .
'This option is not supported by all the LCD panels, leave "default" if unsure.',
'<br />'
);

$form->add($section); // Add the section to our form
Expand Down