Current time: 05-18-2024, 11:07 PM Hello There, Guest! (LoginRegister)


Post Reply 
[Resuelto] Problemilla con el PMA
Author Message
Nuxwin
Unregistered

 
Post: #2
RE: Problemilla con el PMA
(07-26-2010 06:08 PM)sfera Wrote:  Buenos dias a todos.

Tras largas jornadas y dormir muy pero que muy poco, ya he conseguido migrar el server a un openVZ manualmente. Voy a hacer un how to proximamente para explicar el metodo basado en el que hizo en su dia kurgans ya que aunque es un fallo tonto lo que tenia, no se si los demas tambien lo tendran. Primero he de preguntar por ahi.

Por cierto gracias Kurgans por soportar mis preguntas Tongue

Bueno por otro lado, el unico problema que he detectado es el siguiente:

- Cuando cualquier cliente entra a su panel de control, y va a la administracion de bases de datos, al pulsas el link que da acceso al PMA y que se supone que te loguea en el, en vez de irte a la direccion http://admin.domain.tdl/pma te envia a https://admin.domain.tdl/pma y claro al no tener configurado el ssl da como que la pagina no existe. como puedo hacer para que apunte al http simplemente ?

Un saludo y gracias por adelantado

Easy fix for that:

Replace the client/sql_auth.php script content by the following:

Code:
/***
* Script short description:
*
* This script allows PhpMyAdmin authentication from ispCP
*/

/*******************************************************************************
* Functions
*/

/**
* Get database login credentials
*
* @author Laurent Declercq <laurent.declercq@ispcp.net>
* @access private
* @param  int $dbUserId Database user unique identifier
* @return array Array that contains login credentials or FALSE on failure
*/
function _getLoginCredentials($dbUserId) {

    global $sql;

    // @todo Should be optimized
    $query = "
        SELECT
            `sqlu_name`, `sqlu_pass`
        FROM
            `sql_user`, `sql_database`, `domain`
        WHERE
            `sql_user`.`sqld_id` = `sql_database`.`sqld_id`
        AND
            `sql_user`.`sqlu_id` = ?
        AND
            `sql_database`.`domain_id` = `domain`.`domain_id`
        AND
            `domain`.`domain_admin_id` = ?
        ;
    ";

    $stmt = exec_query($sql, $query, array($dbUserId, $_SESSION['user_id']));

    if($stmt->rowCount() == 1) {
            return array(
                $stmt->fields['sqlu_name'],
                decrypt_db_password($stmt->fields['sqlu_pass'])
        );
    } else {
        return false;
    }
}

/**
* Creates all cookies for PhpMyAdmin
*
* @author Laurent Declercq <laurent.declercq@ispcp.net>
* @access private
* @param  array $cookies Array that contains cookies definitions for PMA
* @return void
*/
function _pmaCreateCookies($cookies) {

    foreach($cookies as $cookie) {
        header("Set-Cookie: $cookie", false);
    }
}

/**
* PhpMyAdmin authentication
*
* @author Laurent Declercq <laurent.declercq@ispcp.net>
* @param  int $dbUserId Database user unique identifier
* @return bool TRUE on success, FALSE otherwise
*/
function pmaAuth($dbUserId) {

    $credentials = _getLoginCredentials($dbUserId);

    if($credentials) {
        $data = http_build_query(
            array(
                'pma_username' => $credentials[0],
                'pma_password' => stripcslashes($credentials[1])
            )
        );
    } else {
        set_page_message(tr('Error: Unknown SQL user id!'));

        return false;
    }

    // Prepares PhpMyadmin absolute Uri to use
    if(isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS'])) {
        $port = ($_SERVER['SERVER_PORT'] != '443')
            ? ':' . $_SERVER['SERVER_PORT'] : '';

        $pmaUri = "https://{$_SERVER['SERVER_NAME']}$port/pma/";
    } else {
        $port = ($_SERVER['SERVER_PORT'] != '80')
            ? ':' . $_SERVER['SERVER_PORT'] : '';

        $pmaUri = "http://{$_SERVER['SERVER_NAME']}$port/pma/";
    }

    // Set stream context (http) options
    stream_context_get_default(
        array(
            'http' => array(
                'method' => 'POST',
                'header' => "Host: {$_SERVER['SERVER_NAME']}$port\r\n" .
                    "Content-Type: application/x-www-form-urlencoded\r\n" .
                    'Content-Length: ' . strlen($data) . "\r\n" .
                    "Connection: close\r\n\r\n",
                'content' => $data,
                'user_agent' => 'Mozilla/5.0',
                'max_redirects' => 1
            )
        )
    );

    // Gets the headers from PhpMyAdmin
    $headers = get_headers($pmaUri, true);

    if(!$headers || !isset($headers['Location'])) {
        set_page_message(tr('Error: An error occurred while authentication!'));

        return false;
    } else {
        _pmaCreateCookies($headers['Set-Cookie']);
        header("Location: {$headers['Location']}");
    }

    return true;
}

/*******************************************************************************
* Main program
*/

// Include all needed libraries and process to the ispCP intialization
require '../include/ispcp-lib.php';

// Check login
check_login(__FILE__);

/**
*  Dispatches the request
*/
if(isset($_GET['id'])) {
    if(!pmaAuth((int) $_GET['id'])) {
        user_goto('sql_manage.php');
    }
} else {
    user_goto('/index.php');
}



This is the new version of the script from trunk adapted for ispCP version 1.0.5.
07-26-2010 08:37 PM
Quote this message in a reply
Post Reply 


Messages In This Thread
[Resuelto] Problemilla con el PMA - sfera - 07-26-2010, 06:08 PM
RE: Problemilla con el PMA - Nuxwin - 07-26-2010 08:37 PM
RE: Problemilla con el PMA - sfera - 07-26-2010, 09:58 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)