-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6485722
Showing
12 changed files
with
573 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Changelog | ||
|
||
All Notable changes to `backupmanager` will be documented in this file | ||
|
||
## NEXT - YYYY-MM-DD | ||
|
||
### Added | ||
- Nothing | ||
|
||
### Deprecated | ||
- Nothing | ||
|
||
### Fixed | ||
- Nothing | ||
|
||
### Removed | ||
- Nothing | ||
|
||
### Security | ||
- Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Contributing | ||
|
||
Contributions are **welcome** and will be fully **credited**. | ||
|
||
We accept contributions via Pull Requests on [Github](https://github.com/thephpleague/:package_name). | ||
|
||
|
||
## Pull Requests | ||
|
||
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). | ||
|
||
- **Add tests!** - Your patch won't be accepted if it doesn't have tests. | ||
|
||
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. | ||
|
||
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. | ||
|
||
- **Create feature branches** - Don't ask us to pull from your master branch. | ||
|
||
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. | ||
|
||
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. | ||
|
||
|
||
## Running Tests | ||
|
||
``` bash | ||
$ phpunit | ||
``` | ||
|
||
|
||
**Happy coding**! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Cristian Tabacitu <[email protected]> | ||
|
||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
> in the Software without restriction, including without limitation the rights | ||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
> copies of the Software, and to permit persons to whom the Software is | ||
> furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in | ||
> all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
> THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# backupmanager | ||
|
||
[](https://packagist.org/packages/tabacitu/backupmanager) | ||
[](LICENSE.md) | ||
[](https://travis-ci.org/tabacitu/backupmanager) | ||
[](https://scrutinizer-ci.com/g/tabacitu/backupmanager/code-structure) | ||
[](https://scrutinizer-ci.com/g/tabacitu/backupmanager) | ||
[](https://packagist.org/packages/tabacitu/backupmanager) | ||
|
||
An admin interface for managing backups (download and delete). Used in the Dick Admin package, on Laravel 5. | ||
|
||
## Install | ||
|
||
Via Composer | ||
|
||
``` bash | ||
$ composer require dick/backupmanager | ||
``` | ||
|
||
Then add the service providers to your config/app.php file: | ||
|
||
``` | ||
'Spatie\Backup\BackupServiceProvider', | ||
'Dick\BackupManager\BackupManagerServiceProvider', | ||
``` | ||
|
||
Publish the config files: | ||
|
||
``` | ||
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider" | ||
php artisan vendor:publish --provider="Dick\BackupManager\BackupManagerServiceProvider" | ||
``` | ||
|
||
## Usage | ||
|
||
Add a menu element for it: | ||
|
||
``` php | ||
[ | ||
'label' => "Backups", | ||
'route' => 'admin/backup', | ||
'icon' => 'fa fa-hdd-o', | ||
], | ||
``` | ||
|
||
Or just try at **your-project-domain/admin/backup** | ||
|
||
## Change log | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. | ||
|
||
## Testing | ||
|
||
``` bash | ||
$ composer test | ||
``` | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](CONTRIBUTING.md) for details. | ||
|
||
## Security | ||
|
||
If you discover any security related issues, please email [email protected] instead of using the issue tracker. | ||
|
||
## Credits | ||
|
||
- [Cristian Tabacitu](https://github.com/tabacitu) | ||
- [All Contributors](../../contributors) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "Dick/BackupManager", | ||
"description": "Admin interface for managing backups in Dick, on Laravel 5.", | ||
"keywords": [ | ||
"dick", | ||
"backupmanager", | ||
"tabacitu", | ||
"laravel" | ||
], | ||
"homepage": "https://github.com/tabacitu/BackupManager", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Cristian Tabacitu", | ||
"email": "[email protected]", | ||
"homepage": "http://tabacitu.ro", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"illuminate/support": "~5.1", | ||
"php" : ">=5.3.0", | ||
"spatie/laravel-backup": "^2.4" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit" : "4.*", | ||
"scrutinizer/ocular": "~1.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Dick\\BackupManager\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Dick\\BackupManager\\Test\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "phpunit" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Dick\BackupManager; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Illuminate\Routing\Router; | ||
|
||
class BackupManagerServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Perform post-registration booting of services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
// use this if your package has views | ||
$this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backupmanager'); | ||
|
||
// use this if your package has routes | ||
$this->setupRoutes($this->app->router); | ||
|
||
// use this if your package needs a config file | ||
$this->publishes([ | ||
__DIR__.'/config/config.php' => config_path('dick/backupmanager.php'), | ||
]); | ||
} | ||
|
||
/** | ||
* Define the routes for the application. | ||
* | ||
* @param \Illuminate\Routing\Router $router | ||
* @return void | ||
*/ | ||
public function setupRoutes(Router $router) | ||
{ | ||
$router->group(['namespace' => 'Dick\BackupManager\Http\Controllers'], function($router) | ||
{ | ||
require __DIR__.'/Http/routes.php'; | ||
}); | ||
} | ||
|
||
/** | ||
* Register any package services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->registerBackupManager(); | ||
|
||
// use this if your package has a config file | ||
config([ | ||
'config/config.php', | ||
]); | ||
} | ||
|
||
private function registerBackupManager() | ||
{ | ||
$this->app->bind('backupmanager',function($app){ | ||
return new BackupManager($app); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php namespace Dick\BackupManager\Http\Controllers; | ||
|
||
use App\Http\Requests; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Auth; | ||
use App; | ||
use Storage; | ||
use Carbon\Carbon; | ||
use Artisan; | ||
|
||
class BackupController extends Controller { | ||
|
||
public function __construct() | ||
{ | ||
$this->middleware('auth'); | ||
|
||
// Check for the right roles to access these pages | ||
if (!\Entrust::can('view-backups')) { | ||
abort(403, 'Unauthorized access - you do not have the necessary permissions to see this page.'); | ||
} | ||
} | ||
|
||
public function index() | ||
{ | ||
$disk = Storage::disk('local'); | ||
$files = $disk->files('backups'); | ||
$this->data['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)) { | ||
$this->data['backups'][] = [ | ||
'file_path' => $f, | ||
'file_name' => str_replace('backups/', '', $f), | ||
'file_size' => $disk->size($f), | ||
'last_modified' => $disk->lastModified($f), | ||
]; | ||
} | ||
} | ||
|
||
// reverse the backups, so the newest one would be on top | ||
$this->data['backups'] = array_reverse($this->data['backups']); | ||
|
||
return view("backupmanager::backup", $this->data); | ||
} | ||
|
||
public function create() | ||
{ | ||
if (!\Entrust::can('make-backups')) { | ||
abort(403, 'Unauthorized access - you do not have the necessary permission to make backups.'); | ||
} | ||
|
||
try { | ||
Artisan::call('backup:run'); | ||
echo 'done backup:run'; | ||
} catch (Exception $e) { | ||
Response::make($e->getMessage(), 500); | ||
} | ||
|
||
// return 'success'; | ||
} | ||
|
||
/** | ||
* Downloads a backup zip file. | ||
* | ||
* TODO: make it work no matter the flysystem driver (S3 Bucket, etc). | ||
*/ | ||
public function download($file_name) | ||
{ | ||
if (!\Entrust::can('download-backups')) { | ||
abort(403, 'Unauthorized access - you do not have the necessary permission to download backups.'); | ||
} | ||
|
||
$disk = Storage::disk('local'); | ||
|
||
if ($disk->exists('backups/'.$file_name)) { | ||
return response()->download(storage_path('backups/'.$file_name)); | ||
} | ||
else | ||
{ | ||
abort(404, "The backup file doesn't exist."); | ||
} | ||
} | ||
|
||
/** | ||
* Deletes a backup file. | ||
*/ | ||
public function delete($file_name) | ||
{ | ||
if (!\Entrust::can('delete-backups')) { | ||
abort(403, 'Unauthorized access - you do not have the necessary permission to delete backups.'); | ||
} | ||
|
||
$disk = Storage::disk('local'); | ||
|
||
if ($disk->exists('backups/'.$file_name)) { | ||
$disk->delete('backups/'.$file_name); | ||
|
||
return 'success'; | ||
} | ||
else | ||
{ | ||
abort(404, "The backup file doesn't exist."); | ||
} | ||
} | ||
} |
Oops, something went wrong.