예제 #1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     set_time_limit(0);
     \Log::debug('Set PHP time limit to zero (no limit)');
     //Create the Duo Admin Client and set the timeout higher than default
     $duoAdmin = new DuoAdmin();
     $duoAdmin->setRequesterOption('timeout', '6000000');
     \Log::debug('Created new DuoAdmin object', [$duoAdmin]);
     $response = $duoAdmin->groups();
     $groups = $response['response']['response'];
     \Log::debug('Obtained Groups from Duo API - ', [count($groups)]);
     //Loop Duo Groups
     foreach ($groups as $group) {
         \Log::debug('Processing Duo Group', [$group]);
         //Get an existing Duo Group or create a new one
         $duoGroup = Group::firstOrCreate(['group_id' => $group['group_id']]);
         //Update Duo Group Settings
         $duoGroup->name = $group['name'];
         $duoGroup->desc = $group['desc'];
         $duoGroup->status = $group['status'];
         $duoGroup->mobile_otp_enabled = $group['mobile_otp_enabled'];
         $duoGroup->push_enabled = $group['push_enabled'];
         $duoGroup->sms_enabled = $group['sms_enabled'];
         $duoGroup->voice_enabled = $group['voice_enabled'];
         //Save Duo Group
         $duoGroup->touch();
         $duoGroup->save();
     }
     \Log::debug('Completed FetchDuoGroups Job');
 }
예제 #2
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     set_time_limit(0);
     ini_set('memory_limit', '2048M');
     \Log::debug('Set PHP time limit to zero (no limit) and memory to 2GB');
     //Create the Duo Admin Client and set the timeout higher than default
     $duoAdmin = new DuoAdmin();
     $duoAdmin->setRequesterOption('timeout', '6000000');
     \Log::debug('Created new DuoAdmin object', [$duoAdmin]);
     //Query Duo REST API
     $response = $duoAdmin->users($this->username);
     //Duo SDK puts results in nested array [response][response]
     $this->users = $response['response']['response'];
     \Log::debug('Obtained User(s) from Duo API - ', [count($this->users)]);
     //Remove local Duo accounts that no longer exist in the Duo online database
     $this->removeStaleAccounts($this->users);
     \Log::debug('Finished removeStaleAccounts function');
     //If we only queried for one user
     //there's just one user to process
     \Log::debug('Begin extractUserData function');
     if (!isset($this->users[0])) {
         //Begin main process for looping Duo User Data
         $this->extractUserData($this->users);
     } else {
         //Loop the array of users
         foreach ($this->users as $user) {
             //Begin main process for looping Duo User Data
             $this->extractUserData($user);
         }
     }
     \Log::debug('Completed FetchDuoUsers Job');
 }
예제 #3
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     set_time_limit(0);
     ini_set('memory_limit', '2048M');
     //Create the Duo Admin Client and set the timeout higher than default
     $duoAdmin = new DuoAdmin();
     $duoAdmin->setRequesterOption('timeout', '6000000');
     // Set the log $count value to 1000
     $count = 1000;
     $backoff = NULL;
     while ($count >= 1000) {
         \Log::debug('Start Log gathering', ['count' => $count, 'backoff' => $backoff]);
         //Query Duo REST API
         $response = $duoAdmin->logs($this->getMinTime());
         if (isset($response['response']['code']) && $response['response']['code'] == '42901') {
             $backoff += 10;
             \Log::debug('Received backoff notice', ['response' => $response, 'set-backoff' => $backoff]);
             sleep($backoff);
             continue;
         }
         //Duo SDK puts results in nested array [response][response]
         $logs = $response['response']['response'];
         $backoff = NULL;
         \Log::debug('Received Duo Response Object.  Adding new entries ', ['object-count' => count($logs), 'set-backoff' => $backoff]);
         // Loop each log to save
         foreach ($logs as $log) {
             // Get the DuoUser ID to create a relation
             $duoUserId = User::where('username', $log['username'])->first();
             // Sometimes the 'username' from Duo doesn't exist locally....
             if ($duoUserId) {
                 $log['duo_user_id'] = $duoUserId->id;
             } else {
                 $log['duo_user_id'] = NULL;
             }
             // Save the log
             Log::create($log);
         }
         // Set the count to number of logs returned in the last call.
         // If it's less than 1000, we've reached the end of the logs
         \Log::debug('Added new log entries.  Setting count: ', ['count' => count($logs)]);
         $count = count($logs);
     }
 }