Welcome to mirror list, hosted at ThFree Co, Russian Federation.

download_logs.php « ncp-web - github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5e02469fe3b251a386fe326c8c03f1c087c24a33 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
///
// NextCloudPi Web Panel backend
//
// Copyleft 2019 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
// GPL licensed (see end of file) * Use at your own risk!
//
// More at https://nextcloudpi.com
///

include ('csrf.php');
session_start();

// CSRF check
$token = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';
if ( empty($token) || !validateCSRFToken($token) )
  exit('Unauthorized download');

$file = '/var/log/ncp.log';

if (!file_exists($file)
    die('File not found');

if (!is_readable($file))
    die('NCP does not have read permissions on this file');

function filesize_compat($file)
{
  if(PHP_INT_SIZE === 4) # workaround for 32-bit architectures
    return trim(shell_exec("stat -c%s " . escapeshellarg($file)));
  else
    return filesize($file);
}

$size = filesize_compat($file);

$mime_type = 'text/plain';

ob_start();
ob_clean();
header('Content-Description: File Transfer');
header('Content-Type: ' . $mime_type);
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file) . "\"");
header('Content-Length: ' . $size);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');

$chunksize = 8 * (1024 * 1024);

if($size > $chunksize || PHP_INT_SIZE === 4) # always chunk for 32-bit architectures
{
  $handle = fopen($file, 'rb') or die("Error opening file");

  while (!feof($handle))
  {
    $buffer = fread($handle, $chunksize);
    echo $buffer;

    ob_flush();
    flush();
  }

  fclose($handle);
}
else
  readfile($file);

ob_flush();
flush();

exit();

?>