forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.log.export.php
39 lines (28 loc) · 1000 Bytes
/
cron.log.export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* Export the log as a CSV file.
*/
$allowed_levels = array(9);
require_once '../bootstrap.php';
redirect_if_role_not_allowed($allowed_levels);
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=cron-log.csv');
$output = fopen('php://output', 'w');
$log_query = "SELECT * FROM " . TABLE_CRON_LOG . " ORDER BY id DESC";
$log_sql = $dbh->query( $log_query );
$log_count = $log_sql->rowCount();
function filter_pipe($input) {
$output = str_replace('|', '\|', $input);
return $output;
}
if ($log_count > 0) {
$log_sql->setFetchMode(PDO::FETCH_ASSOC);
while ( $log = $log_sql->fetch() ) {
$rendered = [];
$rendered['timestamp'] = format_date($log['timestamp']);
if (!empty($log['sapi'])) { $rendered['sapi'] = $log['sapi']; };
if (!empty($log['results'])) { $rendered['results'] = $log['results']; };
fputcsv($output, $rendered);
}
}
setCookie("log_download_started", 1, time() + 20, '/', "", false, false);