2024.8.23
Loading...
Searching...
No Matches
class.bin.postgresql.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
10/**
11 * Class BinPostgresql
12 *
13 * This class represents the PostgreSQL module in the Bearsampp application.
14 * It handles the configuration, management, and operations related to PostgreSQL.
15 */
16class BinPostgresql extends Module
17{
18 const SERVICE_NAME = 'bearsampppostgresql';
19
20 const ROOT_CFG_ENABLE = 'postgresqlEnable';
21 const ROOT_CFG_VERSION = 'postgresqlVersion';
22
23 const LOCAL_CFG_CTL_EXE = 'postgresqlCtlExe';
24 const LOCAL_CFG_CLI_EXE = 'postgresqlCliExe';
25 const LOCAL_CFG_DUMP_EXE = 'postgresqlDumpExe';
26 const LOCAL_CFG_DUMP_ALL_EXE = 'postgresqlDumpAllExe';
27 const LOCAL_CFG_CONF = 'postgresqlConf';
28 const LOCAL_CFG_HBA_CONF = 'postgresqlUserConf';
29 const LOCAL_CFG_ALT_CONF = 'postgresqlAltConf';
30 const LOCAL_CFG_ALT_HBA_CONF = 'postgresqlAltUserConf';
31 const LOCAL_CFG_PORT = 'postgresqlPort';
32 const LOCAL_CFG_ROOT_USER = 'postgresqlRootUser';
33 const LOCAL_CFG_ROOT_PWD = 'postgresqlRootPwd';
34
35 const CMD_VERSION = '--version';
36
37 private $service;
38 private $errorLog;
39 private $ctlExe;
40 private $cliExe;
41 private $dumpExe;
42 private $dumpAllExe;
43 private $conf;
44 private $hbaConf;
45 private $altConf;
46 private $altHbaConf;
47 private $port;
48 private $rootUser;
49 private $rootPwd;
50
51 /**
52 * Constructor for the BinPostgresql class.
53 *
54 * @param string $id The ID of the module.
55 * @param string $type The type of the module.
56 */
57 public function __construct($id, $type)
58 {
59 Util::logInitClass( $this );
60 $this->reload( $id, $type );
61 }
62
63 /**
64 * Reloads the module configuration based on the provided ID and type.
65 *
66 * @param string|null $id The ID of the module. If null, the current ID is used.
67 * @param string|null $type The type of the module. If null, the current type is used.
68 */
69 public function reload($id = null, $type = null)
70 {
72 Util::logReloadClass( $this );
73
74 $this->name = $bearsamppLang->getValue( Lang::POSTGRESQL );
75 $this->version = $bearsamppConfig->getRaw( self::ROOT_CFG_VERSION );
76 parent::reload( $id, $type );
77
78 $this->enable = $this->enable && $bearsamppConfig->getRaw( self::ROOT_CFG_ENABLE );
79 $this->service = new Win32Service( self::SERVICE_NAME );
80 $this->errorLog = $bearsamppRoot->getLogsPath() . '/postgresql.log';
81
82 if ( $this->bearsamppConfRaw !== false ) {
83 $this->ctlExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CTL_EXE];
84 $this->cliExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CLI_EXE];
85 $this->dumpExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_DUMP_EXE];
86 $this->dumpAllExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_DUMP_ALL_EXE];
87 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
88 $this->hbaConf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_HBA_CONF];
89 $this->altConf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ALT_CONF];
90 $this->altHbaConf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_ALT_HBA_CONF];
91 $this->port = $this->bearsamppConfRaw[self::LOCAL_CFG_PORT];
92 $this->rootUser = isset( $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] ) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_USER] : 'postgres';
93 $this->rootPwd = isset( $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] ) ? $this->bearsamppConfRaw[self::LOCAL_CFG_ROOT_PWD] : '';
94 }
95
96 if ( !$this->enable ) {
97 Util::logInfo( $this->name . ' is not enabled!' );
98
99 return;
100 }
101 if ( !is_dir( $this->currentPath ) ) {
102 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_FILE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->currentPath ) );
103
104 return;
105 }
106 if ( !is_dir( $this->symlinkPath ) ) {
107 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_FILE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->symlinkPath ) );
108
109 return;
110 }
111 if ( !is_file( $this->bearsamppConf ) ) {
112 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_CONF_NOT_FOUND ), $this->name . ' ' . $this->version, $this->bearsamppConf ) );
113
114 return;
115 }
116 if ( !file_exists( $this->conf ) ) {
117 $this->conf = $this->altConf;
118 }
119 if ( !file_exists( $this->hbaConf ) ) {
120 $this->hbaConf = $this->altHbaConf;
121 }
122
123 if ( !is_file( $this->ctlExe ) ) {
124 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->ctlExe ) );
125
126 return;
127 }
128 if ( !is_file( $this->cliExe ) ) {
129 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->cliExe ) );
130
131 return;
132 }
133 if ( !is_file( $this->dumpExe ) ) {
134 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->dumpExe ) );
135
136 return;
137 }
138 if ( !is_file( $this->dumpAllExe ) ) {
139 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_EXE_NOT_FOUND ), $this->name . ' ' . $this->version, $this->dumpAllExe ) );
140
141 return;
142 }
143 if ( !is_file( $this->conf ) ) {
144 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_CONF_NOT_FOUND ), $this->name . ' ' . $this->version, $this->conf ) );
145
146 return;
147 }
148 if ( !is_file( $this->hbaConf ) ) {
149 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_CONF_NOT_FOUND ), $this->name . ' ' . $this->version, $this->hbaConf ) );
150
151 return;
152 }
153 if ( !is_numeric( $this->port ) || $this->port <= 0 ) {
154 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_INVALID_PARAMETER ), self::LOCAL_CFG_PORT, $this->port ) );
155
156 return;
157 }
158 if ( empty( $this->rootUser ) ) {
159 Util::logError( sprintf( $bearsamppLang->getValue( Lang::ERROR_INVALID_PARAMETER ), self::LOCAL_CFG_ROOT_USER, $this->rootUser ) );
160
161 return;
162 }
163
164 $this->service->setDisplayName( APP_TITLE . ' ' . $this->getName() );
165 $this->service->setBinPath( $this->ctlExe );
166 $this->service->setStartType( Win32Service::SERVICE_DEMAND_START );
167 $this->service->setErrorControl( Win32Service::SERVER_ERROR_NORMAL );
168 }
169
170 /**
171 * Replaces multiple key-value pairs in the configuration file.
172 *
173 * @param array $params An associative array of key-value pairs to replace.
174 */
175 protected function replaceAll($params)
176 {
177 $content = file_get_contents( $this->bearsamppConf );
178
179 foreach ( $params as $key => $value ) {
180 $content = preg_replace( '|' . $key . ' = .*|', $key . ' = ' . '"' . $value . '"', $content );
181 $this->bearsamppConfRaw[$key] = $value;
182 switch ( $key ) {
184 $this->port = $value;
185 break;
187 $this->rootUser = $value;
188 break;
190 $this->rootPwd = $value;
191 break;
192 }
193 }
194
195 file_put_contents( $this->bearsamppConf, $content );
196 }
197
198 /**
199 * Changes the port used by PostgreSQL.
200 *
201 * @param int $port The new port number.
202 * @param bool $checkUsed Whether to check if the port is already in use.
203 * @param mixed $wbProgressBar The progress bar object for UI updates.
204 *
205 * @return bool|string True if the port was changed successfully, or the process using the port if it is in use.
206 */
207 public function changePort($port, $checkUsed = false, $wbProgressBar = null)
208 {
209 global $bearsamppWinbinder;
210
211 if ( !Util::isValidPort( $port ) ) {
212 Util::logError( $this->getName() . ' port not valid: ' . $port );
213
214 return false;
215 }
216
217 $port = intval( $port );
218 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
219
220 $isPortInUse = Util::isPortInUse( $port );
221 if ( !$checkUsed || $isPortInUse === false ) {
222 // bearsampp.conf
223 $this->setPort( $port );
224 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
225
226 // conf
227 $this->update();
228 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
229
230 return true;
231 }
232
233 Util::logDebug( $this->getName() . ' port in used: ' . $port . ' - ' . $isPortInUse );
234
235 return $isPortInUse;
236 }
237
238 /**
239 * Checks if the specified port is used by PostgreSQL.
240 *
241 * @param int $port The port number to check.
242 * @param bool $showWindow Whether to show a message box with the result.
243 *
244 * @return bool True if the port is used by PostgreSQL, false otherwise.
245 */
246 public function checkPort($port, $showWindow = false)
247 {
248 global $bearsamppLang, $bearsamppWinbinder;
249 $boxTitle = sprintf( $bearsamppLang->getValue( Lang::CHECK_PORT_TITLE ), $this->getName(), $port );
250
251 if ( !Util::isValidPort( $port ) ) {
252 Util::logError( $this->getName() . ' port not valid: ' . $port );
253
254 return false;
255 }
256
257 $fp = @fsockopen( '127.0.0.1', $port, $errno, $errstr, 5 );
258 if ( $fp ) {
259 $dbLink = pg_connect( 'host=127.0.0.1 port=' . $port . ' user=' . $this->rootUser . ' password=' . $this->rootPwd );
260
261 $isPostgresql = false;
262 $version = false;
263
264 if ( $dbLink ) {
265 $result = pg_version( $dbLink );
266 pg_close( $dbLink );
267 if ( $result ) {
268 if ( isset( $result['server'] ) && $result['server'] == $this->getVersion() ) {
269 $version = $result['server'];
270 $isPostgresql = true;
271 }
272 if ( !$isPostgresql ) {
273 Util::logDebug( $this->getName() . ' port used by another DBMS: ' . $port );
274 if ( $showWindow ) {
275 $bearsamppWinbinder->messageBoxWarning(
277 $boxTitle
278 );
279 }
280 }
281 else {
282 Util::logDebug( $this->getName() . ' port ' . $port . ' is used by: ' . $this->getName() . ' ' . $version );
283 if ( $showWindow ) {
284 $bearsamppWinbinder->messageBoxInfo(
285 sprintf( $bearsamppLang->getValue( Lang::PORT_USED_BY ), $port, $this->getName() . ' ' . $version ),
286 $boxTitle
287 );
288 }
289
290 return true;
291 }
292 }
293 }
294 else {
295 Util::logDebug( $this->getName() . ' port ' . $port . ' is used by another application' );
296 if ( $showWindow ) {
297 $bearsamppWinbinder->messageBoxWarning(
298 sprintf( $bearsamppLang->getValue( Lang::PORT_NOT_USED_BY ), $port ),
299 $boxTitle
300 );
301 }
302 }
303 }
304 else {
305 Util::logDebug( $this->getName() . ' port ' . $port . ' is not used' );
306 if ( $showWindow ) {
307 $bearsamppWinbinder->messageBoxError(
308 sprintf( $bearsamppLang->getValue( Lang::PORT_NOT_USED ), $port ),
309 $boxTitle
310 );
311 }
312 }
313
314 return false;
315 }
316
317 /**
318 * Changes the root password for PostgreSQL.
319 *
320 * @param string $currentPwd The current root password.
321 * @param string $newPwd The new root password.
322 * @param mixed $wbProgressBar The progress bar object for UI updates.
323 *
324 * @return bool|string True if the password was changed successfully, or an error message if it failed.
325 */
326 public function changeRootPassword($currentPwd, $newPwd, $wbProgressBar = null)
327 {
328 global $bearsamppWinbinder;
329 $error = null;
330
331 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
332 $dbLink = pg_connect( 'host=127.0.0.1 port=' . $this->port . ' user=' . $this->rootUser . ' password=' . $currentPwd );
333
334 if ( !$dbLink ) {
335 $error = pg_last_error( $dbLink );
336 }
337
338 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
339 $pgr = pg_query_params( $dbLink, 'SELECT quote_ident($1)', array(pg_escape_string( $this->rootUser )) );
340 list( $quoted_user ) = pg_fetch_array( $pgr );
341 $password = pg_escape_string( $newPwd );
342 $result = pg_query( $dbLink, "ALTER USER $quoted_user WITH PASSWORD '$password'" );
343 if ( empty( $error ) && !$result ) {
344 $error = pg_last_error( $dbLink );
345 }
346
347 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
348 if ( $dbLink ) {
349 pg_close( $dbLink );
350 }
351
352 if ( !empty( $error ) ) {
353 return $error;
354 }
355
356 // bearsampp.conf
357 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
358 $this->setRootPwd( $newPwd );
359
360 // conf
361 $this->update();
362 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
363
364 return true;
365 }
366
367 /**
368 * Checks if the provided root password is correct.
369 *
370 * @param string|null $currentPwd The current root password. If null, the stored root password is used.
371 * @param mixed $wbProgressBar The progress bar object for UI updates.
372 *
373 * @return bool|string True if the password is correct, or an error message if it is incorrect.
374 */
375 public function checkRootPassword($currentPwd = null, $wbProgressBar = null)
376 {
377 global $bearsamppWinbinder;
378 $currentPwd = $currentPwd == null ? $this->rootPwd : $currentPwd;
379 $error = null;
380
381 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
382 $dbLink = pg_connect( 'host=127.0.0.1 port=' . $this->port . ' user=' . $this->rootUser . ' password=' . $currentPwd );
383 if ( !$dbLink ) {
384 $error = pg_last_error( $dbLink );
385 }
386
387 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
388 if ( $dbLink ) {
389 pg_close( $dbLink );
390 }
391
392 if ( !empty( $error ) ) {
393 return $error;
394 }
395
396 return true;
397 }
398
399 /**
400 * Switches the PostgreSQL version.
401 *
402 * @param string $version The version to switch to.
403 * @param bool $showWindow Whether to show a message box with the result.
404 *
405 * @return bool True if the version was switched successfully, false otherwise.
406 */
407 public function switchVersion($version, $showWindow = false)
408 {
409 Util::logDebug( 'Switch ' . $this->name . ' version to ' . $version );
410
411 return $this->updateConfig( $version, 0, $showWindow );
412 }
413
414 /**
415 * Updates the PostgreSQL configuration.
416 *
417 * @param string|null $version The version to update to. If null, the current version is used.
418 * @param int $sub The sub-level for logging indentation.
419 * @param bool $showWindow Whether to show a window during the update process.
420 *
421 * @return bool True if the configuration was updated successfully, false otherwise.
422 */
423 protected function updateConfig($version = null, $sub = 0, $showWindow = false)
424 {
425 global $bearsamppLang, $bearsamppApps, $bearsamppWinbinder;
426
427 if ( !$this->enable ) {
428 return true;
429 }
430
431 $version = $version == null ? $this->version : $version;
432 Util::logDebug( ($sub > 0 ? str_repeat( ' ', 2 * $sub ) : '') . 'Update ' . $this->name . ' ' . $version . ' config' );
433
434 $boxTitle = sprintf( $bearsamppLang->getValue( Lang::SWITCH_VERSION_TITLE ), $this->getName(), $version );
435
436 $currentPath = str_replace( 'postgresql' . $this->getVersion(), 'postgresql' . $version, $this->getCurrentPath() );
437 $conf = str_replace( 'postgresql' . $this->getVersion(), 'postgresql' . $version, $this->getConf() );
438 $bearsamppConf = str_replace( 'postgresql' . $this->getVersion(), 'postgresql' . $version, $this->bearsamppConf );
439
440 if ( $this->version != $version ) {
441 $this->initData( $currentPath );
442 }
443
444 if ( !file_exists( $conf ) || !file_exists( $bearsamppConf ) ) {
445 Util::logError( 'bearsampp config files not found for ' . $this->getName() . ' ' . $version );
446 if ( $showWindow ) {
447 $bearsamppWinbinder->messageBoxError(
448 sprintf( $bearsamppLang->getValue( Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR ), $this->getName() . ' ' . $version ),
449 $boxTitle
450 );
451 }
452
453 return false;
454 }
455
456 $bearsamppConfRaw = parse_ini_file( $bearsamppConf );
457 if ( $bearsamppConfRaw === false || !isset( $bearsamppConfRaw[self::ROOT_CFG_VERSION] ) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version ) {
458 Util::logError( 'bearsampp config file malformed for ' . $this->getName() . ' ' . $version );
459 if ( $showWindow ) {
460 $bearsamppWinbinder->messageBoxError(
461 sprintf( $bearsamppLang->getValue( Lang::BEARSAMPP_CONF_MALFORMED_ERROR ), $this->getName() . ' ' . $version ),
462 $boxTitle
463 );
464 }
465
466 return false;
467 }
468
469 // bearsampp.conf
470 $this->setVersion( $version );
471
472 // conf
473 Util::replaceInFile( $this->getConf(), array(
474 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
475 ) );
476
477 // phppgadmin
478 $bearsamppApps->getPhppgadmin()->update( $sub + 1 );
479
480 // adminer
481 $bearsamppApps->getAdminer()->update( $sub + 1 );
482
483 return true;
484 }
485
486 /**
487 * Initializes the data directory for PostgreSQL if it does not already exist.
488 *
489 * @param string|null $path The path to the PostgreSQL data directory. If null, the current path is used.
490 */
491 public function initData($path = null)
492 {
493 $path = $path != null ? $path : $this->getCurrentPath();
494
495 if ( file_exists( $path . '/data' ) ) {
496 return;
497 }
498
500 }
501
502 /**
503 * Rebuilds the PostgreSQL configuration files by updating the port number.
504 */
505 public function rebuildConf()
506 {
507 Util::replaceInFile( $this->conf, array(
508 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
509 ) );
510 Util::replaceInFile( $this->altConf, array(
511 '/^port(.*?)=(.*?)(\d+)/' => 'port = ' . $this->port
512 ) );
513 }
514
515 /**
516 * Executes a PostgreSQL command line instruction and returns the output.
517 *
518 * @param string $cmd The command to execute.
519 *
520 * @return string|null The output of the command, or null if the command failed.
521 */
522 public function getCmdLineOutput($cmd)
523 {
524 $result = null;
525
526 $bin = $this->getCliExe();
527 if ( file_exists( $bin ) ) {
528 $tmpResult = Batch::exec( 'postgresqlGetCmdLineOutput', '"' . $bin . '" ' . $cmd );
529 if ( $tmpResult !== false && is_array( $tmpResult ) ) {
530 $result = trim( str_replace( $bin, '', implode( PHP_EOL, $tmpResult ) ) );
531 }
532 }
533
534 return $result;
535 }
536
537 /**
538 * Sets the version of PostgreSQL and reloads the configuration.
539 *
540 * @param string $version The version to set.
541 */
542 public function setVersion($version)
543 {
544 global $bearsamppConfig;
545 $this->version = $version;
546 $bearsamppConfig->replace( self::ROOT_CFG_VERSION, $version );
547 $this->reload();
548 }
549
550 /**
551 * Gets the service object for PostgreSQL.
552 *
553 * @return Win32Service The service object.
554 */
555 public function getService()
556 {
557 return $this->service;
558 }
559
560 /**
561 * Enables or disables the PostgreSQL module.
562 *
563 * @param bool $enabled Whether to enable or disable the module.
564 * @param bool $showWindow Whether to show a message box with the result.
565 */
566 public function setEnable($enabled, $showWindow = false)
567 {
568 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
569
570 if ( $enabled == Config::ENABLED && !is_dir( $this->currentPath ) ) {
571 Util::logDebug( $this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath );
572 if ( $showWindow ) {
573 $bearsamppWinbinder->messageBoxError(
574 sprintf( $bearsamppLang->getValue( Lang::ENABLE_BUNDLE_NOT_EXIST ), $this->getName(), $this->getVersion(), $this->currentPath ),
575 sprintf( $bearsamppLang->getValue( Lang::ENABLE_TITLE ), $this->getName() )
576 );
577 }
578 $enabled = Config::DISABLED;
579 }
580
581 Util::logInfo( $this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled') );
582 $this->enable = $enabled == Config::ENABLED;
583 $bearsamppConfig->replace( self::ROOT_CFG_ENABLE, $enabled );
584
585 $this->reload();
586 if ( $this->enable ) {
587 Util::installService( $this, $this->port, null, $showWindow );
588 }
589 else {
590 Util::removeService( $this->service, $this->name );
591 }
592 }
593
594 /**
595 * Gets the path to the PostgreSQL error log file.
596 *
597 * @return string The path to the error log file.
598 */
599 public function getErrorLog()
600 {
601 return $this->errorLog;
602 }
603
604 /**
605 * Gets the path to the PostgreSQL control executable.
606 *
607 * @return string The path to the control executable.
608 */
609 public function getCtlExe()
610 {
611 return $this->ctlExe;
612 }
613
614 /**
615 * Gets the path to the PostgreSQL command line interface executable.
616 *
617 * @return string The path to the CLI executable.
618 */
619 public function getCliExe()
620 {
621 return $this->cliExe;
622 }
623
624 /**
625 * Gets the path to the PostgreSQL dump executable.
626 *
627 * @return string The path to the dump executable.
628 */
629 public function getDumpExe()
630 {
631 return $this->dumpExe;
632 }
633
634 /**
635 * Gets the path to the PostgreSQL dump all executable.
636 *
637 * @return string The path to the dump all executable.
638 */
639 public function getDumpAllExe()
640 {
641 return $this->dumpAllExe;
642 }
643
644 /**
645 * Gets the path to the PostgreSQL configuration file.
646 *
647 * @return string The path to the configuration file.
648 */
649 public function getConf()
650 {
651 return $this->conf;
652 }
653
654 /**
655 * Gets the path to the PostgreSQL host-based authentication configuration file.
656 *
657 * @return string The path to the HBA configuration file.
658 */
659 public function getHbaConf()
660 {
661 return $this->hbaConf;
662 }
663
664 /**
665 * Gets the port number used by PostgreSQL.
666 *
667 * @return int The port number.
668 */
669 public function getPort()
670 {
671 return $this->port;
672 }
673
674 /**
675 * Sets the port number used by PostgreSQL.
676 *
677 * @param int $port The port number to set.
678 */
679 public function setPort($port)
680 {
681 $this->replace( self::LOCAL_CFG_PORT, $port );
682 }
683
684 /**
685 * Gets the root user for PostgreSQL.
686 *
687 * @return string The root user.
688 */
689 public function getRootUser()
690 {
691 return $this->rootUser;
692 }
693
694 /**
695 * Sets the root user for PostgreSQL.
696 *
697 * @param string $rootUser The root user to set.
698 */
699 public function setRootUser($rootUser)
700 {
701 $this->replace( self::LOCAL_CFG_ROOT_USER, $rootUser );
702 }
703
704 /**
705 * Gets the root password for PostgreSQL.
706 *
707 * @return string The root password.
708 */
709 public function getRootPwd()
710 {
711 return $this->rootPwd;
712 }
713
714 /**
715 * Sets the root password for PostgreSQL.
716 *
717 * @param string $rootPwd The root password to set.
718 */
719 public function setRootPwd($rootPwd)
720 {
721 $this->replace( self::LOCAL_CFG_ROOT_PWD, $rootPwd );
722 }
723}
$result
global $bearsamppLang
global $bearsamppRoot
static exec($basename, $content, $timeout=true, $catchOutput=true, $standalone=false, $silent=true, $rebuild=true)
static initializePostgresql($path)
changePort($port, $checkUsed=false, $wbProgressBar=null)
checkPort($port, $showWindow=false)
setEnable($enabled, $showWindow=false)
switchVersion($version, $showWindow=false)
checkRootPassword($currentPwd=null, $wbProgressBar=null)
changeRootPassword($currentPwd, $newPwd, $wbProgressBar=null)
updateConfig($version=null, $sub=0, $showWindow=false)
reload($id=null, $type=null)
const DISABLED
const ENABLED
const ENABLE_TITLE
const PORT_NOT_USED_BY
const ERROR_FILE_NOT_FOUND
const PORT_USED_BY_ANOTHER_DBMS
const ERROR_INVALID_PARAMETER
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const CHECK_PORT_TITLE
const ENABLE_BUNDLE_NOT_EXIST
const ERROR_CONF_NOT_FOUND
const SWITCH_VERSION_TITLE
const ERROR_EXE_NOT_FOUND
const POSTGRESQL
const PORT_USED_BY
const PORT_NOT_USED
const BEARSAMPP_CONF_MALFORMED_ERROR
update($sub=0, $showWindow=false)
replace($key, $value)
static logReloadClass($classInstance)
static replaceInFile($path, $replaceList)
static logError($data, $file=null)
static isValidPort($port)
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static removeService($service, $name)
static logDebug($data, $file=null)
static logInitClass($classInstance)
static isPortInUse($port)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26
const APP_TITLE
Definition root.php:12