2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * "Echo" service to allow force downloading of exported charts (png or svg)
5 * and server status monitor settings
10 use PMA\libraries\PMA_String
;
12 define('PMA_MINIMUM_COMMON', true);
13 require_once 'libraries/common.inc.php';
15 /* For chart exporting */
16 if (isset($_REQUEST['filename']) && isset($_REQUEST['image'])) {
19 'image/svg+xml' => 'svg',
22 /* Check whether MIME type is allowed */
23 if (! isset($allowed[$_REQUEST['type']])) {
24 PMA_fatalError(__('Invalid export type'));
28 * Check file name to match mime type and not contain new lines
29 * to prevent response splitting.
31 $extension = $allowed[$_REQUEST['type']];
32 $valid_match = '/^[^\n\r]*\.' . $extension . '$/';
33 if (! preg_match($valid_match, $_REQUEST['filename'])) {
34 if (! preg_match('/^[^\n\r]*$/', $_REQUEST['filename'])) {
35 /* Filename is unsafe, discard it */
36 $filename = 'download.' . $extension;
39 $filename = $_REQUEST['filename'] . '.' . $extension;
42 /* Filename from request should be safe here */
43 $filename = $_REQUEST['filename'];
46 /** @var String $pmaString */
47 $pmaString = $GLOBALS['PMA_String'];
50 if ($extension != 'svg') {
51 $data = /*overload*/mb_substr(
53 /*overload*/mb_strpos($_REQUEST['image'], ',') +
1
55 $data = base64_decode($data);
57 $data = $_REQUEST['image'];
60 /* Send download header */
64 /*overload*/mb_strlen($data)
70 } else if (isset($_REQUEST['monitorconfig'])) {
71 /* For monitor chart config export */
72 PMA_downloadHeader('monitor.cfg', 'application/force-download');
73 echo urldecode($_REQUEST['monitorconfig']);
75 } else if (isset($_REQUEST['import'])) {
76 /* For monitor chart config import */
77 header('Content-type: text/plain');
78 if (!file_exists($_FILES['file']['tmp_name'])) {
81 echo file_get_contents($_FILES['file']['tmp_name']);