fogproject  1.5.9
About: FOG is a Linux-based network computer cloning solution for Windows, Mac OSX and various Linux distributions that ties together a few open-source tools with a PHP-based web interface. FOG doesn’t use any boot disks, or CDs; everything is done via TFTP and PXE.
  Fossies Dox: fogproject-1.5.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

logtoview.php
Go to the documentation of this file.
1 <?php
22 require_once '../commons/base.inc.php';
23 session_write_close();
24 ignore_user_abort(true);
25 set_time_limit(0);
26 header('Content-Type: text/event-stream');
27 header('Connection: close');
28 if (!(isset($_POST['ip'])
29  && is_string($_POST['ip']))
30 ) {
31  echo json_encode(_('Invalid IP'));
32  exit;
33 }
34 if (!(isset($_POST['file'])
35  && is_string($_POST['file']))
36 ) {
37  echo json_encode(_('Invalid File'));
38  exit;
39 }
40 $file = '';
41 $lines = '';
52 function vals($reverse, $HookManager, $lines, $file)
53 {
54  ini_set("auto_detect_line_endings", true);
55  $folder = sprintf(
56  '/%s/',
57  trim(
58  trim(
59  dirname($file)
60  ),
61  '/'
62  )
63  );
64  $pattern = sprintf(
65  '#^%s$#',
66  $folder
67  );
68  $folders = array(
69  '/var/log/fog/',
70  '/opt/fog/log/',
71  '/var/log/httpd/',
72  '/var/log/apache2/',
73  '/var/log/nginx/',
74  '/var/log/php-fpm/',
75  '/var/log/php5.6-fpm/',
76  '/var/log/php5-fpm/',
77  '/var/log/php7.0-fpm/'
78  );
79  $HookManager->processEvent('LOG_FOLDERS', array('folders'=>&$folders));
80  if (!preg_grep($pattern, $folders)) {
81  return _('Invalid Folder');
82  }
83  $file = trim(basename($file));
84  $path = sprintf('%s%s', $folder, $file);
85  $path = trim($path);
86  if (($fh = fopen($path, 'rb')) === false) {
87  return _('Unable to open file for reading');
88  }
89  $buffer = 4096;
90  fseek($fh, -1, SEEK_END);
91  if (fread($fh, 1) != "\n") {
92  $lines -= 1;
93  }
94  $output = '';
95  $chunk = '';
96  while (ftell($fh) > 0 && $lines >= 0) {
97  $seek = min(ftell($fh), $buffer);
98  fseek($fh, -$seek, SEEK_CUR);
99  $output = ($chunk = fread($fh, $seek)).$output;
100  fseek($fh, -mb_strlen($chunk, '8bit'), SEEK_CUR);
101  $lines -= substr_count($chunk, "\n");
102  }
103  while ($lines++ < 0) {
104  $output = substr(
105  $output,
106  strpos(
107  $output,
108  "\n"
109  )
110  + 1
111  );
112  }
113  fclose($fh);
114  if ($reverse) {
115  $output = implode(
116  "\n",
117  array_reverse(
118  explode(
119  "\n",
120  $output
121  )
122  )
123  );
124  }
125  return trim($output);
126 }
127 if (!(isset($_POST['ip'])
128  && is_string($_POST['ip']))
129 ) {
130  echo _('Invalid IP');
131  exit;
132 }
133 if (!(isset($_POST['file'])
134  && is_string($_POST['file']))
135 ) {
136  echo _('Invalid File');
137  exit;
138 }
139 if (!(isset($_POST['lines'])
140  && is_numeric($_POST['lines']))
141 ) {
142  $_POST['lines'] = 20;
143 }
144 if (!(isset($_POST['reverse'])
145  && is_numeric($_POST['reverse']))
146 ) {
147  $_POST['reverse'] = 0;
148 }
149 $ip = $_POST['ip'];
150 $file = sprintf(
151  '%s%s%s',
152  dirname($_POST['file']),
153  DS,
154  basename($_POST['file'])
155 );
156 $lines = $_POST['lines'];
157 $reverse = $_POST['reverse'];
158 $ip = base64_decode($ip);
160 $ip = trim($ip);
161 if (filter_var($ip, FILTER_VALIDATE_IP) === false) {
162  return print json_encode(_('IP Passed is incorrect'));
163 }
164 if (false !== strpos(filter_input(INPUT_SERVER, 'HTTP_HOST'), $ip)) {
165  $str = vals(
166  $reverse,
167  $HookManager,
168  $lines,
169  $file
170  );
171  echo json_encode($str);
172  exit;
173 }
174 $url = sprintf(
175  '%s://%s/fog/status/logtoview.php',
177  $ip
178 );
179 $process = array(
180  'ip' => base64_encode($ip),
181  'file' => $file,
182  'lines' => $lines,
183  'reverse' => $reverse
184 );
185 $response = $FOGURLRequests->process(
186  $url,
187  'POST',
188  $process
189 );
190 echo json_decode(
191  json_encode(
192  array_shift($response)
193  ),
194  true
195 );
exit
exit
Definition: download.php:102
$response
$response
Definition: logtoview.php:185
$url
if(filter_var($ip, FILTER_VALIDATE_IP)===false) if(false !==strpos(filter_input(INPUT_SERVER, 'HTTP_HOST'), $ip)) $url
Definition: logtoview.php:174
$folder
if(!(file_exists($decodePath) &&is_readable($decodePath) &&is_dir($decodePath))) $folder
Definition: freespace.php:33
$reverse
$reverse
Definition: logtoview.php:157
FOGBase\$httpproto
static $httpproto
Definition: fogbase.class.php:298
FOGBase\resolveHostname
static resolveHostname($host)
Definition: fogbase.class.php:2497
$str
if(! $Image->isValid()) $str
Definition: progress.php:41
$path
if(!is_string($_GET['path'])) $path
Definition: getfiles.php:31
$output
$output
Definition: freespace.php:36
vals
vals($reverse, $HookManager, $lines, $file)
Definition: logtoview.php:52
$file
if(!(isset($_POST['ip']) &&is_string($_POST['ip']))) if(!(isset($_POST['file']) &&is_string($_POST['file']))) $file
Definition: logtoview.php:40
$ip
if(!(isset($_POST['ip']) &&is_string($_POST['ip']))) if(!(isset($_POST['file']) &&is_string($_POST['file']))) if(!(isset($_POST['lines']) &&is_numeric($_POST['lines']))) if(!(isset($_POST['reverse']) &&is_numeric($_POST['reverse']))) $ip
Definition: logtoview.php:149
$process
$process
Definition: logtoview.php:179
$lines
$lines
Definition: logtoview.php:41