Andrea Pollastri 5 år sedan
förälder
incheckning
32f3c3d5e1
2 ändrade filer med 9 tillägg och 18 borttagningar
  1. 6 6
      app/Http/Controllers/ApplicationsController.php
  2. 3 12
      storage/app/scripts/hostadd.sh

+ 6 - 6
app/Http/Controllers/ApplicationsController.php

@@ -47,7 +47,7 @@ class ApplicationsController extends Controller {
         $dbpass = sha1(microtime().uniqid().$request->ip);
         $appcode= sha1(uniqid().$request->domain.microtime().$request->server_id);
         $base   = $request->basepath;
-        Application::create([
+        $application = Application::create([
             'domain'        => $request->domain,
             'server_id'     => $request->server_id,
             'username'      => $user,
@@ -57,6 +57,10 @@ class ApplicationsController extends Controller {
             'php'           => $request->php,
             'appcode'       => $appcode,
         ]);
+        if(!$application) {
+            $request->session()->flash('alert-error', 'There was a problem! Retry.');
+            return redirect('/applications');
+        }
         $ssh = New SSH($server->ip, $server->port);
         if(!$ssh->login($server->username, $server->password)) {
             $request->session()->flash('alert-error', 'There was a problem with server connection.');
@@ -64,13 +68,9 @@ class ApplicationsController extends Controller {
         }
         $ssh->setTimeout(360);
         $response = $ssh->exec('echo '.$server->password.' | sudo -S sudo sh /cipi/host-add.sh -d '.$request->domain.' -u '.$user.' -p '.$pass.' -dbp '.$dbpass.' -b '.$base.' -a '.$appcode);
-        if(strpos($response, '###CIPI###') === false) {
-            $request->session()->flash('alert-error', 'There was a problem with server connection.');
-            return redirect('/applications');
-        }
         $response = explode('###CIPI###', $response);
         if(strpos($response[1], 'Ok') === false) {
-            $request->session()->flash('alert-error', 'There was a problem with server connection.');
+            $request->session()->flash('alert-error', 'There was a problem with server scripts.');
             return redirect('/applications');
         }
         $app = [

+ 3 - 12
storage/app/scripts/hostadd.sh

@@ -41,18 +41,9 @@ while [ -n "$1" ] ; do
 done
 
 #CREATE USER
-isUserExits() {
-    grep $1 /etc/passwd > /dev/null
-    [ $? -eq 0 ] && return $TRUE || return $FALSE
-}
-if(!isUserExits $USER_NAME) then
-    sudo useradd -m -s $USER_SHELL -d /home/$USER_NAME -G www-data $USER_NAME
-    echo "$USER_NAME:$PASSWORD"|chpasswd
-    sudo chmod o-r /home/$USER_NAME
-else
-    echo "Error: Retry!"
-    exit 1
-fi
+sudo useradd -m -s $USER_SHELL -d /home/$USER_NAME -G www-data $USER_NAME
+echo "$USER_NAME:$PASSWORD"|chpasswd
+sudo chmod o-r /home/$USER_NAME
 
 #WELCOME PAGE
 if [ $BASE_PATH != "" ]; then