82 $this->enable = $this->enable &&
$bearsamppConfig->getRaw( self::ROOT_CFG_ENABLE );
84 $this->modulesPath = $this->symlinkPath .
'/modules';
85 $this->sslConf = $this->symlinkPath .
'/conf/extra/httpd-ssl.conf';
86 $this->accessLog =
$bearsamppRoot->getLogsPath() .
'/apache_access.log';
87 $this->rewriteLog =
$bearsamppRoot->getLogsPath() .
'/apache_rewrite.log';
88 $this->errorLog =
$bearsamppRoot->getLogsPath() .
'/apache_error.log';
90 if ( $this->bearsamppConfRaw !==
false ) {
91 $this->exe = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
92 $this->conf = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
93 $this->port = $this->bearsamppConfRaw[self::LOCAL_CFG_PORT];
94 $this->sslPort = $this->bearsamppConfRaw[self::LOCAL_CFG_SSL_PORT];
95 $this->opensslExe = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_OPENSSL_EXE];
98 if ( !$this->enable ) {
103 if ( !is_dir( $this->currentPath ) ) {
108 if ( !is_dir( $this->symlinkPath ) ) {
113 if ( !is_file( $this->bearsamppConf ) ) {
118 if ( !is_file( $this->sslConf ) ) {
123 if ( !is_file( $this->exe ) ) {
128 if ( !is_file( $this->conf ) ) {
133 if ( !is_numeric( $this->port ) || $this->port <= 0 ) {
138 if ( !is_numeric( $this->sslPort ) || $this->sslPort <= 0 ) {
143 if ( !is_file( $this->opensslExe ) ) {
149 $nssm =
new Nssm( self::SERVICE_NAME );
151 $nssm->setBinPath( $this->exe );
154 $this->service->setNssm( $nssm );
164 $content = file_get_contents( $this->bearsamppConf );
166 foreach ( $params as $key => $value ) {
167 $content = preg_replace(
'|' . $key .
' = .*|', $key .
' = ' .
'"' . $value .
'"', $content );
168 $this->bearsamppConfRaw[$key] = $value;
170 case self::LOCAL_CFG_PORT:
171 $this->port = $value;
173 case self::LOCAL_CFG_SSL_PORT:
174 $this->sslPort = $value;
179 file_put_contents( $this->bearsamppConf, $content );
193 global $bearsamppWinbinder;
202 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
205 if ( !$checkUsed || $isPortInUse ===
false ) {
208 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
212 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
243 if ( !empty( $headers ) ) {
244 foreach ( $headers as $row ) {
246 Util::logDebug( $this->
getName() .
' port ' .
$port .
' is used by: ' . $this->
getName() .
' ' . str_replace(
'Server: ',
'', str_replace(
'server: ',
'', trim( $row ) ) ) );
248 $bearsamppWinbinder->messageBoxInfo(
259 $bearsamppWinbinder->messageBoxWarning(
268 $bearsamppWinbinder->messageBoxError(
306 if ( !$this->enable ) {
311 Util::logDebug( ($sub > 0 ? str_repeat(
' ', 2 * $sub ) :
'') .
'Update ' . $this->name .
' ' .
$version .
' config' );
320 $apachePhpModuleName =
null;
321 if ( $tsDll !==
false ) {
322 $apachemoduleNamePrefix = substr( $tsDll, 0, 4 );
323 $apachePhpModuleName = ($apachemoduleNamePrefix ==
'php8' ?
'php' : $apachemoduleNamePrefix) .
'_module';
326 $apachePhpModuleDll = basename( $apachePhpModulePath );
328 Util::logDebug( ($sub > 0 ? str_repeat(
' ', 2 * $sub ) :
'') .
'PHP TsDll found: ' . $tsDll );
329 Util::logDebug( ($sub > 0 ? str_repeat(
' ', 2 * $sub ) :
'') .
'PHP Apache module found: ' . $apachePhpModulePath );
334 $bearsamppWinbinder->messageBoxError(
347 $bearsamppWinbinder->messageBoxError(
356 if ( $tsDll ===
false || $apachePhpModulePath ===
false ) {
359 $bearsamppWinbinder->messageBoxError(
375 '/^#?PHPIniDir\s.*/' => (
$bearsamppBins->getPhp()->isEnable() ?
'' :
'#') .
'PHPIniDir "' .
$bearsamppBins->getPhp()->getSymlinkPath() .
'"',
376 '/^#?LoadFile\s.*php.ts\.dll.*/' => (
$bearsamppBins->getPhp()->isEnable() ?
'' :
'#') . (!file_exists(
$bearsamppBins->getPhp()->getSymlinkPath() .
'/' . $tsDll ) ?
'#' :
'') .
'LoadFile "' .
$bearsamppBins->getPhp()->getSymlinkPath() .
'/' . $tsDll .
'"',
377 '/^#?LoadModule\sphp.*/' => (
$bearsamppBins->getPhp()->isEnable() ?
'' :
'#') .
'LoadModule ' . $apachePhpModuleName .
' "' .
$bearsamppBins->getPhp()->getSymlinkPath() .
'/' . $apachePhpModuleDll .
'"',
378 '/^#?LoadModule\sphp_*/' => (
$bearsamppBins->getPhp()->isEnable() ?
'' :
'#') .
'LoadModule ' . $apachePhpModuleName .
' "' .
$bearsamppBins->getPhp()->getSymlinkPath() .
'/' . $apachePhpModuleDll .
'"',
382 '/^Listen\s(\d+)/' =>
'Listen ' . $this->port,
383 '/^ServerName\s+([a-zA-Z0-9.]+):(\d+)/' =>
'ServerName {{1}}:' . $this->port,
384 '/^NameVirtualHost\s+([a-zA-Z0-9.*]+):(\d+)/' =>
'NameVirtualHost {{1}}:' . $this->port,
385 '/^<VirtualHost\s+([a-zA-Z0-9.*]+):(\d+)>/' =>
'<VirtualHost {{1}}:' . $this->port .
'>'
389 foreach ( $this->
getVhosts() as $vhost ) {
391 '/^<VirtualHost\s+([a-zA-Z0-9.*]+):(\d+)>$/' =>
'<VirtualHost {{1}}:' . $this->port .
'>$'
397 '/(.*)http:\/\/localhost(.*)/' =>
'{{1}}http://localhost' . ($this->port != 80 ?
':' . $this->port :
'') .
'/$1 [QSA,R=301,L]',
412 $result = array_merge( $fromFolder, $fromConf );
427 if ( !$this->enable ) {
431 $confContent = file( $this->
getConf() );
432 foreach ( $confContent as $row ) {
434 if ( preg_match(
'/^(#)?LoadModule\s*([a-z0-9_-]+)\s*"?(.*)"?/i', $row, $modMatch ) ) {
435 $name = $modMatch[2];
438 if ( $modMatch[1] ==
'#' ) {
479 if ( !$this->enable ) {
488 while (
false !== ($file = readdir( $handle )) ) {
490 $name = str_replace( array(
'mod_',
'.so',
'.dll'),
'', $file ) .
'_module';
516 while (
false !== ($file = readdir( $handle )) ) {
517 if ( $file !=
'.' && $file !=
'..' &&
Util::endWith( $file,
'.conf' ) ) {
518 $result[] = str_replace(
'.conf',
'', $file );
543 while (
false !== ($file = readdir( $handle )) ) {
544 if ( $file !=
'.' && $file !=
'..' &&
Util::endWith( $file,
'.conf' ) ) {
545 $result[] = str_replace(
'.conf',
'', $file );
565 foreach ( $this->
getVhosts() as $vhost ) {
566 $vhostContent = file(
$bearsamppRoot->getVhostsPath() .
'/' . $vhost .
'.conf' );
567 foreach ( $vhostContent as $vhostLine ) {
568 $vhostLine = trim( $vhostLine );
570 if ( preg_match_all(
'/ServerName\s+(.*)/', $vhostLine, $matches ) ) {
571 foreach ( $matches as $match ) {
572 $found = isset( $match[1] ) ? trim( $match[1] ) : trim( $match[0] );
573 if ( filter_var(
'http://' . $found, FILTER_VALIDATE_URL ) !==
false ) {
600 while (
false !== ($file = readdir( $handle )) ) {
601 if ( $file !=
'.' && $file !=
'..' && is_dir(
$bearsamppRoot->getWwwPath() .
'/' . $file ) ) {
626 if ( file_exists( $this->
getExe() ) ) {
627 $tmpResult =
Batch::exec(
'apacheGetCmdLineOutput',
'"' . $this->
getExe() .
'" ' . $cmd );
628 if ( $tmpResult !==
false && is_array( $tmpResult ) ) {
629 $result[
'syntaxOk'] = trim( $tmpResult[count( $tmpResult ) - 1] ) ==
'Syntax OK';
631 unset( $tmpResult[count( $tmpResult ) - 1] );
633 $result[
'content'] = implode( PHP_EOL, $tmpResult );
650 $result = self::TAG_START_SWITCHONLINE . PHP_EOL;
653 $result .=
'Require all granted' . PHP_EOL;
656 $result .=
'Order Allow,Deny' . PHP_EOL .
657 'Allow from all' . PHP_EOL;
660 return $result . self::TAG_END_SWITCHONLINE;
673 $result = self::TAG_START_SWITCHONLINE . PHP_EOL;
676 $result .=
'Require local' . PHP_EOL;
679 $result .=
'Order Deny,Allow' . PHP_EOL .
680 'Deny from all' . PHP_EOL .
681 'Allow from 127.0.0.1 ::1' . PHP_EOL;
684 return $result . self::TAG_END_SWITCHONLINE;
713 return 'Alias /' .
$name .
' "' . $dest .
'"' . PHP_EOL . PHP_EOL .
714 '<Directory "' . $dest .
'">' . PHP_EOL .
715 ' Options Indexes FollowSymLinks MultiViews' . PHP_EOL .
716 ' AllowOverride all' . PHP_EOL .
718 '</Directory>' . PHP_EOL;
735 return '<VirtualHost *:' . $this->
getPort() .
'>' . PHP_EOL .
736 ' ServerAdmin webmaster@' . $serverName . PHP_EOL .
737 ' DocumentRoot "' . $documentRoot .
'"' . PHP_EOL .
738 ' ServerName ' . $serverName . PHP_EOL .
739 ' ErrorLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_error.log"' . PHP_EOL .
740 ' CustomLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_access.log" combined' . PHP_EOL . PHP_EOL .
741 ' <Directory "' . $documentRoot .
'">' . PHP_EOL .
742 ' Options Indexes FollowSymLinks MultiViews' . PHP_EOL .
743 ' AllowOverride all' . PHP_EOL .
745 ' </Directory>' . PHP_EOL .
746 '</VirtualHost>' . PHP_EOL . PHP_EOL .
747 '<IfModule ssl_module>' . PHP_EOL .
748 '<VirtualHost *:' . $this->
getSslPort() .
'> #SSL' . PHP_EOL .
749 ' DocumentRoot "' . $documentRoot .
'"' . PHP_EOL .
750 ' ServerName ' . $serverName . PHP_EOL .
751 ' ServerAdmin webmaster@' . $serverName . PHP_EOL .
752 ' ErrorLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_error.log"' . PHP_EOL .
753 ' TransferLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_access.log"' . PHP_EOL . PHP_EOL .
754 ' SSLEngine on' . PHP_EOL .
755 ' SSLProtocol all -SSLv2' . PHP_EOL .
756 ' SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5' . PHP_EOL .
757 ' SSLCertificateFile "' .
$bearsamppRoot->getSslPath() .
'/' . $serverName .
'.crt"' . PHP_EOL .
758 ' SSLCertificateKeyFile "' .
$bearsamppRoot->getSslPath() .
'/' . $serverName .
'.pub"' . PHP_EOL .
759 ' BrowserMatch "MSIE [2-5]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0' . PHP_EOL .
760 ' CustomLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_sslreq.log" "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"' . PHP_EOL . PHP_EOL .
761 ' <Directory "' . $documentRoot .
'">' . PHP_EOL .
762 ' SSLOptions +StdEnvVars' . PHP_EOL .
763 ' Options Indexes FollowSymLinks MultiViews' . PHP_EOL .
764 ' AllowOverride all' . PHP_EOL .
766 ' </Directory>' . PHP_EOL .
767 '</VirtualHost>' . PHP_EOL .
768 '</IfModule>' . PHP_EOL;
778 if ( !$this->enable ) {
787 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s',
$conf, $matches );
788 Util::logTrace( isset( $matches[1] ) ? print_r( $matches[1],
true ) :
'N/A' );
791 $conf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent,
$conf, -1, $count );
794 $conf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent,
$conf, -1, $count );
801 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s',
$sslConf, $matches );
802 Util::logTrace( isset( $matches[1] ) ? print_r( $matches[1],
true ) :
'N/A' );
805 $sslConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent,
$sslConf, -1, $count );
808 $sslConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent,
$sslConf, -1, $count );
823 if ( !$this->enable ) {
830 foreach ( $this->
getAlias() as $alias ) {
831 $aliasConf = file_get_contents(
$bearsamppRoot->getAliasPath() .
'/' . $alias .
'.conf' );
833 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $aliasConf, $matches );
834 Util::logTrace( isset( $matches[1] ) ? print_r( $matches[1],
true ) :
'N/A' );
837 $aliasConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent, $aliasConf, -1, $count );
840 $aliasConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent, $aliasConf, -1, $count );
842 file_put_contents(
$bearsamppRoot->getAliasPath() .
'/' . $alias .
'.conf', $aliasConf );
859 if ( !$this->enable ) {
866 foreach ( $this->
getVhosts() as $vhost ) {
867 $vhostConf = file_get_contents(
$bearsamppRoot->getVhostsPath() .
'/' . $vhost .
'.conf' );
869 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $vhostConf, $matches );
870 Util::logTrace( isset( $matches[1] ) ? print_r( $matches[1],
true ) :
'N/A' );
873 $vhostConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent, $vhostConf, -1, $count );
876 $vhostConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent, $vhostConf, -1, $count );
878 file_put_contents(
$bearsamppRoot->getVhostsPath() .
'/' . $vhost .
'.conf', $vhostConf );
893 public function setEnable($enabled, $showWindow =
false)
900 $bearsamppWinbinder->messageBoxError(
913 if ( $this->enable ) {
static exec($basename, $content, $timeout=true, $catchOutput=true, $standalone=false, $silent=true, $rebuild=true)
const TAG_START_SWITCHONLINE
const CMD_CONFIG_DIRECTIVES
getRequiredContent($version=null)
getOnlineContent($version=null)
updateConfig($version=null, $sub=0, $showWindow=false)
getAliasContent($name, $dest)
const CMD_COMPILE_SETTINGS
switchVersion($version, $showWindow=false)
const CMD_COMPILED_MODULES
changePort($port, $checkUsed=false, $wbProgressBar=null)
setEnable($enabled, $showWindow=false)
checkPort($port, $ssl=false, $showWindow=false)
const TAG_END_SWITCHONLINE
getVhostContent($serverName, $documentRoot)
const LOCAL_CFG_OPENSSL_EXE
reload($id=null, $type=null)
getOfflineContent($version=null)
const CMD_VHOSTS_SETTINGS
refreshVhosts($putOnline)
const ENABLE_BUNDLE_NOT_EXIST
const BEARSAMPP_CONF_MALFORMED_ERROR
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const ERROR_INVALID_PARAMETER
const SWITCH_VERSION_TITLE
const ERROR_FILE_NOT_FOUND
update($sub=0, $showWindow=false)
const SERVICE_DEMAND_START
static logError($data, $file=null)
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static logInitClass($classInstance)
static removeService($service, $name)
static logTrace($data, $file=null)
static isValidPort($port)
static logInfo($data, $file=null)
static getHttpHeaders($pingUrl)
static logDebug($data, $file=null)
static logReloadClass($classInstance)
static startWith($string, $search)
static endWith($string, $search)
static formatUnixPath($path)
static isPortInUse($port)
static replaceInFile($path, $replaceList)
global $bearsamppHomepage