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'];
45 if ($extension != 'svg') {
48 mb_strpos($_REQUEST['image'], ',') +
1
50 $data = base64_decode($data);
52 $data = $_REQUEST['image'];
55 /* Send download header */
65 } else if (isset($_REQUEST['monitorconfig'])) {
66 /* For monitor chart config export */
67 PMA_downloadHeader('monitor.cfg', 'application/force-download');
68 echo urldecode($_REQUEST['monitorconfig']);
70 } else if (isset($_REQUEST['import'])) {
71 /* For monitor chart config import */
72 header('Content-type: text/plain');
73 if (!file_exists($_FILES['file']['tmp_name'])) {
76 echo file_get_contents($_FILES['file']['tmp_name']);