#!/usr/bin/perl
# ==================================================================
# Gossamer Forum -
#
#   Website  : http://gossamer-threads.com/
#   Support  : http://gossamer-threads.com/scripts/support/
#   CVS Info :
#   Revision : $Id: gforum.cgi,v 1.40 2001/11/05 20:33:21 jagerman Exp $
#
# Copyright (c) 2001 Gossamer Threads Inc.  All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
# see LICENSE file for full details.
# ==================================================================

print "Content-type: text/html\n\n<html>\n<body>\n<br><br><center><b>Приносим свои извинения, форум временно закрыт</b><BR><BR><a href=http://www.rusmoney.com><img src=/images/Index.jpg alt=\"Финансовая информация для частных лиц\" width=\"600\" border=\"0\" height=\"57\"></a></center></body></html>";
exit;

use lib '/home/httpd/vhosts/rusmoney.com/httpdocs/petrovich/forum/main/admin';

use strict;

use GForum qw/:forum :user $DB $IN $CFG $USER %HIDDEN $TEMPLATE_SET/;
use GForum::Template;
use GForum::Authenticate;

#if (serverload() > 1.5) {
#  print "Content-type: text/html\n\n<html>\n<body>\n<br><br><center><b>Server overload, please try later</b></body></html>";
#  exit;
#}

GForum::reset_env() if $GForum::PERSIST;

main();

sub serverload {
  return 100 if !open(LA, "/proc/loadavg");
  my $buff = <LA>;
  close LA;
  my ($l1, $l5, $l15) = split(/\s+/, $buff);
  $l1 = 100 if $l1 eq undef;
  $l5 = 100 if $l5 eq undef;
  return ($l1 > $l5) ? $l5 : $l1;
}

sub main {
# -------------------------------------------------------------------
# Display whatever page the user has requested
#
    local $SIG{__DIE__} = \&GForum::fatal;
    GForum::init();
    if (lc $ENV{QUERY_STRING} eq 'about') {
        print $IN->header;
        return GForum::Template->parse_print("about.html");
    }
    # Show the disabled page if the forum has been disabled
    if ($CFG->{disabled}) {
        print $IN->header;
        return GForum::Template->parse_print("disabled.html" => { message => $CFG->{disabled_message} });
    }
    # If the user is banned, simply deny them access
    for (@{$CFG->{bans}}) {
        # Turn a ban into a regexp
        my $ban = quotemeta($_);
        # *'s match anything
        $ban =~ s/\\\*/.*/g;
        # ?'s match any single character
        $ban =~ s/\\\?/./g;
        if ($ENV{REMOTE_HOST} and $ENV{REMOTE_HOST} =~ /^$ban$/i or $ENV{REMOTE_ADDR} =~ /^$ban$/i) {
            print $IN->header;
            return GForum::Template->parse_print($CFG->{functions}->{banned}->{page}, { error => GForum::language('USER_BANNED') });
        }
    }
    GForum::authenticate() or return; # False = stop!


    my $template_set = $IN->param('t');
    if (not $template_set or $template_set !~ /^[\w-]+$/ or not -d "$CFG->{admin_root_path}/templates/$template_set" or $template_set =~ /^(?:help|admin|fileman|CVS)$/) {
        $template_set = '';
    }
    else { # It's good!
        $HIDDEN{t} = $template_set;
    }

    if ($USER) {
        if (not $template_set and $USER->{user_template} and $USER->{user_template} =~ /^[\w-]+$/ and -d "$CFG->{admin_root_path}/templates/$USER->{user_template}" and $USER->{user_template} !~ /^(?:help|admin|fileman|CVS)$/i) {
            $template_set = $USER->{user_template}; # $USER has a good template set
        }
        if ($USER->{user_time_offset}) {
            if ($GT::Date::OFFSET) {
                $GT::Date::OFFSET += 60 * 60 * $USER->{user_time_offset};
            }
            else {
                $GT::Date::OFFSET = 60 * 60 * $USER->{user_time_offset};
            }
        }
    }

    if ($template_set) {
        $TEMPLATE_SET = $template_set;
    }
    else {
        $TEMPLATE_SET = $CFG->{default_template_set};
    }
    GForum::Template->root("$CFG->{admin_root_path}/templates/$TEMPLATE_SET");

    my $do = $IN->param('do') || '';

    $do = $USER ? '' : 'login' if $do eq 'admin_login'; # The "Login" link from the admin will either go to the login page, or just the main page if the user is identified

    unless ($do) {
        $do =
            $IN->param('forum')                          ? 'forum_view' :
            $IN->param('post')                           ? 'post_view'  :
            $IN->param('user') || $IN->param('username') ? 'user_view'  :
            $IN->param('category')                       ? 'cat_view'   :
            $IN->param('url')                            ? 'url'        :
                                                           'cat_list' ;
    }
    GForum::do_func($do);
    $DB->table('User')->update({ user_last_seen => CORE::time }, { user_id => $USER->{user_id} }) if $USER;
}

1;