daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Dec 23rd, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function adminer_object() {
  4.     class YourClass extends Adminer {
  5.  
  6.         protected $externals;
  7.  
  8.         function __construct($externals) {
  9.             $this->externals = $externals;
  10.         }
  11.  
  12.         function name() {
  13.             return 'YourApp Adminer';
  14.         }
  15.  
  16.         function credentials() {
  17.             if (!$this->externals->authenticated) {
  18.                 auth_error('External authentication expired.');
  19.             }
  20.             return [
  21.                 $this->externals->host,
  22.                 $this->externals->user,
  23.                 $this->externals->pass,
  24.             ];
  25.         }
  26.  
  27.         function database() {
  28.             return $this->externals->database;
  29.         }
  30.  
  31.         function loginForm() {
  32.             if ($this->externals->authenticated) {
  33.                 # form fields required for login() to be triggered
  34.                 ?>
  35.                 <style>form { display: none; }</style>
  36.                 <?php
  37.                 parent::loginForm();
  38.                 ?>
  39.                 <script>document.forms[0].submit()</script>
  40.                 <?php
  41.             }
  42.             else {
  43.                 ?>
  44.                 <a href="#link-to-your-log-in-page">Log in</a>
  45.                 <?php
  46.             }
  47.         }
  48.  
  49.         function login($login, $password) {
  50.             return $this->externals->authenticated;
  51.         }
  52.     }
  53.  
  54.     # add logic to integrate with your system, here
  55.     $host = $yourDbConfig->host;
  56.     $database = $yourDbConfig->database;
  57.     $user = $yourDbConfig->user;
  58.     $password = $yourDbConfig->password;
  59.     $authenticated = $yourAuth->isLoggedIn() && $yourAuth->hasPermissionTo('ruin_your_db');
  60.  
  61.     if (empty($_GET['db']) && $database != '') {
  62.         $_GET['db'] = $database;
  63.     }
  64.  
  65.     return new YourClass((object) compact('host', 'database', 'user', 'pass', 'authenticated'));
  66. }
  67.  
  68. require 'path/to/your/adminer.php';
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top