public function index() { $this->title = _('FOG Hosts and Users Login'); print '<center><a href="export.php?type=csv" target="_blank"><i class="fa fa-file-excel-o fa-2x"></i></a><a href="export.php?type=pdf" target="_blank"><i class="fa fa-file-pdf-o fa-2x"></i></a></center><br/>'; $report = new ReportMaker(); $report->appendHTML('<table cellpadding="0" cellspacing="0" border="0" width="100%">'); $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Hostname</b></td><td><b>MAC</b></td><td><b>Registered</b></td></tr>'); $report->addCSVCell('Hostname'); $report->addCSVCell('MAC'); $report->addCSVCell('Registered'); $report->endCSVLine(); $Hosts = $this->FOGCore->getClass('HostManager')->find('', '', '', '', '', 'name'); $cnt = 0; foreach ($Hosts as $Host) { $bg = $cnt++ % 2 == 0 ? "#E7E7E7" : ''; $report->appendHTML('<tr bgcolor="' . $bg . '"><td>' . $Host->get('name') . '</td><td>' . $Host->get('mac') . '</td><td>' . $Host->get('createdTime') . '</td></tr>'); $report->addCSVCell($Host->get('name')); $report->addCSVCell($Host->get('mac')); $report->addCSVCell($Host->get('createdTime')); if ($Host->get('users')) { $report->endCSVLine(); $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Username</b></td><td><b>Action</b></td><td><b>Date</b></td><td><b>Time</b></td></tr>'); $report->addCSVCell('Username'); $report->addCSVCell('Action'); $report->addCSVCell('Time'); $report->endCSVLine(); $cnt1 = 0; $Users = $this->getClass('UserTrackingManager')->find(array('hostID' => $Host->get('id'), 'action' => array(null, 0, 1)), '', array('username', 'datetime'), 'DESC', '', 'username'); foreach ($Users as $User) { if ($User->get('username') != 'Array') { $bg1 = $cnt1++ % 2 == 0 ? "#E7E7E7" : ''; $logintext = $User->get('action') == 1 ? 'Login' : 'Logout'; $report->appendHTML('<tr bgcolor="' . $bg1 . '"><td>' . $User->get('username') . '</td><td>' . $logintext . '</td><td>' . $User->get('date') . '</td><td>' . $User->get('datetime') . '</td></tr>'); $report->addCSVCell($User->get('username')); $report->addCSVCell($logintext); $report->addCSVCell($User->get('date')); $report->addCSVCell($User->get('datetime')); $report->endCSVLine(); } } $report->appendHTML('<table cellpadding="0" cellspacing="0" border="0" width="100%">'); $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Hostname</b></td><td><b>MAC</b></td><td><b>Registered</b></td></tr>'); $report->addCSVCell('Hostname'); $report->addCSVCell('MAC'); $report->addCSVCell('Registered'); $report->endCSVLine(); } } $report->appendHTML('</table>'); $report->outputReport(0); $_SESSION['foglastreport'] = serialize($report); }
private function makeReport() { print '<h2>' . _('FOG Hosts and Users Login') . '<a href="export.php?type=csv&filename=HostsandUsers" target="_blank"><img class="noBorder" src="images/csv.png" /></a><a href="export.php?type=pdf&filename=HostsandUsers" target="_blank"><img class="noBorder" src="images/pdf.png" /></a></h2>'; $Hosts = $this->getClass('HostManager')->find(); $report = new ReportMaker(); $report->appendHTML('<table cellpadding="0" cellspacing="0" border="0" width="100%">'); $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Hostname</b></td><td><b>MAC</b></td><td><b>Registered</b></td></tr>'); $report->addCSVCell('Hostname'); $report->addCSVCell('MAC'); $report->addCSVCell('Registered'); $report->endCSVLine(); $cnt = 0; foreach ($Hosts as $Host) { $bg = $cnt++ % 2 == 0 ? "#E7E7E7" : ''; $report->appendHTML('<tr bgcolor="' . $bg . '"><td>' . $Host->get('name') . '</td><td>' . $Host->get('mac') . '</td><td>' . $Host->get('createdTime') . '</td></tr>'); $report->addCSVCell($Host->get('name')); $report->addCSVCell($Host->get('mac')); $report->addCSVCell($Host->get('createdTime')); if ($Host->get('users')) { $report->endCSVLine(); $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Username</b></td><td><b>Action</b></td><td><b>Date</b></td><td><b>Time</b></td></tr>'); $report->addCSVCell('Username'); $report->addCSVCell('Action'); $report->addCSVCell('Time'); $report->endCSVLine(); $cnt1 = 0; foreach ($Host->get('users') as $User) { $bg1 = $cnt1++ % 2 == 0 ? "#E7E7E7" : ''; $logintext = $User->get('action') == 1 ? 'Login' : (!$User->get('action') ? 'Logout' : ($User->get('action') == 99 ? 'Service Start' : 'N/A')); if ($logintext == 'Login' || $logintext == 'Logout') { $report->appendHTML('<tr bgcolor="' . $bg1 . '"><td>' . $User->get('username') . '</td><td>' . $logintext . '</td><td>' . $User->get('date') . '</td><td>' . $User->get('datetime') . '</td></tr>'); $report->addCSVCell($User->get('username')); $report->addCSVCell($logintext); $report->addCSVCell($User->get('date')); $report->addCSVCell($User->get('datetime')); $report->endCSVLine(); } } $report->appendHTML('<table cellpadding="0" cellspacing="0" border="0" width="100%">'); $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Hostname</b></td><td><b>MAC</b></td><td><b>Registered</b></td></tr>'); $report->addCSVCell('Hostname'); $report->addCSVCell('MAC'); $report->addCSVCell('Registered'); $report->endCSVLine(); } else { $report->endCSVLine(); } } $report->appendHTML('</table>'); $report->outputReport(ReportMaker::FOG_REPORT_HTML); $_SESSION['foglastreport'] = serialize($report); }
/** snapin_log_post() Display's the dates to filter through. */ public function snapin_log_post() { // Set title $this->title = _('FOG Snapin Log'); // This gets the download links for which type of file you want. print "\n\t\t\t\t<h2>" . '<a href="export.php?type=csv&filename=SnapinLog" alt="Export CSV" title="Export CSV" target="_blank">' . $this->csvfile . '</a> <a href="export.php?type=pdf&filename=SnapinLog" alt="Export PDF" title="Export PDF" target="_blank">' . $this->pdffile . '</a></h2>'; // Header Data $this->headerData = array(_('Snapin Name'), _('State'), _('Return Code'), _('Return Desc'), _('Create Date'), _('Create Time')); // Templates $this->templates = array('${snap_name}', '${snap_state}', '${snap_return}', '${snap_detail}', '${snap_create}', '${snap_time}'); // Setup Report Maker for this class. $ReportMaker = new ReportMaker(); // Set dates and check order is proper $date1 = $_REQUEST['date1']; $date2 = $_REQUEST['date2']; if ($date1 > $date2) { $date1 = $_REQUEST['date2']; $date2 = $_REQUEST['date1']; } $date2 = date('Y-m-d', strtotime($date2 . '+1 day')); // This is just for the header in the CSV: $csvHead = array(_('Host ID'), _('Host Name'), _('Host MAC'), _('Snapin ID'), _('Snapin Name'), _('Snapin Description'), _('Snapin File'), _('Snapin Args'), _('Snapin Run With'), _('Snapin Run With Args'), _('Snapin State'), _('Snapin Return Code'), _('Snapin Return Detail'), _('Snapin Creation Date'), _('Snapin Creation Time'), _('Job Create Date'), _('Job Create Time'), _('Task Checkin Date'), _('Task Checkin Time')); foreach ((array) $csvHead as $csvHeader) { $ReportMaker->addCSVCell($csvHeader); } $ReportMaker->endCSVLine(); // Find all snapin tasks $SnapinTasks = $this->getClass('SnapinTaskManager')->find(array('checkin' => '', 'complete' => ''), 'OR', '', '', "BETWEEN '{$date1}' AND '{$date2}'"); foreach ((array) $SnapinTasks as $SnapinTask) { $SnapinCheckin1 = $this->nice_date($SnapinTask->get('checkin')); $SnapinCheckin2 = $this->nice_date($SnapinTask->get('complete')); // Get the Task based on create date thru complete date // Get the snapin $Snapin = new Snapin($SnapinTask->get('snapinID')); // Get the Job $SnapinJob = new SnapinJob($SnapinTask->get('jobID')); // Get the Host $Host = new Host($SnapinJob->get('hostID')); $hostID = $SnapinJob->get('hostID'); $hostName = $Host->isValid() ? $Host->get('name') : ''; $hostMac = $Host->isValid() ? $Host->get('mac') : ''; $snapinID = $SnapinTask->get('snapinID'); $snapinName = $Snapin->isValid() ? $Snapin->get('name') : ''; $snapinDesc = $Snapin->isValid() ? $Snapin->get('description') : ''; $snapinFile = $Snapin->isValid() ? $Snapin->get('file') : ''; $snapinArgs = $Snapin->isValid() ? $Snapin->get('args') : ''; $snapinRw = $Snapin->isValid() ? $Snapin->get('runWith') : ''; $snapinRwa = $Snapin->isValid() ? $Snapin->get('runWithArgs') : ''; $snapinState = $SnapinTask->get('stateID'); $snapinReturn = $SnapinTask->get('return'); $snapinDetail = $SnapinTask->get('detail'); $snapinCreateDate = $Snapin->isValid() ? $this->formatTime($Snapin->get('createdTime'), 'Y-m-d') : ''; $snapinCreateTime = $Snapin->isValid() ? $this->formatTime($Snapin->get('createdTime'), 'H:i:s') : ''; $jobCreateDate = $this->formatTime($SnapinJob->get('createdTime'), 'Y-m-d'); $jobCreateTime = $this->formatTime($SnapinJob->get('createdTime'), 'H:i:s'); $TaskCheckinDate = $SnapinCheckin1->format('Y-m-d'); $TaskCheckinTime = $SnapinCheckin2->format('H:i:s'); $this->data[] = array('snap_name' => $snapinName, 'snap_state' => $snapinState, 'snap_return' => $snapinReturn, 'snap_detail' => $snapinDetail, 'snap_create' => $snapinCreateDate, 'snap_time' => $snapinCreateTime); $ReportMaker->addCSVCell($hostID); $ReportMaker->addCSVCell($hostName); $ReportMaker->addCSVCell($HostMac); $ReportMaker->addCSVCell($snapinID); $ReportMaker->addCSVCell($snapinName); $ReportMaker->addCSVCell($snapinDesc); $ReportMaker->addCSVCell($snapinFile); $ReportMaker->addCSVCell($snapinArgs); $ReportMaker->addCSVCell($snapinRw); $ReportMaker->addCSVCell($snapinRwa); $ReportMaker->addCSVCell($snapinState); $ReportMaker->addCSVCell($snapinReturn); $ReportMaker->addCSVCell($snapinDetail); $ReportMaker->addCSVCell($snapinCreateDate); $ReportMaker->addCSVCell($snapinCreateTime); $ReportMaker->addCSVCell($jobCreateDate); $ReportMaker->addCSVCell($jobCreateTime); $ReportMaker->addCSVCell($TaskCheckinDate); $ReportMaker->addCSVCell($TaskCheckinTime); $ReportMaker->endCSVLine(); } // This is for the pdf. $ReportMaker->appendHTML($this->process()); $ReportMaker->outputReport(false); $_SESSION['foglastreport'] = serialize($ReportMaker); }
/** export() Exports the hosts from the database. */ public function export() { $this->title = 'Export Hosts'; // Header Data unset($this->headerData); // Attributes $this->attributes = array(array(), array()); // Templates $this->templates = array('${field}', '${input}'); // Fields $fields = array(_('Click the button to download the hosts table backup.') => '<input type="submit" value="' . _('Export') . '" />'); $report = new ReportMaker(); $Hosts = $this->getClass('HostManager')->find(); foreach ((array) $Hosts as $Host) { if ($Host && $Host->isValid()) { $macs[] = $Host->get('mac'); foreach ($Host->get('additionalMACs') as $AddMAC) { if ($AddMAC && $AddMAC->isValid()) { $macs[] = $AddMAC->__toString(); } } $report->addCSVCell(implode('|', (array) $macs)); $report->addCSVCell($Host->get('name')); $report->addCSVCell($Host->get('ip')); $report->addCSVCell('"' . $Host->get('description') . '"'); $report->addCSVCell($Host->get('imageID')); $this->HookManager->processEvent('HOST_EXPORT_REPORT', array('report' => &$report, 'Host' => &$Host)); $report->endCSVLine(); unset($macs); } } $_SESSION['foglastreport'] = serialize($report); print "\n\t\t\t" . '<form method="post" action="export.php?type=host">'; foreach ((array) $fields as $field => $input) { $this->data[] = array('field' => $field, 'input' => $input); } // Hook $this->HookManager->processEvent('HOST_EXPORT', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes)); // Output $this->render(); print "</form>"; }