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 define('PMA_MINIMUM_COMMON', true);
11 require_once 'libraries/common.inc.php';
13 /* For chart exporting */
14 if (isset($_REQUEST['filename']) && isset($_REQUEST['image'])) {
17 'image/svg+xml' => 'svg',
20 /* Check whether MIME type is allowed */
21 if (! isset($allowed[$_REQUEST['type']])) {
22 PMA_fatalError(__('Invalid export type'));
26 * Check file name to match mime type and not contain new lines
27 * to prevent response splitting.
29 $extension = $allowed[$_REQUEST['type']];
30 $valid_match = '/^[^\n\r]*\.' . $extension . '$/';
31 if (! preg_match($valid_match, $_REQUEST['filename'])) {
32 if (! preg_match('/^[^\n\r]*$/', $_REQUEST['filename'])) {
33 /* Filename is unsafe, discard it */
34 $filename = 'download.' . $extension;
37 $filename = $_REQUEST['filename'] . '.' . $extension;
40 /* Filename from request should be safe here */
41 $filename = $_REQUEST['filename'];
44 /** @var PMA_String $pmaString */
45 $pmaString = $GLOBALS['PMA_String'];
48 if ($extension != 'svg') {
49 $data = /*overload*/mb_substr(
51 /*overload*/mb_strpos($_REQUEST['image'], ',') +
1
53 $data = base64_decode($data);
55 $data = $_REQUEST['image'];
58 /* Send download header */
62 /*overload*/mb_strlen($data)
68 } else if (isset($_REQUEST['monitorconfig'])) {
69 /* For monitor chart config export */
70 PMA_downloadHeader('monitor.cfg', 'application/force-download');
71 echo urldecode($_REQUEST['monitorconfig']);
73 } else if (isset($_REQUEST['import'])) {
74 /* For monitor chart config import */
75 header('Content-type: text/plain');
76 if (!file_exists($_FILES['file']['tmp_name'])) {
79 echo file_get_contents($_FILES['file']['tmp_name']);