2016-06-13 15:51:19 +02:00
|
|
|
<?php
|
2016-06-19 00:16:25 +02:00
|
|
|
|
2016-06-13 22:59:05 +02:00
|
|
|
/**
|
2016-11-29 15:24:22 +01:00
|
|
|
* download.php, Kopano Webapp contact to vcf im/exporter
|
2016-06-13 22:59:05 +02:00
|
|
|
*
|
|
|
|
* Author: Christoph Haas <christoph.h@sprinternet.at>
|
2018-03-08 10:33:06 +01:00
|
|
|
* Copyright (C) 2012-2018 Christoph Haas
|
2016-06-13 22:59:05 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
2016-06-13 15:51:19 +02:00
|
|
|
class DownloadHandler
|
|
|
|
{
|
2016-11-30 12:25:38 +01:00
|
|
|
/**
|
|
|
|
* Download the given vcf file.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function doDownload()
|
|
|
|
{
|
|
|
|
if (isset($_GET["token"])) {
|
|
|
|
$token = $_GET["token"];
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-13 15:51:19 +02:00
|
|
|
|
2016-11-30 12:25:38 +01:00
|
|
|
if (isset($_GET["filename"])) {
|
|
|
|
$filename = $_GET["filename"];
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-13 15:51:19 +02:00
|
|
|
|
2016-11-30 12:25:38 +01:00
|
|
|
// validate token
|
|
|
|
if (!preg_match('/^[a-zA-Z0-9]+$/', $token)) { // token is a md5 hash
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-13 15:51:19 +02:00
|
|
|
|
2016-11-30 12:25:38 +01:00
|
|
|
$file = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD . "vcf_" . $token . ".vcf";
|
2016-06-13 15:51:19 +02:00
|
|
|
|
2016-11-30 12:25:38 +01:00
|
|
|
if (!file_exists($file)) { // invalid token
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-13 15:51:19 +02:00
|
|
|
|
2016-11-30 12:25:38 +01:00
|
|
|
// set headers here
|
|
|
|
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
2016-06-13 15:51:19 +02:00
|
|
|
|
2016-11-30 12:25:38 +01:00
|
|
|
// no caching
|
|
|
|
header('Expires: 0'); // set expiration time
|
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
|
|
header('Content-Length: ' . filesize($file));
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
header('Pragma: public');
|
|
|
|
flush();
|
2016-06-13 15:51:19 +02:00
|
|
|
|
2016-11-30 12:25:38 +01:00
|
|
|
// print the downloaded file
|
|
|
|
readfile($file);
|
|
|
|
ignore_user_abort(true);
|
|
|
|
unlink($file);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-13 15:51:19 +02:00
|
|
|
}
|