1<?php
2
3/**
4 *	Generate XLS file
5 *********************************/
6
7/* functions */
8require_once( dirname(__FILE__) . '/../../../functions/functions.php' );
9
10# initialize user object
11$Database 	= new Database_PDO;
12$User 		= new User ($Database);
13
14# verify that user is logged in
15$User->check_user_session();
16
17$mysqldump = Config::get('mysqldump_cli_binary', '/usr/bin/mysqldump');
18
19if ( !file_exists($mysqldump) ) {
20    $filename = "error_message.txt";
21
22    $content  = _("Unable to locate executable: ").$mysqldump."\n";
23    $content .= _("Please configure \$mysqldump_cli_binary in config.php\n");
24} else {
25    $filename = "phpipam_MySQL_dump_". date("Y-m-d") .".sql";
26
27    $db = Config::get('db');
28
29    $command      = "$mysqldump --opt -h '". $db['host'] ."' -u '". $db['user'] ."' -p'". $db['pass'] ."' '". $db['name'] ."'";
30    $command_safe = "$mysqldump --opt -h '". $db['host'] ."' -u '". "<REDACTED>" ."' -p'". "<REDACTED>" ."' '". $db['name'] ."'";
31
32    $content  = "# phpipam Database dump \n";
33    $content .= "#    command executed: $command_safe \n";
34    $content .= "# --------------------- \n\n";
35    $content .= shell_exec($command);
36}
37
38header("Cache-Control: private");
39header("Content-Description: File Transfer");
40header("Content-Type: application/octet-stream");
41header('Content-Disposition: attachment; filename="'. $filename .'"');
42header("Content-Length: " . strlen($content));
43
44print($content);
45