예제 #1
0
 /**
  * @param $id
  * @return \BladeView|bool|\Illuminate\View\View
  */
 public function showUser($id)
 {
     $user = DuoUser::find($id);
     $reports = Report::where('name', 'like', '%duo%')->get();
     $groups = Group::all();
     return view('duo.show', compact('user', 'reports', 'groups'));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //Get all reports where type = cucm_daily
     $reports = Report::where('type', 'cucm_daily')->get();
     //Get all configured CUCM clusters
     $clusters = $this->cluster->all();
     //Set timestamp for file names
     $timeStamp = Carbon::now('America/New_York')->toDateTimeString();
     //Create array to track attachments
     $attachments = [];
     //Loop reports
     foreach ($reports as $index => $report) {
         $attachments[$index] = $report->path . $report->name . '-' . $timeStamp . '.csv';
         //Persist report to disk
         Storage::put($attachments[$index], $report->csv_headers);
         //Loop each cluster and run the reports
         foreach ($clusters as $cluster) {
             $this->dispatch(new $report->job($cluster, $attachments[$index]));
         }
     }
     //Reports are done running, let's email to results
     $beautymail = app()->make(\Snowfire\Beautymail\Beautymail::class);
     $beautymail->send('emails.cucmDailyReporting', [], function ($message) use($attachments) {
         //TODO: Create system for users to manage report subscriptions.
         $message->to(['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'])->subject('CUCM Daily Report');
         //Add all reports to email
         foreach ($attachments as $report) {
             $message->attach(storage_path($report));
         }
     });
 }
 /**
  * @throws \PHPExcel_Exception
  * @throws \PHPExcel_Writer_Exception
  */
 public function handle()
 {
     //Create the reporting Excel Object
     $objPHPExcel = new PHPExcel();
     //Check if the recipient is assigned to a group.  If not, log and continue.
     if ($this->user->duoGroups()->count()) {
         $groups = $this->user->duoGroups()->get();
     } else {
         \Log::debug($this->user->username . ' has no groups:', [$this->user]);
     }
     //Set timestamp for file names
     $timeStamp = Carbon::now('America/New_York')->toDateTimeString();
     //Get our Report object
     $duoReport = Report::where('name', 'DuoRegisteredUsersReport')->first();
     $fileName = storage_path() . '/' . $duoReport->path . $timeStamp . '-' . $duoReport->name . '-' . $this->user->username . '.xlsx';
     //Loop each Duo Group
     foreach ($groups as $group) {
         //Explode csv_headers to array
         $duoReportHeaders = explode(',', $duoReport->csv_headers);
         //Create the group main worksheet
         $this->createWorksheet($objPHPExcel, $group->name, $duoReportHeaders);
         //Create the 'not enrolled' worksheet
         $notEnrolledWorksheetName = $group->name . ' - Not Enrolled';
         $this->createWorksheet($objPHPExcel, $notEnrolledWorksheetName, $duoReportHeaders);
         //Create an array to track users that haven't enrolled.
         $usersNotEnrolled = [];
         //Set the active sheet to the main group sheet
         $objPHPExcel->setActiveSheetIndexByName($group->name);
         //Get all users that belong to this group
         $duoGroupMembers = $group->duoUsers()->get();
         /*
          * Write User data
          */
         $row = 2;
         foreach ($duoGroupMembers as $member) {
             //Check if the user has a registered phone or token
             if ($member->duoPhones()->count() || $member->duoTokens()->count()) {
                 //Record the user details in the main worksheet
                 $objPHPExcel->getActiveSheet()->setCellValue('A' . $row, $member->username);
                 $objPHPExcel->getActiveSheet()->setCellValue('B' . $row, $member->email);
                 $objPHPExcel->getActiveSheet()->setCellValue('C' . $row, $member->status);
                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $row, $member->last_login);
                 $objPHPExcel->getActiveSheet()->setCellValue('E' . $row, $member->duoGroups()->first()->name);
                 $row++;
             } else {
                 //This user hasn't enrolled.
                 //We'll write their info to another worksheet.
                 array_push($usersNotEnrolled, $member);
             }
         }
         //Set the active sheet to the 'not enrolled' group sheet
         $objPHPExcel->setActiveSheetIndexByName($notEnrolledWorksheetName);
         /*
          * Write 'not enrolled' data
          */
         $row = 2;
         foreach ($usersNotEnrolled as $user) {
             //Record the user details in the 'not enrolled' worksheet
             $objPHPExcel->getActiveSheet()->setCellValue('A' . $row, $user->username);
             $objPHPExcel->getActiveSheet()->setCellValue('B' . $row, $user->email);
             $objPHPExcel->getActiveSheet()->setCellValue('C' . $row, $user->status);
             $objPHPExcel->getActiveSheet()->setCellValue('D' . $row, 'Not Enrolled');
             $objPHPExcel->getActiveSheet()->setCellValue('E' . $row, $user->duoGroups()->first()->name);
             $row++;
         }
         unset($usersNotEnrolled);
     }
     //Remove the default sheet (there's gotta be a better way to do this....)
     $objPHPExcel->removeSheetByIndex(0);
     //Write the document
     $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
     $objWriter->save($fileName);
     //Reports are done running, let's email to results
     $beautymail = app()->make(\Snowfire\Beautymail\Beautymail::class);
     $beautymail->send('emails.duo-registered-users', [], function ($message) use($fileName) {
         //TODO: Create system for users to manage report subscriptions.
         $message->from('*****@*****.**', 'Duo Reporting')->to($this->user->email)->subject('Duo Registered Users Report')->attach($fileName);
     });
 }
예제 #4
0
 public function AddForAll()
 {
     $organizations = \App\Models\Organization::all();
     foreach ($organizations as $organization) {
         $id = $organization->id;
         $reports = $organization->reports;
         if ($reports->count()) {
             $maxYear = \App\Models\Report::where('organization_id', '=', $id)->max('year');
             $maxQuarter = \App\Models\Report::where('organization_id', '=', $id)->where('year', '=', $maxYear)->max('quarter');
             if ($maxQuarter == 4 && $maxYear != 2016) {
                 $year = ++$maxYear;
                 $report = new \App\Models\Report();
                 $report->year = $year;
                 $report->quarter = 1;
                 $report->organization_id = $id;
                 $report->state = 'not_accepted';
                 $report->save();
             } elseif ($maxQuarter != 4) {
                 $quarter = $maxQuarter + 1;
                 $report = new \App\Models\Report();
                 $report->year = $maxYear;
                 $report->quarter = $quarter;
                 $report->organization_id = $id;
                 $report->state = 'not_accepted';
                 $report->save();
             }
         } else {
             $report = new \App\Models\Report();
             $report->year = 2015;
             $report->quarter = 1;
             $report->organization_id = $id;
             $report->state = 'not_accepted';
             $report->save();
         }
     }
     return redirect()->back();
 }
예제 #5
0
 public function acceptedReports()
 {
     $reports = \App\Models\Report::where('state', 'accepted')->orderBy('accepted_date', 'desc')->get();
     return View::make('inspector.reports', compact('reports'));
 }
 /**
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\BinaryFileResponse
  */
 public function firmwareStore(Request $request)
 {
     // Avoid PHP timeouts when querying large clusters
     set_time_limit(0);
     //Get the authenticated users active cluster
     $cluster = \Auth::user()->activeCluster();
     //Get the file submitted from the form
     $file = $request->file('file');
     //Make sure the file is a csv and redirect back if it's not
     if ($file->getClientMimeType() != "text/csv" && $file->getClientOriginalExtension() != "csv") {
         alert()->error('File type invalid.  Please use a CSV file format.');
         return redirect()->back();
     }
     //Create new Keboola\Csv Object with the submitted file
     $csvFile = new CsvFile($file);
     $csv = '';
     //Loop the csv file and store the device names in an array
     foreach ($csvFile as $key => $row) {
         $csv[] = $row[0];
     }
     // $deviceList will hold our array for RisPort
     $deviceList = [];
     // Loop device name array and assign devicename to $deviceList
     foreach ($csv as $phone) {
         $deviceList[]['DeviceName'] = $phone;
     }
     //Query the RisPort API to get IP/Registration status
     $devices = Utils::generateEraserList($deviceList, $cluster, false);
     //Get details for the phone_firmware report type
     $report = Report::where('type', 'phone_firmware')->first();
     //Create file name for report
     $fileName = storage_path() . '/' . $report->path . 'firmware-report-' . Carbon::now('America/New_York')->toDateTimeString() . '.csv';
     //Generate new output csv file
     new CsvFile($fileName);
     //Call the App\Jobs\GetPhoneFirmware Job
     $this->dispatch(new $report->job($devices, $fileName, $report->csv_headers));
     //Return a response with the firmware report
     return response()->download($fileName);
 }