Andrea Pollastri 5 年之前
父節點
當前提交
5655fcc628

+ 25 - 19
app/Http/Controllers/ShellController.php

@@ -53,13 +53,16 @@ class ScriptsController extends Controller
         if(!$application) {
             return abort(403);
         }
+        if($application->basepath) {
+            $basepath = '/home/'.$application->username.'/web/'.$application->basepath;
+        } else {
+            $basepath = '/home/'.$application->username.'/web';
+        }
         $script = Storage::get('scripts/haget.sh');
-        $script = Str::replaceArray('???', [
-            $application->username,
-            $application->basepath,
-            $application->php,
-            $application->domain
-        ], $script);
+        $script = Str::replace('???USER???', $application->username, $script);
+        $script = Str::replace('???BASE???', $basepath, $script);
+        $script = Str::replace('???PHP???', $application->php, $script);
+        $script = Str::replace('???DOMAIN???', $application->domain, $script);
         return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
     }
 
@@ -108,23 +111,26 @@ class ScriptsController extends Controller
         if(!$application) {
             return abort(403);
         }
-        $script = Storage::get('scripts/haget.sh');
-        $script = Str::replaceArray('???', [
-            $application->username,
-            $application->basepath,
-            $application->php,
-            $domain
-        ], $script);
-        return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
+        if($application->basepath) {
+            $basepath = '/home/'.$application->username.'/web/'.$application->basepath;
+        } else {
+            $basepath = '/home/'.$application->username.'/web';
+        }
+        $script = Storage::get('scripts/haget.conf');
+        $script = Str::replace('???USER???', $application->username, $script);
+        $script = Str::replace('???BASE???', $basepath, $script);
+        $script = Str::replace('???PHP???', $application->php, $script);
+        $script = Str::replace('???DOMAIN???', $domain, $script);
+        return response($script)->withHeaders(['Content-Type' =>'text/plain']);
     }
 
-    public function ssl() {
-        $script = Storage::get('scripts/ssl.sh');
-        return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
+    public function nginx() {
+        $script = Storage::get('scripts/nginx.conf');
+        return response($script)->withHeaders(['Content-Type' =>'text/plain']);
     }
 
-    public function nginx() {
-        $script = Storage::get('scripts/nginx.sh');
+    public function ssl() {
+        $script = Storage::get('scripts/ssl.sh');
         return response($script)->withHeaders(['Content-Type' =>'application/x-sh']);
     }
 

+ 5 - 5
database/migrations/2020_04_27_000003_create_alias_table.php → database/migrations/2020_04_27_000003_create_aliases_table.php

@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Database\Migrations\Migration;
 
-class CreateAliasTable extends Migration
+class CreateAliasesTable extends Migration
 {
     /**
      * Run the migrations.
@@ -14,7 +14,7 @@ class CreateAliasTable extends Migration
     public function up()
     {
 
-        Schema::create('alias', function (Blueprint $table) {
+        Schema::create('aliases', function (Blueprint $table) {
             $table->id();
             $table->string('domain');
             $table->bigInteger('application_id')->unsigned()->index();
@@ -22,8 +22,8 @@ class CreateAliasTable extends Migration
         });
 
 
-        Schema::table('alias', function (Blueprint $table) {
-            $table->foreign('application_id', 'alias_application_id_foreign')
+        Schema::table('aliases', function (Blueprint $table) {
+            $table->foreign('application_id', 'aliases_application_id_foreign')
                 ->references('id')
                 ->on('applications')
                 ->onDelete('cascade');
@@ -38,6 +38,6 @@ class CreateAliasTable extends Migration
      */
     public function down()
     {
-        Schema::dropIfExists('alias');
+        Schema::dropIfExists('aliases');
     }
 }

+ 14 - 21
storage/app/scripts/aliasadd.sh

@@ -1,28 +1,21 @@
 #!/usr/bin/env bash
 
-
-# Check if user is root
-if [ $(id -u) != "0" ]; then
-    echo "Error: You must be root to run this script."
-    exit 1
-fi
-
 while [ -n "$1" ] ; do
-            case $1 in
-            -d | --domain )
-                    shift
-                    DOMAIN=$1
-                    ;;
-            -a |  --appcode )
-                    shift
-                    APPCODE=$1
-                    ;;
-            * )
-                    echo "ERROR: Unknown option: $1"
-                    exit -1
-                    ;;
-            esac
+    case $1 in
+    -d | --domain )
+            shift
+            DOMAIN=$1
+            ;;
+    -a |  --appcode )
             shift
+            APPCODE=$1
+            ;;
+    * )
+            echo "ERROR: Unknown option: $1"
+            exit -1
+            ;;
+    esac
+    shift
 done
 
 #VIRTUAL HOST

+ 13 - 25
storage/app/scripts/aliasdel.sh

@@ -1,35 +1,23 @@
 #!/usr/bin/env bash
 
-# Check if user is root
-if [ $(id -u) != "0" ]; then
-    echo "Error: You must be root to run this script."
-    exit 1
-fi
-
 while [ -n "$1" ] ; do
-            case $1 in
-            -d | --domain )
-                    shift
-                    DOMAIN=$1
-                    ;;
-            * )
-                    echo "ERROR: Unknown option: $1"
-                    exit -1
-                    ;;
-            esac
+    case $1 in
+    -d | --domain )
             shift
+            DOMAIN=$1
+            ;;
+    * )
+            echo "ERROR: Unknown option: $1"
+            exit -1
+            ;;
+    esac
+    shift
 done
 
 sudo unlink /etc/nginx/sites-available/$DOMAIN.conf
 sudo unlink /etc/nginx/sites-enabled/$DOMAIN.conf
 sudo systemctl restart nginx.service
 
-
-$ssh->setTimeout(60);
-$ssh->exec('echo '.$alias->server->password.' | sudo -S unlink /etc/apache2/sites-available/'.$alias->application->username.'.conf');
-$ssh->exec('echo '.$alias->server->password.' | sudo -S wget '.env('APP_URL').'/storage/'.$alias->application->username.'.conf  -O /etc/apache2/sites-available/'.$alias->application->username.'.conf');
-$ssh->exec('echo '.$alias->server->password.' | sudo -S a2ensite '.$alias->application->username.'.conf');
-$ssh->exec('echo '.$alias->server->password.' | sudo -S unlink /etc/cron.d/certbot_renew_'.$alias->domain.'.crontab');
-$ssh->exec('echo '.$alias->server->password.' | sudo -S unlink /cipi/certbot_renew_'.$alias->domain.'.sh');
-$ssh->exec('echo '.$alias->server->password.' | sudo -S service apache2 reload');
-$ssh->exec('echo '.$alias->server->password.' | sudo -S systemctl reload apache2');
+#RESUME
+clear
+echo "###CIPI###Ok"

+ 26 - 0
storage/app/scripts/haget.conf

@@ -0,0 +1,26 @@
+server {
+
+    listen 80;
+    listen [::]:80;
+
+    server_tokens off;
+
+    server_name ???DOMAIN???
+
+    root ???BASE??
+
+    access_log /home/???USER???/nginx/log/???DOMAIN???.access.log;
+    error_log /home/???USER???/nginx/log/???DOMAIN???.error.log;
+
+    include /home/???USER???/nginx/custom.conf;
+
+    location ~ \.php$ {
+        include snippets/fastcgi-php.conf;
+        fastcgi_pass unix:/var/run/php/php???PHP???-fpm.sock;
+    }
+
+    location ~ /\.(?!well-known).* {
+        deny all;
+    }
+
+}

+ 0 - 37
storage/app/scripts/haget.sh

@@ -1,37 +0,0 @@
-#!/usr/bin/env bash
-
-USER_NAME=???
-BASE_PATH=???
-PHP_VERSION=???
-DOMAIN=???
-
-server {
-
-    listen 80;
-    listen [::]:80;
-
-    server_tokens off;
-
-    server_name $DOMAIN
-
-    if [ $BASE_PATH != "" ]; then
-        root /home/$USER_NAME/web/$BASE_PATH
-    else
-        root /home/$USER_NAME/web
-    fi
-
-    access_log /home/$USER_NAME/nginx/log/$DOMAIN.access.log;
-    error_log /home/$USER_NAME/nginx/log/$DOMAIN.error.log;
-
-    include /home/$USER_NAME/nginx/custom.conf;
-
-    location ~ \.php$ {
-        include snippets/fastcgi-php.conf;
-        fastcgi_pass unix:/var/run/php/php$PHP_VERSION-fpm.sock;
-    }
-
-    location ~ /\.(?!well-known).* {
-        deny all;
-    }
-
-}

+ 34 - 34
storage/app/scripts/hostadd.sh

@@ -13,37 +13,37 @@ if [ $(id -u) != "0" ]; then
 fi
 
 while [ -n "$1" ] ; do
-            case $1 in
-            -d | --domain )
-                    shift
-                    DOMAIN=$1
-                    ;;
-            -u | --user )
-                    shift
-                    USER_NAME=$1
-                    ;;
-            -p | --pass )
-                    shift
-                    PASSWORD=$1
-                    ;;
-            -dbp | --dbpass )
-                    shift
-                    DBPASS=$1
-                    ;;
-            -b |  --base )
-                    shift
-                    BASE_PATH=$1
-                    ;;
-            -a |  --appcode )
-                    shift
-                    APPCODE=$1
-                    ;;
-            * )
-                    echo "ERROR: Unknown option: $1"
-                    exit -1
-                    ;;
-            esac
+    case $1 in
+    -d | --domain )
             shift
+            DOMAIN=$1
+            ;;
+    -u | --user )
+            shift
+            USER_NAME=$1
+            ;;
+    -p | --pass )
+            shift
+            PASSWORD=$1
+            ;;
+    -dbp | --dbpass )
+            shift
+            DBPASS=$1
+            ;;
+    -b |  --base )
+            shift
+            BASE_PATH=$1
+            ;;
+    -a |  --appcode )
+            shift
+            APPCODE=$1
+            ;;
+    * )
+            echo "ERROR: Unknown option: $1"
+            exit -1
+            ;;
+    esac
+    shift
 done
 
 #CREATE USER
@@ -121,10 +121,6 @@ GRANT USAGE ON *.* TO '$DBUSER'@'localhost' IDENTIFIED BY '$DBPASS' WITH MAX_QUE
 GRANT ALL PRIVILEGES ON $DBNAME.* TO $DBUSER@'localhost';
 EOF
 
-#RESUME
-clear
-echo "###CIPI###Ok"
-
 #GIT
 sudo mkdir /home/$USER_NAME/git/
 sudo cp /cipi/github /home/$USER_NAME/git/deploy
@@ -136,3 +132,7 @@ sudo rpl -q "###CIPI-USER###" "$USER_NAME" /home/$USER_NAME/git/deploy.sh
 sudo chown -R $USER_NAME:$USER_NAME /home/$USER_NAME/git/
 sudo chown -R $USER_NAME:$USER_NAME /home/$USER_NAME/web/
 sudo chown -R $USER_NAME:$USER_NAME /home/$USER_NAME
+
+#RESUME
+clear
+echo "###CIPI###Ok"

+ 0 - 0
storage/app/scripts/nginx.sh → storage/app/scripts/nginx.conf