CornController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/7/9
  6. * Time: 下午5:32
  7. */
  8. namespace app\backend\controllers;
  9. use Illuminate\Routing\Controller;
  10. class CornController extends Controller
  11. {
  12. public function index()
  13. {
  14. // Get security key from config
  15. $cronkeyConfig = \Config::get('liebigCron.cronKey');
  16. // If no security key is set in the config, this route is disabled
  17. if (empty($cronkeyConfig)) {
  18. \Log::error('Cron route call with no configured security key');
  19. \App::abort(404);
  20. }
  21. // Get security key from request
  22. $cronkeyRequest = request()->get('key');
  23. // Create validator for security key
  24. $validator = \Validator::make(
  25. array('cronkey' => $cronkeyRequest),
  26. array('cronkey' => 'required|alpha_num')
  27. );
  28. if ($validator->passes()) {
  29. if ($cronkeyConfig === $cronkeyRequest) {
  30. \Artisan::call('cron:run', array());
  31. } else {
  32. // Configured security key is not equals the sent security key
  33. \Log::error('Cron route call with wrong security key');
  34. \App::abort(404);
  35. }
  36. } else {
  37. // Validation not passed
  38. \Log::error('Cron route call with missing or no alphanumeric security key');
  39. \App::abort(404);
  40. }
  41. return;
  42. }
  43. }