<?php
    /*
     * $Id: adminsystem.php 1439 2009-11-17 23:31:04Z dmorton $
     *
     * MAIA MAILGUARD LICENSE v.1.0
     *
     * Copyright 2004 by Robert LeBlanc <rjl@renaissoft.com>
     *                   David Morton   <mortonda@dgrmm.net>
     * All rights reserved.
     *
     * PREAMBLE
     *
     * This License is designed for users of Maia Mailguard
     * ("the Software") who wish to support the Maia Mailguard project by
     * leaving "Maia Mailguard" branding information in the HTML output
     * of the pages generated by the Software, and providing links back
     * to the Maia Mailguard home page.  Users who wish to remove this
     * branding information should contact the copyright owner to obtain
     * a Rebranding License.
     *
     * DEFINITION OF TERMS
     *
     * The "Software" refers to Maia Mailguard, including all of the
     * associated PHP, Perl, and SQL scripts, documentation files, graphic
     * icons and logo images.
     *
     * GRANT OF LICENSE
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * 1. Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * 3. The end-user documentation included with the redistribution, if
     *    any, must include the following acknowledgment:
     *
     *    "This product includes software developed by Robert LeBlanc
     *    <rjl@renaissoft.com>."
     *
     *    Alternately, this acknowledgment may appear in the software itself,
     *    if and wherever such third-party acknowledgments normally appear.
     *
     * 4. At least one of the following branding conventions must be used:
     *
     *    a. The Maia Mailguard logo appears in the page-top banner of
     *       all HTML output pages in an unmodified form, and links
     *       directly to the Maia Mailguard home page; or
     *
     *    b. The "Powered by Maia Mailguard" graphic appears in the HTML
     *       output of all gateway pages that lead to this software,
     *       linking directly to the Maia Mailguard home page; or
     *
     *    c. A separate Rebranding License is obtained from the copyright
     *       owner, exempting the Licensee from 4(a) and 4(b), subject to
     *       the additional conditions laid out in that license document.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */

    require_once ("core.php");
    require_once ("maia_db.php");
    require_once ("authcheck.php");
    require_once ("display.php");
    $display_language = get_display_language($euid);
    require_once ("./locale/$display_language/db.php");
    require_once ("./locale/$display_language/display.php");
    require_once ("./locale/$display_language/adminsystem.php");

    require_once ("smarty.php");
    $smarty->assign("auth_method", $auth_method);
    
    // Only the superadministrator should be here.
    if (!is_superadmin($uid)) {
       header("Location: index.php" . $sid);
       exit();
    }

    // Cancel any impersonations currently in effect
    // by resetting EUID = UID and forcing a reload
    // of this page.
    if ($uid != $euid) {
       $euid = $uid;
       $_SESSION["euid"] = $uid;
       header("Location: adminsystem.php" . $sid);
       exit();
    }

    $select = "SELECT enable_user_autocreation, " .
                     "enable_false_negative_management, " .
                     "enable_stats_tracking, " .
                     "enable_virus_scanning, " .
                     "enable_spam_filtering, " .
                     "enable_banned_files_checking, " .
                     "enable_bad_header_checking, " .
                     "enable_charts, " .
                     "enable_spamtraps, " .
                     "enable_stats_reporting, " .
                     "enable_address_linking, " .
                     "enable_privacy_invasion, " .
                     "enable_username_changes, " .
                     "internal_auth, " .
                     "system_default_user_is_local, " .
                     "user_virus_scanning, " .
                     "user_spam_filtering, " .
                     "user_banned_files_checking, " .
                     "user_bad_header_checking, " .
                     "size_limit, " .
                     "oversize_policy, " .
                     "key_file, " .
                     "admin_email, " .
                     "expiry_period, " .
                     "ham_cache_expiry_period, " .
                     "reminder_threshold_count, " .
                     "reminder_threshold_size, " .
                     "reminder_template_file, " .
                     "reminder_login_url, " .
                     "smtp_server, " .
                     "smtp_port, " .
                     "newuser_template_file, " .
                     "currency_label, " .
                     "bandwidth_cost, " .
                     "chart_ham_colour, " .
                     "chart_spam_colour, " .
                     "chart_virus_colour, " .
                     "chart_fp_colour, " .
                     "chart_fn_colour, " .
                     "chart_suspected_ham_colour, " .
                     "chart_suspected_spam_colour, " .
                     "chart_wl_colour, " .
                     "chart_bl_colour, " .
                     "chart_background_colour, " .
                     "chart_font_colour, " .
//                     "chart_autogeneration_interval, " .
                     "banner_title, " .
                     "use_icons, " .
                     "use_logo, " .
                     "logo_url, " .
                     "logo_file, " .
                     "logo_alt_text, " .
                     "virus_info_url, " .
                     "virus_lookup, " .
                     "primary_report_server, " .
                     "primary_report_port, " .
                     "secondary_report_server, " .
                     "secondary_report_port, " .
                     "reporter_sitename, " .
                     "reporter_username, " .
                     "reporter_password " .
              "FROM maia_config WHERE id = 0";
    $sth = $dbh->query($select);
    if ($row = $sth->fetchrow()) {
        $smarty->assign('enable_user_autocreation', ($row["enable_user_autocreation"] == 'Y'));
        $smarty->assign('enable_false_negative_management', ($row["enable_false_negative_management"] == 'Y'));
        $smarty->assign('enable_stats_tracking', ($row["enable_stats_tracking"] == 'Y'));
        $smarty->assign('enable_virus_scanning', ($row["enable_virus_scanning"] == 'Y'));
        $smarty->assign('enable_spam_filtering', ($row["enable_spam_filtering"] == 'Y'));
        $smarty->assign('enable_banned_files_checking', ($row["enable_banned_files_checking"] == 'Y'));
        $smarty->assign('enable_bad_header_checking', ($row["enable_bad_header_checking"] == 'Y'));
        $smarty->assign('enable_charts', ($row["enable_charts"] == 'Y'));
        $smarty->assign('enable_spamtraps', ($row["enable_spamtraps"] == 'Y'));
        $smarty->assign('enable_stats_reporting', ($row["enable_stats_reporting"] == 'Y'));
        $smarty->assign('enable_address_linking', ($row["enable_address_linking"] == 'Y'));
  	$smarty->assign('enable_privacy_invasion', ($row["enable_privacy_invasion"] == 'Y'));
  	$smarty->assign('enable_username_changes', ($row["enable_username_changes"] == 'Y'));
        $smarty->assign('internal_auth', ($row["internal_auth"] == 'Y'));
        $smarty->assign('system_default_user_is_local', ($row["system_default_user_is_local"] == 'Y'));
        $smarty->assign('user_virus_scanning', ($row["user_virus_scanning"] == 'Y'));
        $smarty->assign('user_spam_filtering', ($row["user_spam_filtering"] == 'Y'));
        $smarty->assign('user_banned_files_checking', ($row["user_banned_files_checking"] == 'Y'));
        $smarty->assign('user_bad_header_checking', ($row["user_bad_header_checking"] == 'Y'));
        $smarty->assign('size_limit', $row["size_limit"]);
        $smarty->assign('key_file',  $row["key_file"]);
        $smarty->assign('oversize_policy', $row["oversize_policy"]);
        $smarty->assign('admin_email', $row["admin_email"]);
        $smarty->assign('expiry_period', $row["expiry_period"]);
        $smarty->assign('ham_cache_expiry_period', $row["ham_cache_expiry_period"]);
        $smarty->assign('reminder_threshold_count', $row["reminder_threshold_count"]);
        $smarty->assign('reminder_threshold_size', $row["reminder_threshold_size"]);
        $smarty->assign('reminder_template_file', $row["reminder_template_file"]);
        $smarty->assign('reminder_login_url', $row["reminder_login_url"]);
        $smarty->assign('smtp_server', strtolower($row["smtp_server"]));
        $smarty->assign('smtp_port', $row["smtp_port"]);
        $smarty->assign('newuser_template_file', $row["newuser_template_file"]);
        $smarty->assign('currency_label', $row["currency_label"]);
        $smarty->assign('bandwidth_cost', $row["bandwidth_cost"]);
        $smarty->assign('chart_ham_colour', $row["chart_ham_colour"]);
        $smarty->assign('chart_spam_colour', $row["chart_spam_colour"]);
        $smarty->assign('chart_virus_colour', $row["chart_virus_colour"]);
        $smarty->assign('chart_fp_colour', $row["chart_fp_colour"]);
        $smarty->assign('chart_fn_colour', $row["chart_fn_colour"]);
        $smarty->assign('chart_suspected_ham_colour', $row["chart_suspected_ham_colour"]);
        $smarty->assign('chart_suspected_spam_colour', $row["chart_suspected_spam_colour"]);
        $smarty->assign('chart_wl_colour', $row["chart_wl_colour"]);
        $smarty->assign('chart_bl_colour', $row["chart_bl_colour"]);
        $smarty->assign('chart_background_colour', $row["chart_background_colour"]);
        $smarty->assign('chart_font_colour', $row["chart_font_colour"]);
//        $smarty->assign('chart_autogeneration_interval', $row["chart_autogeneration_interval"]);
        $smarty->assign('banner_title', $row["banner_title"]);
        $smarty->assign('use_icons', ($row["use_icons"] == 'Y'));
        $smarty->assign('use_logo', ($row["use_logo"] == 'Y'));
        $smarty->assign('logo_url', $row["logo_url"]);
        $smarty->assign('logo_file', $row["logo_file"]);
        $smarty->assign('logo_alt_text', $row["logo_alt_text"]);
        $smarty->assign('virus_info_url', $row["virus_info_url"]);
        $smarty->assign('virus_lookup', $row["virus_lookup"]);
        $smarty->assign('primary_report_server', strtolower($row["primary_report_server"]));
        $smarty->assign('primary_report_port', $row["primary_report_port"]);
        $smarty->assign('secondary_report_server', strtolower($row["secondary_report_server"]));
        $smarty->assign('secondary_report_port', $row["secondary_report_port"]);
        $smarty->assign('reporter_sitename', $row["reporter_sitename"]);
        $smarty->assign('reporter_username', strtolower($row["reporter_username"]));
        $smarty->assign('reporter_password', $row["reporter_password"]);
    }
    $sth->free();

    $smarty->display('adminsystem.tpl');
    
?>
