Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
adminer autologin sqlite

adminer autologin sqlite

A way to make adminer not ask for any of credentials, using default values for: fake-username, fake-password and sqlite file database path.

Steps:

  • Download adminer.php, put in the same folder of index.php (root) and set the correct filename there;
  • Download plugin.php and put it in plugins folder;
  • Move auto-login.php and login-sqlite.php into plugins folder;
  • Set correct sqlite file database path.

Sources:

<?php
# Place in `plugins/`
/** Enable auto-login for SQLite
* @link https://www.adminer.org/plugins/#use
* @author Jakub Vrana, https://www.vrana.cz/
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerAutoLogin {
function credentials() {
return array("sladmin", "mypassword");
}
function login($login, $password) {
return true;
}
function loginForm() {
?>
<script type="text/javascript">
addEventListener('load', function () {
var driver = document.getElementsByName('auth[driver]')[0];
if (isTag(driver, 'select')) {
driver.onchange = function () {
var trs = parentTag(driver, 'table').rows;
for (var i=1; i < trs.length - 1; i++) {
var disabled = /sqlite/.test(driver.value);
alterClass(trs[i], 'hidden', disabled);
trs[i].getElementsByTagName('input')[0].disabled = disabled;
}
};
}
driver.onchange();
});
</script>
<?php
}
}
<?php
$_GET["sqlite"] = "";
$_GET["username"] = "sladmin";
$_GET["db"] = "../../var/data.db";
function adminer_object() {
// Required to run any plugin.
include_once(__DIR__ . "/plugins/plugin.php");
// Load plugins.
foreach (glob(__DIR__ . "/plugins/*.php") as $file) {
include_once($file);
}
$plugins = [
new AdminerLoginSqlite("sladmin", password_hash("mypassword", PASSWORD_DEFAULT)),
new AdminerAutoLogin(),
];
return new AdminerPlugin($plugins);
}
// Include original Adminer or Adminer Editor.
include 'adminer-4.7.1.php';
<?php
# Place in `plugins/`
/** Enable auto-login for SQLite
* @link https://www.adminer.org/plugins/#use
* @author Jakub Vrana, https://www.vrana.cz/
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerLoginSqlite {
function login($login, $password) {
return true;
}
function loginForm() {
?>
<script type="text/javascript">
addEventListener('load', function () {
var driver = document.getElementsByName('auth[driver]')[0];
if (isTag(driver, 'select')) {
driver.onchange = function () {
var trs = parentTag(driver, 'table').rows;
for (var i=1; i < trs.length - 1; i++) {
var disabled = /sqlite/.test(driver.value);
alterClass(trs[i], 'hidden', disabled);
trs[i].getElementsByTagName('input')[0].disabled = disabled;
}
};
}
driver.onchange();
});
</script>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.