activate control

This commit is contained in:
Mario Fetka
2026-05-21 16:04:16 +02:00
parent d763467440
commit 7d4a2f1b99
6 changed files with 82 additions and 5 deletions

View File

@@ -10,6 +10,15 @@
# Generated files
##############
if(NOT DEFINED MARS_NWE_SYSTEMD_SERVICE)
set(MARS_NWE_SYSTEMD_SERVICE "mars-nwe-serv.service" CACHE STRING "MARS_NWE systemd service name")
endif()
find_program(SYSTEMCTL_EXECUTABLE systemctl)
if(NOT SYSTEMCTL_EXECUTABLE)
set(SYSTEMCTL_EXECUTABLE "/usr/bin/systemctl")
endif()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
@@ -25,6 +34,11 @@ configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/smart"
IMMEDIATE @ONLY)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/control.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/control"
IMMEDIATE @ONLY)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/static/start.html.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/static/start.html"
@@ -74,6 +88,7 @@ target_link_libraries(check_login
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/smart.conf DESTINATION ${MARS_NWE_INSTALL_FULL_CONFDIR})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/smart DESTINATION ${MARS_NWE_INSTALL_FULL_LIBEXECDIR})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/control DESTINATION ${MARS_NWE_INSTALL_FULL_LIBEXECDIR})
install(FILES smart.pamd DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/pam.d RENAME smart)
install(PROGRAMS apply.pl DESTINATION ${MARS_NWE_INSTALL_FULL_LIBEXECDIR})

View File

@@ -5,7 +5,10 @@
#define NWWEBUI_VERSION "@MARS_NWE_VERSION@"
#define DEFAULT_SMART_CONF "@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf"
#define DEFAULT_SMART_PERL "@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/smart"
#define DEFAULT_SMART_PERL "@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/smart"
#define DEFAULT_CONTROL_PERL "@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/control"
#define DEFAULT_MARS_SERVICE "@MARS_NWE_SYSTEMD_SERVICE@"
#define DEFAULT_SYSTEMCTL_PATH "@SYSTEMCTL_EXECUTABLE@"
#define LOG_PATH_DEFAULT "@MARS_NWE_LOG_DIR@/nwwebui.log"

View File

@@ -38,6 +38,9 @@ typedef struct {
char smart_conf[512];
char smart_perl_path[512];
char smart_control_path[512];
char mars_nwe_service[256];
char systemctl_path[512];
} nw_config_t;
static FILE *g_log_fp = NULL;
@@ -445,6 +448,9 @@ static void init_defaults(nw_config_t *cfg, const char *smart_conf_path)
snprintf(cfg->log_file, sizeof(cfg->log_file), "%s", LOG_PATH_DEFAULT);
snprintf(cfg->smart_perl_path, sizeof(cfg->smart_perl_path), "%s", DEFAULT_SMART_PERL);
snprintf(cfg->smart_control_path, sizeof(cfg->smart_control_path), "%s", DEFAULT_CONTROL_PERL);
snprintf(cfg->mars_nwe_service, sizeof(cfg->mars_nwe_service), "%s", DEFAULT_MARS_SERVICE);
snprintf(cfg->systemctl_path, sizeof(cfg->systemctl_path), "%s", DEFAULT_SYSTEMCTL_PATH);
snprintf(cfg->smart_conf, sizeof(cfg->smart_conf), "%s", smart_conf_path);
snprintf(g_log_path, sizeof(g_log_path), "%s", LOG_PATH_DEFAULT);
@@ -490,6 +496,12 @@ static void load_smart_conf(nw_config_t *cfg)
snprintf(cfg->key_file, sizeof(cfg->key_file), "%s", val);
} else if (strcmp(key, "smart_perl_path") == 0) {
snprintf(cfg->smart_perl_path, sizeof(cfg->smart_perl_path), "%s", val);
} else if (strcmp(key, "smart_control_path") == 0) {
snprintf(cfg->smart_control_path, sizeof(cfg->smart_control_path), "%s", val);
} else if (strcmp(key, "mars_nwe_service") == 0) {
snprintf(cfg->mars_nwe_service, sizeof(cfg->mars_nwe_service), "%s", val);
} else if (strcmp(key, "smart_systemctl_path") == 0) {
snprintf(cfg->systemctl_path, sizeof(cfg->systemctl_path), "%s", val);
}
}
@@ -649,6 +661,10 @@ static pid_t spawn_smart_perl(const nw_config_t *cfg, int *child_stdin_fd, int *
close(outpipe[0]);
close(outpipe[1]);
setenv("SMART_CONTROL_PATH", cfg->smart_control_path, 1);
setenv("MARS_NWE_SERVICE", cfg->mars_nwe_service, 1);
setenv("SMART_SYSTEMCTL_PATH", cfg->systemctl_path, 1);
execl(cfg->smart_perl_path, cfg->smart_perl_path, (char *)NULL);
perror("execl smart_perl_path");
@@ -1023,8 +1039,11 @@ int main(int argc, char **argv)
log_msg(LOG_LEVEL_INFO, "%s version %s starting", NWWEBUI_NAME, NWWEBUI_VERSION);
log_msg(LOG_LEVEL_INFO, "Using SMArT Perl path: %s", cfg.smart_perl_path);
log_msg(LOG_LEVEL_INFO, "Using SMArT control path: %s", cfg.smart_control_path);
log_msg(LOG_LEVEL_INFO, "Using MARS_NWE service: %s", cfg.mars_nwe_service);
log_msg(LOG_LEVEL_INFO, "Using systemctl path: %s", cfg.systemctl_path);
log_msg(LOG_LEVEL_INFO,
"%s version %s config loaded: bind=%s log_level=%d ssl_enable=%d http_port=%d https_port=%d daemonize=%d cert=%s key=%s pid_file=%s log_file=%s smart.conf=%s",
"%s version %s config loaded: bind=%s log_level=%d ssl_enable=%d http_port=%d https_port=%d daemonize=%d cert=%s key=%s pid_file=%s log_file=%s smart_control=%s mars_service=%s systemctl=%s smart.conf=%s",
NWWEBUI_NAME,
NWWEBUI_VERSION,
cfg.bind_ip,
@@ -1037,6 +1056,9 @@ int main(int argc, char **argv)
cfg.key_file,
cfg.pid_file,
cfg.log_file,
cfg.smart_control_path,
cfg.mars_nwe_service,
cfg.systemctl_path,
cfg.smart_conf);
if (cfg.daemonize) {

View File

@@ -38,11 +38,20 @@ $ENV{HOME} = '@MARS_NWE_INSTALL_FULL_CONFDIR@';
$smart_libexec_dir = '@MARS_NWE_INSTALL_FULL_LIBEXECDIR@';
$smart_libexec_dir =~ s#/*$##;
$smart_control_path = $ENV{SMART_CONTROL_PATH} unless defined $smart_control_path;
$smart_control_path = $smart_libexec_dir . '/control' unless defined $smart_control_path;
$mars_nwe_service = $ENV{MARS_NWE_SERVICE} unless defined $mars_nwe_service;
$mars_nwe_service = '@MARS_NWE_SYSTEMD_SERVICE@' unless defined $mars_nwe_service;
$smart_systemctl_path = $ENV{SMART_SYSTEMCTL_PATH} unless defined $smart_systemctl_path;
$smart_systemctl_path = '@SYSTEMCTL_EXECUTABLE@' unless defined $smart_systemctl_path;
$l = <STDIN>;
$l =~ s/[\n\r]//g;
$request_uri = "";
@c = split( ' ', $l );
if( scalar( @c ) > 2 )
{
$request_uri = $c[1];
while( keys( %h ) < 15 ) # Who would ever want to send more headers???
{
$l = <STDIN>;
@@ -104,7 +113,21 @@ foreach $p ( @p )
}
@c = split( '/', $c );
if( $c[0] eq 'apply' )
if( $c[0] eq 'cgi-bin' && $c[1] eq 'control' )
{
$ENV{'QUERY_STRING'} = $cc;
$ENV{'REQUEST_URI'} = $request_uri;
$ENV{'SMART_SYSTEMCTL_PATH'} = $smart_systemctl_path if defined $smart_systemctl_path;
$ENV{'MARS_NWE_SERVICE'} = $mars_nwe_service if defined $mars_nwe_service;
my $rv = do( $smart_control_path );
if( ! defined $rv )
{
error( 500 );
}
handle_request();
exit;
}
elsif( $c[0] eq 'apply' )
{
do( $smart_libexec_dir . '/readconfig.pl' );
do( $smart_libexec_dir . '/apply.pl' );

View File

@@ -64,6 +64,16 @@ $smart_log_path = '@MARS_NWE_LOG_DIR@/smart.log';
# Path to the PAM-based login helper used for root authentication.
$smart_check_login = '@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/check_login';
# Path to the SMArT service-control helper.
$smart_control_path = '@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/control';
# systemd unit controlled by the SMArT service-control page.
$mars_nwe_service = '@MARS_NWE_SYSTEMD_SERVICE@';
# systemctl executable used by the service-control helper.
$smart_systemctl_path = '@SYSTEMCTL_EXECUTABLE@';
# Optional explicit path to the main SMArT Perl program.
# This is normally not required, because nwwebui already has a built-in default.
# Uncomment and adjust only if a non-standard location must be used.

View File

@@ -100,8 +100,12 @@
<DIV CLASS="actions">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="50%"><A CLASS="action" HREF="/cgi-bin/control?start">Start <TT>MARS_NWE</TT></A></TD>
<TD WIDTH="50%"><A CLASS="action secondary" HREF="/cgi-bin/control?stop">Stop <TT>MARS_NWE</TT></A></TD>
<TD WIDTH="25%"><A CLASS="action" HREF="/cgi-bin/control?start">Start <TT>MARS_NWE</TT></A></TD>
<TD WIDTH="25%"><A CLASS="action secondary" HREF="/cgi-bin/control?stop">Stop <TT>MARS_NWE</TT></A></TD>
</TR>
<TR>
<TD WIDTH="25%"><A CLASS="action secondary" HREF="/cgi-bin/control?restart">Restart <TT>MARS_NWE</TT></A></TD>
<TD WIDTH="25%"><A CLASS="action secondary" HREF="/cgi-bin/control?status">Status <TT>MARS_NWE</TT></A></TD>
</TR>
</TABLE>
</DIV>