| Server IP : 103.161.17.216 / Your IP : 216.73.216.1 Web Server : nginx/1.18.0 System : Linux tipsysaigoncharming 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/app.ansachsongkhoe.net/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Storage;
use Log;
use App\Utils\Util;
class BackUpController extends Controller
{
/**
* All Utils instance.
*
*/
protected $commonUtil;
public function __construct(Util $commonUtil)
{
$this->commonUtil = $commonUtil;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
if (!auth()->user()->can('backup')) {
abort(403, 'Unauthorized action.');
}
$disk = Storage::disk(config('backup.backup.destination.disks')[0]);
$files = $disk->files(config('backup.backup.name'));
$backups = [];
// make an array of backup files, with their filesize and creation date
foreach ($files as $k => $f) {
// only take the zip files into account
if (substr($f, -4) == '.zip' && $disk->exists($f)) {
$backups[] = [
'file_path' => $f,
'file_name' => str_replace(config('backup.backup.name') . '/', '', $f),
'file_size' => $disk->size($f),
'last_modified' => $disk->lastModified($f),
];
}
}
// reverse the backups, so the newest one would be on top
$backups = array_reverse($backups);
$cron_job_command = $this->commonUtil->getCronJobCommand();
$backup_clean_cron_job_command = $this->commonUtil->getBackupCleanCronJobCommand();
return view("backup.index")
->with(compact('backups', 'cron_job_command', 'backup_clean_cron_job_command'));
}
/**
* Create a resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
if (!auth()->user()->can('backup')) {
abort(403, 'Unauthorized action.');
}
try {
//Disable in demo
$notAllowed = $this->commonUtil->notAllowedInDemo();
if (!empty($notAllowed)) {
return $notAllowed;
}
// start the backup process
Artisan::call('backup:run');
$output = Artisan::output();
// log the results
Log::info("Backpack\BackupManager -- new backup started from admin interface \r\n" . $output);
$output = ['success' => 1,
'msg' => __('lang_v1.success')
];
} catch (Exception $e) {
$output = ['success' => 0,
'msg' => $e->getMessage()
];
}
return back()->with('status', $output);
}
/**
* Downloads a backup zip file.
*
* TODO: make it work no matter the flysystem driver (S3 Bucket, etc).
*/
public function download($file_name)
{
if (!auth()->user()->can('backup')) {
abort(403, 'Unauthorized action.');
}
//Disable in demo
if (config('app.env') == 'demo') {
$output = ['success' => 0,
'msg' => 'Feature disabled in demo!!'
];
return back()->with('status', $output);
}
$file = config('backup.backup.name') . '/' . $file_name;
$disk = Storage::disk(config('backup.backup.destination.disks')[0]);
if ($disk->exists($file)) {
$fs = Storage::disk(config('backup.backup.destination.disks')[0])->getDriver();
$stream = $fs->readStream($file);
return \Response::stream(function () use ($stream) {
fpassthru($stream);
}, 200, [
"Content-Type" => $fs->getMimetype($file),
"Content-Length" => $fs->getSize($file),
"Content-disposition" => "attachment; filename=\"" . basename($file) . "\"",
]);
} else {
abort(404, "The backup file doesn't exist.");
}
}
/**
* Deletes a backup file.
*/
public function delete($file_name)
{
if (!auth()->user()->can('backup')) {
abort(403, 'Unauthorized action.');
}
//Disable in demo
if (config('app.env') == 'demo') {
$output = ['success' => 0,
'msg' => 'Feature disabled in demo!!'
];
return back()->with('status', $output);
}
$disk = Storage::disk(config('backup.backup.destination.disks')[0]);
if ($disk->exists(config('backup.backup.name') . '/' . $file_name)) {
$disk->delete(config('backup.backup.name') . '/' . $file_name);
return redirect()->back();
} else {
abort(404, "The backup file doesn't exist.");
}
}
}