From e76c6265d7c9982655c7f7ef0f523650afca9bdf Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 23 Mar 2018 17:43:33 +0300 Subject: [PATCH] cronjob thru url #1956 --- app/Http/Controllers/AppController.php | 25 +++++++++++++++++++++++++ routes/web.php | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/app/Http/Controllers/AppController.php b/app/Http/Controllers/AppController.php index 0e1c8b5370..bcbccb3400 100644 --- a/app/Http/Controllers/AppController.php +++ b/app/Http/Controllers/AppController.php @@ -439,4 +439,29 @@ class AppController extends BaseController echo $invoice->getPDFString(); exit; } + + public function runCommand() + { + if (Utils::isNinjaProd()) { + abort(400, 'Not allowed'); + } + + $command = request()->command; + $options = request()->options ?: []; + $secret = env('CRON_SECRET'); + + if (! $secret) { + exit('Set a value for CRON_SECRET in the .env file'); + } elseif (! hash_equals($secret, request()->secret ?: '')) { + exit('Invalid secret'); + } + + if (! $command || ! in_array($command, ['send-invoices', 'send-reminders', 'update-key'])) { + exit('Invalid command: Valid options are send-invoices, send-reminders or update-key'); + } + + Artisan::call('ninja:' . $command, $options); + + return response(nl2br(Artisan::output())); + } } diff --git a/routes/web.php b/routes/web.php index 2a19444f96..64fea11b43 100644 --- a/routes/web.php +++ b/routes/web.php @@ -109,6 +109,10 @@ Route::group(['middleware' => ['lookup:contact']], function () { Route::get('/proposal/image/{account_key}/{document_key}/{filename?}', 'ClientPortalProposalController@getProposalImage'); }); +if (Utils::isSelfHost()) { + Route::get('/run_command', 'AppController@runCommand'); +} + if (Utils::isReseller()) { Route::post('/reseller_stats', 'AppController@stats'); }