]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6555 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Dec 2023 15:13:45 +0000 (16:13 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Dec 2023 15:13:45 +0000 (16:13 +0100)
app/Models/FluidbookExternalInstallServer.php
bin/startup.sh
resources/hosting/docker-compose.yml [new file with mode: 0644]
resources/hosting/nginxproxy/docker-compose.yml [new file with mode: 0644]
resources/hosting/nginxproxy/update [new file with mode: 0644]
resources/hosting/updateall [new file with mode: 0644]

index a74f42caee09402ecda6c25b0bb7ddfd3d5e7b8c..ae26473232d00963501d00c8c5384b4db2cc54ff 100644 (file)
@@ -10,6 +10,7 @@ use Cubist\Backpack\Magic\Models\ExternalServer;
 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')
@@ -24,10 +25,15 @@ class FluidbookExternalInstallServer extends ExternalServer
 
     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)
@@ -37,17 +43,53 @@ class FluidbookExternalInstallServer extends ExternalServer
 
     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();
@@ -56,8 +98,7 @@ class FluidbookExternalInstallServer extends ExternalServer
 
     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>
@@ -82,9 +123,13 @@ class FluidbookExternalInstallServer extends ExternalServer
 
     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
@@ -95,12 +140,13 @@ class FluidbookExternalInstallServer extends ExternalServer
         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 = [])
index b94fbc0aadace01009ebee4a1628f2104b4418a3..4aa50f28fb1ef40f8c78e3d3695f514bdd961c0a 100644 (file)
@@ -47,6 +47,13 @@ else
     sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o uid=1002 -o gid=33 -o allow_other fluidbook@clockwork.cubedesigners.com:/data/fluidbook/hosting /mnt/hosting
 fi
 
+mkdir -p /mnt/hosting2
+if mountpoint -q "/mnt/hosting2"; then
+    :
+else
+    sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o uid=1002 -o gid=33 -o allow_other fluidbook@clockwork.cubedesigners.com:/data/fluidbook/hosting2 /mnt/hosting2
+fi
+
 mkdir -p /application/usstorage
 if mountpoint -q "/application/usstorage"; then
     :
diff --git a/resources/hosting/docker-compose.yml b/resources/hosting/docker-compose.yml
new file mode 100644 (file)
index 0000000..124a2bd
--- /dev/null
@@ -0,0 +1,18 @@
+version: '3.1'
+services:
+    webserver:
+        container_name: fluidbook-$hosting-server-$sid
+        image: $image
+        volumes:
+            - '$path:/usr/local/apache2/htdocs'
+        environment:
+            VIRTUAL_HOST: $domains
+            LETSENCRYPT_HOST: $domains
+        networks:
+            - fluidbook-$hosting
+        restart: unless-stopped
+
+networks:
+  fluidbook-$hosting:
+    external:
+      name: fluidbook-$hosting
diff --git a/resources/hosting/nginxproxy/docker-compose.yml b/resources/hosting/nginxproxy/docker-compose.yml
new file mode 100644 (file)
index 0000000..4b631fe
--- /dev/null
@@ -0,0 +1,36 @@
+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
diff --git a/resources/hosting/nginxproxy/update b/resources/hosting/nginxproxy/update
new file mode 100644 (file)
index 0000000..29cddbd
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+cd /docker/fluidbook-hosting/nginxproxy/
+docker-compose pull
+docker-compose down
+docker-compose up -d
diff --git a/resources/hosting/updateall b/resources/hosting/updateall
new file mode 100644 (file)
index 0000000..74733e3
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+docker network create fluidbook-$hosting
+/docker/fluidbook-$hosting/nxginxproxy/update
+