#!/usr/bin/perl

# 管理画面CGIスクリプト名
$CGI_ADMIN = 'atstepmail.cgi';




#------------------------------------------------------------------------
#------------------------------------------------------------------------
&baseDir();

my $boot = $BASE_DIR. 'bin/admin_pl.cgi';

# 読み込み検査
unless( -e $boot ){
	&start_error();
	exit;
}

require $boot;
exit;

sub start_error {

	print <<'END';
Content-type: text/html

<html><head><title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>
<body>
<br>基本構成ディレクトリの指定に誤りがあります。<br>
</body></html>
END
	exit;
}

sub regulation
{
	my $ref = shift;
	return if( $$ref eq '' );
	if( $$ref !~ /\/$/ ){
		$$ref = $$ref . '/';
	}
}

sub baseDir
{
	# カレントディレクトリ
	my $current = "";
	if( $ARGV[0] eq 'start' ){
		$current = $0;
		$current =~ s|(.*)/.*|$1|;
		if( $ARGV[1] =~ /^[^\s]+$/ ){
			$current = $ARGV[1];
		}
		$current = &regulation(\$current);
	}
	$CGI_ADMIN =~ s/^[.\/]+//g;
	
	my $code;
	open( CGI, "<$current$CGI_ADMIN" );
	while(<CGI>){
		if( $_ =~ /^#+-+/ ){
			last;
		}
		$code .= $_;
	}
	close(CGI);
	eval $code;
	
	$BASE_DIR = $current. $BASE_DIR;
	$DEF_IMGDIR = $current. $DEF_IMGDIR;
	
}

sub error {

	print "Content-type: text/html\n\n";
	print "<html><head><title>CGI</title></head>\n";
	print "<body>\n";
	print "$_[0]";
	print "</body></html>\n";
	exit;
}

