554 lines
13 KiB
Perl
554 lines
13 KiB
Perl
#
|
|
# SMArT
|
|
#
|
|
# Apply changes
|
|
#
|
|
# 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
|
|
#
|
|
#
|
|
|
|
sub read_smart_bindery_values()
|
|
{
|
|
my( $bind_server, $bind_user, $bind_pass ) = ( '', '', '' );
|
|
|
|
if( open( my $fh, '<' . $smart_nwclient_path ) )
|
|
{
|
|
my $line = <$fh>;
|
|
close( $fh );
|
|
|
|
chomp( $line ) if defined( $line );
|
|
( $bind_server, $bind_user, $bind_pass ) = split( '[/ ]', $line ) if defined( $line );
|
|
}
|
|
|
|
$bind_server = '' unless defined( $bind_server );
|
|
$bind_user = '' unless defined( $bind_user );
|
|
$bind_pass = '' unless defined( $bind_pass );
|
|
|
|
return( $bind_server, $bind_user, $bind_pass );
|
|
}
|
|
|
|
sub write_smart_bindery_values( $$$ )
|
|
{
|
|
my( $bind_server, $bind_user, $bind_pass ) = @_;
|
|
|
|
$bind_server = '' unless defined( $bind_server );
|
|
$bind_user = '' unless defined( $bind_user );
|
|
$bind_pass = '' unless defined( $bind_pass );
|
|
|
|
open( my $fh, '>' . $smart_nwclient_path ) or die "Could not open $smart_nwclient_path: $!";
|
|
print( $fh $bind_server . '/' . $bind_user . ' ' . $bind_pass . "\n" );
|
|
close( $fh );
|
|
|
|
chown( scalar( getpwnam( $nonroot_user ) ), 0, $smart_nwclient_path );
|
|
chmod( 0600, $smart_nwclient_path );
|
|
}
|
|
|
|
|
|
sub handle_request()
|
|
{
|
|
if( $c[1] eq 'general' )
|
|
{
|
|
setc( 2, server_name );
|
|
setc( 3, internal_net );
|
|
if( defined( $p{sync_smart_bind_server} ) && $p{sync_smart_bind_server} eq 'on' && defined( $p{server_name} ) && $p{server_name} ne '' )
|
|
{
|
|
my( $old_bind_server, $old_bind_user, $old_bind_pass ) = read_smart_bindery_values();
|
|
write_smart_bindery_values( $p{server_name}, $old_bind_user, $old_bind_pass );
|
|
}
|
|
setc( 16, test );
|
|
setc( 210, timing_down );
|
|
setc( 211, timing_warn );
|
|
delconfigline( 6 );
|
|
if( $p{version} ne '' )
|
|
{
|
|
if( $p{burst_enabled} eq 'on' )
|
|
{ addconfigline( '6 ' . $p{version} . ' 1' ); }
|
|
else
|
|
{ addconfigline( '6 ' . $p{version} . ' 0' ); }
|
|
}
|
|
delconfigline( 30 );
|
|
if( $p{burst_read} ne '' )
|
|
{ addconfigline( '30 ' . $p{burst_read} . ' ' . $p{burst_write} ); }
|
|
}
|
|
elsif( $c[1] eq 'dirs' )
|
|
{
|
|
setc( 40, path_cache );
|
|
setc( 41, share_lock );
|
|
setc( 42, spool );
|
|
setc( 45, bindery );
|
|
setc( 46, attribute );
|
|
setc( 47, trustee );
|
|
}
|
|
elsif( $c[1] eq 'configh' )
|
|
{
|
|
setc( 60, max_conn );
|
|
setc( 61, max_vol );
|
|
setc( 63, max_dirbase );
|
|
if( $p{mmap} eq 'on' )
|
|
{ $p{mmap} = 1; }
|
|
else
|
|
{ $p{mmap} = 0; }
|
|
setc( 68, mmap );
|
|
setc( 69, sap );
|
|
setc( 70, net_serial );
|
|
setc( 71, net_app );
|
|
}
|
|
elsif( $c[1] eq 'security' )
|
|
{
|
|
setc( 7, encrypt );
|
|
delconfigline( 9 );
|
|
if( $p{creat_dir} ne '' )
|
|
{ addconfigline( '9 ' . $p{creat_dir} . ' ' . $p{creat_file} ); }
|
|
}
|
|
elsif( $c[1] eq 'susers' )
|
|
{
|
|
setc( 10, guest_group );
|
|
setc( 11, guest_user );
|
|
delconfigline( 12 );
|
|
if( ( $p{root_user} ne '' ) and ( $p{root_name} ne '' ) )
|
|
{ addconfigline( '12 ' . $p{root_name} . ' ' . $p{root_user} . ' ' . $p{root_password} ); }
|
|
delconfigline( 15 );
|
|
if( $p{map} ne '' )
|
|
{ addconfigline( '15 ' . $p{map} . ' ' . $p{map_password} ); }
|
|
}
|
|
elsif( $c[1] eq 'volumes' )
|
|
{
|
|
if( $c[2] ne '' )
|
|
{
|
|
delconfigline( '1 ' . $c[2] );
|
|
}
|
|
if( $p{name} ne '' )
|
|
{
|
|
cbc( 'm' );
|
|
cbc( 'n' );
|
|
cbc( 'o' );
|
|
cbc( 'p' );
|
|
cbc( 'r' );
|
|
cbc( 'O' );
|
|
cbc( 'N' );
|
|
addconfigline( '1 ' . $p{name} . ' ' . $p{path} . ' ' . $p{case} . $p{trustee} . $p{m} . $p{n} . $p{o} . $p{p} . $p{r} . $p{O} . $p{N} );
|
|
}
|
|
redirect( '/settings/volumes' );
|
|
}
|
|
elsif( $c[1] eq 'devices' )
|
|
{
|
|
if( $c[2] ne '' )
|
|
{
|
|
delconfigline( '4 ' . $c[2] );
|
|
}
|
|
$p{interface} =~ s/[^-_\.A-Za-z0-9:\*]//g;
|
|
if( $p{number} ne '' )
|
|
{
|
|
addconfigline( '4 ' . $p{number} . ' ' . $p{interface} . ' ' . $p{frametype} . ' ' . $p{delay} );
|
|
}
|
|
redirect( '/settings/devices' );
|
|
}
|
|
elsif( $c[1] eq 'logging' )
|
|
{
|
|
setc( 100, ipx );
|
|
setc( 101, nwserv );
|
|
setc( 102, ncpserv );
|
|
setc( 103, nwconn );
|
|
setc( 104, nwclient );
|
|
setc( 105, nwbind );
|
|
setc( 106, nwrouted );
|
|
setc( 200, startup );
|
|
setc( 201, general_log );
|
|
delconfigline( 202 );
|
|
addconfigline( 202 . ' ' . ( $p{g_creat} + 2 * $p{error} ) );
|
|
setc( 300, routing_interval );
|
|
setc( 301, routing_log );
|
|
delconfigline( 302 );
|
|
addconfigline( 302 . ' ' . ( $p{r_creat} + 2 * $p{r_file} ) );
|
|
}
|
|
elsif( $c[1] eq 'smart' )
|
|
{
|
|
if( $p{mars_config} ne $mars_config )
|
|
{
|
|
# Just append the line. Messy but easy. ;)
|
|
open( FILE, '>>' . $smart_conf_path ) or die "Could not open $smart_conf_path: $!";
|
|
print( FILE "\n" . '$mars_config = \'' . $p{mars_config} . '\';' . "\n" );
|
|
close( FILE );
|
|
}
|
|
|
|
write_smart_bindery_values( $p{bind_server}, $p{bind_user}, $p{bind_pass} );
|
|
|
|
if( defined( $p{sync_general_server_name} ) && $p{sync_general_server_name} eq 'on' && defined( $p{bind_server} ) && $p{bind_server} ne '' )
|
|
{
|
|
$p{server_name} = $p{bind_server};
|
|
setc( 2, server_name );
|
|
}
|
|
}
|
|
elsif( $c[1] eq 'users' )
|
|
{
|
|
drop_root();
|
|
|
|
$server = get_server();
|
|
if( $c[2] eq 'add_new' )
|
|
{
|
|
system( 'nwbocreate', '-S', $server, '-t', '1', '-o', $p{name} );
|
|
$c[2] = $p{name};
|
|
}
|
|
else
|
|
{
|
|
system( 'nwbprm', '-S', $server, '-t', '1', '-o', $c[2], '-p', 'UNIX_USER' );
|
|
system( 'nwbprm', '-S', $server, '-t', '1', '-o', $c[2], '-p', 'IDENTIFICATION' );
|
|
system( 'nwbprm', '-S', $server, '-t', '1', '-o', $c[2], '-p', 'GROUPS_I\'M_IN' );
|
|
system( 'nwbprm', '-S', $server, '-t', '1', '-o', $c[2], '-p', 'SECURITY_EQUALS' );
|
|
}
|
|
|
|
$id = ( split( ' ', ( grep( /^$c[2] /, split( "\n", `nwbols -S $server` ) ) )[0] ) )[1]; # Woohoo... ;)
|
|
$id =~ s/[^ ][^ ]/$& /g;
|
|
$id = join( '', reverse( split( ' ', $id ) ) );
|
|
# $id =~ s/ //g;
|
|
|
|
if( scalar( keys( %p ) ) == 0 )
|
|
{
|
|
system( 'nwborm', '-S', $server, '-t', '1', '-o', $c[2] );
|
|
}
|
|
else
|
|
{
|
|
write_property_string( $c[2], 1, 'UNIX_USER', 0, 30, $p{unix_user} );
|
|
write_property_string( $c[2], 1, 'IDENTIFICATION', 0, 30, $p{fullname} );
|
|
|
|
open( FILE, '|' . 'nwbpset -S ' . $server );
|
|
print FILE <<EOF;
|
|
0001
|
|
$c[2]
|
|
GROUPS_I'M_IN
|
|
2
|
|
31
|
|
EOF
|
|
@g = grep( /^group_/, keys( %p ) );
|
|
foreach $g ( @g )
|
|
{
|
|
$g =~ s/^group_//;
|
|
print( FILE '0002' . "\n", $g . "\n" );
|
|
|
|
system( 'nwbpadd -S ' . $server . ' -o ' . $g . ' -t 2 -p GROUP_MEMBERS ' . $id . ' > /dev/null' );
|
|
}
|
|
close( FILE );
|
|
|
|
open( FILE, '|' . 'nwbpset -S ' . $server );
|
|
print FILE <<EOF;
|
|
0001
|
|
$c[2]
|
|
SECURITY_EQUALS
|
|
2
|
|
31
|
|
EOF
|
|
@g = grep( /^group_/, keys( %p ) );
|
|
foreach $g ( @g )
|
|
{
|
|
$g =~ s/^group_//;
|
|
print( FILE '0002' . "\n", $g . "\n" );
|
|
}
|
|
close( FILE );
|
|
|
|
if( $p{password} ne '' )
|
|
{
|
|
$p = get_bindery_password();
|
|
open( FILE, '|' . 'nwpasswd -O ' . $c[2] . ' > /dev/null' );
|
|
print( STDERR 'nwpasswd -O ' . $c[2] . ' > /dev/null' . "\n" );
|
|
print( FILE $p . "\n" . $p{password} . "\n" . $p{password} . "\n" );
|
|
close( FILE );
|
|
}
|
|
}
|
|
|
|
redirect( '/settings/users' );
|
|
}
|
|
elsif( $c[1] eq 'groups' )
|
|
{
|
|
drop_root();
|
|
|
|
$server = get_server();
|
|
if( $c[2] eq 'add_new' )
|
|
{
|
|
system( 'nwbocreate', '-S', $server, '-t', '2', '-o', $p{name} );
|
|
open( FILE, '|' . 'nwbpset -S ' . $server );
|
|
print FILE <<EOF;
|
|
0002
|
|
$p{name}
|
|
GROUP_MEMBERS
|
|
2
|
|
31
|
|
EOF
|
|
close( FILE );
|
|
$c[2] = $p{name};
|
|
}
|
|
else
|
|
{
|
|
system( 'nwbprm', '-S', $server, '-t', '2', '-o', $c[2], '-p', 'IDENTIFICATION' );
|
|
system( 'nwbprm', '-S', $server, '-t', '2', '-o', $c[2], '-p', 'OBJ_SUPERVISORS' );
|
|
}
|
|
|
|
if( scalar( keys( %p ) ) == 0 )
|
|
{
|
|
system( 'nwborm', '-S', $server, '-t', '2', '-o', $c[2] );
|
|
}
|
|
else
|
|
{
|
|
write_property_string( $c[2], 2, 'IDENTIFICATION', 0, 30, $p{fullname} );
|
|
|
|
open( FILE, '|' . 'nwbpset -S ' . $server );
|
|
print FILE <<EOF;
|
|
0002
|
|
$c[2]
|
|
OBJ_SUPERVISORS
|
|
2
|
|
31
|
|
EOF
|
|
@g = grep( /^man_/, keys( %p ) );
|
|
foreach $g ( @g )
|
|
{
|
|
my @g = split( '_', $g );
|
|
|
|
print( FILE $g[1] . "\n", $g[2] . "\n" );
|
|
}
|
|
close( FILE );
|
|
}
|
|
|
|
redirect( '/settings/groups' );
|
|
}
|
|
elsif( $c[1] eq 'queues' )
|
|
{
|
|
drop_root();
|
|
|
|
$server = get_server();
|
|
if( $c[2] eq 'add_new' )
|
|
{
|
|
system( 'nwbocreate', '-S', $server, '-t', '3', '-o', $p{name} );
|
|
$c[2] = $p{name};
|
|
|
|
open( FILE, '|' . 'nwbpset -S ' . $server );
|
|
print FILE <<EOF;
|
|
0003
|
|
$c[2]
|
|
Q_SERVERS
|
|
2
|
|
31
|
|
EOF
|
|
close( FILE );
|
|
|
|
open( FILE, '|' . 'nwbpset -S ' . $server );
|
|
print FILE <<EOF;
|
|
0003
|
|
$c[2]
|
|
Q_USERS
|
|
2
|
|
31
|
|
0002
|
|
EVERYONE
|
|
EOF
|
|
close( FILE );
|
|
|
|
open( FILE, '|' . 'nwbpset -S ' . $server );
|
|
print FILE <<EOF;
|
|
0003
|
|
$c[2]
|
|
Q_OPERATORS
|
|
2
|
|
31
|
|
0001
|
|
SUPERVISOR
|
|
EOF
|
|
close( FILE );
|
|
}
|
|
else
|
|
{
|
|
system( 'nwbprm', '-S', $server, '-t', '3', '-o', $c[2], '-p', 'Q_UNIX_PRINT' );
|
|
system( 'nwbprm', '-S', $server, '-t', '3', '-o', $c[2], '-p', 'Q_DIRECTORY' );
|
|
}
|
|
|
|
if( scalar( keys( %p ) ) == 0 )
|
|
{
|
|
system( 'nwborm', '-S', $server, '-t', '3', '-o', $c[2] );
|
|
}
|
|
else
|
|
{
|
|
|
|
if( $p{spool_dir} eq '' )
|
|
{
|
|
$id = ( split( ' ', ( grep( /^$c[2] /, split( "\n", `nwbols -S $server` ) ) )[0] ) )[1]; # Woohoo... ;)
|
|
$p{spool_dir} = 'SYS:SYSTEM/' . $id . '.QDR';
|
|
}
|
|
|
|
write_property_string( $c[2], 3, 'Q_UNIX_PRINT', 0, 31, $p{unix_print} );
|
|
write_property_string( $c[2], 3, 'Q_DIRECTORY', 0, 31, $p{spool_dir} );
|
|
}
|
|
|
|
redirect( '/settings/queues' );
|
|
}
|
|
|
|
elsif( $c[1] eq 'advanced' )
|
|
{
|
|
my $advanced_category = $p{advanced_category};
|
|
$advanced_category = 'all' if ! defined( $advanced_category ) || $advanced_category eq '';
|
|
|
|
my $save_devices = ( $advanced_category eq 'all' || $advanced_category eq 'devices' );
|
|
my $save_security = ( $advanced_category eq 'all' || $advanced_category eq 'security' );
|
|
my $save_users = ( $advanced_category eq 'all' || $advanced_category eq 'users' );
|
|
my $save_queues = ( $advanced_category eq 'all' || $advanced_category eq 'queues' );
|
|
my $save_configh = ( $advanced_category eq 'all' || $advanced_category eq 'configh' );
|
|
my $save_stations = ( $advanced_category eq 'all' || $advanced_category eq 'stations' );
|
|
my $save_network = ( $advanced_category eq 'all' || $advanced_category eq 'network' );
|
|
|
|
if( $save_devices )
|
|
{
|
|
my $device_flags = 0;
|
|
$device_flags += 1 if $p{dev_keep} eq 'on';
|
|
$device_flags += 2 if $p{dev_auto} eq 'on';
|
|
$device_flags += 4 if $p{dev_remove_all} eq 'on';
|
|
|
|
delconfigline( 5 );
|
|
addconfigline( '5 ' . $device_flags ) if $device_flags != 0;
|
|
}
|
|
|
|
if( $save_security )
|
|
{
|
|
my $security_flags = 0;
|
|
$security_flags += 0x8 if $p{sec_supervisor_ignore} eq 'on';
|
|
$security_flags += 0x40 if $p{sec_2gb_free} eq 'on';
|
|
$security_flags += 0x200 if $p{sec_int17} eq 'on';
|
|
$security_flags += 0x2 if $p{sec_delete_open} eq 'on';
|
|
$security_flags += 0x4 if $p{sec_rename_open} eq 'on';
|
|
|
|
delconfigline( 8 );
|
|
addconfigline( '8 ' . $security_flags ) if $security_flags != 0;
|
|
}
|
|
|
|
if( $save_users )
|
|
{
|
|
my $bindery_flags = 0;
|
|
$bindery_flags += 1 if $p{bindery_empty_scripts} eq 'on';
|
|
|
|
delconfigline( 17 );
|
|
addconfigline( '17 ' . $bindery_flags ) if $bindery_flags != 0;
|
|
}
|
|
|
|
if( $save_queues )
|
|
{
|
|
my $queue_flags = 0;
|
|
$queue_flags += 1 if $p{queue_no_banner} eq 'on';
|
|
|
|
delconfigline( 18 );
|
|
addconfigline( '18 ' . $queue_flags ) if $queue_flags != 0;
|
|
|
|
delconfigline( 22 );
|
|
foreach my $line ( split( /\r?\n/, $p{print_servers} ) )
|
|
{
|
|
$line =~ s/^\s+//;
|
|
$line =~ s/\s+$//;
|
|
next if $line eq '';
|
|
$line =~ s/#.*//;
|
|
next if $line eq '';
|
|
addconfigline( '22 ' . $line );
|
|
}
|
|
}
|
|
|
|
if( $save_configh )
|
|
{
|
|
setc( 50, conversion_tables );
|
|
setc( 80, max_dir_search_handles );
|
|
}
|
|
|
|
if( $save_network )
|
|
{
|
|
setc( 310, watchdogs );
|
|
}
|
|
|
|
if( $save_stations )
|
|
{
|
|
setc( 400, station_file );
|
|
setc( 401, nearest_replies );
|
|
setc( 402, connect_replies );
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
putp();
|
|
return( 0 );
|
|
}
|
|
redirect( '/static/start.html' );
|
|
|
|
writeconfig();
|
|
}
|
|
|
|
|
|
sub add_mask_flag( $$$ )
|
|
{
|
|
my( $value, $param, $mask ) = @_;
|
|
if( defined( $p{$param} ) && $p{$param} ne '' )
|
|
{
|
|
$value |= $mask;
|
|
}
|
|
return $value;
|
|
}
|
|
|
|
sub addconfig_hex( $$ )
|
|
{
|
|
delconfigline( $_[0] );
|
|
addconfigline( $_[0] . ' 0x' . sprintf( '%x', $_[1] ) );
|
|
}
|
|
|
|
sub sanitize_simple_value( $ )
|
|
{
|
|
my $v = $_[0];
|
|
$v = '' unless defined $v;
|
|
$v =~ s/[\r\n]//g;
|
|
$v =~ s/^\s+//;
|
|
$v =~ s/\s+$//;
|
|
$v =~ s/[^-_\.\/\:\~A-Za-z0-9]//g;
|
|
return $v;
|
|
}
|
|
|
|
sub sanitize_number_value( $ )
|
|
{
|
|
my $v = $_[0];
|
|
$v = '' unless defined $v;
|
|
$v =~ s/[^0-9xXa-fA-F\-]//g;
|
|
return $v;
|
|
}
|
|
|
|
sub putp()
|
|
{
|
|
$cc =~ s/.*\?//;
|
|
$cc =~ s/&/\n/g;
|
|
print <<EOF;
|
|
HTTP/1.0 200 OK
|
|
Content-Type: text/plain
|
|
|
|
$cc
|
|
EOF
|
|
}
|
|
|
|
sub setc( $$ )
|
|
{
|
|
delconfigline( $_[0] );
|
|
if( $p{$_[1]} ne '' )
|
|
{ addconfigline( $_[0] . ' ' . $p{$_[1]} ); }
|
|
}
|
|
|
|
sub cbc( $ )
|
|
{
|
|
if( $p{$_[0]} ne '' )
|
|
{ $p{$_[0]} = $_[0]; }
|
|
}
|
|
|