You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.1 KiB
PHTML
141 lines
4.1 KiB
PHTML
18 years ago
|
<?php
|
||
17 years ago
|
/**
|
||
|
* Postfix Admin
|
||
|
*
|
||
|
* LICENSE
|
||
|
* This source file is subject to the GPL license that is bundled with
|
||
|
* this package in the file LICENSE.TXT.
|
||
|
*
|
||
11 years ago
|
* Further details on the project are available at http://postfixadmin.sf.net
|
||
17 years ago
|
*
|
||
|
* @version $Id$
|
||
|
* @license GNU GPL v2 or later.
|
||
|
*
|
||
|
* File: backup.php
|
||
|
* Used to save all settings - but only works for MySQL databases.
|
||
|
* Template File: -none-
|
||
|
*
|
||
|
* Template Variables: -none-
|
||
|
*
|
||
|
* Form POST \ GET Variables: -none-
|
||
|
*/
|
||
18 years ago
|
|
||
17 years ago
|
require_once('common.php');
|
||
17 years ago
|
|
||
|
authentication_require_role('global-admin');
|
||
|
|
||
14 years ago
|
(($CONF['backup'] == 'NO') ? header("Location: main.php") && exit : '1');
|
||
18 years ago
|
|
||
|
// TODO: make backup supported for postgres
|
||
11 years ago
|
if (db_pgsql()) {
|
||
11 years ago
|
flash_error('Sorry: Backup is currently not supported for your DBMS ('.$CONF['database_type'].').');
|
||
15 years ago
|
$smarty->assign ('smarty_template', 'message');
|
||
|
$smarty->display ('index.tpl');
|
||
14 years ago
|
die;
|
||
18 years ago
|
}
|
||
14 years ago
|
|
||
|
if (safeget('download') == "") {
|
||
11 years ago
|
$smarty->assign ('smarty_template', 'backupwarning');
|
||
14 years ago
|
$smarty->display ('index.tpl');
|
||
|
die;
|
||
|
}
|
||
|
|
||
|
# Still here? Then let's create the database dump...
|
||
|
|
||
18 years ago
|
/*
|
||
|
SELECT attnum,attname,typname,atttypmod-4,attnotnull,atthasdef,adsrc
|
||
|
AS def FROM pg_attribute,pg_class,pg_type,pg_attrdef
|
||
|
WHERE pg_class.oid=attrelid AND pg_type.oid=atttypid
|
||
|
AND attnum>0 AND pg_class.oid=adrelid AND adnum=attnum AND atthasdef='t' AND lower(relname)='admin'
|
||
|
UNION SELECT attnum,attname,typname,atttypmod-4,attnotnull,atthasdef,''
|
||
|
AS def FROM pg_attribute,pg_class,pg_type
|
||
|
WHERE pg_class.oid=attrelid
|
||
|
AND pg_type.oid=atttypid
|
||
|
AND attnum>0
|
||
|
AND atthasdef='f'
|
||
|
AND lower(relname)='admin'
|
||
|
$db = $_GET['db'];
|
||
|
$cmd = "pg_dump -c -D -f /tix/miner/miner.sql -F p -N -U postgres $db";
|
||
|
$res = `$cmd`;
|
||
|
// Alternate: $res = shell_exec($cmd);
|
||
|
echo $res;
|
||
|
*/
|
||
|
|
||
|
if ($_SERVER['REQUEST_METHOD'] == "GET")
|
||
|
{
|
||
|
umask (077);
|
||
15 years ago
|
$path = (ini_get('upload_tmp_dir') != '') ? ini_get('upload_tmp_dir') : '/tmp';
|
||
13 years ago
|
date_default_timezone_set(@date_default_timezone_get()); # Suppress date.timezone warnings
|
||
18 years ago
|
$filename = "postfixadmin-" . date ("Ymd") . "-" . getmypid() . ".sql";
|
||
15 years ago
|
$backup = $path . DIRECTORY_SEPARATOR . $filename;
|
||
18 years ago
|
|
||
|
$header = "#\n# Postfix Admin $version\n# Date: " . date ("D M j G:i:s T Y") . "\n#\n";
|
||
|
|
||
|
if (!$fh = fopen ($backup, 'w'))
|
||
|
{
|
||
13 years ago
|
flash_error("<div class=\"error_msg\">Cannot open file ($backup)</div>");
|
||
15 years ago
|
$smarty->assign ('smarty_template', 'message');
|
||
|
$smarty->display ('index.tpl');
|
||
18 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
fwrite ($fh, $header);
|
||
|
|
||
17 years ago
|
$tables = array(
|
||
|
'admin',
|
||
|
'alias',
|
||
17 years ago
|
'alias_domain',
|
||
17 years ago
|
'config',
|
||
|
'domain',
|
||
|
'domain_admins',
|
||
|
'fetchmail',
|
||
|
'log',
|
||
|
'mailbox',
|
||
15 years ago
|
'quota',
|
||
|
'quota2',
|
||
17 years ago
|
'vacation',
|
||
|
'vacation_notification'
|
||
|
);
|
||
18 years ago
|
|
||
|
for ($i = 0 ; $i < sizeof ($tables) ; ++$i)
|
||
|
{
|
||
16 years ago
|
$result = db_query ("SHOW CREATE TABLE " . table_by_key($tables[$i]));
|
||
18 years ago
|
if ($result['rows'] > 0)
|
||
|
{
|
||
|
while ($row = db_array ($result['result']))
|
||
|
{
|
||
17 years ago
|
fwrite ($fh, "$row[1];\n\n");
|
||
18 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for ($i = 0 ; $i < sizeof ($tables) ; ++$i)
|
||
|
{
|
||
16 years ago
|
$result = db_query ("SELECT * FROM " . table_by_key($tables[$i]));
|
||
18 years ago
|
if ($result['rows'] > 0)
|
||
|
{
|
||
|
while ($row = db_assoc ($result['result']))
|
||
|
{
|
||
13 years ago
|
$fields = array_keys($row);
|
||
|
$values = array_values($row);
|
||
|
$values = array_map('escape_string', $values);
|
||
18 years ago
|
|
||
17 years ago
|
fwrite ($fh, "INSERT INTO ". $tables[$i] . " (". implode (',',$fields) . ") VALUES ('" . implode ('\',\'',$values) . "');\n");
|
||
18 years ago
|
$fields = "";
|
||
|
$values = "";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
16 years ago
|
header ("Content-Type: text/plain");
|
||
18 years ago
|
header ("Content-Disposition: attachment; filename=\"$filename\"");
|
||
|
header ("Content-Transfer-Encoding: binary");
|
||
|
header ("Content-Length: " . filesize("$backup"));
|
||
|
header ("Content-Description: Postfix Admin");
|
||
|
$download_backup = fopen ("$backup", "r");
|
||
|
unlink ("$backup");
|
||
|
fpassthru ($download_backup);
|
||
|
}
|
||
17 years ago
|
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
|
||
18 years ago
|
?>
|