diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 22a4336e61..9f15493e21 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -11,7 +11,6 @@ use App\Models\Setting; use App\Models\User; use App\Notifications\FirstAdminNotification; use App\Notifications\MailTest; -use Artisan; use Auth; use Crypt; use DB; @@ -22,6 +21,8 @@ use Image; use Input; use Redirect; use Response; +use Illuminate\Support\Str; +use Illuminate\Support\Facades\Artisan; /** * This controller handles all actions related to Settings for @@ -1136,6 +1137,98 @@ class SettingsController extends Controller } } + + /** + * Uploads a backup file + * + * @author [A. Gianotto] [] + * + * @since [v6.0] + * + * @return Redirect + */ + + public function postUploadBackup(Request $request) { + + $max_file_size = Helper::file_upload_max_size(); + + $rules = [ + 'file' => 'required|mimes:zip|max:'.$max_file_size, + ]; + + $validator = \Validator::make($request->all(), $rules); + + if ($validator->passes()) { + + if ($request->hasFile('file')) { + + $upload_filename = 'uploaded-'.date('U').'-'.Str::slug(pathinfo($request->file('file')->getClientOriginalName(), PATHINFO_FILENAME)).'.zip'; + + Storage::putFileAs('app/backups', $request->file('file'), $upload_filename); + + return redirect()->route('settings.backups.index')->with('success', 'File uploaded'); + + } else { + return redirect()->route('settings.backups.index')->with('error', 'No file uploaded'); + } + + } else { + return redirect()->route('settings.backups.index')->withErrors($request->getErrors()); + } + + } + + /** + * Restore the backup file. + * + * @author [A. Gianotto] [] + * + * @since [v6.0] + * + * @return View + */ + public function postRestore($filename = null) + { + + if (! config('app.lock_passwords')) { + $path = 'app/backups'; + + if (Storage::exists($path.'/'.$filename)) { + + // grab the user's info so we can make sure they exist in the system + $user = User::find(Auth::user()->id); + + // run the restore command + Artisan::call('snipeit:restore', + [ + '--force' => true, + '--no-progress' => true, + 'filename' => storage_path($path).'/'.$filename + ]); + + $output = Artisan::output(); + + + // If it's greater than 300, it probably worked + if (strlen($output) > 300) { + return redirect()->route('settings.backups.index')->with('success', 'Your system has been restored.'); + + } else { + return redirect()->route('settings.backups.index')->with('error', $output); + + } + //dd($output); + + // insert the user if they are not there in the old one + // log the user out + } else { + return redirect()->route('settings.backups.index')->with('error', trans('admin/settings/message.backup.file_not_found')); + } + } else { + return redirect()->route('settings.backups.index')->with('error', trans('general.feature_disabled')); + } + } + /** * Return a form to allow a super admin to update settings. *