Thomas Bruederli
2013-03-27 ce0c1f44a3ff447cfaec315bc984bb4a4e1f09e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
 
 +-----------------------------------------------------------------------+
 | program/steps/utils/save_pref.inc                                     |
 |                                                                       |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2013, The Roundcube Dev Team                       |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Save preferences setting in database                                |
 |                                                                       |
 +-----------------------------------------------------------------------+
 | Author: Aleksander Machniak <alec@alec.pl>                            |
 +-----------------------------------------------------------------------+
*/
 
$name = get_input_value('_name', RCUBE_INPUT_POST);
$value = get_input_value('_value', RCUBE_INPUT_POST);
$whitelist = array(
    'preview_pane',
    'list_cols',
    'collapsed_folders',
    'collapsed_abooks',
);
 
if (!in_array($name, array_merge($whitelist, $RCMAIL->plugins->allowed_prefs))) {
    raise_error(array('code' => 500, 'type' => 'php',
        'file' => __FILE__, 'line' => __LINE__,
        'message' => sprintf("Hack attempt detected (user: %s)", $_SESSION['username'])),
        true, false);
 
    $OUTPUT->reset();
    $OUTPUT->send();
}
 
// save preference value
$RCMAIL->user->save_prefs(array($name => $value));
 
// update also session if requested
if ($sessname = get_input_value('_session', RCUBE_INPUT_POST)) {
    // Support multidimensional arrays...
    $vars = explode('/', $sessname);
 
    // ... up to 3 levels
    if (count($vars) == 1)
        $_SESSION[$vars[0]] = $value;
    else if (count($vars) == 2)
        $_SESSION[$vars[0]][$vars[1]] = $value;
    else if (count($vars) == 3)
        $_SESSION[$vars[0]][$vars[1]][$vars[2]] = $value;
}
 
$OUTPUT->reset();
$OUTPUT->send();