Add smart

This commit is contained in:
Mario Fetka
2026-04-21 04:52:41 +02:00
parent 24f48e1f96
commit bb9392b9b0
6 changed files with 47 additions and 32 deletions

View File

@@ -138,17 +138,17 @@ sub handle_request()
if( $p{mars_config} ne $mars_config ) if( $p{mars_config} ne $mars_config )
{ {
# Just append the line. Messy but easy. ;) # 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" ); print( FILE "\n" . '$mars_config = \'' . $p{mars_config} . '\';' . "\n" );
close( FILE ); 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" ); print( FILE $p{bind_server} . '/' . $p{bind_user} . ' ' . $p{bind_pass } . "\n" );
close( FILE ); close( FILE );
chown( scalar( getpwnam( $nonroot_user ) ), 0, $base . '.nwclient' ); chown( scalar( getpwnam( $nonroot_user ) ), 0, $smart_nwclient_path );
chmod( 0600, $base . '.nwclient' ); chmod( 0600, $smart_nwclient_path );
} }
elsif( $c[1] eq 'users' ) elsif( $c[1] eq 'users' )
{ {

View File

@@ -1167,7 +1167,7 @@ EOF
} }
elsif( $c[1] eq 'smart' ) elsif( $c[1] eq 'smart' )
{ {
open( FILE, '<' . $base . '.nwclient' ); open( FILE, '<' . $smart_nwclient_path ) or die "Could not open $smart_nwclient_path: $!";
$x = <FILE>; $x = <FILE>;
close( FILE ); close( FILE );

View File

@@ -25,16 +25,18 @@
$redirected = 0; $redirected = 0;
$server_id = 'Server: SMArT/Perl/0.99'; $server_id = 'Server: SMArT/Perl/@MARS_NWE_VERSION@';
$base = $0;
$base =~ s/\/[^\/]*$//g;
$base .= '/';
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 ); close( STDERR );
open( STDERR, '>>' . $base . 'error.log' ); open( STDERR, '>>' . $smart_log_path )
$ENV{HOME} = $base; 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 = <STDIN>; $l = <STDIN>;
$l =~ s/[\n\r]//g; $l =~ s/[\n\r]//g;
@@ -75,7 +77,7 @@ else
if( $l[0] ne 'root' ) if( $l[0] ne 'root' )
{ error( 401 ); } { error( 401 ); }
else else
{ if( $x = system( $base . 'check_login', @l ) ) { if( $x = system( $smart_check_login, @l ) )
{ error( 401 ); } } { error( 401 ); } }
} }
} }
@@ -104,14 +106,14 @@ foreach $p ( @p )
if( $c[0] eq 'apply' ) if( $c[0] eq 'apply' )
{ {
do( $base . 'readconfig.pl' ); do( $smart_libexec_dir . '/readconfig.pl' );
do( $base . 'apply.pl' ); do( $smart_libexec_dir . '/apply.pl' );
handle_request(); handle_request();
exit; exit;
} }
elsif( $c[0] eq 'settings' ) elsif( $c[0] eq 'settings' )
{ {
do( $base . 'readconfig.pl' ); do( $smart_libexec_dir . '/readconfig.pl' );
} }
drop_root(); drop_root();
@@ -137,11 +139,11 @@ EOF
} }
elsif( $c[0] eq 'static' ) elsif( $c[0] eq 'static' )
{ {
do( $base . 'static.pl' ); do( $smart_libexec_dir . '/static.pl' );
} }
elsif( $c[0] eq 'settings' ) elsif( $c[0] eq 'settings' )
{ {
do( $base . 'settings.pl' ); do( $smart_libexec_dir . '/settings.pl' );
} }
else else
{ {
@@ -239,7 +241,7 @@ EOF
sub get_server sub get_server
{ {
open( SFILE, '<' . $base . '.nwclient' ); open( SFILE, '<' . $smart_nwclient_path );
chomp( $line = <SFILE> ); chomp( $line = <SFILE> );
close( SFILE ); close( SFILE );
@@ -249,7 +251,7 @@ sub get_server
sub get_bindery_password sub get_bindery_password
{ {
open( SFILE, '<' . $base . '.nwclient' ); open( SFILE, '<' . $smart_nwclient_path );
chomp( $line = <SFILE> ); chomp( $line = <SFILE> );
close( SFILE ); close( SFILE );

View File

@@ -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';

24
smart.conf.cmake Normal file
View File

@@ -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';

View File

@@ -26,7 +26,7 @@ sub handle_request()
{ {
$f = $c[1]; $f = $c[1];
$f =~ s/[^-_\.A-Za-z0-9]//g; $f =~ s/[^-_\.A-Za-z0-9]//g;
if( ! open( FILE, $base . 'static/' . $f ) ) if( ! open( FILE, $smart_static_dir . '/' . $f ) )
{ {
error( 404 ); error( 404 );
} }