Skip to content

Commit

Permalink
Autoinstall start
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Pollastri committed Dec 6, 2019
1 parent be1e07e commit 1a70d1c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ USER_NAME="Cipi Admin"
USER_EMAIL=[email protected]
USER_PASSWORD=12345678

SSH_DEFAULT_PORT=22

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
Expand Down
17 changes: 10 additions & 7 deletions app/Http/Controllers/ApplicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ public function create(Request $request)
}


$code = uniqid();
$pass = str_random(16);
$dbpass = str_random(16);
$code = 'u'.hash('crc32', uniqid()).str_random(5);
$pass = str_random(40);
$dbpass = str_random(32);
$base = $request->basepath;
$appcode= md5(uniqid().microtime().$request->name);
$appcode= sha1(uniqid().microtime().$request->name);


$autoinstall = $request->autoinstall;


$ssh = New \phpseclib\Net\SSH2($server->ip, $server->port);
Expand All @@ -79,17 +82,17 @@ public function create(Request $request)


$ssh->setTimeout(60);
$response = $ssh->exec('echo '.$server->password.' | sudo -S sudo sh /cipi/host-add.sh -d '.$request->domain.' -u '.$code.' -p '.$pass.' -dbp '.$dbpass.' -b '.$base);
$response = $ssh->exec('echo '.$server->password.' | sudo -S sudo sh /cipi/host-add.sh -d '.$request->domain.' -u '.$code.' -p '.$pass.' -dbp '.$dbpass.' -b '.$base.' -ai '.$autoinstall);


if(strpos($response, '###CIPI###') === false) {
$messagge = 'There was a problem with server. Try later!';
return view('generic', compact('profile','messagge'));
return view('generic', compact('profile','messagge'));
}


$response = explode('###CIPI###', $response);
if(strpos($response[1], 'Ok') === false) {
if(strpos($response[1], 'Ok') === false) {
$messagge = 'There was a problem with server. Try later!';
return view('generic', compact('profile','messagge'));
}
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/ServersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function create(Request $request)
'location' => $request->location,
'ip' => $request->ip,
'port' => config('app.cipi_ssh_port'),
'username' => uniqid(),
'password' => str_random(32),
'dbroot' => str_random(32),
'username' => uniqid().hash('crc32', str_random(64)),
'password' => str_random(64),
'dbroot' => str_random(48),
'servercode'=> md5(uniqid().microtime().$request->name),
]);

Expand Down
1 change: 0 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,4 @@
'cipi_user' => env('USER_NAME', 'Cipi Admin'),
'cipi_email' => env('USER_EMAIL', '[email protected]'),
'cipi_password' => env('USER_PASSWORD', 12345678),
'cipi_ssh_port' => env('SSH_DEFAULT_PORT', 22),
];
18 changes: 12 additions & 6 deletions resources/views/applications.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">{{ __('Applications') }}</h1>
<a href="#" class="btn btn-sm btn-secondary shadow-sm " data-toggle="modal" data-target="#createModal" ><i class="fas fa-plus"></i><span class="d-none d-md-inline"> {{ __('CREATE NEW') }}</span></a>
<a href="#" class="btn btn-sm btn-secondary shadow-sm " data-toggle="modal" data-target="#createModal" ><i class="fas fa-plus"></i><span class="d-none d-md-inline"> {{ __('CREATE NEW') }}</span></a>
</div>
<div class="card shadow mb-4">
<div class="card-body">
Expand All @@ -31,14 +31,14 @@
<i class="fab fa-expeditedssl ssl-click" style="margin-right: 18px; cursor: pointer; color: gray;" data-application="{{ $application->appcode }}" id="ssl-{{ $application->appcode }}"></i>
<i class="fas fa-trash-alt" data-toggle="modal" data-target="#deleteModal" class="fas fa-trash-alt" data-app-code="{{ $application->appcode }}" data-app-domain="{{ $application->domain }}" style="color:gray; cursor: pointer;"></i>
</td>
</tr>
</tr>
@endforeach

</tbody>
</table>
</div>
</div>
</div>
</div>


<!-- CREATE -->
Expand Down Expand Up @@ -74,6 +74,12 @@
<input id="basepath" type="text" class="form-control @error('name') is-invalid @enderror" name="basepath" autocomplete="off" required autofocus placeholder="E.g. 'public'" value="public">
</div>
</div>
<div class="form-group row">
<label for="autoinstall" class="col-md-4 col-form-label text-md-right">{{ __('Autoinstall') }}*</label>
<div class="col-md-6">
<input id="autoinstall" type="text" class="form-control @error('name') is-invalid @enderror" name="autoinstall" autocomplete="off" required autofocus placeholder="E.g. 'laravel'">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{ __('Close') }}</button>
Expand Down Expand Up @@ -124,7 +130,7 @@
});
</script>
<script>
$.get("{{ url('/') }}/ajaxservers/", function(servers) {
$.get("{{ url('/') }}/ajaxservers/", function(servers) {
JSON.parse(servers).forEach(server => {
$("#server-list").append("<option value='"+server["id"]+"'>"+server["name"]+" ("+server["ip"]+")</option>");
});
Expand All @@ -137,7 +143,7 @@ function generatessl(application) {
$.ajax({
url: "{{ url('/') }}/server/api/sslapplication/"+application,
type: "GET",
success: function(response){
success: function(response){
if(response != "OK") {
$("#ssl-"+application).removeClass("fa-spinner fa-spin");
$("#ssl-"+application).removeClass("ssl-click");
Expand Down
18 changes: 16 additions & 2 deletions storage/app/scripts/hostadd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ while [ -n "$1" ] ; do
shift
BASE_PATH=$1
;;
-ai | --autoinstall )
shift
AUTO_INSTALL=$1
;;
* )
echo "ERROR: Unknown option: $1"
exit -1
Expand Down Expand Up @@ -283,8 +287,6 @@ chown -R $USER_NAME:$USER_NAME /home/$USER_NAME/web/
chown -R $USER_NAME:$USER_NAME /home/$USER_NAME/web/$BASE_PATH/




#MYSQL USER AND DB
/usr/bin/mysql -u root -p$DBROOT <<EOF
CREATE DATABASE IF NOT EXISTS $DBNAME;
Expand All @@ -303,6 +305,18 @@ sudo a2ensite $USER_NAME.conf
sudo systemctl restart apache2
sudo service apache2 restart


#AUTOINSTALL
if [ "$AUTO_INSTALL" = "laravel" ]; then
cd /home/$USER_NAME/web/
rm -rf $BASE_PATH
composer create-project laravel/laravel .
fi
if [ "$AUTO_INSTALL" = "wordpress" ]; then
cd /home/$USER_NAME/web/
composer create-project johnpbloch/wordpress $BASE_PATH
fi

#RESUME
clear
echo "###CIPI###Ok"

0 comments on commit 1a70d1c

Please sign in to comment.