Skip to content

Commit

Permalink
Pathfix, readme update + Databases + DB & SSH user reset split
Browse files Browse the repository at this point in the history
  • Loading branch information
andreapollastri committed May 5, 2020
1 parent 1960c76 commit 89c8081
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
![](http://cipi.sh/home/assets/images/home.gif)

## About
Cipi is a Laravel based cloud server control panel that supports Digital Ocean, AWS, Vultr, Google Cloud, Linode, Azure and other VPS. It comes with nginx, Mysql, multi PHP-FPM versions, multi users, Supervisor, Composer, npm, free Let's Encrypt certificates, Git deployment, backups, fail2ban and with a simple graphical interface useful to manage Laravel, Codeigniter, Symphony, WordPress or other PHP applications. With Cipi you don’t need to be a Sys Admin to deploy and manage websites and PHP applications powered by cloud VPS.
Cipi is a Laravel based cloud server control panel that supports Digital Ocean, AWS, Vultr, Google Cloud, Linode, Azure and other VPS. It comes with nginx, Mysql, multi PHP-FPM versions, multi users, Supervisor, Composer, npm, free Let's Encrypt certificates, Git deployment, backups, postfix, phpmyadmin, fail2ban and with a simple graphical interface useful to manage Laravel, Codeigniter, Symphony, WordPress or other PHP applications. With Cipi you don’t need to be a Sys Admin to deploy and manage websites and PHP applications powered by cloud VPS.

## Features
- Easy install: setup one or more servers with a click in less than ten minutes without be a Linux expert.
Expand Down
59 changes: 59 additions & 0 deletions app/Http/Controllers/DatabasesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Application;
use phpseclib\Net\SSH2 as SSH;


class DatabasesController extends Controller {


public function index() {
$databases = Application::all();
return view('databases', compact('databases'));
}


public function reset(Request $request) {
$this->validate($request, [
'username' => 'required'
]);
$application = Application::where('username', $request->username)->with('server')->firstOrFail();
$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->ip);
$ssh->setTimeout(360);
$response = $ssh->exec('echo '.$application->server->password.' | sudo -S sudo sh /cipi/passwd.sh -u '.$request->username.' -p '.$application->password.' -dbp '.$pass. ' -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->dbpass = $pass;
$application->save();
$app = [
'user' => $request->username,
'pass' => $request->password,
'dbname' => $request->username,
'dbuser' => $request->username,
'dbpass' => $pass,
'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'));
}

}
8 changes: 3 additions & 5 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public function reset(Request $request) {
$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);
$pass = sha1(uniqid().microtime().$application->domain);
$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);
$response = $ssh->exec('echo '.$application->server->password.' | sudo -S sudo sh /cipi/passwd.sh -u '.$request->username.' -p '.$pass.' -dbp '.$application->dbpass. ' -dbop '.$application->dbpass);
if(strpos($response, '###CIPI###') === false) {
$request->session()->flash('alert-error', 'There was a problem with server scripts.');
return redirect('/users');
Expand All @@ -40,14 +39,13 @@ public function reset(Request $request) {
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,
'dbpass' => $application->dbpass,
'path' => $application->basepath,
'domain' => $application->domain,
'php' => $application->php,
Expand Down
2 changes: 1 addition & 1 deletion resources/views/applications.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<td class="text-center">{{ $application->domain }}</td>
<td class="text-center">{{ $application->server->ip }}</td>
<td class="text-center">{{ $application->username }}</td>
<td class="text-center">{{ $application->basepath }}</td>
<td class="text-center">/{{ $application->basepath }}</td>
<td class="text-center">{{ $application->php }}</td>
<td class="text-center">{{ count($application->aliases) }}</td>
<td class="text-center">
Expand Down
104 changes: 104 additions & 0 deletions resources/views/databases.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
@extends('layouts.app')



@section('title')
Databases
@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">Database</th>
<th class="text-center d-none d-lg-table-cell">Application</th>
<th class="text-center d-none d-lg-table-cell">IP</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
@foreach($databases as $database)
<tr>
<td class="text-center">{{ $database->username }}</td>
<td class="text-center">{{ $database->username }}</td>
<td class="text-center">{{ $database->domain }}</td>
<td class="text-center d-none d-lg-table-cell">{{ $database->server->ip }}</td>
<td class="text-center">
<a target="_blank" style="margin-right: 18px;" href="http://{{ $database->server->ip }}/pma">
<i class="fas fa-table" style="color:gray;"></i>
</a>
<a href="#" data-toggle="modal" data-target="#resetModal" data-username="{{ $database->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 database 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>
MySQL password will be reset!<br><br>
<form action="databases/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
6 changes: 6 additions & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
<span>Aliases</span>
</a>
</li>
<li class="nav-item {{ request()->is('databases') ? 'active' : '' }}">
<a class="nav-link" href="/databases">
<i class="fas fa-fw fa-database"></i>
<span>Databases</span>
</a>
</li>
<li class="nav-item {{ request()->is('users') ? 'active' : '' }}">
<a class="nav-link" href="/users">
<i class="fas fa-fw fa-users"></i>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/server.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<tr>
<td class="text-center">{{ $application->domain }}</td>
<td class="text-center">{{ $application->username }}</td>
<td class="text-center">{{ $application->basepath }}</td>
<td class="text-center">/{{ $application->basepath }}</td>
<td class="text-center">{{ $application->php }}</td>
<td class="text-center">{{ count($application->aliases) }}</td>
<td class="text-center">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/users.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="resetModalLabel">Reset user</h5>
<h5 class="modal-title" id="resetModalLabel">Reset SSH/SFTP 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>
SSH/SFTP password will be reset!<br><br>
<form action="users/reset" method="POST">
@csrf
<input type="hidden" name="username" value="" class="ajax-username-form">
Expand Down
4 changes: 4 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
Route::post('/destroy', 'AliasesController@destroy');
Route::get('/ssl/{aliascode}', 'AliasesController@ssl');
});
Route::group(['prefix' => 'databases'], function () {
Route::get('/', 'DatabasesController@index');
Route::post('/reset', 'DatabasesController@reset');
});
Route::group(['prefix' => 'users'], function () {
Route::get('/', 'UsersController@index');
Route::post('/reset', 'UsersController@reset');
Expand Down

0 comments on commit 89c8081

Please sign in to comment.