From bb9392b9b024ef0aad731fa982fb09fd40c8bd2a Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Tue, 21 Apr 2026 04:52:41 +0200 Subject: [PATCH] Add smart --- apply.pl | 8 ++++---- settings.pl | 2 +- smart => smart.cmake | 32 +++++++++++++++++--------------- smart.conf | 11 ----------- smart.conf.cmake | 24 ++++++++++++++++++++++++ static.pl | 2 +- 6 files changed, 47 insertions(+), 32 deletions(-) rename smart => smart.cmake (86%) delete mode 100644 smart.conf create mode 100644 smart.conf.cmake diff --git a/apply.pl b/apply.pl index ecf8328..576fd3f 100644 --- a/apply.pl +++ b/apply.pl @@ -138,17 +138,17 @@ sub handle_request() if( $p{mars_config} ne $mars_config ) { # Just append the line. Messy but easy. ;) - open( FILE, '>>' . $base . 'smart.conf' ); + open( FILE, '>>' . $smart_conf_path ) or die "Could not open $smart_conf_path: $!"; print( FILE "\n" . '$mars_config = \'' . $p{mars_config} . '\';' . "\n" ); close( FILE ); } - open( FILE, '>' . $base . '.nwclient' ); + open( FILE, '>' . $smart_nwclient_path ) or die "Could not open $smart_nwclient_path: $!"; print( FILE $p{bind_server} . '/' . $p{bind_user} . ' ' . $p{bind_pass } . "\n" ); close( FILE ); - chown( scalar( getpwnam( $nonroot_user ) ), 0, $base . '.nwclient' ); - chmod( 0600, $base . '.nwclient' ); + chown( scalar( getpwnam( $nonroot_user ) ), 0, $smart_nwclient_path ); + chmod( 0600, $smart_nwclient_path ); } elsif( $c[1] eq 'users' ) { diff --git a/settings.pl b/settings.pl index edc088c..cfa0a8c 100644 --- a/settings.pl +++ b/settings.pl @@ -1167,7 +1167,7 @@ EOF } elsif( $c[1] eq 'smart' ) { - open( FILE, '<' . $base . '.nwclient' ); + open( FILE, '<' . $smart_nwclient_path ) or die "Could not open $smart_nwclient_path: $!"; $x = ; close( FILE ); diff --git a/smart b/smart.cmake similarity index 86% rename from smart rename to smart.cmake index c25826c..c52a90a 100755 --- a/smart +++ b/smart.cmake @@ -25,16 +25,18 @@ $redirected = 0; -$server_id = 'Server: SMArT/Perl/0.99'; -$base = $0; -$base =~ s/\/[^\/]*$//g; -$base .= '/'; +$server_id = 'Server: SMArT/Perl/@MARS_NWE_VERSION@'; -do( $base . 'smart.conf' ); +do( '@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf' ) + or die "Could not load @MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf: $@ $!"; close( STDERR ); -open( STDERR, '>>' . $base . 'error.log' ); -$ENV{HOME} = $base; +open( STDERR, '>>' . $smart_log_path ) + or die "Could not open $smart_log_path: $!"; + +$ENV{HOME} = '@MARS_NWE_INSTALL_FULL_CONFDIR@'; +$smart_libexec_dir = '@MARS_NWE_INSTALL_FULL_LIBEXEC@'; +$smart_libexec_dir =~ s#/*$##; $l = ; $l =~ s/[\n\r]//g; @@ -75,7 +77,7 @@ else if( $l[0] ne 'root' ) { error( 401 ); } else - { if( $x = system( $base . 'check_login', @l ) ) + { if( $x = system( $smart_check_login, @l ) ) { error( 401 ); } } } } @@ -104,14 +106,14 @@ foreach $p ( @p ) if( $c[0] eq 'apply' ) { - do( $base . 'readconfig.pl' ); - do( $base . 'apply.pl' ); + do( $smart_libexec_dir . '/readconfig.pl' ); + do( $smart_libexec_dir . '/apply.pl' ); handle_request(); exit; } elsif( $c[0] eq 'settings' ) { - do( $base . 'readconfig.pl' ); + do( $smart_libexec_dir . '/readconfig.pl' ); } drop_root(); @@ -137,11 +139,11 @@ EOF } elsif( $c[0] eq 'static' ) { - do( $base . 'static.pl' ); + do( $smart_libexec_dir . '/static.pl' ); } elsif( $c[0] eq 'settings' ) { - do( $base . 'settings.pl' ); + do( $smart_libexec_dir . '/settings.pl' ); } else { @@ -239,7 +241,7 @@ EOF sub get_server { - open( SFILE, '<' . $base . '.nwclient' ); + open( SFILE, '<' . $smart_nwclient_path ); chomp( $line = ); close( SFILE ); @@ -249,7 +251,7 @@ sub get_server sub get_bindery_password { - open( SFILE, '<' . $base . '.nwclient' ); + open( SFILE, '<' . $smart_nwclient_path ); chomp( $line = ); close( SFILE ); diff --git a/smart.conf b/smart.conf deleted file mode 100644 index f158177..0000000 --- a/smart.conf +++ /dev/null @@ -1,11 +0,0 @@ -$COLOR_BACK = "#F0F0FF"; -$COLOR_HEAD_BACK = "#C0C0FF"; -$COLOR_HEAD_FORE = "#000000"; -$COLOR_SUBH_BACK = "#D0D0FF"; -$COLOR_SUBH_FORE = "#000000"; -$COLOR_TEXT_BACK = "#E0E0FF"; -$COLOR_TEXT_FORE = "#000000"; - -$mars_config = '/usr/local/etc/nwserv.conf'; - -$nonroot_user = 'nobody'; diff --git a/smart.conf.cmake b/smart.conf.cmake new file mode 100644 index 0000000..7ce1f6f --- /dev/null +++ b/smart.conf.cmake @@ -0,0 +1,24 @@ +$COLOR_BACK = "#F0F0FF"; +$COLOR_HEAD_BACK = "#C0C0FF"; +$COLOR_HEAD_FORE = "#000000"; +$COLOR_SUBH_BACK = "#D0D0FF"; +$COLOR_SUBH_FORE = "#000000"; +$COLOR_TEXT_BACK = "#E0E0FF"; +$COLOR_TEXT_FORE = "#000000"; + +$mars_config = '@MARS_NWE_INSTALL_FULL_CONFDIR@/nwserv.conf'; + +$nonroot_user = 'nobody'; + +$smart_conf_path = '@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf'; +$smart_nwclient_path = '@MARS_NWE_INSTALL_FULL_CONFDIR@/.nwclient'; +$smart_static_dir = '@MARS_NWE_INSTALL_FULL_LIBEXEC@/static'; +$smart_log_path = '@MARS_NWE_LOG_DIR@/smart.log'; + +$smart_check_login = '@MARS_NWE_INSTALL_FULL_LIBEXEC@/check_login'; + +$nw_bind_ip = '0.0.0.0'; +$nw_tls_port = 9443; + +$nw_cert_file = '@MARS_NWE_INSTALL_FULL_CONFDIR@/server.crt'; +$nw_key_file = '@MARS_NWE_INSTALL_FULL_CONFDIR@/server.key'; diff --git a/static.pl b/static.pl index 62731ae..02894a4 100644 --- a/static.pl +++ b/static.pl @@ -26,7 +26,7 @@ sub handle_request() { $f = $c[1]; $f =~ s/[^-_\.A-Za-z0-9]//g; - if( ! open( FILE, $base . 'static/' . $f ) ) + if( ! open( FILE, $smart_static_dir . '/' . $f ) ) { error( 404 ); }