# All rights reserved (c) 2002;  Author: Daniel Dinev;  http://chatologica.com

package MTS4::ADMIN::Main;                                  # MAKE THE DEFAULT/MAIN PAGE

use strict;
use MTS4::STD::Common;
use MTS4::STD::CGI_Response;
use MTS4::ADMIN::HTACCESS;
use MTS4::STD::Files;



sub run                                                     # THE LOGIC OF THIS NAVIGATION DESTINATION
{

    my ($class) = @_;
    my $me = {}; bless $me, $class;                         # setting standard object variables:
    my $P = $$me{'P'} = ${$UNIVERSAL::MTS4}{'Parameters'};
    my $E = $$me{'E'} = ${$UNIVERSAL::MTS4}{'ENV'};
    my $in = $$me{'in'} = $$E{'CGI_INPUT_HASH'};
    my $R = $$me{'R'} = new MTS4::STD::CGI_Response;
    my $out = $$me{'out'} = $$R{'out'};                     # init input fields:
    &init_keys($in,[qw()],1);
    $me->update_host;
    if ($ENV{'SERVER_SOFTWARE'} !~ /IIS|MS|Microsoft|nformation/i){
        my $size = (stat 'admin/.htaccess')[7] || 0;
        my $size1 = (stat 'admin/.nsconfig')[7] || 0;
        if (($$E{'CWD'} ne './') && (($size < 5) || ($size1 < 5))) {    # password is not set yet
            MTS4::ADMIN::HTACCESS->run;                                 # shows password change page
            &quit;
        };
    };
    $R->send_page('Main.htm');
};



sub update_host
{
    my($me) = @_;
    my $current_host = &read_file('data/host.txt') || '';
    if(!$current_host) {
        my $my_host = $ENV{'HTTP_HOST'};
        my $err = &save_file('data/host.txt',$my_host);
        die $err if $err;
    };
};


1; # must return TRUE


