/**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $formattedEraserList = generateEraserList($this->eraserList);
     foreach ($formattedEraserList as $device) {
         //Create the Phone model
         $phone = Phone::firstOrCreate(['mac' => $device['DeviceName'], 'description' => $device['Description']]);
         //Start creating Eraser
         $tleObj = Eraser::create(['phone_id' => $phone->id, 'ip_address' => $device['IpAddress'], 'eraser_type' => $device['type']]);
         if (isset($device['bulk_id'])) {
             $tleObj->bulks()->attach($device['bulk_id']);
         }
         if ($device['IpAddress'] == "Unregistered/Unknown") {
             $tleObj->result = 'Fail';
             $tleObj->failure_reason = 'Unregistered/Unknown';
             $tleObj->save();
             continue;
         }
         $keys = setKeys($device['Model'], $device['type']);
         if (!$keys) {
             $tleObj->result = 'Fail';
             $tleObj->failure_reason = 'Unsupported Model';
             $tleObj->save();
             return;
         }
         $dialer = new PhoneDialer($device['IpAddress']);
         $status = $dialer->dial($tleObj, $keys);
         //Successful if returned true
         $passFail = $status ? 'Success' : 'Fail';
         $tleObj->result = $passFail;
         $tleObj->save();
     }
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $macList = array_column($this->eraserArray, 'MAC');
     $phoneList = new PreparePhoneList();
     $risPortResults = $phoneList->createList($macList);
     foreach ($this->eraserArray as $row) {
         $key = array_search($row['MAC'], array_column($risPortResults, 'DeviceName'));
         $risPortResults[$key]['TLE'] = $row['TLE'];
         $risPortResults[$key]['BULK_ID'] = $row['BULK_ID'];
     }
     //Loop Devices and erase Trust List
     foreach ($risPortResults as $device) {
         //Create the Phone model
         $phone = Phone::firstOrCreate(['mac' => $device['DeviceName'], 'description' => $device['Description']]);
         //Start creating Eraser
         $tleObj = Eraser::create(['phone_id' => $phone->id, 'ip_address' => $device['IpAddress'], 'eraser_type' => $device['TLE']]);
         $tleObj->bulks()->attach($device['BULK_ID']);
         if ($device['IpAddress'] == "Unregistered/Unknown") {
             //Not registered, save as failed
             $tleObj->result = 'Fail';
             $tleObj->failure_reason = 'Unregistered/Unknown';
             $tleObj->save();
             Log::info('Device Unregistered/Unknown.', [$device]);
             continue;
         }
         /*
          * Get the key press series
          */
         $keys = setKeys($device['Model'], $tleObj->eraser_type);
         Log::info('setKeys(),$keys', [$tleObj->eraser_type]);
         if (!$keys) {
             $tleObj->result = 'Fail';
             $tleObj->failure_reason = 'Unsupported Model';
             $tleObj->save();
             return;
         }
         $dialer = new PhoneDialer($device['IpAddress']);
         //Dial the keys
         $status = $dialer->dial($tleObj, $keys);
         //Successful if returned true
         $passFail = $status ? 'Success' : 'Fail';
         $tleObj->result = $passFail;
         $tleObj->save();
         return;
     }
 }
Exemple #3
0
 public function dial(Eraser $tle, $keys)
 {
     $mac = $tle->phone->mac;
     $ip = $this->phoneIP;
     foreach ($keys as $k) {
         if ($k == "Key:Sleep") {
             sleep(2);
             continue;
         }
         $xml = 'XML=<CiscoIPPhoneExecute><ExecuteItem Priority="0" URL="' . $k . '"/></CiscoIPPhoneExecute>';
         try {
             $response = $this->client->post('http://' . $tle->ip_address . '/CGI/Execute', ['body' => $xml]);
             //Temp workaround for USC NAT
             //                $response = $this->client->post('http://10.134.174.78/CGI/Execute',['body' => $xml]);
         } catch (RequestException $e) {
             if ($e instanceof ClientException) {
                 //Unauthorized
                 $tle->failure_reason = "Authentication Exception";
                 $tle->save();
                 throw new PhoneDialerException("{$mac} @ {$ip} Authentication Exception");
             } elseif ($e instanceof ConnectException) {
                 //Can't Connect
                 $tle->failure_reason = "Connection Exception";
                 $tle->save();
                 throw new PhoneDialerException("{$mac} @ {$ip} Connection Exception");
             } else {
                 //Other exception
                 $tle->failure_reason = "Unknown Exception";
                 $tle->save();
                 throw new PhoneDialerException("{$mac} @ {$ip} {$e->getMessage}()");
             }
             return false;
         }
         /*
          * Check our response code and flip
          * $return to false if non zero
          */
         $this->reader->xml($response->getBody()->getContents());
         $response = $this->reader->parse();
         if (isset($response['CiscoIPPhoneResponse'])) {
             Log::info('dial(),response', [$response]);
         } elseif (isset($response['name']) && $response['name'] == '{}CiscoIPPhoneError') {
             //Log an Error
             switch ($response['attributes']['Number']) {
                 case 4:
                     $errorType = 'Authentication Exception';
                     break;
                 case 6:
                     $errorType = 'Invalid URL Exception';
                     break;
                 default:
                     $errorType = 'Unknown Exception';
                     break;
             }
             $tle->failure_reason = $errorType;
             $tle->result = "Fail";
             $tle->save();
             throw new PhoneDialerException("{$mac} @ {$ip} {$errorType}");
         }
     }
     return true;
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function ctlIndex()
 {
     $ctls = Eraser::where('eraser_type', 'ctl')->get();
     return view('ctl.index', compact('ctls'));
 }