use Cubist\Net\Transfer\Local;
use Cubist\Util\Files\Files;
use Cubist\Util\Json;
+use Cubist\Util\Text;
use Illuminate\Support\Facades\DB;
// __('!! Serveurs externes')
protected static $_permissionBase = 'fluidbook-external-install-server';
- protected static $hostingProtocols = ['hosting', 'ushosting'];
protected $_operations = [ServerOperation::class];
+ protected static $hostingBasePaths = [
+ 'hosting' => '/mnt/hosting/',
+ 'hosting2' => '/mnt/hosting2',
+ 'ushosting' => '/application/usstorage/hosting/'
+ ];
+
private static $id;
protected static function _getOneServer($server)
public function setFields()
{
-
- $nothostingProtocols = array_diff(array_keys($this->getProtocols(), static::$hostingProtocols));
+ $nothostingProtocols = array_diff(array_keys($this->getProtocols(), $this->getHostingProtocols()));
parent::setFields();
$this->getField('base_url')->setAttribute('when', ['protocol' => $nothostingProtocols]);
- $this->addField('subdomains', Textarea::class, __('Sous-domaines'), ['when' => ['protocol' => static::$hostingProtocols]]);
- $this->addField('php', Checkbox::class, __('Activer le support de PHP'), ['default' => false, 'when' => ['protocol' => static::$hostingProtocols]]);
+ $this->addField('subdomains', Textarea::class, __('Sous-domaines'), ['when' => ['protocol' => $this->getHostingProtocols()]]);
+ $this->addField('php', Checkbox::class, __('Activer le support de PHP'), ['default' => false, 'when' => ['protocol' => $this->getHostingProtocols()]]);
$this->addField('redirections', Table::class, __('Redirections'), ['entity_singular' => __('redirection'), 'columns' => ['from' => __('De'), 'to' => __('Vers')], 'when' => ['protocol' => 'hosting']]);
$this->addField('allows_root', Checkbox::class, __('Autoriser le chargement à la racine (sur le chemin de base)'), ['default' => false]);
}
+ public function onSaving(): bool
+ {
+ if ($this->isHosting()) {
+ $servers = static::withoutGlobalScopes()->where('protocol', $this->getProtocol())->get();
+ foreach ($servers as $server) {
+ $d = Files::mkdir(protected_path($this->getProtocol()) . '/server_' . $server->id);
+ }
+ }
+
+ return parent::onSaving();
+ }
+
+ protected function isHosting()
+ {
+ return in_array($this->getProtocol(), $this->getHostingProtocols());
+ }
+
+ public function getBaseURL()
+ {
+ if ($this->isHosting()) {
+ $subdomains = $this->getSubdomains();
+ if (count($subdomains)) {
+ return 'https://' . $subdomains[0] . '/';
+ }
+ return '';
+ }
+ return parent::getBaseURL();
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getSubdomains()
+ {
+ return Text::explodeNewLines($this->subdomains);
+ }
+
public function onSaved(): bool
{
$this->updateHtaccess();
protected function updateHtaccess()
{
- if ($this->getProtocol() === 'hosting') {
-
+ if ($this->isHosting()) {
$redirections = Json::isJson($this->redirections) ? json_decode($this->redirections, true) : $this->redirections;
$content = '<IfModule mod_rewrite.c>
public function getProtocols()
{
- return ['FTP' => __('FTP non sécurisé'), 'SFTP' => 'SFTP', 'hosting' => 'Hosting', 'ushosting' => 'US Hosting'];
+ return ['FTP' => __('FTP non sécurisé'), 'SFTP' => 'SFTP', 'hosting' => 'Hosting', 'hosting2' => 'Hosting #2', 'ushosting' => 'US Hosting'];
}
+ protected function getHostingProtocols()
+ {
+ return array_keys(static::$hostingBasePaths);
+ }
/**
* @return \Cubist\Net\Transfer\Driver
if (null !== $res) {
return $res;
}
- if ($this->getProtocol() === 'hosting') {
- return new Local($this, '/mnt/hosting/');
- }
- if ($this->getProtocol() === 'ushosting') {
- return new Local($this, '/application/usstorage/hosting/');
- }
+ return new Local($this, $this->getHostingBasePath());
+ }
+
+ protected function getHostingBasePath()
+ {
+
+ return static::$hostingBasePaths[$this->getProtocol()];
}
public static function verifyServerConnexion($id, $data = [])
--- /dev/null
+version: '2'
+services:
+ nginx-proxy:
+ image: nginxproxy/nginx-proxy
+ container_name: fluidbook-$hosting-proxy
+ networks:
+ - fluidbook-$hosting
+ - "$ip:80:80"
+ - "$ip:443:443"
+ volumes:
+ - /var/run/docker.sock:/tmp/docker.sock:ro
+ - ./config/timeout.conf:/etc/nginx/conf.d/timeout.conf:ro
+ - ./config/custom_proxy_settings.conf:/etc/nginx/conf.d/custom_proxy_settings.conf:ro
+ - ./vhosts:/etc/nginx/vhost.d
+ - ./html:/usr/share/nginx/html
+ - ./certs:/etc/nginx/certs
+ restart: unless-stopped
+
+ acme-companion:
+ image: nginxproxy/acme-companion
+ container_name: nginx-proxy-acme
+ networks:
+ - fluidbook-$hosting
+ environment:
+ - DEFAULT_EMAIL=vincent@cubedesigners.com
+ volumes_from:
+ - nginx-proxy
+ volumes:
+ - ./certs:/etc/nginx/certs:rw
+ - ./acme:/etc/acme.sh
+ - /var/run/docker.sock:/var/run/docker.sock:ro
+
+networks:
+ fluidbook-$hosting:
+ external:
+ name: fluidbook-$hosting