feat: improve nwwebui configuration, logging and daemon support

This commit is contained in:
Mario Fetka
2026-04-21 09:48:15 +02:00
parent 4bd8223415
commit 2696ff557c
4 changed files with 1058 additions and 216 deletions

View File

@@ -1,21 +1,29 @@
#ifndef NWWEBUI_CONFIG_H
#define NWWEBUI_CONFIG_H
#define DEFAULT_SMART_CONF "@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf"
#define DEFAULT_SMART_PERL "@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/smart"
#define NWWEBUI_NAME "nwwebui"
#define NWWEBUI_VERSION "@MARS_NWE_VERSION@"
#define LOG_PATH_DEFAULT "@MARS_NWE_LOG_DIR@/nwwebui.log"
#define DEFAULT_SMART_CONF "@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf"
#define DEFAULT_SMART_PERL "@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/smart"
#define LOG_LEVEL_ERROR 0
#define LOG_LEVEL_INFO 1
#define LOG_LEVEL_DEBUG 2
#define LOG_LEVEL_DEFAULT LOG_LEVEL_INFO
#define LOG_PATH_DEFAULT "@MARS_NWE_LOG_DIR@/nwwebui.log"
#define DEFAULT_BIND_IP "0.0.0.0"
#define DEFAULT_TLS_PORT 9443
#define LOG_LEVEL_ERROR 0
#define LOG_LEVEL_INFO 1
#define LOG_LEVEL_DEBUG 2
#define LOG_LEVEL_DEFAULT LOG_LEVEL_INFO
#define DEFAULT_CERT_FILE "@MARS_NWE_INSTALL_FULL_CONFDIR@/server.crt"
#define DEFAULT_KEY_FILE "@MARS_NWE_INSTALL_FULL_CONFDIR@/server.key"
#define DEFAULT_BIND_IP "0.0.0.0"
#define DEFAULT_SSL_ENABLE 1
#define DEFAULT_HTTP_PORT 9080
#define DEFAULT_HTTPS_PORT 9443
#define DEFAULT_CERT_FILE "@MARS_NWE_INSTALL_FULL_CONFDIR@/server.crt"
#define DEFAULT_KEY_FILE "@MARS_NWE_INSTALL_FULL_CONFDIR@/server.key"
#define DEFAULT_PID_FILE "@MARS_NWE_PID_DIR@/nwwebui.pid"
#define DEFAULT_DAEMONIZE 0
#define NW_BACKLOG 64
#define NW_BUF_SZ 16384

801
nwwebui.c

File diff suppressed because it is too large Load Diff

View File

@@ -1,28 +1,12 @@
#
# SMArT
#
#
# Configuration file code
#
#
# Copyright 2001 Wilmer van der Gaast (lintux@lintux.cx)
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# Updated for marker-aware config writing.
my( @info, @conf, $l );
my( @info, @conf, @rawconf, $l );
$info[1] = 'Volume';
$info[2] = 'Server name';
@@ -53,6 +37,7 @@ $info[47] = 'Trustee files';
$info[50] = 'Conversion tables';
$info[60] = 'MAX_CONNECTIONS';
$info[61] = 'MAX_NW_VOLS';
$info[62] = 'Reserved';
$info[63] = 'MAX_DIR_BASE_ENTRIES';
$info[68] = 'USE_MMAP';
$info[69] = 'HANDLE_ALL_SAP_TYPS';
@@ -79,19 +64,25 @@ $info[400] = 'nwserv.stations file';
$info[401] = 'Reply to nearest server requests';
$info[402] = 'Reply to connect requests';
open( CONF, '<' . $mars_config );
open( CONF, '<' . $mars_config ) or die "Could not open $mars_config: $!";
@conf = ();
@rawconf = ();
while( $l = <CONF> )
{
$l =~ s/[\r\n]//g;
$l =~ s/[\t ]+/ /g;
$l =~ s/#.*//;
$l =~ s/^[\t ]*//;
$l =~ s/[\t ]*$//;
if( $l ne '' )
{
unshift( @conf, $l );
}
push( @rawconf, $l );
my $x = $l;
$x =~ s/[\r\n]//g;
$x =~ s/[\t ]+/ /g;
$x =~ s/#.*//;
$x =~ s/^[\t ]*//;
$x =~ s/[\t ]*$//;
if( $x ne '' )
{
push( @conf, $x );
}
}
close( CONF );
@@ -99,53 +90,279 @@ sortconfig();
sub sortconfig()
{
@conf = sort( { $a cmp $b } @conf );
@conf = sort( { ( split( ' ', $a ) )[0] <=> ( split( ' ', $b ) )[0] } @conf );
@conf = sort( { $a cmp $b } @conf );
@conf = sort( { ( split( ' ', $a ) )[0] <=> ( split( ' ', $b ) )[0] } @conf );
}
sub getconfigline( $ )
{
my( @c, $c );
@c = getconfig( @_ );
$c = $c[0];
$c =~ s/^[0-9]* //;
return( $c );
my( @c, $c );
@c = getconfig( @_ );
$c = $c[0];
$c =~ s/^[0-9]* //;
return( $c );
}
sub getconfig( $ )
{
my( @c );
@c = grep( /^$_[0] /i, @conf );
return( @c );
my( @c );
@c = grep( /^$_[0] /i, @conf );
return( @c );
}
sub addconfigline( $ )
{
unshift( @conf, $_[0] );
unshift( @conf, $_[0] );
}
sub delconfigline( $ )
{
@conf = grep( !/^$_[0] /i, grep( !/^$_[0]$/i, @conf ) );
@conf = grep( !/^$_[0] /i, grep( !/^$_[0]$/i, @conf ) );
}
sub normalize_line( $ )
{
my $x = $_[0];
$x =~ s/[\r\n]//g;
$x =~ s/[\t ]+/ /g;
$x =~ s/#.*//;
$x =~ s/^[\t ]*//;
$x =~ s/[\t ]*$//;
return( $x );
}
sub section_of_line( $ )
{
my $x = normalize_line( $_[0] );
if( $x =~ /^([0-9]+)\b/ )
{
return( $1 );
}
return( '' );
}
sub grouped_section_key( $ )
{
my $sec = $_[0];
if( $sec >= 100 && $sec <= 106 ) { return '100-106'; }
if( $sec >= 200 && $sec <= 202 ) { return '200-202'; }
if( $sec >= 210 && $sec <= 211 ) { return '210-211'; }
if( $sec >= 300 && $sec <= 302 ) { return '300-302'; }
return $sec;
}
sub build_marker_map()
{
my( %map, $line, $sec, $key );
foreach $line ( @conf )
{
$sec = section_of_line( $line );
next if $sec eq '';
$key = grouped_section_key( $sec );
push( @{ $map{$key} }, $line );
}
# Keep SYS as first entry in section 1
if( defined( $map{'1'} ) )
{
my @sys = grep( /^1 SYS /, @{ $map{'1'} } );
my @rest = grep( !/^1 SYS /, @{ $map{'1'} } );
$map{'1'} = [ @sys, @rest ];
}
return %map;
}
sub writeconfig_compact()
{
my( $i, $l );
sortconfig();
open( CONF, '>' . $mars_config ) or die "Could not write $mars_config: $!";
$l = ( getconfig( '1 SYS' ) )[0];
delconfigline( '1 SYS' );
addconfigline( $l );
foreach $i ( @conf )
{
$l = $i;
$l =~ s/ .*//;
printf( CONF "%-50s # %s\n", $i, $info[$l] );
}
close( CONF );
}
sub writeconfig_markers()
{
my( %secmap, %emitted );
my( $line, $active_key, $inside_active );
%secmap = build_marker_map();
$inside_active = '';
open( CONF, '>' . $mars_config ) or die "Could not write $mars_config: $!";
foreach $line ( @rawconf )
{
if( $line =~ /^\s*#\s*>>>\s*SMARTHOOK\s+SECTION\s+([0-9]+(?:-[0-9]+)?)\s+ACTIVE\s+BEGIN/i )
{
$active_key = $1;
$inside_active = $active_key;
print CONF $line;
if( defined( $secmap{$active_key} ) )
{
foreach my $entry ( @{ $secmap{$active_key} } )
{
print CONF $entry . "\n";
}
}
$emitted{$active_key} = 1;
next;
}
if( $line =~ /^\s*#\s*<<<\s*SMARTHOOK\s+SECTION\s+([0-9]+(?:-[0-9]+)?)\s+ACTIVE\s+END/i )
{
$inside_active = '';
print CONF $line;
next;
}
if( $inside_active ne '' )
{
# Skip old content inside ACTIVE blocks completely.
next;
}
print CONF $line;
}
close( CONF );
}
sub writeconfig_preserve_layout()
{
my( %secmap, %written, @sections, $sec, $line, $sysline );
my( $heading_sec );
sortconfig();
$sysline = ( grep( /^1 SYS /, @conf ) )[0];
if( defined( $sysline ) )
{
@conf = grep( $_ ne $sysline, @conf );
unshift( @conf, $sysline );
}
foreach $line ( @conf )
{
$sec = section_of_line( $line );
if( $sec ne '' )
{
push( @{ $secmap{$sec} }, $line );
}
}
open( CONF, '>' . $mars_config ) or die "Could not write $mars_config: $!";
foreach $line ( @rawconf )
{
if( $line =~ /^\s*#.*Section\s+([0-9]+)\b/i )
{
$heading_sec = $1;
foreach $sec ( sort { $a <=> $b } keys( %secmap ) )
{
next if $written{$sec};
next if $sec > $heading_sec;
if( defined( $secmap{$sec} ) )
{
foreach my $entry ( @{ $secmap{$sec} } )
{
print CONF $entry . "\n";
}
}
$written{$sec} = 1;
}
}
$sec = section_of_line( $line );
if( $sec eq '' )
{
print CONF $line;
next;
}
if( ! $written{$sec} )
{
if( defined( $secmap{$sec} ) )
{
foreach my $entry ( @{ $secmap{$sec} } )
{
print CONF $entry . "\n";
}
}
$written{$sec} = 1;
}
}
@sections = sort { $a <=> $b } keys( %secmap );
foreach $sec ( @sections )
{
next if $written{$sec};
print CONF "\n";
foreach my $entry ( @{ $secmap{$sec} } )
{
print CONF $entry . "\n";
}
$written{$sec} = 1;
}
close( CONF );
}
sub config_has_smart_markers()
{
foreach my $line ( @rawconf )
{
if( $line =~ /SMARTHOOK\s+SECTION/i )
{
return 1;
}
}
return 0;
}
sub writeconfig()
{
my( $i, $l );
sortconfig();
open( CONF, '>' . $mars_config );
$l = ( getconfig( '1 SYS' ) )[0];
delconfigline( '1 SYS' );
addconfigline( $l );
foreach $i ( @conf )
{
$l = $i;
$l =~ s/ .*//;
printf( CONF "%-50s # %s\n", $i, $info[$l] );
}
close( CONF );
if( defined( $smart_compact_nwservconf ) && $smart_compact_nwservconf )
{
writeconfig_compact();
}
elsif( config_has_smart_markers() )
{
writeconfig_markers();
}
else
{
writeconfig_preserve_layout();
}
}

View File

@@ -1,24 +1,118 @@
# SMArT / nwwebui configuration file
# ------------------------------------------------------------
# UI colors
# ------------------------------------------------------------
# Background color used for the main page body.
$COLOR_BACK = "#F0F0FF";
# Background color used for section headers.
$COLOR_HEAD_BACK = "#C0C0FF";
# Text color used for section headers.
$COLOR_HEAD_FORE = "#000000";
# Background color used for subsection headers.
$COLOR_SUBH_BACK = "#D0D0FF";
# Text color used for subsection headers.
$COLOR_SUBH_FORE = "#000000";
# Background color used for normal content rows.
$COLOR_TEXT_BACK = "#E0E0FF";
# Text color used for normal content rows.
$COLOR_TEXT_FORE = "#000000";
# ------------------------------------------------------------
# Main MARS NWE configuration
# ------------------------------------------------------------
# Path to the main mars_nwe server configuration file.
# This file is read and modified by the SMArT configuration pages.
$mars_config = '@MARS_NWE_INSTALL_FULL_CONFDIR@/nwserv.conf';
# User name used when SMArT drops privileges for non-root operations.
# Keep this set to an unprivileged local account.
$nonroot_user = 'nobody';
$smart_conf_path = '@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf';
# Write the mars_nwe configuration file in compact form.
# 0 = preserve comments, blank lines and the original section layout
# 1 = write a compact configuration file without the original long comments
$smart_compact_nwservconf = 0;
# ------------------------------------------------------------
# SMArT internal file layout
# ------------------------------------------------------------
# Absolute path to the SMArT configuration file itself.
# Used when SMArT needs to append updated settings.
$smart_conf_path = '@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf';
# File used to store bindery login information for SMArT helper tools.
# This file should remain readable only by the service user or root.
$smart_nwclient_path = '@MARS_NWE_INSTALL_FULL_CONFDIR@/.nwclient';
$smart_static_dir = '@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/static';
$smart_log_path = '@MARS_NWE_LOG_DIR@/smart.log';
$smart_check_login = '@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/check_login';
# Directory containing static HTML and image files served by SMArT.
$smart_static_dir = '@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/static';
$nw_bind_ip = '0.0.0.0';
$nw_tls_port = 9443;
# Log file used by the Perl SMArT frontend.
# Keep this separate from the nwwebui log file.
$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';
# 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.
# $smart_perl_path = '@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/smart';
# ------------------------------------------------------------
# nwwebui listener settings
# ------------------------------------------------------------
# IP address used for the HTTP and HTTPS listeners.
# Use 0.0.0.0 to listen on all IPv4 interfaces.
# Use 127.0.0.1 for local-only testing.
$nw_bind_ip = '0.0.0.0';
# Log level used by nwwebui.
# 0 = errors only
# 1 = informational messages
# 2 = debug messages
$nw_log_level = 1;
# Run nwwebui in daemon mode by default.
# 0 = stay in foreground
# 1 = detach into background
$nw_daemonize = 0;
# PID file written by nwwebui.
$nw_pid_file = '@MARS_NWE_PID_DIR@/nwwebui.pid';
# Enable or disable TLS/SSL support.
# 1 = enable HTTPS listener
# 0 = disable HTTPS listener
#
# When disabled, nwwebui can still serve plain HTTP if nw_http_port > 0.
$nw_ssl_enable = 0;
# Plain HTTP listener port.
# Set to 0 to disable plain HTTP completely.
# This is useful for local or isolated-network testing.
$nw_http_port = 9080;
# HTTPS listener port.
# Used only when $nw_ssl_enable is set to 1.
# Set to 0 to disable HTTPS listening.
$nw_https_port = 9443;
# TLS certificate file in PEM format.
# Required only when HTTPS is enabled.
$nw_cert_file = '@MARS_NWE_INSTALL_FULL_CONFDIR@/server.crt';
$nw_key_file = '@MARS_NWE_INSTALL_FULL_CONFDIR@/server.key';
# TLS private key file in PEM format.
# Required only when HTTPS is enabled.
$nw_key_file = '@MARS_NWE_INSTALL_FULL_CONFDIR@/server.key';