162 $this->enable = $this->enable &&
$bearsamppConfig->getRaw(self::ROOT_CFG_ENABLE);
166 if ($this->bearsamppConfRaw !==
false) {
167 $this->ctlExe = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CTL_EXE];
168 $this->cliExe = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CLI_EXE];
169 $this->dumpExe = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_DUMP_EXE];
170 $this->dumpAllExe = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_DUMP_ALL_EXE];
171 $this->conf = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
172 $this->hbaConf = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_HBA_CONF];
173 $this->altConf = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ALT_CONF];
174 $this->altHbaConf = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ALT_HBA_CONF];
175 $this->port = $this->bearsamppConfRaw[self::LOCAL_CFG_PORT];
176 $this->rootUser = isset($this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER]) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] :
'postgres';
177 $this->rootPwd = isset($this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD]) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] :
'';
180 if (!$this->enable) {
181 Log::info($this->name .
' is not enabled!');
185 if (!is_dir($this->currentPath)) {
190 if (!is_dir($this->symlinkPath)) {
195 if (!is_file($this->bearsamppConf)) {
200 if (!file_exists($this->conf)) {
203 if (!file_exists($this->hbaConf)) {
207 if (!is_file($this->ctlExe)) {
212 if (!is_file($this->cliExe)) {
217 if (!is_file($this->dumpExe)) {
222 if (!is_file($this->dumpAllExe)) {
227 if (!is_file($this->conf)) {
232 if (!is_file($this->hbaConf)) {
237 if (!is_numeric($this->port) || $this->port <= 0) {
242 if (empty($this->rootUser)) {
249 $this->service->setBinPath($this->ctlExe);
261 $content = file_get_contents($this->bearsamppConf);
263 foreach ($params as $key => $value) {
264 $content = preg_replace(
'|' . $key .
' = .*|', $key .
' = ' .
'"' . $value .
'"', $content);
265 $this->bearsamppConfRaw[$key] = $value;
267 case self::LOCAL_CFG_PORT:
268 $this->port = $value;
270 case self::LOCAL_CFG_ROOT_USER:
271 $this->rootUser = $value;
273 case self::LOCAL_CFG_ROOT_PWD:
274 $this->rootPwd = $value;
279 file_put_contents($this->bearsamppConf, $content);
343 $dbLink = @pg_connect(
'host=' .
APP_LOCALHOST .
" port=$port user={$this->rootUser} password={$this->rootPwd}");
345 $lastError = error_get_last();
346 $errorMsg = $lastError ? $lastError[
'message'] :
'Unknown error';
353 $connectionStatus = pg_connection_status($dbLink);
354 $isPostgres = $connectionStatus === PGSQL_CONNECTION_OK;
360 $bearsamppWinbinder->messageBoxInfo(
413 global $bearsamppWinbinder;
416 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
417 $dbLink = pg_connect(
'host=' .
APP_LOCALHOST .
' port=' . $this->port .
' user=' . $this->rootUser .
' password=' . $currentPwd);
420 $error = error_get_last()[
'message'];
423 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
424 $pgr = pg_query_params($dbLink,
'SELECT quote_ident($1)', array(pg_escape_string($this->rootUser)));
425 list($quoted_user) = pg_fetch_array($pgr);
426 $password = pg_escape_string($newPwd);
427 $result = pg_query($dbLink,
"ALTER USER $quoted_user WITH PASSWORD '$password'");
428 if (empty($error) && !
$result) {
429 $error = pg_last_error($dbLink);
432 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
437 if (!empty($error)) {
442 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
447 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
512 if (!$this->enable) {
517 Log::debug(($sub > 0 ? str_repeat(
' ', 2 * $sub) :
'') .
'Update ' . $this->name .
' ' .
$version .
' config');
530 Log::error(
'bearsampp config files not found for ' . $this->
getName() .
' ' . $version);
532 $bearsamppWinbinder->messageBoxError(
543 Log::error(
'bearsampp config file malformed for ' . $this->
getName() .
' ' . $version);
545 $bearsamppWinbinder->messageBoxError(
559 '/^port(.*?)=(.*?)(\d+)/' =>
'port = ' . $this->port
563 $bearsamppApps->getPhppgadmin()->update($sub + 1);