Example #1
0
/**
 * Generate the HTML code for the monitoring logs panel.
 *
 * @param  string $api_key The CloudProxy API key.
 * @return string          The parsed-content of the monitoring logs panel.
 */
function sucuriscan_monitoring_logs($api_key = '')
{
    $template_variables = array('AuditLogs.List' => '', 'AuditLogs.CountText' => 0, 'AuditLogs.DenialTypeOptions' => '', 'AuditLogs.NoItemsVisibility' => 'visible', 'AuditLogs.PaginationVisibility' => 'hidden', 'AuditLogs.AuditPagination' => '', 'AuditLogs.TargetDate' => '', 'AuditLogs.DateYears' => '', 'AuditLogs.DateMonths' => '', 'AuditLogs.DateDays' => '');
    $date = date('Y-m-d');
    if ($api_key) {
        // Retrieve the date filter from the GET request (if any).
        if ($date_by_get = SucuriScanRequest::get('date', '_yyyymmdd')) {
            $date = $date_by_get;
        }
        // Retrieve the date filter from the POST request (if any).
        $year = SucuriScanRequest::post(':year');
        $month = SucuriScanRequest::post(':month');
        $day = SucuriScanRequest::post(':day');
        if ($year && $month && $day) {
            $date = sprintf('%s-%s-%s', $year, $month, $day);
        }
        $logs_data = SucuriScanAPI::get_cloudproxy_logs($api_key, $date);
        if ($logs_data) {
            add_thickbox();
            /* Include the Thickbox library. */
            $template_variables['AuditLogs.NoItemsVisibility'] = 'hidden';
            $template_variables['AuditLogs.CountText'] = $logs_data->limit . '/' . $logs_data->total_lines;
            $template_variables['AuditLogs.List'] = sucuriscan_monitoring_access_logs($logs_data->access_logs);
            $template_variables['AuditLogs.DenialTypeOptions'] = sucuriscan_monitoring_denial_types($logs_data->access_logs);
        }
    }
    $template_variables['AuditLogs.TargetDate'] = SucuriScan::escape($date);
    $template_variables['AuditLogs.DateYears'] = sucuriscan_monitoring_dates('years', $date);
    $template_variables['AuditLogs.DateMonths'] = sucuriscan_monitoring_dates('months', $date);
    $template_variables['AuditLogs.DateDays'] = sucuriscan_monitoring_dates('days', $date);
    return SucuriScanTemplate::get_section('monitoring-logs', $template_variables);
}