169 $this->enable = $this->enable &&
$bearsamppConfig->getRaw(self::ROOT_CFG_ENABLE);
171 $this->modulesPath = $this->symlinkPath .
'/modules';
172 $this->sslConf = $this->symlinkPath .
'/conf/extra/httpd-ssl.conf';
177 if ($this->bearsamppConfRaw !==
false) {
178 $this->exe = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
179 $this->conf = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
180 $this->port = $this->bearsamppConfRaw[self::LOCAL_CFG_PORT];
181 $this->sslPort = $this->bearsamppConfRaw[self::LOCAL_CFG_SSL_PORT];
182 $this->opensslExe = $this->symlinkPath .
'/' . $this->bearsamppConfRaw[self::LOCAL_CFG_OPENSSL_EXE];
185 if (!$this->enable) {
186 Log::info($this->name .
' is not enabled!');
190 if (!is_dir($this->currentPath)) {
195 if (!is_dir($this->symlinkPath)) {
200 if (!is_file($this->bearsamppConf)) {
205 if (!is_file($this->sslConf)) {
210 if (!is_file($this->exe)) {
215 if (!is_file($this->conf)) {
220 if (!is_numeric($this->port) || $this->port <= 0) {
225 if (!is_numeric($this->sslPort) || $this->sslPort <= 0) {
230 if (!is_file($this->opensslExe)) {
236 $nssm =
new Nssm(self::SERVICE_NAME);
238 $nssm->setBinPath($this->exe);
239 $nssm->setParams(
'');
242 $this->service->setNssm($nssm);
252 $content = file_get_contents($this->bearsamppConf);
254 foreach ($params as $key => $value) {
255 $content = preg_replace(
'|' . $key .
' = .*|', $key .
' = ' .
'"' . $value .
'"', $content);
256 $this->bearsamppConfRaw[$key] = $value;
258 case self::LOCAL_CFG_PORT:
259 $this->port = $value;
261 case self::LOCAL_CFG_SSL_PORT:
262 $this->sslPort = $value;
267 file_put_contents($this->bearsamppConf, $content);
283 global $bearsamppWinbinder;
292 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
295 if (!$checkUsed || $isPortInUse ===
false) {
298 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
302 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
335 if (!empty($headers)) {
336 foreach ($headers as $row) {
339 $this->
getName() .
' port ' .
$port .
' is used by: ' . $this->
getName() .
' ' . str_replace(
'Server: ',
'', str_replace(
'server: ',
'', trim($row)))
342 $bearsamppWinbinder->messageBoxInfo(
353 $bearsamppWinbinder->messageBoxWarning(
361 $bearsamppWinbinder->messageBoxError(
399 if (!$this->enable) {
404 Log::debug(($sub > 0 ? str_repeat(
' ', 2 * $sub) :
'') .
'Update ' . $this->name .
' ' .
$version .
' config');
413 $apachePhpModuleName =
null;
414 if ($tsDll !==
false) {
415 $apachemoduleNamePrefix = substr($tsDll, 0, 4);
416 $apachePhpModuleName = ($apachemoduleNamePrefix ==
'php8' ?
'php' : $apachemoduleNamePrefix) .
'_module';
419 $apachePhpModuleDll = basename($apachePhpModulePath);
421 Log::debug(($sub > 0 ? str_repeat(
' ', 2 * $sub) :
'') .
'PHP TsDll found: ' . $tsDll);
422 Log::debug(($sub > 0 ? str_repeat(
' ', 2 * $sub) :
'') .
'PHP Apache module found: ' . $apachePhpModulePath);
425 Log::error(
'bearsampp config files not found for ' . $this->
getName() .
' ' . $version);
427 $bearsamppWinbinder->messageBoxError(
438 Log::error(
'bearsampp config file malformed for ' . $this->
getName() .
' ' . $version);
440 $bearsamppWinbinder->messageBoxError(
449 if ($tsDll ===
false || $apachePhpModulePath ===
false) {
452 $bearsamppWinbinder->messageBoxError(
471 '/^#?LoadFile\s.*php.ts\.dll.*/' => (
$bearsamppBins->getPhp()->isEnable() ?
'' :
'#') . (!file_exists(
477 ) .
'/' . $apachePhpModuleDll .
'"',
481 ) .
'/' . $apachePhpModuleDll .
'"',
485 '/^Listen\s(\d+)/' =>
'Listen ' . $this->port,
486 '/^ServerName\s+([a-zA-Z0-9.]+):(\d+)/' =>
'ServerName {{1}}:' . $this->port,
487 '/^NameVirtualHost\s+([a-zA-Z0-9.*]+):(\d+)/' =>
'NameVirtualHost {{1}}:' . $this->port,
488 '/^<VirtualHost\s+([a-zA-Z0-9.*]+):(\d+)>/' =>
'<VirtualHost {{1}}:' . $this->port .
'>'
494 '/^<VirtualHost\s+([a-zA-Z0-9.*]+):(\d+)>$/' =>
'<VirtualHost {{1}}:' . $this->port .
'>$'
500 '/(.*)http:\/\/localhost(.*)/' =>
'{{1}}http://localhost' . ($this->port != 80 ?
':' . $this->port :
'') .
'/$1 [QSA,R=301,L]',
515 $result = array_merge($fromFolder, $fromConf);
530 if (!$this->enable) {
534 $confContent = file($this->
getConf());
535 foreach ($confContent as $row) {
537 if (preg_match(
'/^(#)?LoadModule\s*([a-z0-9_-]+)\s*"?(.*)"?/i', $row, $modMatch)) {
538 $name = $modMatch[2];
541 if ($modMatch[1] ==
'#') {
581 if (!$this->enable) {
590 while (
false !== ($file = readdir($handle))) {
592 $name = str_replace(array(
'mod_',
'.so',
'.dll'),
'', $file) .
'_module';
618 while (
false !== ($file = readdir($handle))) {
620 $result[] = str_replace(
'.conf',
'', $file);
645 while (
false !== ($file = readdir($handle))) {
647 $result[] = str_replace(
'.conf',
'', $file);
669 foreach ($vhostContent as $vhostLine) {
670 $vhostLine = trim($vhostLine);
672 if (preg_match_all(
'/ServerName\s+(.*)/', $vhostLine, $matches)) {
673 foreach ($matches as $match) {
674 $found = isset($match[1]) ? trim($match[1]) : trim($match[0]);
675 if (filter_var(
'http://' . $found, FILTER_VALIDATE_URL) !==
false) {
702 while (
false !== ($file = readdir($handle))) {
703 if ($file !=
'.' && $file !=
'..' && is_dir(
Path::getWwwPath() .
'/' . $file)) {
728 if (file_exists($this->
getExe())) {
729 $tmpResult =
Batch::exec(
'apacheGetCmdLineOutput',
'"' . $this->
getExe() .
'" ' . $cmd);
730 if ($tmpResult !==
false && is_array($tmpResult)) {
731 $result[
'syntaxOk'] = trim($tmpResult[count($tmpResult) - 1]) ==
'Syntax OK';
733 unset($tmpResult[count($tmpResult) - 1]);
735 $result[
'content'] = implode(PHP_EOL, $tmpResult);
752 $result = self::TAG_START_SWITCHONLINE . PHP_EOL;
755 $result .=
'Require all granted' . PHP_EOL;
757 $result .=
'Order Allow,Deny' . PHP_EOL .
758 'Allow from all' . PHP_EOL;
761 return $result . self::TAG_END_SWITCHONLINE;
774 $result = self::TAG_START_SWITCHONLINE . PHP_EOL;
777 $result .=
'Require local' . PHP_EOL;
779 $result .=
'Order Deny,Allow' . PHP_EOL .
780 'Deny from all' . PHP_EOL .
784 return $result . self::TAG_END_SWITCHONLINE;
813 return 'Alias /' .
$name .
' "' . $dest .
'"' . PHP_EOL . PHP_EOL .
814 '<Directory "' . $dest .
'">' . PHP_EOL .
815 ' Options Indexes FollowSymLinks MultiViews' . PHP_EOL .
816 ' AllowOverride all' . PHP_EOL .
818 '</Directory>' . PHP_EOL;
835 return '<VirtualHost *:' . $this->
getPort() .
'>' . PHP_EOL .
836 ' ServerAdmin webmaster@' . $serverName . PHP_EOL .
837 ' DocumentRoot "' . $documentRoot .
'"' . PHP_EOL .
838 ' ServerName ' . $serverName . PHP_EOL .
839 ' ErrorLog "' .
Path::getLogsPath() .
'/' . $serverName .
'_error.log"' . PHP_EOL .
840 ' CustomLog "' .
Path::getLogsPath() .
'/' . $serverName .
'_access.log" combined' . PHP_EOL . PHP_EOL .
841 ' <Directory "' . $documentRoot .
'">' . PHP_EOL .
842 ' Options Indexes FollowSymLinks MultiViews' . PHP_EOL .
843 ' AllowOverride all' . PHP_EOL .
845 ' </Directory>' . PHP_EOL .
846 '</VirtualHost>' . PHP_EOL . PHP_EOL .
847 '<IfModule ssl_module>' . PHP_EOL .
848 '<VirtualHost *:' . $this->
getSslPort() .
'> #SSL' . PHP_EOL .
849 ' DocumentRoot "' . $documentRoot .
'"' . PHP_EOL .
850 ' ServerName ' . $serverName . PHP_EOL .
851 ' ServerAdmin webmaster@' . $serverName . PHP_EOL .
852 ' ErrorLog "' .
Path::getLogsPath() .
'/' . $serverName .
'_error.log"' . PHP_EOL .
853 ' TransferLog "' .
Path::getLogsPath() .
'/' . $serverName .
'_access.log"' . PHP_EOL . PHP_EOL .
854 ' SSLEngine on' . PHP_EOL .
855 ' SSLProtocol all -SSLv2' . PHP_EOL .
856 ' SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5' . PHP_EOL .
857 ' SSLCertificateFile "' .
Path::getSslPath() .
'/' . $serverName .
'.crt"' . PHP_EOL .
858 ' SSLCertificateKeyFile "' .
Path::getSslPath() .
'/' . $serverName .
'.ppk"' . PHP_EOL .
859 ' BrowserMatch "MSIE [2-5]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0' . PHP_EOL .
860 ' CustomLog "' .
Path::getLogsPath() .
'/' . $serverName .
'_sslreq.log" "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"' . PHP_EOL . PHP_EOL .
861 ' <Directory "' . $documentRoot .
'">' . PHP_EOL .
862 ' SSLOptions +StdEnvVars' . PHP_EOL .
863 ' Options Indexes FollowSymLinks MultiViews' . PHP_EOL .
864 ' AllowOverride all' . PHP_EOL .
866 ' </Directory>' . PHP_EOL .
867 '</VirtualHost>' . PHP_EOL .
868 '</IfModule>' . PHP_EOL;
878 if (!$this->enable) {
887 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s',
$conf, $matches);
888 Log::trace(isset($matches[1]) ? print_r($matches[1],
true) :
'N/A');
891 $conf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent,
$conf, -1, $count);
893 $conf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent,
$conf, -1, $count);
896 Log::debug(
'Refresh ' . $this->
getConf() .
': ' . $count .
' occurrence(s) replaced');
900 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s',
$sslConf, $matches);
901 Log::trace(isset($matches[1]) ? print_r($matches[1],
true) :
'N/A');
904 $sslConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent,
$sslConf, -1, $count);
906 $sslConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent,
$sslConf, -1, $count);
921 if (!$this->enable) {
928 foreach ($this->
getAlias() as $alias) {
931 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $aliasConf, $matches);
932 Log::trace(isset($matches[1]) ? print_r($matches[1],
true) :
'N/A');
935 $aliasConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent, $aliasConf, -1, $count);
937 $aliasConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent, $aliasConf, -1, $count);
956 if (!$this->enable) {
966 preg_match(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $vhostConf, $matches);
967 Log::trace(isset($matches[1]) ? print_r($matches[1],
true) :
'N/A');
970 $vhostConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $onlineContent, $vhostConf, -1, $count);
972 $vhostConf = preg_replace(
'/' . self::TAG_START_SWITCHONLINE .
'(.*?)' . self::TAG_END_SWITCHONLINE .
'/s', $offlineContent, $vhostConf, -1, $count);
989 public function setEnable($enabled, $showWindow =
false)
994 Log::debug($this->
getName() .
' cannot be enabled because bundle ' . $this->
getVersion() .
' does not exist in ' . $this->currentPath);
996 $bearsamppWinbinder->messageBoxError(
1009 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)
static getHttpHeaders($pingUrl, $verify=true)
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
static info($data, $file=null)
static debug($data, $file=null)
static reloadClass($classInstance)
static trace($data, $file=null)
static error($data, $file=null)
static initClass($classInstance)
update($sub=0, $showWindow=false)
static invalidateConfigCacheForPath($sourcePath)
const SERVICE_DEMAND_START
static getWebResourcesPath()
static getAliasPath($aetrayPath=false)
static getSslPath($aetrayPath=false)
static getLogsPath($aetrayPath=false)
static getWwwPath($aetrayPath=false)
static getVhostsPath($aetrayPath=false)
static formatUnixPath($path)
static getModuleSymlinkPath($module)
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static removeService($service, $name)
static isPortInUse($port)
static isValidPort($port)
static replaceInFile($path, $replaceList)
static startWith($string, $search)
static endWith($string, $search)
global $bearsamppHomepage