浏览代码

Users + fix

Andrea Pollastri 5 年之前
父节点
当前提交
2d3e9955d1

+ 1 - 1
app/Http/Controllers/SetupController.php → app/Http/Controllers/SettingsController.php

@@ -7,7 +7,7 @@ use App\Http\Controllers\Controller;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Hash;
 
 
-class SetupController extends Controller
+class SettingsController extends Controller
 {
 {
 
 
     public function index() {
     public function index() {

+ 65 - 0
app/Http/Controllers/UsersController.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use App\Application;
+use \phpseclib\Net\SSH2 as SSH;
+
+
+class UsersController extends Controller {
+
+
+    public function index() {
+        $users = Application::all();
+        return view('users', compact('users'));
+    }
+
+
+    public function reset(Request $request) {
+        $this->validate($request, [
+            'username' => 'required'
+        ]);
+        $application = Application::where('username', $request->username)->with('server')->first();
+        if(!$application) {
+            $request->session()->flash('alert-error', 'User not found!');
+            return redirect('/users');
+        }
+        $ssh = New SSH($application->server->ip, $application->server->port);
+        if(!$ssh->login($application->server->username, $application->server->password)) {
+            $request->session()->flash('alert-error', 'There was a problem with server connection.');
+            return redirect('/users');
+        }
+        $pass   = sha1(uniqid().microtime().$application->domain);
+        $dbpass = sha1(microtime().uniqid().$application->server->ip);
+        $ssh->setTimeout(360);
+        $response = $ssh->exec('echo '.$application->server->password.' | sudo -S sudo sh /cipi/passwd.sh -u '.$request->username.' -p '.$pass.' -dbp '.$dbpass. ' -dbop '.$application->dbpass);
+        if(strpos($response, '###CIPI###') === false) {
+            $request->session()->flash('alert-error', 'There was a problem with server scripts.');
+            return redirect('/users');
+        }
+        $response = explode('###CIPI###', $response);
+        if(strpos($response[1], 'Ok') === false) {
+            $request->session()->flash('alert-error', 'There was a problem with server scripts.');
+            return redirect('/users');
+        }
+        $application->password = $pass;
+        $application->dbpass   = $dbpass;
+        $application->save();
+        $app = [
+            'user'          => $request->username,
+            'pass'          => $pass,
+            'dbname'        => $request->username,
+            'dbuser'        => $request->username,
+            'dbpass'        => $dbpass,
+            'path'          => $application->basepath,
+            'domain'        => $application->domain,
+            'php'           => $application->php,
+            'host'          => $application->server->ip,
+            'port'          => $application->server->port,
+        ];
+        $appcode = $application->appcode;
+        return view('application', compact('app','appcode'));
+    }
+
+}

+ 58 - 1
go.sh

@@ -277,6 +277,34 @@ sleep 3s
 
 
 
 
 
 
+
+#LET'S ENCRYPT
+clear
+echo "Let's Encrypt installation..."
+sleep 3s
+
+sudo add-apt-repository -y ppa:certbot/certbot
+sudo apt-get -y install python-certbot-nginx
+
+echo "Let's Encrypt: OK!"
+sleep 3s
+
+
+
+#GIT
+clear
+echo "Git installation..."
+sleep 3s
+
+sudo apt-get -y install git
+sudo ssh-keygen -t rsa -C "git@github.com" -f /cipi/github -q -P ""
+
+clear
+echo "Git installation: OK!"
+sleep 3s
+
+
+
 #COMPOSER
 #COMPOSER
 clear
 clear
 echo "Composer installation..."
 echo "Composer installation..."
@@ -294,6 +322,33 @@ sleep 3s
 
 
 
 
 
 
+#SUPERVISOR
+echo "Supervisor installation..."
+sleep 3s
+
+sudo apt-get -y install supervisor
+service supervisor restart
+
+clear
+echo "Supervisor installation: OK!"
+sleep 3s
+
+
+
+#NODE
+clear
+echo "node.js & npm installation..."
+sleep 3s
+
+curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
+sudo apt-get -y install nodejs
+
+clear
+echo "node.js & npm: OK!"
+sleep 3s
+
+
+
 #CIPI USER
 #CIPI USER
 clear
 clear
 echo "User creation..."
 echo "User creation..."
@@ -339,8 +394,9 @@ sudo chown -R www-data:www-data /var/www/html
 cd /var/www/html && composer dump-autoload
 cd /var/www/html && composer dump-autoload
 cd /var/www/html && php artisan cache:clear
 cd /var/www/html && php artisan cache:clear
 cd /var/www/html && php artisan storage:link
 cd /var/www/html && php artisan storage:link
+cd /var/www/html && php artisan config:cache
+cd /var/www/html && php artisan view:cache
 cd /var/www/html && php artisan migrate --seed --force
 cd /var/www/html && php artisan migrate --seed --force
-
 clear
 clear
 echo "Application installation: OK!"
 echo "Application installation: OK!"
 sleep 3s
 sleep 3s
@@ -358,6 +414,7 @@ sudo apt-get update
 TASK=/etc/cron.d/cipi.crontab
 TASK=/etc/cron.d/cipi.crontab
 touch $TASK
 touch $TASK
 cat > "$TASK" <<EOF
 cat > "$TASK" <<EOF
+0 5 * * 7 certbot renew --nginx --non-interactive --post-hook "systemctl restart nginx.service"
 5 4 * * sun DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" dist-upgrade
 5 4 * * sun DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" dist-upgrade
 * 3 * * sun apt-get -y update"
 * 3 * * sun apt-get -y update"
 EOF
 EOF

+ 101 - 0
resources/views/users.blade.php

@@ -0,0 +1,101 @@
+@extends('layouts.app')
+
+
+
+@section('title')
+Users
+@endsection
+
+
+
+@section('content')
+<div class="card shadow mb-4">
+    <div class="card-body">
+        <div class="table-responsive">
+            <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
+                <thead>
+                    <tr>
+                        <th class="text-center">User</th>
+                        <th class="text-center d-none d-lg-table-cell">Application</th>
+                        <th class="text-center">Server</th>
+                        <th class="text-center d-none d-lg-table-cell">IP</th>
+                        <th class="text-center">Actions</th>
+                    </tr>
+                </thead>
+                <tbody>
+                    @foreach($users as $user)
+                    <tr>
+                        <td class="text-center">{{ $user->username }}</td>
+                        <td class="text-center">{{ $user->domain }}</td>
+                        <td class="text-center">{{ $user->server->name }}</td>
+                        <td class="text-center d-none d-lg-table-cell">{{ $user->server->ip }}</td>
+                        <td class="text-center">
+                            <a href="#" data-toggle="modal" data-target="#resetModal" data-username="{{ $user->username }}">
+                                <i class="fas fa-key" style="color:gray;"></i>
+                            </a>
+                        </td>
+                    </tr>
+                    @endforeach
+                </tbody>
+            </table>
+        </div>
+    </div>
+</div>
+@endsection
+
+
+
+@section('extra')
+<!-- RESET -->
+<div class="modal fade" id="resetModal" tabindex="-1" role="dialog" aria-labelledby="resetModalLabel" aria-hidden="true">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title" id="resetModalLabel">Reset user</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body text-center">
+                Are you sure to reset password for user:<br>
+                <b><span class="ajax-user"></span></b>?<br><br>
+                SSH/SFTP and MySQL passwords will be reset!<br><br>
+                <form action="users/reset" method="POST">
+                    @csrf
+                    <input type="hidden" name="username" value="" class="ajax-username-form">
+                    <input type="submit" class="btn btn-primary" value="Yes, continue!">
+                </form>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
+            </div>
+        </div>
+    </div>
+</div>
+@endsection
+
+
+
+@section('css')
+<link rel="stylesheet" href="https://allyoucan.cloud/cdn/datatable/1.10.13/css/dataTables.css">
+@endsection
+
+
+
+@section('js')
+<script src="https://allyoucan.cloud/cdn/datatable/1.10.13/js/dataTables.js"></script>
+<script>
+	$(document).ready(function() {
+		$('#dataTable').DataTable();
+	});
+</script>
+<script>
+$('#resetModal').on('show.bs.modal', function (event) {
+    var button = $(event.relatedTarget)
+    var user = button.data('username')
+    var modal = $(this)
+    modal.find('.ajax-user').text(user)
+    modal.find('.ajax-username-form').val(user)
+})
+</script>
+@endsection

+ 7 - 3
routes/web.php

@@ -58,9 +58,13 @@ Route::group(['middleware' => 'auth'], function () {
         Route::post('/destroy', 'AliasesController@destroy');
         Route::post('/destroy', 'AliasesController@destroy');
         Route::get('/ssl/{id}', 'AliasesController@ssl');
         Route::get('/ssl/{id}', 'AliasesController@ssl');
     });
     });
+    Route::group(['prefix' => 'users'], function () {
+        Route::get('/', 'UsersController@index');
+        Route::post('/reset', 'UsersController@reset');
+    });
     Route::group(['prefix' => 'settings'], function () {
     Route::group(['prefix' => 'settings'], function () {
-        Route::get('/', 'SetupController@index');
-        Route::post('/profile', 'SetupController@profile');
-        Route::post('/password', 'SetupController@password');
+        Route::get('/', 'SettingsController@index');
+        Route::post('/profile', 'SettingsController@profile');
+        Route::post('/password', 'SettingsController@password');
     });
     });
 });
 });

+ 2 - 2
storage/app/scripts/aliasadd.sh

@@ -20,13 +20,13 @@ while [ -n "$1" ] ; do
     shift
     shift
 done
 done
 
 
-#VIRTUAL HOST
+
 NGINX=/etc/nginx/sites-available/$DOMAIN.conf
 NGINX=/etc/nginx/sites-available/$DOMAIN.conf
 wget $REMOTE/sh/ag/$APPCODE/$DOMAIN -O $NGINX
 wget $REMOTE/sh/ag/$APPCODE/$DOMAIN -O $NGINX
 sudo dos2unix $NGINX
 sudo dos2unix $NGINX
 sudo ln -s $NGINX /etc/nginx/sites-enabled/$DOMAIN.conf
 sudo ln -s $NGINX /etc/nginx/sites-enabled/$DOMAIN.conf
 sudo systemctl restart nginx.service
 sudo systemctl restart nginx.service
 
 
-#RESUME
+
 clear
 clear
 echo "###CIPI###Ok"
 echo "###CIPI###Ok"

+ 3 - 3
storage/app/scripts/aliasdel.sh

@@ -14,14 +14,14 @@ while [ -n "$1" ] ; do
     shift
     shift
 done
 done
 
 
-#SSL & CRON
+
 sudo unlink /etc/cron.d/certbot_renew_$DOMAIN.crontab
 sudo unlink /etc/cron.d/certbot_renew_$DOMAIN.crontab
 
 
-#NGINX
+
 sudo unlink /etc/nginx/sites-enabled/$USER_NAME.conf
 sudo unlink /etc/nginx/sites-enabled/$USER_NAME.conf
 sudo unlink /etc/nginx/sites-available/$USER_NAME.conf
 sudo unlink /etc/nginx/sites-available/$USER_NAME.conf
 sudo systemctl restart nginx.servic
 sudo systemctl restart nginx.servic
 
 
-#RESUME
+
 clear
 clear
 echo "###CIPI###Ok"
 echo "###CIPI###Ok"

+ 57 - 24
storage/app/scripts/hostadd.sh

@@ -36,7 +36,7 @@ while [ -n "$1" ] ; do
     shift
     shift
 done
 done
 
 
-#CREATE USER
+
 sudo useradd -m -s $USER_SHELL -d /home/$USER_NAME -G www-data $USER_NAME
 sudo useradd -m -s $USER_SHELL -d /home/$USER_NAME -G www-data $USER_NAME
 echo "$USER_NAME:$PASSWORD"|chpasswd
 echo "$USER_NAME:$PASSWORD"|chpasswd
 sudo chmod o-r /home/$USER_NAME
 sudo chmod o-r /home/$USER_NAME
@@ -45,7 +45,7 @@ mkdir /home/$USER_NAME/web
 mkdir /home/$USER_NAME/nginx
 mkdir /home/$USER_NAME/nginx
 mkdir /home/$USER_NAME/nginx/log
 mkdir /home/$USER_NAME/nginx/log
 
 
-#WELCOME PAGE
+
 if [ $BASE_PATH != "" ]; then
 if [ $BASE_PATH != "" ]; then
     mkdir /home/$USER_NAME/web/$BASE_PATH
     mkdir /home/$USER_NAME/web/$BASE_PATH
     WELCOME=/home/$USER_NAME/web/$BASE_PATH/index.php
     WELCOME=/home/$USER_NAME/web/$BASE_PATH/index.php
@@ -54,36 +54,69 @@ else
 fi
 fi
 sudo touch $WELCOME
 sudo touch $WELCOME
 sudo cat > "$WELCOME" <<EOF
 sudo cat > "$WELCOME" <<EOF
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
+<!DOCTYPE html>
+<html lang="en">
     <head>
     <head>
-        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+        <meta charset="utf-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1">
         <title>Coming soon...</title>
         <title>Coming soon...</title>
-        <style type="text/css">
-            body {
+        <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
+        <style>
+            html, body {
+                background-color: #fff;
+                color: #636b6f;
+                font-family: 'Nunito', sans-serif;
+                font-weight: 200;
+                height: 100vh;
+                margin: 0;
+            }
+            .full-height {
+                height: 100vh;
+            }
+            .flex-center {
+                align-items: center;
+                display: flex;
+                justify-content: center;
+            }
+            .position-ref {
+                position: relative;
+            }
+            .content {
                 text-align: center;
                 text-align: center;
-                background: #f0f0f0;
-                font-family: Arial, Helvetica, sans-serif;
-                font-size: 48px;
-                font-weight: bold;
             }
             }
-            h2.c1 {
-                margin-top: 60px;
-                color: #444;
-                font-size: 32px;
-                font-weight: lighter;
+            .title {
+                font-size: 84px;
+            }
+            .links > a {
+                color: #636b6f;
+                padding: 0 25px;
+                font-size: 13px;
+                font-weight: 600;
+                letter-spacing: .1rem;
+                text-decoration: none;
+                text-transform: uppercase;
+            }
+            .m-b-md {
+                margin-bottom: 30px;
             }
             }
         </style>
         </style>
     </head>
     </head>
     <body>
     <body>
-        <h2 class="c1">
-            Coming soon...
-        </h2>
+        <div class="flex-center position-ref full-height">
+            <div class="content">
+                <div class="title m-b-md">
+                    Coming soon...
+                </div>
+                <div class="links">
+                    <a href="https://cipi.sh">Powered by Cipi</a>
+                </div>
+            </div>
+        </div>
     </body>
     </body>
 </html>
 </html>
 EOF
 EOF
 
 
-#VIRTUAL HOST
+
 NGINX=/etc/nginx/sites-available/$USER_NAME.conf
 NGINX=/etc/nginx/sites-available/$USER_NAME.conf
 wget $REMOTE/sh/hg/$APPCODE/ -O $NGINX
 wget $REMOTE/sh/hg/$APPCODE/ -O $NGINX
 sudo dos2unix $NGINX
 sudo dos2unix $NGINX
@@ -94,7 +127,7 @@ sudo ln -s $NGINX /etc/nginx/sites-enabled/$USER_NAME.conf
 sudo chown -R www-data: /home/$USER_NAME
 sudo chown -R www-data: /home/$USER_NAME
 sudo systemctl restart nginx.service
 sudo systemctl restart nginx.service
 
 
-#MYSQL
+
 DBNAME=$USER_NAME
 DBNAME=$USER_NAME
 DBUSER=$USER_NAME
 DBUSER=$USER_NAME
 /usr/bin/mysql -u root -p$DBROOT <<EOF
 /usr/bin/mysql -u root -p$DBROOT <<EOF
@@ -104,18 +137,18 @@ GRANT USAGE ON *.* TO '$DBUSER'@'localhost' IDENTIFIED BY '$DBPASS' WITH MAX_QUE
 GRANT ALL PRIVILEGES ON $DBNAME.* TO $DBUSER@'localhost';
 GRANT ALL PRIVILEGES ON $DBNAME.* TO $DBUSER@'localhost';
 EOF
 EOF
 
 
-#GIT
+
 sudo mkdir /home/$USER_NAME/git/
 sudo mkdir /home/$USER_NAME/git/
 sudo cp /cipi/github /home/$USER_NAME/git/deploy
 sudo cp /cipi/github /home/$USER_NAME/git/deploy
 sudo cp /cipi/github.pub /home/$USER_NAME/git/deploy.pub
 sudo cp /cipi/github.pub /home/$USER_NAME/git/deploy.pub
 sudo cp /cipi/deploy.sh /home/$USER_NAME/git/deploy.sh
 sudo cp /cipi/deploy.sh /home/$USER_NAME/git/deploy.sh
 sudo rpl -q "###CIPI-USER###" "$USER_NAME" /home/$USER_NAME/git/deploy.sh
 sudo rpl -q "###CIPI-USER###" "$USER_NAME" /home/$USER_NAME/git/deploy.sh
 
 
-#PERMISSIONS
+
 sudo chown -R $USER_NAME:$USER_NAME /home/$USER_NAME/git/
 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/web/
 sudo chown -R $USER_NAME:$USER_NAME /home/$USER_NAME
 sudo chown -R $USER_NAME:$USER_NAME /home/$USER_NAME
 
 
-#RESUME
+
 clear
 clear
 echo "###CIPI###Ok"
 echo "###CIPI###Ok"

+ 3 - 3
storage/app/scripts/hostdel.sh

@@ -17,16 +17,16 @@ while [ -n "$1" ] ; do
     shift
     shift
 done
 done
 
 
-#LINUX USER
+
 sudo userdel -r $USER_NAME
 sudo userdel -r $USER_NAME
 
 
-#MYSQL USER AND DB
+
 /usr/bin/mysql -u root -p$DBROOT <<EOF
 /usr/bin/mysql -u root -p$DBROOT <<EOF
 DROP DATABASE $USER_NAME;
 DROP DATABASE $USER_NAME;
 DROP USER '$USER_NAME'@'localhost';
 DROP USER '$USER_NAME'@'localhost';
 EOF
 EOF
 
 
-#NGINX
+
 sudo unlink /etc/nginx/sites-enabled/$USER_NAME.conf
 sudo unlink /etc/nginx/sites-enabled/$USER_NAME.conf
 sudo unlink /etc/nginx/sites-available/$USER_NAME.conf
 sudo unlink /etc/nginx/sites-available/$USER_NAME.conf
 sudo systemctl restart nginx.service
 sudo systemctl restart nginx.service

+ 3 - 9
storage/app/scripts/passwd.sh

@@ -1,11 +1,5 @@
 #!/bin/bash
 #!/bin/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
 while [ -n "$1" ] ; do
     case $1 in
     case $1 in
     -u | --user )
     -u | --user )
@@ -32,12 +26,12 @@ while [ -n "$1" ] ; do
     shift
     shift
 done
 done
 
 
-#CHANGE LINUX USER PASSWORD
+
 echo "$USER:$PASS"| sudo chpasswd
 echo "$USER:$PASS"| sudo chpasswd
 
 
-#CHANGE MYSQL PASSWORD
+
 sudo mysqladmin -u $USER -p$DBOLDPASS password $DBPASS
 sudo mysqladmin -u $USER -p$DBOLDPASS password $DBPASS
 
 
-#RESUME
+
 clear
 clear
 echo "###CIPI###Ok"
 echo "###CIPI###Ok"

+ 2 - 2
storage/app/scripts/ssl.sh

@@ -16,10 +16,10 @@ while [ -n "$1" ] ; do
     shift
     shift
 done
 done
 
 
-#SSL CERTIFICATE
+
 sudo certbot --nginx -d $DOMAIN --non-interactive --agree-tos --register-unsafely-without-email
 sudo certbot --nginx -d $DOMAIN --non-interactive --agree-tos --register-unsafely-without-email
 sudo systemctl restart nginx.service
 sudo systemctl restart nginx.service
 
 
-#RESUME
+
 clear
 clear
 echo "###CIPI###Ok"
 echo "###CIPI###Ok"