├── .gitignore ├── README.md ├── composer.json └── src ├── AdminerServiceProvider.php ├── Console └── UpdateCommand.php ├── controllers └── AdminerController.php ├── resources └── .gitignore ├── routes.php └── views └── not_found.blade.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | vendor 3 | composer.lock 4 | src/resources/* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # adminer-for-laravel 5.* 2 | [Adminer](https://www.adminer.org) is a full-featured database management tool written in PHP. 3 | This package automates setup for adminer and routes your.domain.here/adminer to the the adminer.php script. 4 | 5 | ## Installation 6 | 7 | #### Composer 8 | ```bash 9 | composer require leung/laravel-adminer 10 | ``` 11 | OR 12 | #### Add directly to your `composer.json` 13 | ```json 14 | "require": { 15 | "leung/laravel-adminer": "^2.0" 16 | }, 17 | ``` 18 | 19 | ## Providers 20 | 21 | ### Laravel <5.4 22 | open your `config/app.php` and add this line in providers section 23 | ```php 24 | Simple\Adminer\AdminerServiceProvider::class 25 | ``` 26 | ###### OR prevent it being on production 27 | open your `app/Providers/AppServiceProvider.php` and add this line in the `register()` function 28 | ```php 29 | if ($this->app->environment() !== 'production') { 30 | $this->app->register(\Simple\Adminer\AdminerServiceProvider::class); 31 | } 32 | ``` 33 | 34 | ### Laravel 5.5 providers 35 | auto included via automatic package discovery 36 | ```php 37 | // no need to add anything!!! 38 | ``` 39 | 40 | ## Update adminer.php 41 | 42 | #### Linux command line update 43 | ```bash 44 | php artisan adminer:update 45 | ``` 46 | 47 | You can configure your composer.json to do this after each commit: 48 | 49 | ```js 50 | "scripts": { 51 | "post-install-cmd": [ 52 | "php artisan adminer:update" 53 | ], 54 | "post-update-cmd": [ 55 | "php artisan adminer:update" 56 | ] 57 | } 58 | ``` 59 | --- 60 | ## [Optional] Middleware 61 | 62 | #### Middleware is added in via the service provider 63 | to override this you may add a adminer route to your App routes.php 64 | 65 | ```php 66 | Route::any('adminer', '\Simple\Adminer\Controllers\AdminerController@index')->middleware('adminer_custom_middleware'); // where you defined your middleware in app/Http/Kernel.php 67 | ``` 68 | 69 | #### Add middleware group example 70 | to add a custom middleware group you will need to add it to middlewareGroups in your `app/Http/Kernel.php` 71 | ```php 72 | protected $middlewareGroups = [ 73 | ... 74 | 'adminer_custom_middleware' => [ 75 | \App\Http\Middleware\EncryptCookies::class, 76 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 77 | \Illuminate\Session\Middleware\StartSession::class, 78 | 79 | // you may create customized middleware to fit your needs 80 | ... 81 | ], 82 | ]; 83 | ``` 84 | 85 | #### Modify app/Http/Middleware/VerifyCsrfToken.php 86 | also add adminer to $except array if you are using the example optional adminer group 87 | ```php 88 | protected $except = [ 89 | 'adminer' 90 | ]; 91 | ``` 92 | 93 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leung/laravel-adminer", 3 | "description": "adminer for laravel5.*", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "leung", 8 | "email": "simple@gmail.com" 9 | }, 10 | { 11 | "name": "Artistan", 12 | "email": "artistan@gmail.com" 13 | } 14 | ], 15 | "require": { 16 | "guzzlehttp/guzzle": "^6.3" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "Simple\\Adminer\\": "src/" 21 | } 22 | }, 23 | "extra": { 24 | "laravel": { 25 | "providers": [ 26 | "Simple\\Adminer\\AdminerServiceProvider" 27 | ] 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/AdminerServiceProvider.php: -------------------------------------------------------------------------------- 1 | loadViewsFrom(__DIR__.'/views', 'adminer'); 19 | $this->map(); 20 | } 21 | 22 | public function map() 23 | { 24 | $this->mapAdminerRoutes(); 25 | } 26 | 27 | public function mapAdminerRoutes() 28 | { 29 | \Route::middleware(['encrypt_cookies', 'add_queue_cookies','start_session']) 30 | ->namespace($this->namespace) 31 | ->group(__DIR__.'/routes.php'); 32 | } 33 | 34 | /** 35 | * Register the application services. 36 | * 37 | * @return void 38 | */ 39 | public function register() 40 | { 41 | if(!method_exists($this->app['router'],'middleware')) { 42 | // Laravel 5.4 no longer has middleware function on the router class 43 | $this->app['router']->aliasMiddleware('encrypt_cookies', \Illuminate\Cookie\Middleware\EncryptCookies::class); 44 | $this->app['router']->aliasMiddleware('add_queue_cookies', \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class); 45 | $this->app['router']->aliasMiddleware('start_session', \Illuminate\Session\Middleware\StartSession::class); 46 | } else { 47 | $this->app['router']->middleware('encrypt_cookies', \Illuminate\Cookie\Middleware\EncryptCookies::class); 48 | $this->app['router']->middleware('add_queue_cookies', \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class); 49 | $this->app['router']->middleware('start_session', \Illuminate\Session\Middleware\StartSession::class); 50 | } 51 | 52 | 53 | $this->app->singleton( 54 | 'command.adminer.update', 55 | function ($app) { 56 | return new UpdateCommand($app['files']); 57 | } 58 | ); 59 | 60 | $this->commands( 61 | 'command.adminer.update' 62 | ); 63 | } 64 | 65 | /** 66 | * Get the services provided by the provider. 67 | * 68 | * @return array 69 | */ 70 | public function provides() 71 | { 72 | return array('command.adminer.update'); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/Console/UpdateCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2017 Charles A. Peterson 7 | * @license http://www.opensource.org/licenses/mit-license.php MIT 8 | */ 9 | 10 | namespace Simple\Adminer\Console; 11 | 12 | use Illuminate\Console\Command; 13 | use Illuminate\Filesystem\Filesystem; 14 | use GuzzleHttp\Exception\GuzzleException; 15 | use GuzzleHttp\Client; 16 | 17 | /** 18 | * A command to update the file for adminer.php 19 | * 20 | * @author Charles A. Peterson 21 | */ 22 | class UpdateCommand extends Command 23 | { 24 | /** 25 | * The console command name. 26 | * 27 | * @var string 28 | */ 29 | protected $name = 'adminer:update'; 30 | 31 | /** 32 | * @var Filesystem $files 33 | */ 34 | protected $files; 35 | 36 | /** 37 | * @var String $version 38 | */ 39 | protected $version; 40 | 41 | /** 42 | * @var String $filename 43 | */ 44 | protected $filename; 45 | 46 | /** 47 | * The console command description. 48 | * 49 | * @var string 50 | */ 51 | protected $description = 'Add \Eloquent helper to \Eloquent\Model'; 52 | 53 | /** 54 | * @param Filesystem $files 55 | */ 56 | public function __construct(Filesystem $files) 57 | { 58 | parent::__construct(); 59 | $this->files = $files; 60 | 61 | $resources = realpath(dirname(__FILE__).'/../resources'); 62 | $this->version = $resources.'/version'; 63 | $this->filename = $resources.'/adminer.php'; 64 | $this->tmpfile = $resources.'/tmp.php'; 65 | } 66 | 67 | /** 68 | * Execute the console command. 69 | * 70 | * @return void 71 | */ 72 | public function handle() 73 | { 74 | $latest_version = $this->get('https://api.github.com/repos/vrana/adminer/releases/latest'); 75 | if(!$latest_version || $latest_version->getStatusCode() != '200'){ 76 | $this->error('Adminer: latest release no found??'); 77 | return; 78 | } 79 | $latest_version = json_decode((string) $latest_version->getBody())->tag_name; 80 | try { 81 | $last_version = $this->files->get($this->version); 82 | } catch (\Exception $e) { 83 | // do not care if file not found... 84 | $this->info('Adminer: no last version, welcome!'); 85 | $last_version = false; 86 | } 87 | if($latest_version != $last_version){ 88 | $result = $this->get('http://www.adminer.org/latest.php',['sink' => $this->filename]); 89 | if($result && $result->getStatusCode() == '200'){ 90 | $this->all_sed_and_done(); 91 | $this->files->put($this->version, $latest_version); 92 | $this->info('Adminer: updated!'); 93 | } else { 94 | $this->error('Adminer: '.$result->getStatusCode().' :: file not downloaded?'); 95 | } 96 | } else { 97 | $this->info('Adminer: already latest version!'); 98 | } 99 | } 100 | 101 | /** 102 | * @param $uri 103 | * @param array $params 104 | * 105 | * @return bool|mixed|\Psr\Http\Message\ResponseInterface 106 | */ 107 | private function get($uri,$params=[]){ 108 | try { 109 | $client = new Client(); //GuzzleHttp\Client 110 | return $client->request('GET', $uri, $params); 111 | } catch (GuzzleException $e) { 112 | $this->error($e->getMessage()); 113 | } 114 | return false; 115 | } 116 | 117 | /** 118 | * call replace on functions that are already defined 119 | */ 120 | private function all_sed_and_done(){ 121 | foreach(['redirect','cookie','view'] as $replace) 122 | $this->sed($replace); 123 | } 124 | 125 | /** 126 | * sed prefix functions that are already defined with adminer_ 127 | * 128 | * @param $string 129 | */ 130 | private function sed($string){ 131 | echo shell_exec('LC_ALL=C sed -i -r \'s/([)\;]|^)'.$string.'/\1adminer_'.$string.'/g\' '.$this->filename); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/controllers/AdminerController.php: -------------------------------------------------------------------------------- 1 | middleware('adminer'); 13 | } 14 | // AdminerServiceProvider::register holds the middleware register so it does not need addeed manually. 15 | 16 | $this->adminer = __DIR__.'/../resources/adminer.php'; 17 | } 18 | 19 | public function index() 20 | { 21 | if(file_exists($this->adminer )){ 22 | require($this->adminer); 23 | } else { 24 | return view('adminer::not_found'); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhq0826/adminer-for-laravel/cb8515508760e77c11f68e2efcaabbc5ca1083c4/src/resources/.gitignore -------------------------------------------------------------------------------- /src/routes.php: -------------------------------------------------------------------------------- 1 |