Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 12... Línea 12...
12
// GNU General Public License for more details.
12
// GNU General Public License for more details.
13
//
13
//
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea -...
16
 
-
 
17
/**
-
 
18
 * File based session handler.
-
 
19
 *
-
 
20
 * @package    core
-
 
21
 * @copyright  2013 Petr Skoda {@link http://skodak.org}
-
 
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
23
 */
-
 
24
 
16
 
Línea 25... Línea -...
25
namespace core\session;
-
 
26
 
-
 
27
defined('MOODLE_INTERNAL') || die();
17
namespace core\session;
28
 
18
 
29
/**
19
/**
30
 * File based session handler.
20
 * File based session handler.
31
 *
21
 *
32
 * @package    core
22
 * @package    core
33
 * @copyright  2013 Petr Skoda {@link http://skodak.org}
23
 * @copyright  2013 Petr Skoda {@link http://skodak.org}
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
25
 */
35
 */
26
class file extends handler {
36
class file extends handler {
27
 
Línea 37... Línea 28...
37
    /** @var string session dir */
28
    /** @var string session dir */
38
    protected $sessiondir;
29
    protected $sessiondir;
Línea 48... Línea 39...
48
        } else {
39
        } else {
49
            $this->sessiondir = "$CFG->dataroot/sessions";
40
            $this->sessiondir = "$CFG->dataroot/sessions";
50
        }
41
        }
51
    }
42
    }
Línea 52... Línea -...
52
 
-
 
53
    /**
43
 
54
     * Init session handler.
-
 
55
     */
44
    #[\Override]
56
    public function init() {
45
    public function init() {
57
        if (preg_match('/^[0-9]+;/', $this->sessiondir)) {
46
        if (preg_match('/^[0-9]+;/', $this->sessiondir)) {
58
            throw new exception('sessionhandlerproblem', 'error', '', null, 'Multilevel session directories are not supported');
47
            throw new exception('sessionhandlerproblem', 'error', '', null, 'Multilevel session directories are not supported');
59
        }
48
        }
Línea 62... Línea 51...
62
        if (!is_writable($this->sessiondir)) {
51
        if (!is_writable($this->sessiondir)) {
63
            throw new exception('sessionhandlerproblem', 'error', '', null, 'Session directory is not writable');
52
            throw new exception('sessionhandlerproblem', 'error', '', null, 'Session directory is not writable');
64
        }
53
        }
65
        // Need to disable debugging since disk_free_space()
54
        // Need to disable debugging since disk_free_space()
66
        // will fail on very large partitions (see MDL-19222).
55
        // will fail on very large partitions (see MDL-19222).
67
        $freespace = @disk_free_space($this->sessiondir);
56
        // Moodle supports disable_functions = disk_free_space (MDL-43039).
68
        // MDL-43039: disk_free_space() returns null if disabled.
57
        $freespace = function_exists('disk_free_space') ? disk_free_space($this->sessiondir) : false;
69
        if (!($freespace > 2048) and ($freespace !== false) and ($freespace !== null)) {
58
        if (!($freespace > 2048) && ($freespace !== false)) {
70
            throw new exception('sessiondiskfull', 'error');
59
            throw new exception('sessiondiskfull', 'error');
71
        }
60
        }
Línea 72... Línea 61...
72
 
61
 
73
        // NOTE: we cannot set any lock acquiring timeout here - bad luck.
62
        // NOTE: we cannot set any lock acquiring timeout here - bad luck.
74
        ini_set('session.save_handler', 'files');
63
        ini_set('session.save_handler', 'files');
75
        ini_set('session.save_path', $this->sessiondir);
64
        ini_set('session.save_path', $this->sessiondir);
Línea 76... Línea -...
76
    }
-
 
77
 
-
 
78
    /**
-
 
79
     * Check the backend contains data for this session id.
-
 
80
     *
-
 
81
     * Note: this is intended to be called from manager::session_exists() only.
65
    }
82
     *
-
 
83
     * @param string $sid
-
 
84
     * @return bool true if session found.
66
 
85
     */
67
    #[\Override]
86
    public function session_exists($sid) {
68
    public function session_exists($sid) {
87
        $sid = clean_param($sid, PARAM_FILE);
69
        $sid = clean_param($sid, PARAM_FILE);
88
        if (!$sid) {
70
        if (!$sid) {
89
            return false;
71
            return false;
90
        }
72
        }
91
        $sessionfile = "$this->sessiondir/sess_$sid";
73
        $sessionfile = "$this->sessiondir/sess_$sid";
Línea 92... Línea -...
92
        return file_exists($sessionfile);
-
 
93
    }
-
 
94
 
74
        return file_exists($sessionfile);
95
    /**
-
 
96
     * Kill all active sessions, the core sessions table is
75
    }
97
     * purged afterwards.
76
 
98
     */
77
    #[\Override]
99
    public function kill_all_sessions() {
78
    public function destroy_all(): bool {
100
        if (is_dir($this->sessiondir)) {
79
        if (is_dir($this->sessiondir)) {
101
            foreach (glob("$this->sessiondir/sess_*") as $filename) {
80
            foreach (glob("$this->sessiondir/sess_*") as $filename) {
-
 
81
                @unlink($filename);
-
 
82
            }
102
                @unlink($filename);
83
        }
Línea 103... Línea -...
103
            }
-
 
104
        }
-
 
105
    }
84
 
106
 
-
 
107
    /**
85
        return parent::destroy_all();
108
     * Kill one session, the session record is removed afterwards.
86
    }
109
     * @param string $sid
87
 
110
     */
88
    #[\Override]
111
    public function kill_session($sid) {
89
    public function destroy(string $id): bool {
112
        $sid = clean_param($sid, PARAM_FILE);
90
        $sid = clean_param($id, PARAM_FILE);
113
        if (!$sid) {
91
        if (!$sid) {
114
            return;
92
            return false;
115
        }
93
        }
-
 
94
        $sessionfile = "$this->sessiondir/sess_$sid";
-
 
95
        if (file_exists($sessionfile)) {
116
        $sessionfile = "$this->sessiondir/sess_$sid";
96
            @unlink($sessionfile);
117
        if (file_exists($sessionfile)) {
97
        }