annotate plugins/filesystem_attachments/filesystem_attachments.php @ 11:aff04b06b685 default tip

various small fixes from upgrades to PHP and/or hangover from fix to apt-get overwrite at beginning of the year somehow
author Charlie Root
date Sun, 26 Jan 2025 13:09:03 -0500
parents bf99236cc5cd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 <?php
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 * Filesystem Attachments
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 * This is a core plugin which provides basic, filesystem based
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 * attachment temporary file handling. This includes storing
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 * attachments of messages currently being composed, writing attachments
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 * to disk when drafts with attachments are re-opened and writing
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 * attachments to disk for inline display in current html compositions.
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
10 * It also handles uploaded files for other uses, so not only attachments.
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 * Developers may wish to extend this class when creating attachment
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 * handler plugins:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 * require_once('plugins/filesystem_attachments/filesystem_attachments.php');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 * class myCustom_attachments extends filesystem_attachments
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 *
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
17 * Note for developers: It is plugin's responsibility to care about security.
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
18 * So, e.g. if the plugin is asked about some file path it should check
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
19 * if it's really the storage path of the plugin and not e.g. /etc/passwd.
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
20 * It is done by setting 'status' flag on every plugin hook it uses.
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
21 * Roundcube core will trust the returned path if status=true.
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
22 *
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 * @license GNU GPLv3+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 * @author Ziba Scott <ziba@umich.edu>
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 * @author Thomas Bruederli <roundcube@gmail.com>
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 class filesystem_attachments extends rcube_plugin
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 public $task = '?(?!login).*';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 function init()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 // Save a newly uploaded attachment
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 $this->add_hook('attachment_upload', array($this, 'upload'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 // Save an attachment from a non-upload source (draft or forward)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 $this->add_hook('attachment_save', array($this, 'save'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 // Remove an attachment from storage
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 $this->add_hook('attachment_delete', array($this, 'remove'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 // When composing an html message, image attachments may be shown
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 $this->add_hook('attachment_display', array($this, 'display'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 // Get the attachment from storage and place it on disk to be sent
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 $this->add_hook('attachment_get', array($this, 'get'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 // Delete all temp files associated with this user
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 $this->add_hook('attachments_cleanup', array($this, 'cleanup'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 $this->add_hook('session_destroy', array($this, 'cleanup'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 * Save a newly uploaded attachment
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 function upload($args)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58 $args['status'] = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 $group = $args['group'];
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
60 $rcmail = rcube::get_instance();
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 // use common temp dir for file uploads
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 $temp_dir = $rcmail->config->get('temp_dir');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64 $tmpfname = tempnam($temp_dir, 'rcmAttmnt');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66 if (move_uploaded_file($args['path'], $tmpfname) && file_exists($tmpfname)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67 $args['id'] = $this->file_id();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68 $args['path'] = $tmpfname;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 $args['status'] = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 @chmod($tmpfname, 0600); // set correct permissions (#1488996)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 // Note the file for later cleanup
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 $_SESSION['plugins']['filesystem_attachments'][$group][$args['id']] = $tmpfname;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76 return $args;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80 * Save an attachment from a non-upload source (draft or forward)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 function save($args)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 $group = $args['group'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85 $args['status'] = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87 if (!$args['path']) {
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
88 $rcmail = rcube::get_instance();
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 $temp_dir = $rcmail->config->get('temp_dir');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 if ($fp = fopen($tmp_path, 'w')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 fwrite($fp, $args['data']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94 fclose($fp);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95 $args['path'] = $tmp_path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 return $args;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102 $args['id'] = $this->file_id();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 $args['status'] = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 // Note the file for later cleanup
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 $_SESSION['plugins']['filesystem_attachments'][$group][$args['id']] = $args['path'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108 return $args;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 * Remove an attachment from storage
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 * This is triggered by the remove attachment button on the compose screen
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 function remove($args)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116 {
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
117 $args['status'] = $this->verify_path($args['path']) && @unlink($args['path']);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 return $args;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 * When composing an html message, image attachments may be shown
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 * For this plugin, the file is already in place, just check for
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
124 * the existence of the proper metadata
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126 function display($args)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127 {
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
128 $args['status'] = $this->verify_path($args['path']) && file_exists($args['path']);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 return $args;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133 * This attachment plugin doesn't require any steps to put the file
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 * on disk for use. This stub function is kept here to make this
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135 * class handy as a parent class for other plugins which may need it.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 function get($args)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138 {
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
139 if (!$this->verify_path($args['path'])) {
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
140 $args['path'] = null;
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
141 }
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
142
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 return $args;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147 * Delete all temp files associated with this user
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 function cleanup($args)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 // $_SESSION['compose']['attachments'] is not a complete record of
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 // temporary files because loading a draft or starting a forward copies
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153 // the file to disk, but does not make an entry in that array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 if (is_array($_SESSION['plugins']['filesystem_attachments'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 foreach ($_SESSION['plugins']['filesystem_attachments'] as $group => $files) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 if ($args['group'] && $args['group'] != $group) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 foreach ((array)$files as $filename) {
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
161 if (file_exists($filename)) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 unlink($filename);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 unset($_SESSION['plugins']['filesystem_attachments'][$group]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169 return $args;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 function file_id()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173 {
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
174 $userid = rcube::get_instance()->user->ID;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175 list($usec, $sec) = explode(' ', microtime());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 $id = preg_replace('/[^0-9]/', '', $userid . $sec . $usec);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178 // make sure the ID is really unique (#1489546)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 while ($this->find_file_by_id($id)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 // increment last four characters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 $x = substr($id, -4) + 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182 $id = substr($id, 0, -4) . sprintf('%04d', ($x > 9999 ? $x - 9999 : $x));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 return $id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 private function find_file_by_id($id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 foreach ((array) $_SESSION['plugins']['filesystem_attachments'] as $group => $files) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 if (isset($files[$id])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195 }
8
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
196
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
197 /**
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
198 * For security we'll always verify the file path stored in session,
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
199 * as session entries can be faked in various ways e.g. #6026.
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
200 * We allow only files in Roundcube temp dir
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
201 */
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
202 protected function verify_path($path)
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
203 {
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
204 if (empty($path)) {
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
205 return false;
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
206 }
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
207
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
208 $rcmail = rcube::get_instance();
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
209 $temp_dir = $rcmail->config->get('temp_dir');
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
210 $file_path = pathinfo($path, PATHINFO_DIRNAME);
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
211
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
212 if ($temp_dir !== $file_path) {
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
213 rcube::raise_error(array(
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
214 'code' => 403,
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
215 'file' => __FILE__,
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
216 'line' => __LINE__,
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
217 'message' => sprintf("%s can't read %s (not in temp_dir)",
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
218 $rcmail->get_user_name(), substr($path, 0, 512))
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
219 ), true, false);
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
220
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
221 return false;
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
222 }
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
223
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
224 return true;
bf99236cc5cd try to recover from upgrade fail
Charlie Root
parents: 0
diff changeset
225 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 }