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)  

reportmaker.class.php
Go to the documentation of this file.
1 <?php
22 class ReportMaker extends FOGBase
23 {
29  private $_strHTML = array();
35  private $_strCSV = array();
41  private $_strLine = array();
47  private $_filename = '';
53  public $types = array(
54  'html' => 0,
55  'csv' => 1,
56  'pdf' => 2,
57  'sql' => 3,
58  'user' => 4,
59  'host' => 4,
60  'group' => 4,
61  'image' => 4,
62  'snapin' => 4,
63  'printer' => 4,
64  'sqldump' => 5,
65  );
69  public function __construct()
70  {
71  parent::__construct();
72  self::$HookManager
73  ->processEvent(
74  'REPORT_TYPES',
75  array('types' => &$this->types)
76  );
77  }
85  public function appendHTML($html)
86  {
87  $this->_strHTML[] = $html;
88 
89  return $this;
90  }
98  public function addCSVCell($item)
99  {
100  $this->_strCSV[] = $item;
101 
102  return $this;
103  }
109  public function endCSVLine()
110  {
111  $this->_strLine[] = sprintf(
112  '"%s"%s',
113  implode(
114  '","',
115  $this->_strCSV
116  ),
117  "\n"
118  );
119  unset($this->_strCSV);
120 
121  return $this;
122  }
130  public function setFileName($filename)
131  {
132  $this->_filename = $filename;
133 
134  return $this;
135  }
144  public function outputReport($intType = 0, $nojson = false)
145  {
146  $keys = array_keys($this->types);
147  $type = filter_input(INPUT_GET, 'type');
148  $filename = filter_input(INPUT_GET, 'filename');
149  if (!(isset($type)
150  && is_string($type))
151  ) {
152  $type = $keys[$intType];
153  }
154  if (!in_array($type, $keys)) {
155  echo json_encode(
156  array(
157  'error' => _('Invalid Type')
158  )
159  );
160  exit;
161  }
162  if (!(isset($filename)
163  && is_string($filename))
164  ) {
165  $filename = '';
166  }
167  $file = $filename;
168  $file = basename(
169  trim(
170  $file
171  )
172  );
173  if (!isset($_POST['export'])) {
174  $this->setFileName($file);
175  }
176  $intType = (
177  $intType !== false ?
178  (
179  isset($_POST['export']) ?
180  3 :
181  $this->types[$type]
182  ) :
183  0
184  );
185  if (isset($_POST['nojson']) || true === $nojson) {
186  switch ($intType) {
187  case 0:
188  echo implode("\n", (array)$this->_strHTML);
189  break;
190  case 1:
191  $filename = $this->_filename;
192  header('Content-Type: application/octet-stream');
193  header("Content-Disposition: attachment; filename=$filename.csv");
194  echo implode((array) $this->_strLine);
195  unset($filename, $this->_strLine);
196  break;
197  case 2:
198  $filename = $this->_filename;
199  $htmlfile = sprintf(
200  '%s.html',
201  $filename
202  );
203  $html = sprintf(
204  '<html><body>%s</body></html>',
205  implode((array)$this->_strHTML)
206  );
207  $logoimage = trim(
208  self::getSetting('FOG_CLIENT_BANNER_IMAGE')
209  );
210  if ($logoimage) {
211  $logoimage = sprintf(
212  '--logoimage %s',
213  escapeshellarg(
214  sprintf(
215  'http%s://%s/fog/management/other/%s',
216  (
217  filter_input(INPUT_SERVER, 'HTTPS') ?
218  's' :
219  ''
220  ),
221  filter_input(INPUT_SERVER, 'HTTP_HOST'),
222  $logoimage
223  )
224  )
225  );
226  }
227  $cmd = array(
228  'htmldoc',
229  '--webpage',
230  '--quiet',
231  '--gray',
232  $logoimage,
233  '--header l',
234  '--footer D1/1',
235  '--size letter',
236  '-t pdf14',
237  '--no-compression',
238  $htmlfile
239  );
240  $cmd = implode(' ', (array)$cmd);
241  if (!$handle = fopen($htmlfile, 'w')) {
242  break;
243  }
244  if (!fwrite($handle, $html)) {
245  fclose($handle);
246  unlink($htmlfile);
247  }
248  fclose($handle);
249  ob_start();
250  passthru($cmd);
251  $pdf = ob_get_clean();
252  unlink($htmlfile);
253  header('Content-type: application/pdf');
254  header("Content-Disposition: attachment; filename=$filename.pdf");
255  echo $pdf;
256  unset(
257  $pdf,
258  $html,
259  $htmlfile,
260  $this->_strHTML
261  );
262  break;
263  case 3:
264  $SchemaSave = self::getClass('Schema');
265  $backup_name = sprintf(
266  'fog_backup_%s.sql',
267  self::formatTime('', 'Ymd_His')
268  );
269  $SchemaSave->exportdb($backup_name);
270  unset($SchemaSave);
271  break;
272  case 4:
273  header('Content-Type: application/octet-stream');
274  header(
275  'Content-Disposition: attachment; '
276  ."filename={$type}_export.csv"
277  );
278  echo implode((array) $this->_strLine);
279  unset($this->_strLine);
280  break;
281  case 5:
282  while (ob_get_level()) {
283  ob_end_clean();
284  }
285  $filename = 'fog_backup.sql';
286  $path = sprintf(
287  '%s%smanagement%sother%s',
288  BASEPATH,
289  DS,
290  DS,
291  DS
292  );
293  $filepath = "{$path}{$filename}";
294  $ip = str_replace('p:', '', DATABASE_HOST);
295  if (false === filter_var($ip, FILTER_VALIDATE_IP)) {
296  $ip = gethostbyname($ip);
297  }
298  if (filter_var($ip, FILTER_VALIDATE_IP) === false) {
299  return;
300  }
301  $cmd = sprintf(
302  "mysqldump --opt -u%s -h'$ip' %s > $filepath",
303  escapeshellarg(DATABASE_USERNAME),
304  escapeshellarg(DATABASE_NAME)
305  );
306  if (DATABASE_PASSWORD) {
307  $cmd = sprintf(
308  "mysqldump --opt -u%s -p%s -h'$ip' %s > %s",
309  escapeshellarg(DATABASE_USERNAME),
310  escapeshellarg(DATABASE_PASSWORD),
311  escapeshellarg(DATABASE_NAME),
312  escapeshellarg($filepath)
313  );
314  }
315  exec($cmd);
316  if (($fh = fopen($filepath, 'rb')) === false) {
317  return;
318  }
319  header("X-Sendfile: $filepath");
320  header('Content-Type: application/octet-stream');
321  header("Content-Disposition: attachment; filename=$filename");
322  while (feof($fh) === false) {
323  echo fgets($fh);
324  flush();
325  }
326  fclose($fh);
327  $cmd = sprintf('rm -rf %s', escapeshellarg($filepath));
328  exec($cmd);
329  }
330  } else {
331  echo json_encode(
332  array(
333  'msg' => _('Export Complete')
334  )
335  );
336  }
337  }
338 }
ReportMaker\addCSVCell
addCSVCell($item)
Definition: reportmaker.class.php:98
exit
exit
Definition: download.php:102
ReportMaker\$_strLine
$_strLine
Definition: reportmaker.class.php:41
ReportMaker\__construct
__construct()
Definition: reportmaker.class.php:69
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
$file
if(isset($_REQUEST['legclient'])) if(isset($_REQUEST['newclient'])) if(isset($_REQUEST['fogprep'])) if(isset($_REQUEST['fogcrypt'])) if(isset($_REQUEST['smartinstaller'])) if(!file_exists($filename)) $file
Definition: download.php:61
ReportMaker\appendHTML
appendHTML($html)
Definition: reportmaker.class.php:85
ReportMaker\$_strHTML
$_strHTML
Definition: reportmaker.class.php:29
$keys
$keys
Definition: schema.php:1610
ReportMaker\$_strCSV
$_strCSV
Definition: reportmaker.class.php:35
ReportMaker\$_filename
$_filename
Definition: reportmaker.class.php:47
ReportMaker
Definition: reportmaker.class.php:23
FOGBase
Definition: fogbase.class.php:25
$path
if(!is_string($_GET['path'])) $path
Definition: getfiles.php:31
ReportMaker\endCSVLine
endCSVLine()
Definition: reportmaker.class.php:109
ReportMaker\$types
$types
Definition: reportmaker.class.php:53
ReportMaker\setFileName
setFileName($filename)
Definition: reportmaker.class.php:130
$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
ReportMaker\outputReport
outputReport($intType=0, $nojson=false)
Definition: reportmaker.class.php:144