This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /****************************************************************** |
||
3 | pfile.phtml Muze Ariadne |
||
4 | ------------------------------------------------------------------ |
||
5 | Author: Muze ([email protected]) |
||
6 | Date: 31 october 2002 |
||
7 | |||
8 | Copyright 2002 Muze |
||
9 | |||
10 | This file is part of Ariadne. |
||
11 | |||
12 | Ariadne is free software; you can redistribute it and/or modify |
||
13 | it under the terms of the GNU General Public License as published |
||
14 | by the Free Software Foundation; either version 2 of the License, |
||
15 | or (at your option) any later version. |
||
16 | |||
17 | Ariadne is distributed in the hope that it will be useful, |
||
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
20 | GNU General Public License for more details. |
||
21 | |||
22 | You should have received a copy of the GNU General Public License |
||
23 | along with Ariadne; if not, write to the Free Software |
||
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
||
25 | 02111-1307 USA |
||
26 | |||
27 | ------------------------------------------------------------------- |
||
28 | |||
29 | Class inheritance: pobject > pfile |
||
30 | Description: |
||
31 | |||
32 | This is the class definition file of the pfile class. |
||
33 | |||
34 | ******************************************************************/ |
||
35 | |||
36 | require_once(AriadneBasePath."/objects/pobject.phtml"); |
||
37 | require_once(AriadneBasePath."/modules/mod_url.php"); |
||
38 | require_once(AriadneBasePath."/modules/mod_mimemagic.php"); |
||
39 | |||
40 | class pfile extends pobject { // pfile class definition |
||
41 | |||
42 | protected function getNlsForFile($file,$nls) { |
||
43 | // private function, requires that the push/pop context will be done by the caller |
||
44 | if(!$nls){ |
||
45 | $nls = $this->nls; |
||
46 | } |
||
47 | $ret = ar_store_files::exists($file, $nls); |
||
48 | if (!$ret) { |
||
49 | $nls = $this->data->nls->default; |
||
50 | $ret = ar_store_files::exists($file, $nls); |
||
51 | if (!$ret) { |
||
52 | $nls = null; |
||
53 | } |
||
54 | } |
||
55 | return $nls; |
||
56 | } |
||
57 | |||
58 | function GetFile($file='file', $nls='') { |
||
59 | $this->pushContext( Array( "arCurrentObject" => $this)); |
||
60 | $nls = $this->getNlsForFile($file,$nls); |
||
61 | $ret = ar_store_files::get($file, $nls); |
||
62 | if ( !ar_error::isError($ret) ) { |
||
63 | $ret = $ret->getContents(); |
||
64 | } else { |
||
65 | $ret = null; //backwards compatibility... there was no error checking before |
||
66 | } |
||
67 | $this->popcontext(); |
||
68 | return $ret; |
||
69 | } |
||
70 | |||
71 | function ExistsFile($file='file', $nls='') { |
||
72 | $this->pushContext( Array( "arCurrentObject" => $this)); |
||
73 | $nls = $this->getNlsForFile($file,$nls); |
||
74 | $ret = ar_store_files::exists($file, $nls); |
||
75 | $this->popcontext(); |
||
76 | return $ret; |
||
77 | } |
||
78 | |||
79 | function ParseFile($file='file', $nls='') { |
||
80 | return $this->ParseString( $this->GetFile( $file, $nls ) ); |
||
81 | } |
||
82 | |||
83 | function ParseString($filecontent) { |
||
84 | $this->pushContext( Array( "arCurrentObject" => $this)); |
||
85 | $res = URL::ARtoRAW($filecontent, true); |
||
86 | $this->popcontext(); |
||
87 | return $res; |
||
88 | } |
||
89 | |||
90 | function ShowFile($file='file', $nls='', $mimetype='') { |
||
91 | global $AR, $ARCurrent, $ARnls; |
||
92 | $this->pushContext( Array( "arCurrentObject" => $this)); |
||
93 | $nls = $this->getNlsForFile($file,$nls); |
||
94 | $file = ar_store_files::get( $file, $nls ); |
||
95 | if ( ar_error::isError($file) ) { |
||
96 | $this->popcontext(); |
||
97 | return $file; |
||
98 | } |
||
99 | if ( !$mimetype && isset($this->data->$nls->mimetype) ) { |
||
100 | $mimetype = $this->data->$nls->mimetype; |
||
101 | } |
||
102 | if ( !$mimetype ) { |
||
103 | $defaultnls = $this->data->nls->default; |
||
104 | $mimetype = $this->data->{$defaultnls}->mimetype; |
||
105 | } |
||
106 | if ( !$mimetype ) { |
||
107 | $temp = ar_store_files::temp($file); |
||
108 | $temp_file_meta = $temp->getMetaData(); |
||
109 | $mimetype = get_mime_type($temp_file_meta['uri']); |
||
110 | } |
||
111 | |||
112 | if ($mimetype && function_exists("get_content_type")) { |
||
113 | $mimetype = get_content_type($mimetype, basename($this->path)); |
||
114 | } |
||
115 | if (!$ARCurrent->arDontCache && $ARCurrent->cacheCallChainSettings[$this->id]['serverCache'] != -1 && $this->CheckPublic('read')) { |
||
116 | $ARCurrent->cacheCallChainSettings[$this->id]['serverCache'] = -2; |
||
117 | } |
||
118 | $template = $this->getvar("arCallFunction"); |
||
119 | if (!$template || $template == "view.html") { |
||
120 | $filename = basename($this->path); |
||
121 | } |
||
122 | if (!preg_match("|^text/|", $mimetype)) { |
||
123 | $size = $file->size(); |
||
124 | } |
||
125 | |||
126 | if (ldSetContent($mimetype, $size)) { |
||
127 | $cacheseconds=1800; // 1/2 hour |
||
128 | $expires=time()+$cacheseconds; |
||
129 | if (!$ARCurrent->arDontCache) { |
||
130 | if ($AR->user->data->login=="public" || $this->CheckPublic("read")) { |
||
131 | // always set the client side cache headers, independant of |
||
132 | // server side cache configuration. Except for private content |
||
133 | // (needed to prevent proxies from caching it too). If server |
||
134 | // side caching is on, the loader will override this header. |
||
135 | ldSetClientCache(true, $expires); |
||
136 | } |
||
137 | } |
||
138 | } else if(!preg_match("|^text/|", $mimetype)) { |
||
139 | return ar_error::raiseError( sprintf( $ARnls["err:headerssentnottext"], $this->path ), 501 ); |
||
140 | } |
||
141 | if ($filename) { |
||
142 | ldHeader("Content-Disposition: inline; filename=$filename"); |
||
143 | } |
||
144 | if ($mimetype=="text/html") { // parse {arRoot} |
||
145 | // assume html files to use charset UTF-8; this will always work correctly |
||
146 | // with the MSIE html editor, and won't corrupt 'normal' html. |
||
147 | // ldHeader("Content-Type: text/html; charset=UTF-8"); |
||
148 | echo $this->ParseString($file->getContents()); |
||
149 | } else { |
||
150 | // ldHeader("Content-Type: $mimetype"); |
||
151 | // set pragma: cache; bug workaround for internet explorer and https |
||
152 | if (ldGetServerVar('HTTPS')) { |
||
153 | ldHeader('Pragma: cache'); |
||
154 | } |
||
155 | $file->readfile(); |
||
156 | } |
||
157 | $this->popcontext(); |
||
158 | } |
||
159 | |||
160 | function DownloadFile($file='file', $nls='', $filename=false) { |
||
161 | global $ARCurrent, $ARnls; |
||
162 | $this->pushContext( Array( "arCurrentObject" => $this)); |
||
163 | $nls = $this->getNlsForFile($file,$nls); |
||
164 | $file = ar_store_files::get( $file, $nls ); |
||
165 | if ( ar_error::isError($file) ) { |
||
166 | $this->popcontext(); |
||
167 | return $file; |
||
168 | } |
||
169 | if (!$ARCurrent->arDontCache && $ARCurrent->cachetime!=-1 && $this->CheckPublic('read')) { |
||
170 | $ARCurrent->cachetime=-2; // set cache to onchange |
||
171 | } |
||
172 | $size=$file->size(); |
||
173 | if (!$filename) { |
||
174 | $filename = substr($this->path, strlen($this->parent), -1); |
||
175 | } |
||
176 | ldHeader('Cache-Control: private'); |
||
177 | // set pragma: cache; bug workaround for internet explorer and https |
||
178 | if (ldGetServerVar('HTTPS')) { |
||
179 | ldHeader('Pragma: cache'); |
||
180 | } else { |
||
181 | ldHeader('Pragma: no-cache'); |
||
182 | } |
||
183 | if (!ldHeader("Content-type: application/x-ariadne-download")) { |
||
184 | return ar_error::raiseError( sprintf( $ARnls["err:headerssentnottext"], $this->path ), 501 ); |
||
185 | } else { |
||
186 | ldHeader("Content-Disposition: attachment; filename=\"".$filename."\""); |
||
187 | ldHeader("Content-length:".(string)$size); |
||
188 | $file->readfile(); |
||
189 | } |
||
190 | $this->popcontext(); |
||
191 | } |
||
192 | |||
193 | function GetPlainText($file='file', $nls='') { |
||
194 | global $AR; |
||
195 | $result=""; |
||
196 | $this->pushContext( Array( "arCurrentObject" => $this)); |
||
197 | |||
198 | $nls = $this->getNlsForFile($file,$nls); |
||
199 | |||
200 | if ( isset($this->data->$nls->mimetype) ) { |
||
201 | $mimetype = $this->data->$nls->mimetype; |
||
202 | } |
||
203 | if ( !$mimetype ) { |
||
204 | $defaultnls = $this->data->nls->default; |
||
205 | $nls = $defaultnls; |
||
206 | $mimetype = $this->data->{$defaultnls}->mimetype; |
||
207 | } |
||
208 | $file_plaintext = $file."_plaintext"; |
||
209 | |||
210 | if (ar_store_files::exists($file_plaintext,$nls) ) { |
||
211 | $result = ar_store_files::get($file_plaintext)->getContents(); |
||
212 | } else { |
||
213 | if (preg_match("|^text/|i", $mimetype)) { |
||
214 | $result=$this->GetFile($file, $nls); |
||
215 | if ($mimetype=="text/html") { |
||
216 | $result=$this->html_to_text($result); |
||
217 | } |
||
218 | } else if (preg_match("|^application/(.*)$|i", $mimetype, $regs)) { |
||
219 | $textualizer=$AR->Textualizers[$regs[1]]; |
||
220 | if ($textualizer) { |
||
221 | $file = ar_store_files::get($file, $nls); |
||
222 | $temp = ar_store_files::temp($file); |
||
223 | $temp_file_meta = $temp->getMetaData(); |
||
224 | $temp_file = $temp_file_meta['uri']; |
||
225 | exec(preg_replace('/FILE/', $temp_file, $textualizer), $result, $ret); |
||
226 | @unlink($temp_file); |
||
227 | if (!$ret) { |
||
228 | $result = implode("\n", $result); |
||
229 | } else { |
||
230 | $result = ""; |
||
231 | } |
||
232 | } |
||
233 | } |
||
234 | if( $result != "" ) { |
||
235 | ar_store_files::save($file_plaintext,$result,$nls); |
||
236 | } |
||
237 | } |
||
238 | $this->popcontext(); |
||
239 | return $result; |
||
240 | } |
||
241 | |||
242 | function SaveFile($contents, $mimetype=false, $name='file', $nls='') { |
||
0 ignored issues
–
show
|
|||
243 | $result=""; |
||
244 | $name=preg_replace("|[\\\/]|","",$name); // make sure nobody gets /etc/passwd |
||
245 | if ($name) { |
||
246 | if (!$this->arIsNewObject && $this->CheckSilent('edit')) { |
||
247 | $this->pushContext( Array( "arCurrentObject" => $this)); |
||
248 | $ret = ar_store_files::save($name, $contents, $nls); |
||
249 | $this->popcontext(); |
||
250 | return $ret; |
||
251 | } else if ($this->arIsNewObject && $this->CheckSilent('add','pfile')) { |
||
252 | // new pfile, so it has no id yet, use the tempfile |
||
253 | $result = Array(); |
||
254 | |||
255 | // fake an uploaded file, put it in the normal temp dir |
||
256 | $file_artemp=tempnam($this->store->get_config("files")."temp","upload"); |
||
257 | if ($fp=fopen($file_artemp, "wb")) { |
||
258 | $result=fwrite($fp, $contents); |
||
259 | fclose($fp); |
||
260 | } |
||
261 | |||
262 | // now make the new values available to system.save.data.phtml |
||
263 | $info[$name]=$this->data->name; |
||
264 | $info[$name."_temp"]=substr($file_artemp,strlen($this->store->get_config("files")."temp")); |
||
265 | $info[$name."_size"]=strlen($contents); |
||
266 | if (!$mimetype) { |
||
267 | require_once($this->store->get_config('code')."modules/mod_mimemagic.php"); |
||
268 | $type = get_mime_type($file_artemp); |
||
269 | } else { |
||
270 | $type = $mimetype; |
||
271 | } |
||
272 | $info[$name."_type"]=$type; |
||
273 | $info['mimetype']=$type; |
||
274 | $_POST = array_merge($_POST, $info); |
||
275 | |||
276 | return $info; |
||
277 | } |
||
278 | } else { |
||
279 | return false; |
||
280 | } |
||
281 | } |
||
282 | |||
283 | function _ParseString($content) { |
||
284 | return $this->ParseString($content); |
||
285 | } |
||
286 | |||
287 | function _ParseFile($file='file', $nls='') { |
||
288 | return $this->ParseFile($file, $nls); |
||
289 | } |
||
290 | |||
291 | function _ExistsFile($file='file', $nls='') { |
||
292 | return $this->ExistsFile($file, $nls); |
||
293 | } |
||
294 | |||
295 | function _GetFile($file='file', $nls='') { |
||
296 | return $this->GetFile($file, $nls); |
||
297 | } |
||
298 | |||
299 | function _ShowFile($file='file', $nls='', $mimetype='') { |
||
300 | return $this->ShowFile($file, $nls, $mimetype); |
||
301 | } |
||
302 | |||
303 | function _DownloadFile($file='file', $nls='', $filename=false) { |
||
304 | return $this->DownloadFile($file, $nls, $filename); |
||
305 | } |
||
306 | |||
307 | function _GetPlainText($file='file', $nls='') { |
||
308 | return $this->GetPlainText($file, $nls); |
||
309 | } |
||
310 | |||
311 | function _SaveFile($contents, $mimetype=false, $name='file', $nls='') { |
||
312 | return $this->SaveFile($contents, $mimetype, $name, $nls); |
||
313 | } |
||
314 | |||
315 | } // end of pfile class definition |
||
316 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: