78 $this->enable = $this->enable &&
$bearsamppConfig->getRaw( self::ROOT_CFG_ENABLE );
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] :
'';
96 if ( !$this->enable ) {
97 Log::info( $this->name .
' is not enabled!' );
101 if ( !is_dir( $this->currentPath ) ) {
106 if ( !is_dir( $this->symlinkPath ) ) {
111 if ( !is_file( $this->bearsamppConf ) ) {
116 if ( !file_exists( $this->conf ) ) {
119 if ( !file_exists( $this->hbaConf ) ) {
123 if ( !is_file( $this->ctlExe ) ) {
128 if ( !is_file( $this->cliExe ) ) {
133 if ( !is_file( $this->dumpExe ) ) {
138 if ( !is_file( $this->dumpAllExe ) ) {
143 if ( !is_file( $this->conf ) ) {
148 if ( !is_file( $this->hbaConf ) ) {
153 if ( !is_numeric( $this->port ) || $this->port <= 0 ) {
158 if ( empty( $this->rootUser ) ) {
165 $this->service->setBinPath( $this->ctlExe );
177 $content = file_get_contents( $this->bearsamppConf );
179 foreach ( $params as $key => $value ) {
180 $content = preg_replace(
'|' . $key .
' = .*|', $key .
' = ' .
'"' . $value .
'"', $content );
181 $this->bearsamppConfRaw[$key] = $value;
183 case self::LOCAL_CFG_PORT:
184 $this->port = $value;
186 case self::LOCAL_CFG_ROOT_USER:
187 $this->rootUser = $value;
189 case self::LOCAL_CFG_ROOT_PWD:
190 $this->rootPwd = $value;
195 file_put_contents( $this->bearsamppConf, $content );
254 $dbLink = @pg_connect(
"host=127.0.0.1 port=$port user={$this->rootUser} password={$this->rootPwd}");
256 $lastError = error_get_last();
257 $errorMsg = $lastError ? $lastError[
'message'] :
'Unknown error';
263 $connectionStatus = pg_connection_status($dbLink);
264 $isPostgres = $connectionStatus === PGSQL_CONNECTION_OK;
270 $bearsamppWinbinder->messageBoxInfo(
319 global $bearsamppWinbinder;
322 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
323 $dbLink = pg_connect(
'host=127.0.0.1 port=' . $this->port .
' user=' . $this->rootUser .
' password=' . $currentPwd );
326 $error = error_get_last()[
'message'];
329 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
330 $pgr = pg_query_params( $dbLink,
'SELECT quote_ident($1)', array(pg_escape_string( $this->rootUser )) );
331 list( $quoted_user ) = pg_fetch_array( $pgr );
332 $password = pg_escape_string( $newPwd );
333 $result = pg_query( $dbLink,
"ALTER USER $quoted_user WITH PASSWORD '$password'" );
334 if ( empty( $error ) && !
$result ) {
335 $error = pg_last_error( $dbLink );
338 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
343 if ( !empty( $error ) ) {
348 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
353 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
418 if ( !$this->enable ) {
423 Log::debug( ($sub > 0 ? str_repeat(
' ', 2 * $sub ) :
'') .
'Update ' . $this->name .
' ' .
$version .
' config' );
436 Log::error(
'bearsampp config files not found for ' . $this->
getName() .
' ' . $version );
438 $bearsamppWinbinder->messageBoxError(
449 Log::error(
'bearsampp config file malformed for ' . $this->
getName() .
' ' . $version );
451 $bearsamppWinbinder->messageBoxError(
465 '/^port(.*?)=(.*?)(\d+)/' =>
'port = ' . $this->port
469 $bearsamppApps->getPhppgadmin()->update( $sub + 1 );