Menu

Integration of Adminer inside other app that relies on PHP sessions too

Help
CDuv
2021-08-11
2021-09-22
  • CDuv

    CDuv - 2021-08-11

    Hello,

    I want to add Adminer to ISPConfig, but not the way the [existing plugin](https://github.com/natanfelles/adminer-ispconfig has done it.
    It uses the ISPConfig remote API where I simply want to check if browser is already logged in on ISPConfig (to decide whether to display Adminer or deny) and don't want to auto-fill/connect to SQL database.

    The adminer.php file would be served from the same host, port and path as ISPConfig (http://ispconfig.example.com:8080/adminer.php)

    The way to check for ISPConfig auth is via theses 3 lines of code:

    require_once '/usr/local/ispconfig/interface/lib/config.inc.php';
    require_once '/usr/local/ispconfig/interface/lib/app.inc.php';
    $app->auth->check_module_permissions('client'); // checks and redirect+exit if not granted
    

    So I added thoses at the beginning of adminer.php and it works: accessing http://ispconfig.example.com:8080/adminer.php without being already logged to ISPConfig redirects to ISPConfig's login form.
    If already logged, accessing the same page shows the Adminer SQL connection form.

    For a simple PHP script without sessions (say a simple phpinfo(); helpful page) it would over.
    But Adminer uses sessions and so does ISPConfig: it's not that simple.

    When submitting the Adminer connection form I see some HTTP requests being redirected to /index.php (done by ISPConfig), indicating a loss of session somewhere in the process...

    I tried to swap the sessions (use ISPConfig's to do the auth check and go back to Adminer's), using naive code from https://stackoverflow.com/questions/609756/can-you-switch-php-sessions-in-a-session:

    $current_session_id = session_id();
    $current_session_name = session_name();
    session_write_close();
    $parent_session_name = 'ISPCSESS';
    
    // Does parent session exist?
    if (isset($_COOKIE[$parent_session_name])) {
        session_id($_COOKIE[$parent_session_name]);
        session_name($parent_session_name);
        session_start();
    } else {
        session_name($parent_session_name);
        session_start();
        $success = session_regenerate_id(true);
    }
    $parent_session_id = session_id();
    
    require_once "/usr/local/ispconfig/interface/lib/config.inc.php";
    require_once "/usr/local/ispconfig/interface/lib/app.inc.php";
    $app->auth->check_module_permissions('client');
    
    session_write_close();
    session_id($current_session_id);
    session_name($current_session_name);
    session_start();
    

    Without luck: Adminer now says the Session expired once I submit the connection form...

    Before doing more digging, Is my goal (swap sessions) unreachable?
    Can sid() , restart_session() and stop_session() be of any help?

    I saw multiple integrations but they mostly all use credentials() to auto-connect.

    Thanks

     

    Last edit: CDuv 2021-08-11
  • Akn Toptan

    Akn Toptan - 2021-09-22
     

Log in to post a comment.