Compare commits
17 Commits
master
...
b676c8f5ce
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b676c8f5ce | ||
|
|
a4dfee99e2 | ||
|
|
8e7c97ff7f | ||
|
|
b7206fc83a | ||
|
|
2ee152f543 | ||
|
|
829be767c9 | ||
|
|
a4d3ded77e | ||
|
|
0d3bbdec8e | ||
|
|
ed3acbe2d4 | ||
|
|
9670c4e749 | ||
|
|
a3f7460150 | ||
|
|
476c51ac10 | ||
|
|
5bbe69ac5f | ||
|
|
331fb1a746 | ||
|
|
bb9392b9b0 | ||
|
|
24f48e1f96 | ||
|
|
0a31d87196 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
error.log
|
||||||
75
CMakeLists.txt
Normal file
75
CMakeLists.txt
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#################################
|
||||||
|
# Project
|
||||||
|
##############
|
||||||
|
|
||||||
|
#################################
|
||||||
|
# Dependencies
|
||||||
|
##############
|
||||||
|
|
||||||
|
#################################
|
||||||
|
# Generated files
|
||||||
|
##############
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
|
||||||
|
IMMEDIATE @ONLY)
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/smart.conf.cmake"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/smart.conf"
|
||||||
|
IMMEDIATE @ONLY)
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/smart.cmake"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/smart"
|
||||||
|
IMMEDIATE @ONLY)
|
||||||
|
|
||||||
|
#################################
|
||||||
|
# Compiler Switches
|
||||||
|
##############
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR}/include
|
||||||
|
${CMAKE_BINARY_DIR}/include
|
||||||
|
)
|
||||||
|
|
||||||
|
#################################
|
||||||
|
# Source Files
|
||||||
|
##############
|
||||||
|
|
||||||
|
add_executable(nwwebui nwwebui.c)
|
||||||
|
add_executable(check_login check_login.c)
|
||||||
|
|
||||||
|
#################################
|
||||||
|
# Linking
|
||||||
|
##############
|
||||||
|
|
||||||
|
target_link_libraries(nwwebui
|
||||||
|
OpenSSL::SSL
|
||||||
|
OpenSSL::Crypto
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(check_login
|
||||||
|
${PAM_LIBRARY}
|
||||||
|
${DL_LIBRARY}
|
||||||
|
)
|
||||||
|
|
||||||
|
#################################
|
||||||
|
# Install Files
|
||||||
|
##############
|
||||||
|
|
||||||
|
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 apply.pl DESTINATION ${MARS_NWE_INSTALL_FULL_LIBEXECDIR})
|
||||||
|
install(PROGRAMS readconfig.pl DESTINATION ${MARS_NWE_INSTALL_FULL_LIBEXECDIR})
|
||||||
|
install(PROGRAMS settings.pl DESTINATION ${MARS_NWE_INSTALL_FULL_LIBEXECDIR})
|
||||||
|
install(PROGRAMS static.pl DESTINATION ${MARS_NWE_INSTALL_FULL_LIBEXECDIR})
|
||||||
|
|
||||||
|
install(DIRECTORY static/ DESTINATION ${MARS_NWE_INSTALL_FULL_LIBEXECDIR}/static)
|
||||||
|
|
||||||
|
install(TARGETS check_login DESTINATION ${MARS_NWE_INSTALL_FULL_LIBEXECDIR})
|
||||||
|
|
||||||
|
install(TARGETS nwwebui DESTINATION ${CMAKE_INSTALL_SBINDIR})
|
||||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# mars-smart
|
||||||
|
|
||||||
|
SMArT is a web configuration tool for MARS_NWE, a Novell NetWare 3.x emulator for Linux and FreeBSD.
|
||||||
8
apply.pl
8
apply.pl
@@ -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' )
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
check_login
BIN
check_login
Binary file not shown.
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include <security/pam_appl.h>
|
#include <security/pam_appl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int my_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr);
|
int my_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr);
|
||||||
|
|
||||||
|
|||||||
31
config.h.cmake
Normal file
31
config.h.cmake
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef NWWEBUI_CONFIG_H
|
||||||
|
#define NWWEBUI_CONFIG_H
|
||||||
|
|
||||||
|
#define NWWEBUI_NAME "nwwebui"
|
||||||
|
#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 LOG_PATH_DEFAULT "@MARS_NWE_LOG_DIR@/nwwebui.log"
|
||||||
|
|
||||||
|
#define LOG_LEVEL_ERROR 0
|
||||||
|
#define LOG_LEVEL_INFO 1
|
||||||
|
#define LOG_LEVEL_DEBUG 2
|
||||||
|
#define LOG_LEVEL_DEFAULT LOG_LEVEL_INFO
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
#endif
|
||||||
335
readconfig.pl
335
readconfig.pl
@@ -1,28 +1,12 @@
|
|||||||
#
|
|
||||||
# SMArT
|
# SMArT
|
||||||
#
|
#
|
||||||
# Configuration file code
|
# Configuration file code
|
||||||
#
|
#
|
||||||
# Copyright 2001 Wilmer van der Gaast (lintux@lintux.cx)
|
# 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[1] = 'Volume';
|
||||||
$info[2] = 'Server name';
|
$info[2] = 'Server name';
|
||||||
@@ -53,6 +37,7 @@ $info[47] = 'Trustee files';
|
|||||||
$info[50] = 'Conversion tables';
|
$info[50] = 'Conversion tables';
|
||||||
$info[60] = 'MAX_CONNECTIONS';
|
$info[60] = 'MAX_CONNECTIONS';
|
||||||
$info[61] = 'MAX_NW_VOLS';
|
$info[61] = 'MAX_NW_VOLS';
|
||||||
|
$info[62] = 'Reserved';
|
||||||
$info[63] = 'MAX_DIR_BASE_ENTRIES';
|
$info[63] = 'MAX_DIR_BASE_ENTRIES';
|
||||||
$info[68] = 'USE_MMAP';
|
$info[68] = 'USE_MMAP';
|
||||||
$info[69] = 'HANDLE_ALL_SAP_TYPS';
|
$info[69] = 'HANDLE_ALL_SAP_TYPS';
|
||||||
@@ -79,19 +64,25 @@ $info[400] = 'nwserv.stations file';
|
|||||||
$info[401] = 'Reply to nearest server requests';
|
$info[401] = 'Reply to nearest server requests';
|
||||||
$info[402] = 'Reply to connect requests';
|
$info[402] = 'Reply to connect requests';
|
||||||
|
|
||||||
open( CONF, '<' . $mars_config );
|
open( CONF, '<' . $mars_config ) or die "Could not open $mars_config: $!";
|
||||||
@conf = ();
|
@conf = ();
|
||||||
|
@rawconf = ();
|
||||||
|
|
||||||
while( $l = <CONF> )
|
while( $l = <CONF> )
|
||||||
{
|
{
|
||||||
$l =~ s/[\r\n]//g;
|
push( @rawconf, $l );
|
||||||
$l =~ s/[\t ]+/ /g;
|
|
||||||
$l =~ s/#.*//;
|
my $x = $l;
|
||||||
$l =~ s/^[\t ]*//;
|
$x =~ s/[\r\n]//g;
|
||||||
$l =~ s/[\t ]*$//;
|
$x =~ s/[\t ]+/ /g;
|
||||||
if( $l ne '' )
|
$x =~ s/#.*//;
|
||||||
{
|
$x =~ s/^[\t ]*//;
|
||||||
unshift( @conf, $l );
|
$x =~ s/[\t ]*$//;
|
||||||
}
|
|
||||||
|
if( $x ne '' )
|
||||||
|
{
|
||||||
|
push( @conf, $x );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
close( CONF );
|
close( CONF );
|
||||||
|
|
||||||
@@ -99,53 +90,279 @@ sortconfig();
|
|||||||
|
|
||||||
sub sortconfig()
|
sub sortconfig()
|
||||||
{
|
{
|
||||||
@conf = sort( { $a cmp $b } @conf );
|
@conf = sort( { $a cmp $b } @conf );
|
||||||
@conf = sort( { ( split( ' ', $a ) )[0] <=> ( split( ' ', $b ) )[0] } @conf );
|
@conf = sort( { ( split( ' ', $a ) )[0] <=> ( split( ' ', $b ) )[0] } @conf );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getconfigline( $ )
|
sub getconfigline( $ )
|
||||||
{
|
{
|
||||||
my( @c, $c );
|
my( @c, $c );
|
||||||
|
|
||||||
@c = getconfig( @_ );
|
@c = getconfig( @_ );
|
||||||
$c = $c[0];
|
$c = $c[0];
|
||||||
$c =~ s/^[0-9]* //;
|
$c =~ s/^[0-9]* //;
|
||||||
return( $c );
|
return( $c );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getconfig( $ )
|
sub getconfig( $ )
|
||||||
{
|
{
|
||||||
my( @c );
|
my( @c );
|
||||||
|
|
||||||
@c = grep( /^$_[0] /i, @conf );
|
@c = grep( /^$_[0] /i, @conf );
|
||||||
return( @c );
|
return( @c );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub addconfigline( $ )
|
sub addconfigline( $ )
|
||||||
{
|
{
|
||||||
unshift( @conf, $_[0] );
|
unshift( @conf, $_[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub delconfigline( $ )
|
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()
|
sub writeconfig()
|
||||||
{
|
{
|
||||||
my( $i, $l );
|
if( defined( $smart_compact_nwservconf ) && $smart_compact_nwservconf )
|
||||||
|
{
|
||||||
sortconfig();
|
writeconfig_compact();
|
||||||
|
}
|
||||||
open( CONF, '>' . $mars_config );
|
elsif( config_has_smart_markers() )
|
||||||
$l = ( getconfig( '1 SYS' ) )[0];
|
{
|
||||||
delconfigline( '1 SYS' );
|
writeconfig_markers();
|
||||||
addconfigline( $l );
|
}
|
||||||
foreach $i ( @conf )
|
else
|
||||||
{
|
{
|
||||||
$l = $i;
|
writeconfig_preserve_layout();
|
||||||
$l =~ s/ .*//;
|
}
|
||||||
printf( CONF "%-50s # %s\n", $i, $info[$l] );
|
|
||||||
}
|
|
||||||
close( CONF );
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 );
|
||||||
|
|
||||||
|
|||||||
310
smart
310
smart
@@ -1,310 +0,0 @@
|
|||||||
#!/usr/bin/perl
|
|
||||||
#
|
|
||||||
# SMArT
|
|
||||||
#
|
|
||||||
# Main program file
|
|
||||||
#
|
|
||||||
# Copyright 2001 Wilmer van der Gaast
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
$redirected = 0;
|
|
||||||
|
|
||||||
$server_id = 'Server: SMArT/Perl/0.99';
|
|
||||||
$base = $0;
|
|
||||||
$base =~ s/\/[^\/]*$//g;
|
|
||||||
$base .= '/';
|
|
||||||
|
|
||||||
do( $base . 'smart.conf' );
|
|
||||||
|
|
||||||
close( STDERR );
|
|
||||||
open( STDERR, '>>' . $base . 'error.log' );
|
|
||||||
$ENV{HOME} = $base;
|
|
||||||
|
|
||||||
$l = <STDIN>;
|
|
||||||
$l =~ s/[\n\r]//g;
|
|
||||||
@c = split( ' ', $l );
|
|
||||||
if( scalar( @c ) > 2 )
|
|
||||||
{
|
|
||||||
while( keys( %h ) < 15 ) # Who would ever want to send more headers???
|
|
||||||
{
|
|
||||||
$l = <STDIN>;
|
|
||||||
$l =~ s/[\n\r]//g;
|
|
||||||
if( $l eq '' )
|
|
||||||
{ last; }
|
|
||||||
$n = $l;
|
|
||||||
$n =~ s/:[^:]*$//g;
|
|
||||||
$v = $l;
|
|
||||||
$v =~ s/^[^:]*://g;
|
|
||||||
$h{$n} = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$c[0] = uc( $c[0] );
|
|
||||||
|
|
||||||
if( $h{Authorization} eq '' )
|
|
||||||
{ error( 401 ); }
|
|
||||||
else
|
|
||||||
{
|
|
||||||
@s = split( ' ', $h{Authorization} );
|
|
||||||
if( $s[0] ne 'Basic' or length( $h{Authorization} ) > 80 ) # We can't be too careful, can we...
|
|
||||||
{ error( 401 ); }
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$s[1] =~ tr#A-Za-z0-9+/##cd;
|
|
||||||
$s[1] =~ tr#A-Za-z0-9+/# -_#;
|
|
||||||
$s[1] = pack( 'c', 32 + 0.75 * length( $s[1] ) ) . $s[1];
|
|
||||||
$s[1] = unpack( 'u', $s[1] );
|
|
||||||
$s[1] =~ s/[\r\n]//g;
|
|
||||||
@l = split( ':', $s[1] );
|
|
||||||
if( $l[0] ne 'root' )
|
|
||||||
{ error( 401 ); }
|
|
||||||
else
|
|
||||||
{ if( $x = system( $base . 'check_login', @l ) )
|
|
||||||
{ error( 401 ); } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( $c[0] ne 'GET' )
|
|
||||||
{
|
|
||||||
error( 501 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@p = split( '\?', $c[1] );
|
|
||||||
$cc = $c[1];
|
|
||||||
$cc =~ s/[^\?]*\?//;
|
|
||||||
$c = substr( shift( @p ), 1 );
|
|
||||||
@p = split( '&', $p[0] );
|
|
||||||
foreach $p ( @p )
|
|
||||||
{
|
|
||||||
$n = $p;
|
|
||||||
$n =~ s/=.*//;
|
|
||||||
$v = $p;
|
|
||||||
$v =~ s/.*=//;
|
|
||||||
$v =~ s/\+/ /g;
|
|
||||||
$v =~ s/%([0-9A-F][0-9A-F])/pack('c',hex($1))/gie;
|
|
||||||
$p{$n} = $v;
|
|
||||||
}
|
|
||||||
@c = split( '/', $c );
|
|
||||||
|
|
||||||
if( $c[0] eq 'apply' )
|
|
||||||
{
|
|
||||||
do( $base . 'readconfig.pl' );
|
|
||||||
do( $base . 'apply.pl' );
|
|
||||||
handle_request();
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
elsif( $c[0] eq 'settings' )
|
|
||||||
{
|
|
||||||
do( $base . 'readconfig.pl' );
|
|
||||||
}
|
|
||||||
|
|
||||||
drop_root();
|
|
||||||
|
|
||||||
if( $c[0] eq '' )
|
|
||||||
{
|
|
||||||
print <<EOF;
|
|
||||||
HTTP/1.0 200 OK
|
|
||||||
Content-Type: text/html
|
|
||||||
$server_id
|
|
||||||
|
|
||||||
<HTML>
|
|
||||||
<HEAD>
|
|
||||||
<TITLE>SMArT</TITLE>
|
|
||||||
</HEAD>
|
|
||||||
<FRAMESET COLS="50%,50%">
|
|
||||||
<FRAME NAME="MENU" SRC="/static/menu.html">
|
|
||||||
<FRAME NAME="OPTS" SRC="/static/start.html">
|
|
||||||
</FRAMESET>
|
|
||||||
</HTML>
|
|
||||||
EOF
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
elsif( $c[0] eq 'static' )
|
|
||||||
{
|
|
||||||
do( $base . 'static.pl' );
|
|
||||||
}
|
|
||||||
elsif( $c[0] eq 'settings' )
|
|
||||||
{
|
|
||||||
do( $base . 'settings.pl' );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error( 500 );
|
|
||||||
}
|
|
||||||
|
|
||||||
handle_request();
|
|
||||||
exit;
|
|
||||||
|
|
||||||
##########################################
|
|
||||||
##### END OF MAIN PROCEDURES FOLLOW #####
|
|
||||||
##########################################
|
|
||||||
|
|
||||||
sub error( $ )
|
|
||||||
{
|
|
||||||
if( $_[0] eq '401' )
|
|
||||||
{
|
|
||||||
print <<EOF;
|
|
||||||
HTTP/1.0 401 Access denied
|
|
||||||
Content-Type: text/plain
|
|
||||||
WWW-Authenticate: Basic realm="SMArT"
|
|
||||||
$server_id
|
|
||||||
|
|
||||||
You're not allowed to access this URL.
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
elsif( $_[0] eq '404' )
|
|
||||||
{
|
|
||||||
print <<EOF;
|
|
||||||
HTTP/1.0 404 File not found
|
|
||||||
Content-Type: text/plain
|
|
||||||
$server_id
|
|
||||||
|
|
||||||
The file you requested does not exist.
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
elsif( $_[0] eq '501' )
|
|
||||||
{
|
|
||||||
print <<EOF;
|
|
||||||
HTTP/1.0 501 Unknown command
|
|
||||||
Content-Type: text/plain
|
|
||||||
$server_id
|
|
||||||
|
|
||||||
Unknown command: $c[0]
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print <<EOF;
|
|
||||||
HTTP/1.0 500 Internal server error
|
|
||||||
Content-Type: text/plain
|
|
||||||
$server_id
|
|
||||||
|
|
||||||
Something went wrong...
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub unix_userlist()
|
|
||||||
{
|
|
||||||
my( @c, @d, %e );
|
|
||||||
|
|
||||||
while( @d = getpwent )
|
|
||||||
{
|
|
||||||
unshift( @c, { name => $d[0], uid => $d[2] } );
|
|
||||||
}
|
|
||||||
return( sort( { $a->{"name"} cmp $b->{"name"} } @c ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub unix_grouplist()
|
|
||||||
{
|
|
||||||
my( @c, @d, %e );
|
|
||||||
|
|
||||||
while( @d = getgrent )
|
|
||||||
{
|
|
||||||
unshift( @c, { name => $d[0], gid => $d[2] } );
|
|
||||||
}
|
|
||||||
return( sort( { $a->{"name"} cmp $b->{"name"} } @c ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub redirect( $ )
|
|
||||||
{
|
|
||||||
if( $redirected != 0 )
|
|
||||||
{ return( 0 ); }
|
|
||||||
$redirected = 1;
|
|
||||||
print <<EOF;
|
|
||||||
HTTP/1.0 302 Page relocated
|
|
||||||
Content-Type: text/plain
|
|
||||||
Location: $_[0]
|
|
||||||
$server_id
|
|
||||||
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
sub get_server
|
|
||||||
{
|
|
||||||
open( SFILE, '<' . $base . '.nwclient' );
|
|
||||||
chomp( $line = <SFILE> );
|
|
||||||
close( SFILE );
|
|
||||||
|
|
||||||
$line =~ s/\/.*//;
|
|
||||||
return( $line );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub get_bindery_password
|
|
||||||
{
|
|
||||||
open( SFILE, '<' . $base . '.nwclient' );
|
|
||||||
chomp( $line = <SFILE> );
|
|
||||||
close( SFILE );
|
|
||||||
|
|
||||||
$line =~ s/.* //;
|
|
||||||
return( $line );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub read_property_string
|
|
||||||
{
|
|
||||||
my @x = split( "\n", `nwbpvalues -c -o $_[0] -t $_[1] -p $_[2] -S $server` );
|
|
||||||
my( $i, $s );
|
|
||||||
|
|
||||||
$i = 5;
|
|
||||||
while( hex( $x[$i] ) > 0 )
|
|
||||||
{
|
|
||||||
$s .= pack( 'c', hex( $x[$i] ) );
|
|
||||||
$i ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return( $s );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub read_property_list
|
|
||||||
{
|
|
||||||
my @x = split( "\n", `nwbpvalues -c -o $_[0] -t $_[1] -p $_[2] -S $server` );
|
|
||||||
my( $i, @l );
|
|
||||||
|
|
||||||
$i = 6;
|
|
||||||
while( $x[$i] ne '' )
|
|
||||||
{
|
|
||||||
unshift( @l, $x[$i] );
|
|
||||||
$i += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return( @l );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub write_property_string
|
|
||||||
{
|
|
||||||
open( FILE, '|' . 'nwbpset -S ' . $server );
|
|
||||||
print FILE <<EOF;
|
|
||||||
000$_[1]
|
|
||||||
$_[0]
|
|
||||||
$_[2]
|
|
||||||
$_[3]
|
|
||||||
$_[4]
|
|
||||||
EOF
|
|
||||||
for $i ( 0 .. length( $_[5] ) - 1 )
|
|
||||||
{
|
|
||||||
print( FILE unpack( 'H2', substr( $_[5], $i, 1 ) ) . "\n" );
|
|
||||||
}
|
|
||||||
close( FILE );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub drop_root
|
|
||||||
{
|
|
||||||
$< = $> = getpwnam( $nonroot_user );
|
|
||||||
}
|
|
||||||
320
smart.cmake
Executable file
320
smart.cmake
Executable file
@@ -0,0 +1,320 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
#
|
||||||
|
# SMArT
|
||||||
|
#
|
||||||
|
# Main web frontend
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
$redirected = 0;
|
||||||
|
|
||||||
|
$smart_version = '@MARS_NWE_VERSION@';
|
||||||
|
$server_id = 'Server: SMArT/Perl/' . $smart_version;
|
||||||
|
|
||||||
|
if( ! do('@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf') )
|
||||||
|
{
|
||||||
|
die "Could not load @MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf: $@ $!";
|
||||||
|
}
|
||||||
|
|
||||||
|
$ENV{HOME} = '@MARS_NWE_INSTALL_FULL_CONFDIR@';
|
||||||
|
$smart_libexec_dir = '@MARS_NWE_INSTALL_FULL_LIBEXECDIR@';
|
||||||
|
$smart_libexec_dir =~ s#/*$##;
|
||||||
|
|
||||||
|
close( STDERR );
|
||||||
|
open( STDERR, '>>' . $smart_log_path ) or die "Could not open $smart_log_path: $!";
|
||||||
|
select( STDERR ); $| = 1;
|
||||||
|
select( STDOUT ); $| = 1;
|
||||||
|
|
||||||
|
sub log_timestamp()
|
||||||
|
{
|
||||||
|
my @t = localtime( time() );
|
||||||
|
return sprintf(
|
||||||
|
'%04d-%02d-%02d %02d:%02d:%02d',
|
||||||
|
$t[5] + 1900, $t[4] + 1, $t[3],
|
||||||
|
$t[2], $t[1], $t[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub log_msg( $$ )
|
||||||
|
{
|
||||||
|
my( $level, $msg ) = @_;
|
||||||
|
print STDERR '[' . log_timestamp() . '] [' . $level . '] [SMArT ' . $smart_version . '] ' . $msg . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub log_info( $ )
|
||||||
|
{
|
||||||
|
log_msg( 'INFO', $_[0] );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub log_error( $ )
|
||||||
|
{
|
||||||
|
log_msg( 'ERROR', $_[0] );
|
||||||
|
}
|
||||||
|
|
||||||
|
log_info( 'starting' );
|
||||||
|
log_info( 'loaded configuration from ' . '@MARS_NWE_INSTALL_FULL_CONFDIR@/smart.conf' );
|
||||||
|
|
||||||
|
$l = <STDIN>;
|
||||||
|
if( ! defined( $l ) )
|
||||||
|
{
|
||||||
|
log_error( 'no request line received on stdin' );
|
||||||
|
exit( 1 );
|
||||||
|
}
|
||||||
|
$l =~ s/[\n\r]//g;
|
||||||
|
log_info( 'request: ' . $l );
|
||||||
|
|
||||||
|
@c = split( ' ', $l );
|
||||||
|
$cc = $c[1];
|
||||||
|
@c = split( '/', $c[1] );
|
||||||
|
shift( @c );
|
||||||
|
|
||||||
|
sub error( $ )
|
||||||
|
{
|
||||||
|
my( $e ) = @_;
|
||||||
|
|
||||||
|
log_error( 'HTTP error ' . $e . ' for request ' . $cc );
|
||||||
|
|
||||||
|
print <<EOF;
|
||||||
|
HTTP/1.0 $e Error
|
||||||
|
Content-Type: text/html
|
||||||
|
$server_id
|
||||||
|
|
||||||
|
<HTML>
|
||||||
|
<BODY BGCOLOR=$COLOR_BACK>
|
||||||
|
<H1>Error $e</H1>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
||||||
|
EOF
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub redirect( $ )
|
||||||
|
{
|
||||||
|
my( $u ) = @_;
|
||||||
|
|
||||||
|
print <<EOF;
|
||||||
|
HTTP/1.0 302 Found
|
||||||
|
Location: $u
|
||||||
|
$server_id
|
||||||
|
|
||||||
|
EOF
|
||||||
|
$redirected = 1;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub drop_root()
|
||||||
|
{
|
||||||
|
if( $> == 0 )
|
||||||
|
{
|
||||||
|
my $uid = getpwnam( $nonroot_user );
|
||||||
|
if( ! defined( $uid ) )
|
||||||
|
{
|
||||||
|
log_error( 'could not resolve non-root user ' . $nonroot_user );
|
||||||
|
error( 500 );
|
||||||
|
}
|
||||||
|
$> = $uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_server()
|
||||||
|
{
|
||||||
|
open( SFILE, '<' . $smart_nwclient_path ) or do {
|
||||||
|
log_error( 'could not open ' . $smart_nwclient_path . ': ' . $! );
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
chomp( $line = <SFILE> );
|
||||||
|
close( SFILE );
|
||||||
|
|
||||||
|
$line =~ s/\/.*//;
|
||||||
|
return( $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_bindery_password()
|
||||||
|
{
|
||||||
|
open( SFILE, '<' . $smart_nwclient_path ) or do {
|
||||||
|
log_error( 'could not open ' . $smart_nwclient_path . ': ' . $! );
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
chomp( $line = <SFILE> );
|
||||||
|
close( SFILE );
|
||||||
|
|
||||||
|
$line =~ s/.* //;
|
||||||
|
return( $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub unix_userlist()
|
||||||
|
{
|
||||||
|
my( @l, @r, $u );
|
||||||
|
open( FILE, '</etc/passwd' ) or return();
|
||||||
|
while( <FILE> )
|
||||||
|
{
|
||||||
|
chomp;
|
||||||
|
@l = split( /:/ );
|
||||||
|
$u = {};
|
||||||
|
$u->{name} = $l[0];
|
||||||
|
$u->{uid} = $l[2];
|
||||||
|
push( @r, $u );
|
||||||
|
}
|
||||||
|
close( FILE );
|
||||||
|
return( @r );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub unix_grouplist()
|
||||||
|
{
|
||||||
|
my( @l, @r, $u );
|
||||||
|
open( FILE, '</etc/group' ) or return();
|
||||||
|
while( <FILE> )
|
||||||
|
{
|
||||||
|
chomp;
|
||||||
|
@l = split( /:/ );
|
||||||
|
$u = {};
|
||||||
|
$u->{name} = $l[0];
|
||||||
|
$u->{gid} = $l[2];
|
||||||
|
push( @r, $u );
|
||||||
|
}
|
||||||
|
close( FILE );
|
||||||
|
return( @r );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub write_property_string( $$$$$ )
|
||||||
|
{
|
||||||
|
my( $obj, $type, $prop, $seg, $len, $str ) = @_;
|
||||||
|
|
||||||
|
open( FILE, '|' . 'nwbpset -S ' . get_server() ) or return;
|
||||||
|
print FILE <<EOF;
|
||||||
|
000$type
|
||||||
|
$obj
|
||||||
|
$prop
|
||||||
|
$seg
|
||||||
|
$len
|
||||||
|
$str
|
||||||
|
EOF
|
||||||
|
close( FILE );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub read_property_string( $$$ )
|
||||||
|
{
|
||||||
|
my( $obj, $type, $prop ) = @_;
|
||||||
|
my( @l, $s );
|
||||||
|
|
||||||
|
open( FILE, 'nwbpvalues -S ' . get_server() . ' -o ' . $obj . ' -t ' . $type . ' -p ' . $prop . ' |' ) or return '';
|
||||||
|
@l = <FILE>;
|
||||||
|
close( FILE );
|
||||||
|
|
||||||
|
$s = join( '', @l );
|
||||||
|
$s =~ s/[\r\n]+$//g;
|
||||||
|
return( $s );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub authenticate()
|
||||||
|
{
|
||||||
|
my( @h, $auth, @l, $x );
|
||||||
|
|
||||||
|
while( $l = <STDIN> )
|
||||||
|
{
|
||||||
|
$l =~ s/[\n\r]//g;
|
||||||
|
last if $l eq '';
|
||||||
|
push( @h, $l );
|
||||||
|
}
|
||||||
|
|
||||||
|
($auth) = grep( /^Authorization: /i, @h );
|
||||||
|
if( $auth eq '' )
|
||||||
|
{
|
||||||
|
print <<EOF;
|
||||||
|
HTTP/1.0 401 Unauthorized
|
||||||
|
WWW-Authenticate: Basic realm="SMArT"
|
||||||
|
$server_id
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$auth =~ s/^Authorization:\s*Basic\s*//i;
|
||||||
|
$auth = unpack( 'u', $auth ) if $auth =~ /^[\x20-\x7e]+$/ && $auth !~ /:/;
|
||||||
|
$auth =~ s/[\r\n]//g;
|
||||||
|
|
||||||
|
@l = split( ':', $auth, 2 );
|
||||||
|
if( $l[0] ne 'root' )
|
||||||
|
{
|
||||||
|
log_error( 'authentication failed for non-root user ' . $l[0] );
|
||||||
|
error( 401 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$x = system( $smart_check_login, @l );
|
||||||
|
if( $x )
|
||||||
|
{
|
||||||
|
log_error( 'authentication failed for user root' );
|
||||||
|
error( 401 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticate();
|
||||||
|
|
||||||
|
if( $c[0] eq 'apply' )
|
||||||
|
{
|
||||||
|
do( $smart_libexec_dir . '/readconfig.pl' ) or do {
|
||||||
|
log_error( 'could not load readconfig.pl: ' . $@ . ' ' . $! );
|
||||||
|
error( 500 );
|
||||||
|
};
|
||||||
|
do( $smart_libexec_dir . '/apply.pl' ) or do {
|
||||||
|
log_error( 'could not load apply.pl: ' . $@ . ' ' . $! );
|
||||||
|
error( 500 );
|
||||||
|
};
|
||||||
|
handle_request();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
elsif( $c[0] eq 'settings' )
|
||||||
|
{
|
||||||
|
do( $smart_libexec_dir . '/readconfig.pl' ) or do {
|
||||||
|
log_error( 'could not load readconfig.pl: ' . $@ . ' ' . $! );
|
||||||
|
error( 500 );
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_root();
|
||||||
|
|
||||||
|
if( $cc eq '/' or $cc eq '' )
|
||||||
|
{
|
||||||
|
redirect( '/static/start.html' );
|
||||||
|
}
|
||||||
|
elsif( $c[0] eq 'static' )
|
||||||
|
{
|
||||||
|
do( $smart_libexec_dir . '/static.pl' ) or do {
|
||||||
|
log_error( 'could not load static.pl: ' . $@ . ' ' . $! );
|
||||||
|
error( 500 );
|
||||||
|
};
|
||||||
|
handle_request();
|
||||||
|
}
|
||||||
|
elsif( $c[0] eq 'settings' )
|
||||||
|
{
|
||||||
|
do( $smart_libexec_dir . '/settings.pl' ) or do {
|
||||||
|
log_error( 'could not load settings.pl: ' . $@ . ' ' . $! );
|
||||||
|
error( 500 );
|
||||||
|
};
|
||||||
|
handle_request();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log_error( 'unknown path ' . $cc );
|
||||||
|
error( 404 );
|
||||||
|
}
|
||||||
11
smart.conf
11
smart.conf
@@ -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';
|
|
||||||
118
smart.conf.cmake
Normal file
118
smart.conf.cmake
Normal file
@@ -0,0 +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';
|
||||||
|
|
||||||
|
# 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';
|
||||||
|
|
||||||
|
# Directory containing static HTML and image files served by SMArT.
|
||||||
|
$smart_static_dir = '@MARS_NWE_INSTALL_FULL_LIBEXECDIR@/static';
|
||||||
|
|
||||||
|
# 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';
|
||||||
|
|
||||||
|
# TLS private key file in PEM format.
|
||||||
|
# Required only when HTTPS is enabled.
|
||||||
|
$nw_key_file = '@MARS_NWE_INSTALL_FULL_CONFDIR@/server.key';
|
||||||
Reference in New Issue
Block a user