Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.app.phppgadmin.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
16class AppPhppgadmin extends Module
17{
21 const ROOT_CFG_VERSION = 'phppgadminVersion';
22
26 const LOCAL_CFG_CONF = 'phppgadminConf';
27
31 private $conf;
32
39 public function __construct($id, $type) {
40 Util::logInitClass($this);
41 $this->reload($id, $type);
42 }
43
50 public function reload($id = null, $type = null) {
53
54 $this->name = $bearsamppLang->getValue(Lang::PHPPGADMIN);
55 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
56 parent::reload($id, $type);
57
58 if ($this->bearsamppConfRaw !== false) {
59 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
60 }
61
62 if (!$this->enable) {
63 Util::logInfo($this->name . ' is not enabled!');
64 return;
65 }
66 if (!is_dir($this->currentPath)) {
67 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
68 }
69 if (!is_dir($this->symlinkPath)) {
70 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
71 return;
72 }
73 if (!is_file($this->bearsamppConf)) {
74 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
75 }
76 if (!is_file($this->conf)) {
77 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
78 }
79 }
80
89 protected function updateConfig($version = null, $sub = 0, $showWindow = false) {
91
92 if (!$this->enable) {
93 return true;
94 }
95
96 $version = $version == null ? $this->version : $version;
97 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
98
99 $alias = $bearsamppRoot->getAliasPath() . '/phppgadmin.conf';
100 if (is_file($alias)) {
101 Util::replaceInFile($alias, array(
102 '/^Alias\s\/phppgadmin\s.*/' => 'Alias /phppgadmin "' . $this->getSymlinkPath() . '/"',
103 '/^<Directory\s.*/' => '<Directory "' . $this->getSymlinkPath() . '/">',
104 ));
105 } else {
106 Util::logError($this->getName() . ' alias not found : ' . $alias);
107 }
108
109 if ($bearsamppBins->getPostgresql()->isEnable()) {
110 Util::replaceInFile($this->getConf(), array(
111 '/^\$postgresqlPort\s=\s(\d+)/' => '$postgresqlPort = ' . $bearsamppBins->getPostgresql()->getPort() . ';',
112 '/^\$postgresqlRootUser\s=\s/' => '$postgresqlRootUser = \'' . $bearsamppBins->getPostgresql()->getRootUser() . '\';',
113 '/^\$postgresqlRootPwd\s=\s/' => '$postgresqlRootPwd = \'' . $bearsamppBins->getPostgresql()->getRootPwd() . '\';',
114 '/^\$postgresqlDumpExe\s=\s/' => '$postgresqlDumpExe = \'' . $bearsamppBins->getPostgresql()->getDumpExe() . '\';',
115 '/^\$postgresqlDumpAllExe\s=\s/' => '$postgresqlDumpAllExe = \'' . $bearsamppBins->getPostgresql()->getDumpAllExe() . '\';',
116 ));
117 }
118
119 return true;
120 }
121
127 public function setVersion($version) {
128 global $bearsamppConfig;
129 $this->version = $version;
130 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
131 $this->reload();
132 }
133
139 public function getConf() {
140 return $this->conf;
141 }
142}
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
updateConfig($version=null, $sub=0, $showWindow=false)
reload($id=null, $type=null)
const ERROR_CONF_NOT_FOUND
const PHPPGADMIN
const ERROR_FILE_NOT_FOUND
static logError($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
static logDebug($data, $file=null)
static logReloadClass($classInstance)
static replaceInFile($path, $replaceList)
global $bearsamppConfig
Definition homepage.php:27