81 $this->enable = $this->enable &&
$bearsamppConfig->getRaw( self::ROOT_CFG_ENABLE );
83 $this->modulesPath = $this->symlinkPath .
'/modules';
84 $this->sslConf = $this->symlinkPath .
'/conf/extra/httpd-ssl.conf';
85 $this->accessLog =
$bearsamppRoot->getLogsPath() .
'/apache_access.log';
86 $this->rewriteLog =
$bearsamppRoot->getLogsPath() .
'/apache_rewrite.log';
87 $this->errorLog =
$bearsamppRoot->getLogsPath() .
'/apache_error.log';
89 if ( $this->bearsamppConfRaw !==
false ) {
97 if ( !$this->enable ) {
102 if ( !is_dir( $this->currentPath ) ) {
107 if ( !is_dir( $this->symlinkPath ) ) {
112 if ( !is_file( $this->bearsamppConf ) ) {
117 if ( !is_file( $this->sslConf ) ) {
122 if ( !is_file( $this->exe ) ) {
127 if ( !is_file( $this->conf ) ) {
132 if ( !is_numeric( $this->port ) || $this->port <= 0 ) {
137 if ( !is_numeric( $this->sslPort ) || $this->sslPort <= 0 ) {
142 if ( !is_file( $this->opensslExe ) ) {
148 $nssm =
new Nssm( self::SERVICE_NAME );
150 $nssm->setBinPath( $this->exe );
153 $this->service->setNssm( $nssm );
163 $content = file_get_contents( $this->bearsamppConf );
165 foreach ( $params as $key => $value ) {
166 $content = preg_replace(
'|' . $key .
' = .*|', $key .
' = ' .
'"' . $value .
'"', $content );
167 $this->bearsamppConfRaw[$key] = $value;
170 $this->port = $value;
173 $this->sslPort = $value;
178 file_put_contents( $this->bearsamppConf, $content );
192 global $bearsamppWinbinder;
201 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
204 if ( !$checkUsed || $isPortInUse ===
false ) {
207 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
211 $bearsamppWinbinder->incrProgressBar( $wbProgressBar );
242 if ( !empty( $headers ) ) {
243 foreach ( $headers as $row ) {
245 Util::logDebug( $this->
getName() .
' port ' .
$port .
' is used by: ' . $this->
getName() .
' ' . str_replace(
'Server: ',
'', str_replace(
'server: ',
'', trim( $row ) ) ) );
247 $bearsamppWinbinder->messageBoxInfo(
258 $bearsamppWinbinder->messageBoxWarning(
267 $bearsamppWinbinder->messageBoxError(
305 if ( !$this->enable ) {
310 Util::logDebug( ($sub > 0 ? str_repeat(
' ', 2 * $sub ) :
'') .
'Update ' . $this->name .
' ' .
$version .
' config' );
319 $apachePhpModuleName =
null;
320 if ( $tsDll !==
false ) {
321 $apachemoduleNamePrefix = substr( $tsDll, 0, 4 );
322 $apachePhpModuleName = ($apachemoduleNamePrefix ==
'php8' ?
'php' : $apachemoduleNamePrefix) .
'_module';
325 $apachePhpModuleDll = basename( $apachePhpModulePath );
327 Util::logDebug( ($sub > 0 ? str_repeat(
' ', 2 * $sub ) :
'') .
'PHP TsDll found: ' . $tsDll );
328 Util::logDebug( ($sub > 0 ? str_repeat(
' ', 2 * $sub ) :
'') .
'PHP Apache module found: ' . $apachePhpModulePath );
333 $bearsamppWinbinder->messageBoxError(
346 $bearsamppWinbinder->messageBoxError(
355 if ( $tsDll ===
false || $apachePhpModulePath ===
false ) {
358 $bearsamppWinbinder->messageBoxError(
374 '/^#?PHPIniDir\s.*/' => (
$bearsamppBins->getPhp()->isEnable() ?
'' :
'#') .
'PHPIniDir "' .
$bearsamppBins->getPhp()->getSymlinkPath() .
'"',
375 '/^#?LoadFile\s.*php.ts\.dll.*/' => (
$bearsamppBins->getPhp()->isEnable() ?
'' :
'#') . (!file_exists(
$bearsamppBins->getPhp()->getSymlinkPath() .
'/' . $tsDll ) ?
'#' :
'') .
'LoadFile "' .
$bearsamppBins->getPhp()->getSymlinkPath() .
'/' . $tsDll .
'"',
376 '/^#?LoadModule\sphp.*/' => (
$bearsamppBins->getPhp()->isEnable() ?
'' :
'#') .
'LoadModule ' . $apachePhpModuleName .
' "' .
$bearsamppBins->getPhp()->getSymlinkPath() .
'/' . $apachePhpModuleDll .
'"',
377 '/^#?LoadModule\sphp_*/' => (
$bearsamppBins->getPhp()->isEnable() ?
'' :
'#') .
'LoadModule ' . $apachePhpModuleName .
' "' .
$bearsamppBins->getPhp()->getSymlinkPath() .
'/' . $apachePhpModuleDll .
'"',
382 '/^ServerName\s+([a-zA-Z0-9.]+):(\d+)/' =>
'ServerName {{1}}:' .
$this->port,
383 '/^NameVirtualHost\s+([a-zA-Z0-9.*]+):(\d+)/' =>
'NameVirtualHost {{1}}:' .
$this->port,
384 '/^<VirtualHost\s+([a-zA-Z0-9.*]+):(\d+)>/' =>
'<VirtualHost {{1}}:' . $this->port .
'>'
388 foreach ( $this->
getVhosts() as $vhost ) {
390 '/^<VirtualHost\s+([a-zA-Z0-9.*]+):(\d+)>$/' =>
'<VirtualHost {{1}}:' . $this->port .
'>$'
396 '/(.*)http:\/\/localhost(.*)/' =>
'{{1}}http://localhost' . ($this->port != 80 ?
':' . $this->port :
'') .
'/$1 [QSA,R=301,L]',
411 $result = array_merge( $fromFolder, $fromConf );
426 if ( !$this->enable ) {
430 $confContent = file( $this->
getConf() );
431 foreach ( $confContent as $row ) {
433 if ( preg_match(
'/^(#)?LoadModule\s*([a-z0-9_-]+)\s*"?(.*)"?/i', $row, $modMatch ) ) {
434 $name = $modMatch[2];
437 if ( $modMatch[1] ==
'#' ) {
478 if ( !$this->enable ) {
487 while (
false !== ($file = readdir( $handle )) ) {
489 $name = str_replace( array(
'mod_',
'.so',
'.dll'),
'', $file ) .
'_module';
515 while (
false !== ($file = readdir( $handle )) ) {
516 if ( $file !=
'.' && $file !=
'..' &&
Util::endWith( $file,
'.conf' ) ) {
517 $result[] = str_replace(
'.conf',
'', $file );
542 while (
false !== ($file = readdir( $handle )) ) {
543 if ( $file !=
'.' && $file !=
'..' &&
Util::endWith( $file,
'.conf' ) ) {
544 $result[] = str_replace(
'.conf',
'', $file );
564 foreach ( $this->
getVhosts() as $vhost ) {
565 $vhostContent = file(
$bearsamppRoot->getVhostsPath() .
'/' . $vhost .
'.conf' );
566 foreach ( $vhostContent as $vhostLine ) {
567 $vhostLine = trim( $vhostLine );
569 if ( preg_match_all(
'/ServerName\s+(.*)/', $vhostLine, $matches ) ) {
570 foreach ( $matches as $match ) {
571 $found = isset( $match[1] ) ? trim( $match[1] ) : trim( $match[0] );
572 if ( filter_var(
'http://' . $found, FILTER_VALIDATE_URL ) !==
false ) {
599 while (
false !== ($file = readdir( $handle )) ) {
600 if ( $file !=
'.' && $file !=
'..' && is_dir(
$bearsamppRoot->getWwwPath() .
'/' . $file ) ) {
625 if ( file_exists( $this->
getExe() ) ) {
626 $tmpResult =
Batch::exec(
'apacheGetCmdLineOutput',
'"' . $this->
getExe() .
'" ' . $cmd );
627 if ( $tmpResult !==
false && is_array( $tmpResult ) ) {
628 $result[
'syntaxOk'] = trim( $tmpResult[count( $tmpResult ) - 1] ) ==
'Syntax OK';
630 unset( $tmpResult[count( $tmpResult ) - 1] );
632 $result[
'content'] = implode( PHP_EOL, $tmpResult );
649 $result = self::TAG_START_SWITCHONLINE . PHP_EOL;
652 $result .=
'Require all granted' . PHP_EOL;
655 $result .=
'Order Allow,Deny' . PHP_EOL .
656 'Allow from all' . PHP_EOL;
672 $result = self::TAG_START_SWITCHONLINE . PHP_EOL;
675 $result .=
'Require local' . PHP_EOL;
678 $result .=
'Order Deny,Allow' . PHP_EOL .
679 'Deny from all' . PHP_EOL .
680 'Allow from 127.0.0.1 ::1' . PHP_EOL;
712 return 'Alias /' .
$name .
' "' . $dest .
'"' . PHP_EOL . PHP_EOL .
713 '<Directory "' . $dest .
'">' . PHP_EOL .
714 ' Options Indexes FollowSymLinks MultiViews' . PHP_EOL .
715 ' AllowOverride all' . PHP_EOL .
717 '</Directory>' . PHP_EOL;
734 return '<VirtualHost *:' . $this->
getPort() .
'>' . PHP_EOL .
735 ' ServerAdmin webmaster@' . $serverName . PHP_EOL .
736 ' DocumentRoot "' . $documentRoot .
'"' . PHP_EOL .
737 ' ServerName ' . $serverName . PHP_EOL .
738 ' ErrorLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_error.log"' . PHP_EOL .
739 ' CustomLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_access.log" combined' . PHP_EOL . PHP_EOL .
740 ' <Directory "' . $documentRoot .
'">' . PHP_EOL .
741 ' Options Indexes FollowSymLinks MultiViews' . PHP_EOL .
742 ' AllowOverride all' . PHP_EOL .
744 ' </Directory>' . PHP_EOL .
745 '</VirtualHost>' . PHP_EOL . PHP_EOL .
746 '<IfModule ssl_module>' . PHP_EOL .
747 '<VirtualHost *:' . $this->
getSslPort() .
'> #SSL' . PHP_EOL .
748 ' DocumentRoot "' . $documentRoot .
'"' . PHP_EOL .
749 ' ServerName ' . $serverName . PHP_EOL .
750 ' ServerAdmin webmaster@' . $serverName . PHP_EOL .
751 ' ErrorLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_error.log"' . PHP_EOL .
752 ' TransferLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_access.log"' . PHP_EOL . PHP_EOL .
753 ' SSLEngine on' . PHP_EOL .
754 ' SSLProtocol all -SSLv2' . PHP_EOL .
755 ' SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5' . PHP_EOL .
756 ' SSLCertificateFile "' .
$bearsamppRoot->getSslPath() .
'/' . $serverName .
'.crt"' . PHP_EOL .
757 ' SSLCertificateKeyFile "' .
$bearsamppRoot->getSslPath() .
'/' . $serverName .
'.pub"' . PHP_EOL .
758 ' BrowserMatch "MSIE [2-5]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0' . PHP_EOL .
759 ' CustomLog "' .
$bearsamppRoot->getLogsPath() .
'/' . $serverName .
'_sslreq.log" "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"' . PHP_EOL . PHP_EOL .
760 ' <Directory "' . $documentRoot .
'">' . PHP_EOL .
761 ' SSLOptions +StdEnvVars' . PHP_EOL .
762 ' Options Indexes FollowSymLinks MultiViews' . PHP_EOL .
763 ' AllowOverride all' . PHP_EOL .
765 ' </Directory>' . PHP_EOL .
766 '</VirtualHost>' . PHP_EOL .
767 '</IfModule>' . PHP_EOL;
777 if ( !$this->enable ) {
786 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s',
$conf, $matches );
787 Util::logTrace( isset( $matches[1] ) ? print_r( $matches[1],
true ) :
'N/A' );
790 $conf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent,
$conf, -1, $count );
793 $conf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent,
$conf, -1, $count );
800 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s',
$sslConf, $matches );
801 Util::logTrace( isset( $matches[1] ) ? print_r( $matches[1],
true ) :
'N/A' );
804 $sslConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent,
$sslConf, -1, $count );
807 $sslConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent,
$sslConf, -1, $count );
822 if ( !$this->enable ) {
829 foreach ( $this->
getAlias() as $alias ) {
830 $aliasConf = file_get_contents(
$bearsamppRoot->getAliasPath() .
'/' . $alias .
'.conf' );
832 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $aliasConf, $matches );
833 Util::logTrace( isset( $matches[1] ) ? print_r( $matches[1],
true ) :
'N/A' );
836 $aliasConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent, $aliasConf, -1, $count );
839 $aliasConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent, $aliasConf, -1, $count );
841 file_put_contents(
$bearsamppRoot->getAliasPath() .
'/' . $alias .
'.conf', $aliasConf );
858 if ( !$this->enable ) {
865 foreach ( $this->
getVhosts() as $vhost ) {
866 $vhostConf = file_get_contents(
$bearsamppRoot->getVhostsPath() .
'/' . $vhost .
'.conf' );
868 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $vhostConf, $matches );
869 Util::logTrace( isset( $matches[1] ) ? print_r( $matches[1],
true ) :
'N/A' );
872 $vhostConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent, $vhostConf, -1, $count );
875 $vhostConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent, $vhostConf, -1, $count );
877 file_put_contents(
$bearsamppRoot->getVhostsPath() .
'/' . $vhost .
'.conf', $vhostConf );
892 public function setEnable($enabled, $showWindow =
false)
899 $bearsamppWinbinder->messageBoxError(
912 if ( $this->enable ) {
static exec($basename, $content, $timeout=true, $catchOutput=true, $standalone=false, $silent=true, $rebuild=true)
changePort($port, $checkUsed=false, $wbProgressBar=null)
switchVersion($version, $showWindow=false)
getAliasContent($name, $dest)
reload($id=null, $type=null)
getOfflineContent($version=null)
const CMD_VHOSTS_SETTINGS
setEnable($enabled, $showWindow=false)
updateConfig($version=null, $sub=0, $showWindow=false)
getVhostContent($serverName, $documentRoot)
refreshVhosts($putOnline)
getRequiredContent($version=null)
getOnlineContent($version=null)
const TAG_END_SWITCHONLINE
const TAG_START_SWITCHONLINE
checkPort($port, $ssl=false, $showWindow=false)
const CMD_CONFIG_DIRECTIVES
const CMD_COMPILE_SETTINGS
const LOCAL_CFG_OPENSSL_EXE
const CMD_COMPILED_MODULES
const ERROR_FILE_NOT_FOUND
const ERROR_INVALID_PARAMETER
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const ENABLE_BUNDLE_NOT_EXIST
const ERROR_CONF_NOT_FOUND
const SWITCH_VERSION_TITLE
const ERROR_EXE_NOT_FOUND
const BEARSAMPP_CONF_MALFORMED_ERROR
update($sub=0, $showWindow=false)
const SERVICE_DEMAND_START
static startWith($string, $search)
static logReloadClass($classInstance)
static getHttpHeaders($pingUrl)
static replaceInFile($path, $replaceList)
static logError($data, $file=null)
static endWith($string, $search)
static isValidPort($port)
static formatUnixPath($path)
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)
static logTrace($data, $file=null)
global $bearsamppHomepage