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

pfSense-pkg-LCDproc: add a shutdown/reboot control menu #376

Closed
wants to merge 1 commit into from
Closed
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
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 @@ -411,11 +412,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 @@ -426,6 +423,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 @@ -476,6 +491,15 @@ function outputled_enabled_CFontz633() {
}
}

function cmenu_enabled() {
global $config;
$lcdproc_config = $config['installedpackages']['lcdproc']['config'][0];
$value = $lcdproc_config['controlmenu'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to make sure these array keys exist before access them to avoid PHP errors/warnings. Use empty() or isset() for that

if (is_null($value))
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 @@ -869,6 +893,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 @@ -334,6 +336,17 @@ function updateInputVisibility() {
'LED4: Gateway status (green: ok, red: at least one gateway not responding, off: no gateway configured).'
);

$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.<br />' .
'Currently you can REBOOT and HALT the system from there.'
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove <br /> from the Help string and use a parameter like used in printf()


$section->addInput(
new Form_Select(
Expand Down