2022-08-18 14:01:52 +02:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// OpenSMTPD Admin
|
|
|
|
// by Mischa Peters <mischa at high5 dot nl>
|
|
|
|
// Copyright (c) 2022 High5!
|
|
|
|
// License Info: LICENSE.TXT
|
|
|
|
//
|
|
|
|
// File: backup.php
|
|
|
|
//
|
|
|
|
// Template File: -none-
|
|
|
|
//
|
|
|
|
// Template Variables:
|
|
|
|
//
|
|
|
|
// -none-
|
|
|
|
//
|
|
|
|
// Form POST \ GET Variables:
|
|
|
|
//
|
|
|
|
// -none-
|
|
|
|
//
|
2022-09-04 11:38:47 +02:00
|
|
|
require_once '../functions.inc.php';
|
|
|
|
include '../languages/' . check_language() . '.lang';
|
2022-08-18 14:01:52 +02:00
|
|
|
date_default_timezone_set('Europe/Amsterdam');
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
|
|
|
umask(077);
|
|
|
|
$filename = "opensmtpadmin-" . date("Ymd") . "-" . getmypid() . ".sql";
|
2022-09-04 11:38:47 +02:00
|
|
|
$backup = "/tmp" . $filename;
|
|
|
|
$header = "#\n# OpenSMTPD Admin " . VERSION . "\n# Date: " . date("D M j G:i:s T Y") . "\n#\n";
|
|
|
|
$tables = array('admin','alias','domain','domain_admins','log','mailbox','vacation');
|
2022-08-18 14:01:52 +02:00
|
|
|
|
|
|
|
if (!$fh = fopen($backup, 'w')) {
|
2022-09-04 11:38:47 +02:00
|
|
|
$message = "<div class=\"error_msg\">Cannot open file ($backup)</div>";
|
|
|
|
include '../templates/header.tpl';
|
|
|
|
include '../templates/admin_menu.tpl';
|
|
|
|
include '../templates/message.tpl';
|
|
|
|
include '../templates/footer.tpl';
|
2022-08-18 14:01:52 +02:00
|
|
|
} else {
|
|
|
|
fwrite($fh, $header);
|
2022-09-04 11:38:47 +02:00
|
|
|
$dbh = connect_db();
|
|
|
|
foreach ($tables as $table) {
|
|
|
|
$sth = $dbh->query("SHOW CREATE TABLE $table");
|
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC);
|
|
|
|
fwrite ($fh, $row['Create Table']. "\n\n");
|
|
|
|
}
|
2022-08-18 14:01:52 +02:00
|
|
|
|
2022-09-04 11:38:47 +02:00
|
|
|
foreach ($tables as $table) {
|
|
|
|
$sth = $dbh->query("SELECT * FROM $table");
|
|
|
|
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
|
|
|
|
foreach ($row as $k => $v) {
|
|
|
|
$keys[] = $k;
|
|
|
|
$values[] = $v;
|
2022-08-18 14:01:52 +02:00
|
|
|
}
|
2022-09-04 11:38:47 +02:00
|
|
|
fwrite($fh, "INSERT INTO ". $table . " (". implode (',',$keys) . ") VALUES ('" . implode ('\',\'',$values) . "')\n");
|
|
|
|
$keys = array();
|
|
|
|
$values = array();
|
2022-08-18 14:01:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
header("Content-Type: application/octet-stream");
|
|
|
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Content-Length: " . filesize("$backup"));
|
|
|
|
header("Content-Description: OpenSMTPD Admin");
|
|
|
|
$download_backup = fopen("$backup", "r");
|
|
|
|
unlink("$backup");
|
|
|
|
fpassthru($download_backup);
|
|
|
|
}
|
|
|
|
?>
|