4 // by Mischa Peters <mischa at high5 dot nl>
5 // Copyright (c) 2022 High5!
6 // License Info: LICENSE.TXT
10 // Template File: -none-
12 // Template Variables:
16 // POST / GET Variables:
20 require_once './functions.inc.php';
21 include './languages/' . check_language() . '.lang';
22 date_default_timezone_set('Europe/Amsterdam');
24 $SESSID_USERNAME = check_session();
25 $ROLE = check_role($SESSID_USERNAME);
27 if ($ROLE != ADMIN_ROLE) {
28 header("Location: list-domain.php");
32 if ($_SERVER['REQUEST_METHOD'] == "GET") {
34 $filename = "opensmtpadmin-" . date("Ymd") . "-" . getmypid() . ".sql";
35 $backup = "/tmp/" . $filename;
36 $header = "#\n# OpenSMTPD Admin " . VERSION . "\n# Date: " . date("D M j G:i:s T Y") . "\n#\n";
37 $tables = array('admin','alias','domain','domain_admins','log','mailbox','vacation');
39 if (!$fh = fopen($backup, 'w')) {
40 $message = "<div class=\"error_msg\">Cannot open file ($backup)</div>";
43 if (empty($message)) {
46 foreach ($tables as $table) {
47 $sth = $dbh->query("SHOW CREATE TABLE $table");
48 $row = $sth->fetch(PDO::FETCH_ASSOC);
49 fwrite ($fh, $row['Create Table']. "\n\n");
51 foreach ($tables as $table) {
52 $sth = $dbh->query("SELECT * FROM $table");
53 while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
54 foreach ($row as $k => $v) {
58 fwrite($fh, "INSERT INTO ". $table . " (". implode (',',$keys) . ") VALUES ('" . implode ('\',\'',$values) . "')\n");
63 header("Content-Type: application/octet-stream");
64 header("Content-Disposition: attachment; filename=\"$filename\"");
65 header("Content-Transfer-Encoding: binary");
66 header("Content-Length: " . filesize("$backup"));
67 header("Content-Description: OpenSMTPD Admin");
68 $download_backup = fopen("$backup", "r");
70 fpassthru($download_backup);
72 include './templates/header.tpl';
73 include './templates/menu.tpl';
74 include './templates/message.tpl';
75 include './templates/footer.tpl';