*/ private $localHosts = array('', 'localhost', '::1'); /** @var string */ private $color; /** @var ?bool */ private $remote; /** * @param list $localHosts hosts to also consider local, e.g. a development database or a Docker gateway * @param string $color */ function __construct(array $localHosts = array(), $color = '#dd1818') { $this->localHosts = array_merge($this->localHosts, array_map('strtolower', $localHosts)); $this->color = $color; } function bodyClass() { if ($this->isRemote()) { echo " remote"; } } function head($dark = null) { if ($this->isRemote()) { // #breadcrumb and #menuopen are positioned over the body border echo " "; } } /** Check if the browser or the database is somewhere else than on the machine running Adminer * @return bool */ private function isRemote() { if ($this->remote === null) { $this->remote = !$this->isLocal($_SERVER["REMOTE_ADDR"]) || $_SERVER["HTTP_X_FORWARDED_FOR"] != "" // the request passed through a proxy ; if (!$this->remote && class_exists('Adminer\Db') && Adminer\connection()) { // credentials() can be useless before connecting $credentials = Adminer\adminer()->credentials(); $this->remote = !$this->isLocal(Adminer\first(Adminer\host_port($credentials[0]))); } } return $this->remote; } /** @return bool */ private function isLocal($host) { $host = preg_replace('~^[-+.\w]+://~', '', strval($host)); // scheme is used by some plugin drivers return in_array(strtolower($host), $this->localHosts) || preg_match('~^(127\.|/)~', $host) // loopback, socket directory ; } protected $translations = array( 'cs' => array('' => 'Upozorní červeným pruhem, pokud Adminer nebo databáze neběží na lokálním počítači'), ); }