fix: change web ui for index service

This commit is contained in:
Alexander Navarro 2025-01-10 09:29:24 -03:00
parent 10386c08c2
commit 4259b1e3d2
2 changed files with 8 additions and 201 deletions

View file

@ -1,191 +0,0 @@
<?php
/**
* Quickly switch Adminer themes from browser or command line.
* @author Victor Nogueira <github@victornogueira.io>
* @link https://github.com/felladrin/adminer-theme-switcher
* @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 AdminerThemeSwitcher
{
protected static $themeList;
protected static $option;
public static $prompt = 'Type the number of the theme you want to use: ';
public static function run()
{
if (static::isRunningFromCommandLine()) {
static::printListAvailableThemes();
static::readOptionFromCommandLine();
static::switchTheme();
return;
}
if (static::hasNotSelectedAnOptionFromBrowserYet()) {
static::printListAvailableThemes();
static::printJavascriptPrompt();
} else {
static::readOptionFromBrowser();
static::switchTheme();
}
}
public static function isRunningFromCommandLine()
{
return (php_sapi_name() === 'cli');
}
public static function isRunningOnWindows()
{
return (PHP_OS == 'WINNT');
}
public static function getLineEnding()
{
return (static::isRunningFromCommandLine() ? PHP_EOL : '<br/>');
}
public static function getThemeList()
{
if (!empty(static::$themeList)) {
return static::$themeList;
}
$context = stream_context_create([
'http' => [
'method' => 'GET',
'header' => [
'User-Agent: PHP'
]
],
'ssl' => [
"verify_peer" => false,
"verify_peer_name" => false
]
]);
$urlOfThemesDirFromGithubRepo = 'https://api.github.com/repos/vrana/adminer/contents/designs';
$jsonThemeList = file_get_contents($urlOfThemesDirFromGithubRepo, false, $context);
static::$themeList = ($jsonThemeList ? json_decode($jsonThemeList) : false);
return static::$themeList;
}
public static function downloadTheme($themeIndex = null)
{
if (is_null($themeIndex)) {
$themeIndex = static::$option;
}
$themeName = static::getThemeList()[$themeIndex]->name;
$urlOfCssFileFromGithubRepo = "https://raw.githubusercontent.com/vrana/adminer/master/designs/{$themeName}/adminer.css";
$cssContent = file_get_contents($urlOfCssFileFromGithubRepo);
$filePath = __DIR__ . '/adminer.css';
$fileExists = file_exists('adminer.css');
if (file_put_contents($filePath, $cssContent) !== false) {
if (!$fileExists) {
chmod($filePath, 0777);
}
return true;
}
return false;
}
public static function printListAvailableThemes()
{
echo "List of available Adminer Themes:" . static::getLineEnding() . static::getLineEnding();
if (static::getThemeList()) {
foreach (static::getThemeList() as $index => $theme) {
if ($theme->type !== 'dir') {
continue;
}
echo "[{$index}] {$theme->name}" . static::getLineEnding();
}
}
echo static::getLineEnding();
}
public static function readOptionFromCommandLine()
{
if (static::isRunningOnWindows()) {
echo static::$prompt;
static::$option = stream_get_line(STDIN, 1024, static::getLineEnding());
} else {
static::$option = readline(static::$prompt);
}
return static::$option;
}
public static function printResultOf($download)
{
if ($download) {
echo 'Theme switched successfully!' . static::getLineEnding();
} else {
echo 'Something went wrong with the download. Try again!' . static::getLineEnding();
}
}
public static function printJavascriptPrompt()
{
echo '<script>';
echo 'setTimeout(function() {';
echo 'var option = prompt("' . static::$prompt . '", "0");';
echo 'if (option !== null) { window.location.replace(window.location.href.split("?")[0] + "?option=" + option); }';
echo '}, 1000);';
echo '</script>';
}
public static function readOptionFromBrowser()
{
if (isset($_GET['option'])) {
static::$option = $_GET['option'];
}
return static::$option;
}
public static function hasNotSelectedAnOptionFromBrowserYet()
{
return !isset($_GET['option']);
}
public static function hasSelectedAValidOption()
{
return is_numeric(static::$option) && static::$option < count(static::getThemeList());
}
public static function printInvalidOptionErrorMessage()
{
$errorMessage = static::$option . " is not a number from the options! Try again!";
if (static::isRunningFromCommandLine()) {
echo $errorMessage . static::getLineEnding();
static::run();
} else {
echo '<script>alert("' . $errorMessage . '")</script>';
echo '<script>window.location.replace(window.location.href.split("?")[0])</script>';
}
}
public static function switchTheme()
{
if (static::hasSelectedAValidOption()) {
static::printResultOf(static::downloadTheme());
} else {
static::printInvalidOptionErrorMessage();
}
}
}
AdminerThemeSwitcher::run();

View file

@ -8,23 +8,21 @@ networks:
volumes: volumes:
index_db: index_db:
adminer_plugins: webdb_ssh:
webdb_time_machine:
services: services:
adminer: webdb:
image: ghcr.io/shyim/adminerevo:latest image: webdb/app
restart: unless-stopped restart: unless-stopped
networks: networks:
- default - default
- reverse_proxy - reverse_proxy
volumes: volumes:
- adminer_plugins:/var/www/html/plugins-custom - "webdb_ssh:/root/.ssho"
- "webdb_time_machine:/usr/src/app/static/version"
environment: environment:
ADMINER_DEFAULT_DRIVER: pgsql SCAN_HOSTS: db,tasks.db
ADMINER_DEFAULT_SERVER: tasks.db
ADMINER_DEFAULT_USER: postgres
ADMINER_PLUGINS: tables-filter tinymce edit-calendar edit-foreign enum-option enum-types file-upload slugify struct-comments
ADMINER_DESIGN: 'pepa-linha-dark'
deploy: deploy:
rollback_config: rollback_config:
failure_action: continue failure_action: continue
@ -38,7 +36,7 @@ services:
labels: labels:
- traefik.enable=true - traefik.enable=true
- traefik.http.routers.index.rule=Host(`index.alecodes.page`) - traefik.http.routers.index.rule=Host(`index.alecodes.page`)
- traefik.http.services.index.loadbalancer.server.port=8080 - traefik.http.services.index.loadbalancer.server.port=22071
db: db:
image: postgres image: postgres