mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-21 23:20:24 +00:00
update
This commit is contained in:
parent
4d0ea376b6
commit
eedc2e201a
4 changed files with 394 additions and 104 deletions
|
@ -7,6 +7,7 @@ use App\Events\DomainIsCreated;
|
|||
use App\Events\ModelDomainDeleting;
|
||||
use App\ShellApi;
|
||||
use App\VirtualHosts\ApacheBuild;
|
||||
use App\VirtualHosts\DTO\ApacheVirtualHostSettings;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Modules\Docker\App\Models\DockerContainer;
|
||||
|
@ -241,7 +242,7 @@ class Domain extends Model
|
|||
shell_exec('chmod -f 751 '.$this->domain_public . '/cgi-bin/php');
|
||||
}
|
||||
|
||||
$apacheVirtualHostBuilder = new \App\VirtualHosts\ApacheVirtualHostBuilder();
|
||||
$apacheVirtualHostBuilder = new ApacheVirtualHostSettings();
|
||||
$apacheVirtualHostBuilder->setDomain($this->domain);
|
||||
$apacheVirtualHostBuilder->setDomainPublic($this->domain_public);
|
||||
$apacheVirtualHostBuilder->setDomainRoot($this->domain_root);
|
||||
|
@ -322,7 +323,7 @@ class Domain extends Model
|
|||
}
|
||||
}
|
||||
|
||||
$apacheBaseConfig = $apacheVirtualHostBuilder->buildConfig();
|
||||
$virtualHostSettings = $apacheVirtualHostBuilder->getSettings();
|
||||
|
||||
$catchMainDomain = '';
|
||||
$domainExp = explode('.', $this->domain);
|
||||
|
@ -352,7 +353,7 @@ class Domain extends Model
|
|||
}
|
||||
}
|
||||
|
||||
$apacheBaseConfigWithSSL = null;
|
||||
$virtualHostSettingsWithSSL = null;
|
||||
if ($findDomainSSLCertificate) {
|
||||
|
||||
$sslCertificateFile = $this->home_root . '/certs/' . $this->domain . '/public/cert.pem';
|
||||
|
@ -391,13 +392,13 @@ class Domain extends Model
|
|||
$apacheVirtualHostBuilder->setSSLCertificateKeyFile($sslCertificateKeyFile);
|
||||
$apacheVirtualHostBuilder->setSSLCertificateChainFile($sslCertificateChainFile);
|
||||
|
||||
$apacheBaseConfigWithSSL = $apacheVirtualHostBuilder->buildConfig();
|
||||
$virtualHostSettingsWithSSL = $apacheVirtualHostBuilder->getSettings();
|
||||
|
||||
}
|
||||
|
||||
return [
|
||||
'apacheBaseConfig' => $apacheBaseConfig,
|
||||
'apacheBaseConfigWithSSL' => $apacheBaseConfigWithSSL,
|
||||
'virtualHostSettings' => $virtualHostSettings,
|
||||
'virtualHostSettingsWithSSL' => $virtualHostSettingsWithSSL,
|
||||
];
|
||||
|
||||
}
|
||||
|
|
|
@ -17,113 +17,26 @@ class ApacheBuild
|
|||
|
||||
public function build()
|
||||
{
|
||||
$virtualHostMerged = '
|
||||
#=========================================================================#
|
||||
# PHYRE HOSTING PANEL - Default Web Domain Template #
|
||||
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
|
||||
# https://phyrepanel.com/docs/server-administration/web-templates.html #
|
||||
#=========================================================================#
|
||||
|
||||
DefaultRuntimeDir ${APACHE_RUN_DIR}
|
||||
PidFile ${APACHE_PID_FILE}
|
||||
Timeout 300
|
||||
KeepAlive On
|
||||
MaxKeepAliveRequests 100
|
||||
KeepAliveTimeout 5
|
||||
|
||||
User ${APACHE_RUN_USER}
|
||||
Group ${APACHE_RUN_GROUP}
|
||||
|
||||
HostnameLookups Off
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
LogLevel warn
|
||||
|
||||
IncludeOptional mods-enabled/*.load
|
||||
IncludeOptional mods-enabled/*.conf
|
||||
|
||||
Listen 80
|
||||
|
||||
<IfModule ssl_module>
|
||||
Listen 443
|
||||
</IfModule>
|
||||
|
||||
<IfModule mod_gnutls.c>
|
||||
Listen 443
|
||||
</IfModule>
|
||||
|
||||
<Directory />
|
||||
Options FollowSymLinks
|
||||
AllowOverride None
|
||||
Require all denied
|
||||
</Directory>
|
||||
|
||||
<Directory /usr/share>
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
<Directory /var/www/>
|
||||
Options Indexes FollowSymLinks
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
AccessFileName .htaccess
|
||||
|
||||
<FilesMatch "^\.ht">
|
||||
Require all denied
|
||||
</FilesMatch>
|
||||
|
||||
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %O" common
|
||||
LogFormat "%{Referer}i -> %U" referer
|
||||
LogFormat "%{User-agent}i" agent
|
||||
|
||||
IncludeOptional conf-enabled/*.conf
|
||||
|
||||
';
|
||||
$getAllDomains = Domain::all();
|
||||
$virtualHosts = [];
|
||||
foreach ($getAllDomains as $domain) {
|
||||
|
||||
$domainVirtualHost = $domain->configureVirtualHost($this->fixPermissions);
|
||||
if (isset($domainVirtualHost['apacheBaseConfig'])) {
|
||||
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfig'] . "\n\n";
|
||||
$virtualHostSettings = $domain->configureVirtualHost();
|
||||
if (isset($virtualHostSettings['virtualHostSettings'])) {
|
||||
$virtualHosts[] = $virtualHostSettings['virtualHostSettings'];
|
||||
}
|
||||
if (isset($domainVirtualHost['apacheBaseConfigWithSSL'])) {
|
||||
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfigWithSSL'] . "\n\n";
|
||||
if (isset($virtualHostSettings['virtualHostSettingsWithSSL'])) {
|
||||
$virtualHosts[] = $virtualHostSettings['virtualHostSettingsWithSSL'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty(setting('general.master_domain'))) {
|
||||
// Make master domain virtual host
|
||||
$masterDomain = new MasterDomain();
|
||||
$domainVirtualHost = $masterDomain->configureVirtualHost($this->fixPermissions);
|
||||
if (isset($domainVirtualHost['apacheBaseConfig'])) {
|
||||
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfig'] . "\n\n";
|
||||
}
|
||||
if (isset($domainVirtualHost['apacheBaseConfigWithSSL'])) {
|
||||
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfigWithSSL'] . "\n\n";
|
||||
}
|
||||
}
|
||||
$apache2 = view('actions.samples.ubuntu.apache2-conf-build', [
|
||||
'virtualHosts' => $virtualHosts
|
||||
])->render();
|
||||
|
||||
$wildcardDomain = setting('general.wildcard_domain');
|
||||
if (!empty($wildcardDomain)) {
|
||||
// Make wildcard domain virtual host
|
||||
$masterDomain = new MasterDomain();
|
||||
$masterDomain->domain = $wildcardDomain;
|
||||
$domainVirtualHost = $masterDomain->configureVirtualHost($this->fixPermissions);
|
||||
if (isset($domainVirtualHost['apacheBaseConfig'])) {
|
||||
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfig'] . "\n\n";
|
||||
}
|
||||
if (isset($domainVirtualHost['apacheBaseConfigWithSSL'])) {
|
||||
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfigWithSSL'] . "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents('/etc/apache2/apache2.conf', $virtualHostMerged);
|
||||
file_put_contents('/etc/apache2/apache2.conf', $apache2);
|
||||
|
||||
shell_exec('systemctl reload apache2');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
170
web/app/VirtualHosts/DTO/ApacheVirtualHostSettings.php
Normal file
170
web/app/VirtualHosts/DTO/ApacheVirtualHostSettings.php
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
|
||||
namespace App\VirtualHosts\DTO;
|
||||
|
||||
class ApacheVirtualHostSettings
|
||||
{
|
||||
public $port = 80;
|
||||
|
||||
public $domain;
|
||||
|
||||
public $domainAlias;
|
||||
|
||||
public $domainPublic;
|
||||
|
||||
public $domainRoot;
|
||||
public $homeRoot;
|
||||
|
||||
public $user;
|
||||
public $userGroup;
|
||||
public $additionalServices = [];
|
||||
|
||||
public $sslCertificateFile = null;
|
||||
public $sslCertificateKeyFile = null;
|
||||
public $sslCertificateChainFile = null;
|
||||
|
||||
public $appType = null;
|
||||
|
||||
public $appVersion = null;
|
||||
|
||||
public $passengerAppRoot = null;
|
||||
public $passengerAppType = null;
|
||||
public $passengerStartupFile = null;
|
||||
|
||||
public $serverAdmin = null;
|
||||
|
||||
public $proxyPass = null;
|
||||
|
||||
public $enableLogs = false;
|
||||
|
||||
public function setPort($port)
|
||||
{
|
||||
$this->port = $port;
|
||||
}
|
||||
public function setDomain($domain)
|
||||
{
|
||||
$this->domain = $domain;
|
||||
}
|
||||
|
||||
public function setDomainAlias($domainAlias)
|
||||
{
|
||||
$this->domainAlias = $domainAlias;
|
||||
}
|
||||
|
||||
public function setDomainPublic($domainPublic)
|
||||
{
|
||||
$this->domainPublic = $domainPublic;
|
||||
}
|
||||
|
||||
public function setDomainRoot($domainRoot)
|
||||
{
|
||||
$this->domainRoot = $domainRoot;
|
||||
}
|
||||
|
||||
public function setHomeRoot($homeRoot)
|
||||
{
|
||||
$this->homeRoot = $homeRoot;
|
||||
}
|
||||
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function setUserGroup($userGroup)
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
}
|
||||
|
||||
public function setAdditionalServices($additionalServices)
|
||||
{
|
||||
$this->additionalServices = $additionalServices;
|
||||
}
|
||||
|
||||
public function setSSLCertificateFile($sslCertificateFile)
|
||||
{
|
||||
$this->sslCertificateFile = $sslCertificateFile;
|
||||
}
|
||||
|
||||
public function setSSLCertificateKeyFile($sslCertificateKeyFile)
|
||||
{
|
||||
$this->sslCertificateKeyFile = $sslCertificateKeyFile;
|
||||
}
|
||||
|
||||
public function setSSLCertificateChainFile($sslCertificateChainFile)
|
||||
{
|
||||
$this->sslCertificateChainFile = $sslCertificateChainFile;
|
||||
}
|
||||
|
||||
public function setAppType($appType)
|
||||
{
|
||||
$this->appType = $appType;
|
||||
}
|
||||
|
||||
public function setAppVersion($appVersion)
|
||||
{
|
||||
$this->appVersion = $appVersion;
|
||||
}
|
||||
|
||||
public function setPassengerAppRoot($passengerAppRoot)
|
||||
{
|
||||
$this->passengerAppRoot = $passengerAppRoot;
|
||||
}
|
||||
|
||||
public function setPassengerAppType($passengerAppType)
|
||||
{
|
||||
$this->passengerAppType = $passengerAppType;
|
||||
}
|
||||
|
||||
public function setPassengerStartupFile($passengerStartupFile)
|
||||
{
|
||||
$this->passengerStartupFile = $passengerStartupFile;
|
||||
}
|
||||
|
||||
public function setServerAdmin($email)
|
||||
{
|
||||
$this->serverAdmin = $email;
|
||||
}
|
||||
|
||||
public function setProxyPass($proxyPass)
|
||||
{
|
||||
$this->proxyPass = $proxyPass;
|
||||
}
|
||||
|
||||
public function setEnableLogs($enableLogs)
|
||||
{
|
||||
$this->enableLogs = $enableLogs;
|
||||
}
|
||||
|
||||
public function getSettings()
|
||||
{
|
||||
$settings = [
|
||||
'port' => $this->port,
|
||||
'domain' => $this->domain,
|
||||
'domainAlias' => $this->domainAlias,
|
||||
'domainPublic' => $this->domainPublic,
|
||||
'domainRoot' => $this->domainRoot,
|
||||
'homeRoot' => $this->homeRoot,
|
||||
'serverAdmin' => $this->serverAdmin,
|
||||
'user' => $this->user,
|
||||
'group' => $this->userGroup,
|
||||
'enableRuid2' => true,
|
||||
'sslCertificateFile' => $this->sslCertificateFile,
|
||||
'sslCertificateKeyFile' => $this->sslCertificateKeyFile,
|
||||
'sslCertificateChainFile' => $this->sslCertificateChainFile,
|
||||
'appType' => $this->appType,
|
||||
'appVersion' => $this->appVersion,
|
||||
'passengerAppRoot' => $this->passengerAppRoot,
|
||||
'passengerAppType' => $this->passengerAppType,
|
||||
'passengerStartupFile' => $this->passengerStartupFile,
|
||||
'proxyPass' => $this->proxyPass,
|
||||
'enableLogs' => $this->enableLogs,
|
||||
];
|
||||
|
||||
$apacheVirtualHostConfigs = app()->virtualHostManager->getConfigs($this->additionalServices);
|
||||
|
||||
$settings = array_merge($settings, $apacheVirtualHostConfigs);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,206 @@
|
|||
#=========================================================================#
|
||||
# PHYRE HOSTING PANEL - Default Web Domain Template #
|
||||
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
|
||||
# https://phyrepanel.com/docs/server-administration/web-templates.html #
|
||||
#=========================================================================#
|
||||
|
||||
DefaultRuntimeDir ${APACHE_RUN_DIR}
|
||||
PidFile ${APACHE_PID_FILE}
|
||||
Timeout 300
|
||||
KeepAlive On
|
||||
MaxKeepAliveRequests 100
|
||||
KeepAliveTimeout 5
|
||||
|
||||
User ${APACHE_RUN_USER}
|
||||
Group ${APACHE_RUN_GROUP}
|
||||
|
||||
HostnameLookups Off
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
LogLevel warn
|
||||
|
||||
IncludeOptional mods-enabled/*.load
|
||||
IncludeOptional mods-enabled/*.conf
|
||||
|
||||
Listen 80
|
||||
|
||||
<IfModule ssl_module>
|
||||
Listen 443
|
||||
</IfModule>
|
||||
|
||||
<IfModule mod_gnutls.c>
|
||||
Listen 443
|
||||
</IfModule>
|
||||
|
||||
<Directory />
|
||||
Options FollowSymLinks
|
||||
AllowOverride None
|
||||
Require all denied
|
||||
</Directory>
|
||||
|
||||
<Directory /usr/share>
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
<Directory /var/www/>
|
||||
Options Indexes FollowSymLinks
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
AccessFileName .htaccess
|
||||
|
||||
<FilesMatch "^\.ht">
|
||||
Require all denied
|
||||
</FilesMatch>
|
||||
|
||||
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %O" common
|
||||
LogFormat "%{Referer}i -> %U" referer
|
||||
LogFormat "%{User-agent}i" agent
|
||||
|
||||
IncludeOptional conf-enabled/*.conf
|
||||
|
||||
@foreach($virtualHosts as $virtualHost)
|
||||
|
||||
<VirtualHost *:{{$virtualHost['port']}}>
|
||||
|
||||
@if(!empty($virtualHost['serverAdmin']))
|
||||
|
||||
ServerAdmin {{$virtualHost['serverAdmin']}}
|
||||
|
||||
@endif
|
||||
|
||||
ServerName {{$virtualHost['domain']}}
|
||||
|
||||
@if(!empty($virtualHost['domainAlias']))
|
||||
|
||||
ServerAlias {{$virtualHost['domainAlias']}}
|
||||
|
||||
@endif
|
||||
|
||||
DocumentRoot {{$virtualHost['domainPublic']}}
|
||||
SetEnv APP_DOMAIN {{$virtualHost['domain']}}
|
||||
|
||||
@if(isset($virtualHost['enableRuid2']) && $virtualHost['enableRuid2'] && !empty($virtualHost['user']) && !empty($virtualHost['group']))
|
||||
|
||||
#RDocumentChRoot {{$virtualHost['domainPublic']}}
|
||||
#SuexecUserGroup {{$virtualHost['user']}} {{$virtualHost['group']}}
|
||||
#RUidGid {{$virtualHost['user']}} {{$virtualHost['group']}}
|
||||
|
||||
@endif
|
||||
|
||||
@if($virtualHost['enableLogs'])
|
||||
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %b" common
|
||||
|
||||
CustomLog {{$virtualHost['domainRoot']}}/logs/apache2/bytes.log bytes
|
||||
CustomLog {{$virtualHost['domainRoot']}}/logs/apache2/access.log common
|
||||
ErrorLog {{$virtualHost['domainRoot']}}/logs/apache2/error.log
|
||||
|
||||
@endif
|
||||
|
||||
@if($virtualHost['appType'] == 'php')
|
||||
|
||||
ScriptAlias /cgi-bin/ {{$virtualHost['domainPublic']}}/cgi-bin/
|
||||
|
||||
@endif
|
||||
|
||||
@if (!empty($virtualHost['proxyPass']))
|
||||
|
||||
ProxyPreserveHost On
|
||||
ProxyRequests Off
|
||||
ProxyVia On
|
||||
ProxyPass / {{$virtualHost['proxyPass']}}
|
||||
ProxyPassReverse / {{$virtualHost['proxyPass']}}
|
||||
|
||||
@endif
|
||||
|
||||
<Directory {{$virtualHost['domainPublic']}}>
|
||||
|
||||
Options Indexes FollowSymLinks MultiViews @if($virtualHost['appType'] == 'php') Includes ExecCGI @endif
|
||||
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
|
||||
@if(isset($virtualHost['enableRuid2']) && $virtualHost['enableRuid2'] && !empty($virtualHost['user']) && !empty($virtualHost['group']))
|
||||
|
||||
RMode config
|
||||
RUidGid {{$virtualHost['user']}} {{$virtualHost['group']}}
|
||||
|
||||
@endif
|
||||
|
||||
@if($virtualHost['passengerAppRoot'] !== null)
|
||||
|
||||
PassengerAppRoot {{$virtualHost['passengerAppRoot']}}
|
||||
|
||||
PassengerAppType {{$virtualHost['passengerAppType']}}
|
||||
|
||||
@if($virtualHost['passengerStartupFile'] !== null)
|
||||
PassengerStartupFile {{$virtualHost['passengerStartupFile']}}
|
||||
@endif
|
||||
|
||||
@endif
|
||||
|
||||
@if($virtualHost['appType'] == 'php')
|
||||
|
||||
Action phpcgi-script /cgi-bin/php
|
||||
<Files *.php>
|
||||
SetHandler phpcgi-script
|
||||
</Files>
|
||||
|
||||
@php
|
||||
$appendOpenBaseDirs = $virtualHost['homeRoot'];
|
||||
if (isset($virtualHost['phpAdminValueOpenBaseDirs'])
|
||||
&& is_array($virtualHost['phpAdminValueOpenBaseDirs'])
|
||||
&& !empty($virtualHost['phpAdminValueOpenBaseDirs'])) {
|
||||
$appendOpenBaseDirs .= ':' . implode(':', $virtualHost['phpAdminValueOpenBaseDirs']);
|
||||
}
|
||||
@endphp
|
||||
|
||||
php_admin_value open_basedir {{$appendOpenBaseDirs}}
|
||||
|
||||
php_admin_value upload_tmp_dir {{$virtualHost['homeRoot']}}/tmp
|
||||
php_admin_value session.save_path {{$virtualHost['homeRoot']}}/tmp
|
||||
php_admin_value sys_temp_dir {{$virtualHost['homeRoot']}}/tmp
|
||||
|
||||
@endif
|
||||
|
||||
</Directory>
|
||||
|
||||
@if(!empty($virtualHost['sslCertificateFile']) and !empty($virtualHost['sslCertificateKeyFile']))
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile {{$virtualHost['sslCertificateFile']}}
|
||||
SSLCertificateKeyFile {{$virtualHost['sslCertificateKeyFile']}}
|
||||
|
||||
@if (!empty($virtualHost['sslCertificateChainFile']))
|
||||
|
||||
SSLCertificateChainFile {{$virtualHost['sslCertificateChainFile']}}
|
||||
|
||||
@endif
|
||||
|
||||
|
||||
SSLEngine on
|
||||
|
||||
# Intermediate configuration, tweak to your needs
|
||||
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
|
||||
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
|
||||
SSLHonorCipherOrder off
|
||||
SSLSessionTickets off
|
||||
|
||||
SSLOptions +StrictRequire
|
||||
|
||||
# Add vhost name to log entries:
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined
|
||||
LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
|
||||
|
||||
|
||||
@endif
|
||||
|
||||
</VirtualHost>
|
||||
|
||||
|
||||
@endforeach
|
||||
|
Loading…
Reference in a new issue