#!/usr/bin/perl -w

use CGI;
use DBI;
use locale;
use POSIX qw (locale_h);
unshift(@INC, '.');
use ipac_cfg;
use strict;

my $tmpl_b = $ipac_cfg::user_tpl_b;
my $tmpl_e = $ipac_cfg::user_tpl_e;
my $charset = $ipac_cfg::charset;

my $q = new CGI;

my $path="https://" . $q->server_name();
my $cgi=$path . "/cgi-bin";

setlocale(LC_CTYPE, "");
my $user = $ENV{REMOTE_USER};

if ($ENV{HTTPS} ne "on") {
	print "Location: $cgi/user_home\n\n";
	exit;
}

if (!defined($user eq "") || !length($user)) {
        print $q->header(-type=>"text/html; charset=$charset",
                        -status=>'403 Forbidden'),
            $q->start_html('Forbidden'),
            $q->h1('You dont have permission to access this script'),
            $q->end_html;
	exit;
}

if (!defined($tmpl_b) || !length($tmpl_b)) {
	print $q->header(-type=>"text/html; charset=$charset"),
		$q->start_html('Userland');
} else {
	print $tmpl_b;
}	

	print $q->h3("Welcome to renewed user's page, $user");
	print "<div>Here you can examine your <a href=\"$cgi/traffic\">traffic</a> statistics";
	print "<div>or <a href=\"$cgi/ch_pass\">change</a> your passwords";

if (!defined($tmpl_e) || !length($tmpl_e)) {
	print $q->end_html;
} else {
	print $tmpl_e;
}
