<?php

@( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' );
error_reporting( _E_VALUE );

/* vim: set expandtab tabstop=4 shiftwidth=4: */

// ***** BEGIN LICENSE BLOCK ( DO NOT REMOVE ) *****

// +----------------------------------------------------------------------+
// | MPN 188 Database Administration                                      |
// |                                                                      |
// | -> Entry Point To phpMyAdmin                                         |
// +----------------------------------------------------------------------+
// | VERSION: 0.1 Alpha                                                   |
// +----------------------------------------------------------------------+
// | LICENSE: GPL 2.0 (see docs/LICENSE_GPL)                              |
// |                                                                      |
// | This file is part of MPN Admin Entry For MPN 188_8.                  |
// |                                                                      |
// | MPN Admin Entry For MPN 188_8 is free software; you can              |
// | redistribute it and/or modify it under the terms of the GNU          |
// | General Public License as published by the Free Software Foundation; |
// | either version 2 of the License, or (at your option) any             |
// | later version.                                                       |
// |                                                                      |
// | MPN Admin Entry For MPN 188_8 is distributed in the hope that it     |
// | will be useful, but WITHOUT ANY WARRANTY; without even the implied   |
// | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     |
// | See the GNU General Public License for more details.                 |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with MPN Admin Entry For MPN 188_8; if not, write to the       |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 59 Temple Place, Suite 330                                           |
// | Boston, MA 02111-1307  USA                                           |
// +----------------------------------------------------------------------+
// | AUTHOR(s):                                                           |
// |                                                                      |
// | The Original Code is the MPN Admin Entry For MPN 188_8.              |
// | The Initial Developer of the Original Code is Eric Haddix.           |
// |                                                                      |
// | Portions created by Eric Haddix or Kiril Threndor                    |
// | <support@mpn.illearth.net> are                                       |
// | Copyright (C) 2003 Eric Haddix.  All Rights Reserved.                |
// +----------------------------------------------------------------------+
// | CONTRIBUTOR(s):                                                      |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | MODIFICATIONS:                                                       |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | NOTES:                                                               |
// +----------------------------------------------------------------------+
// | SUPPORT:                                                             |
// |   WEB:   http://myphpnuke.com/                                       |
// |   EMAIL: support@mpn.illearth.net                                    |
// +----------------------------------------------------------------------+

/**
 * MPN_188_8_Modules
 *
 * @package MPN_188_8_Administration
 * @subpackage database
 * @version $Id: phpmyadmin_entry.php,v 1.1.2.7 2004/08/15 12:58:16 kirilt Exp $
 *
 * @author Kiril Threndor <support@mpn.illearth.net>
 * @copyright Copyright (C) 2003 Eric Haddix
 * @license http://www.gnu.org/licenses/gpl.html GPL 2.0
 * @support http://myphpnuke.com/
 * @todo finish CSS & XHTML conversion
 * @todo reformat old style formatted code to new coding style
 * @todo finish and check function comments
 *
 * @tutorial
 * @filesource
 */

// ***** END LICENSE BLOCK ( DO NOT REMOVE ) *****

/**
 *
 *
 *
 */

function phpMyAdmin_Entry()
{
    echo "<h1>" . translate( "phpMyAdmin Version 2.5.6 MySQL Database Administration" ) . "</h1>\n";

    echo "<hr class='w80' /><br />\n";

    echo "<p>\n";

        echo translate( "phpMyAdmin For MPN 188 is provided for your convenience." );

        echo "<br /><br />\n";

        echo translate( "The MPN Development Team does not provide support for this module. " );

        echo "<br /><br />\n";

        echo translate( "If you have problems with this software, please refer to the included documentation." );

    echo "</p>\n";

    echo "<br /><br />\n";

    echo "<h1>SECURITY</h1>\n";

    echo "<hr class='w80' /><br />\n";

    echo "<p>\n";

        echo translate( "While MPN Provides Basic Administrative Verification, it is HIGHLY recommended you take additional precautions to secure the phpMyAdmin directory" );

        echo "<br /><br />\n";

        echo translate( "The Default Login For phpMyAdmin Has Been Set To HTTP Authentication.  You WILL be required to enter your database Username and Password in addition to MPN verification requirements" );

        echo "<br /><br />\n";

    echo "</p>\n";


    echo phpmyadminLoginForm();


    echo "<br /><br />\n";

    echo "<h2>phpMyAdmin&nbsp;<i>README</i></h2>\n";

    echo "<textarea cols='70' rows='15'>\n";

        include( "./admin/dbutil/phpMyAdmin/README" );

    echo "</textarea>\n";

}  // End Function

/**
 *
 *
 *
 */

function processLogin()
{
    global $mpnTables;

    if ( sizeof( $_POST ) > 5 ) { goBack( 'Invalid Request' ); }

    if ( ! isset( $_POST['pwd'] ) || $_POST['pwd'] == '' )
    {
        goBack( translate( "ACCESS DENIED! One Or More Empty Login Fields" ) );
        exit;
    }

    $sql = "SELECT aid
            FROM " . $mpnTables['authors'] . "
            WHERE pwd = '" . md5( $_POST['pwd'] ) . "' && radminsuper = 1";

    if ( ! @( $result = @mysql_query( $sql ) ) && ! @mysql_data_seek( $result, 0 ) )
    {
        unset ( $login_tmp );
        mysql_free_result( $result );
        goBack( translate( "ACCESS DENIED!! Cannot Verify Your Identity" ) );
        exit;
    }
    else // Admin Found
    {
        $temp = mysql_fetch_row( $result );

        if ( ! @( include _DP_ADMIN_ . 'original/dbconfig.php' ) )
        {
            exit( "<h2>FATAL ERROR: Database Config Failure</h2>" );
        }

        if ( md5( $dbpass ) !== md5( $_POST['dbpass'] ) )
        {
            goBack( translate( "ACCESS DENIED! Incorrect Database Password" ) );
            exit;
        }
        else
        {
            echo "<h1>" . translate( "Administrator Verification Complete" ) . ".</h1>\n";

            echo "<br /><br />\n";

            echo "<h2>" . translate ( "You May Login To phpMyAdmin Below" ) . "</h2>\n";

            echo "<br /><br />\n";

            echo "<a class='subtitle1' href='./admin/dbutil/phpMyAdmin/index.php' title='" . translate( "Login Into phpMyAdmin Interface" ) . "' target='_blank'>" . translate( "Login Into phpMyAdmin Interface" ) . "</a>\n";
        }
    }

}  // End Function

/**
 *
 *
 *
 */

function phpmyadminLoginForm()
{
    $content = "<div class='form'>\n";

        $content .= "<form name='loginDB' action='admin.php' method='post'>\n";

            $content .= "<input type='hidden' name='fct' value='dbutil' /> \n";
            $content .= "<input type='hidden' name='op' value='myphpadminLogin' /> \n";

            $content .= "<p>\n";

            $content .= "<div class='row'>\n";

               $content .= "<label>" . translate( 'MPN Admin Password' ) . "&#058;</label>\n";
                $content .= "<input type='password' name='pwd' size='25' maxlength='30' />\n";

            $content .= "</div>\n";

            $content .= "<div class='row'>\n";

                $content .= "<label>" . translate( 'MPN Database Password' ) . "&#058;</label>\n";
                $content .= "<input type='password' name='dbpass' size='25' maxlength='30' />\n";

            $content .= "</div>\n";

            $content .= '<br /><br />' . "\n";

            $content .= "<div class='submit'>\n";

                $content .= "<input class='button' type='submit' value='" . translate( 'Verify' ) . "' />\n";

                $content .= "<input class='button' type='reset' value='" . translate( 'Reset' ) . "' />";

            $content .= "</div>\n";

            $content .= "<p>\n";

        $content .= "</form>";

    $content .= "</div>\n";

    return $content;

}  // End Function

?>