~ubuntu-branches/ubuntu/lucid/mahara/lucid-security

« back to all changes in this revision

Viewing changes to htdocs/lib/dwoo/dwoo/plugins/builtin/functions/fetch.php

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2009-11-27 22:09:03 UTC
  • mfrom: (6.3.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091127220903-aiigd3tr46z0rmcg
Tags: 1.2.0-2
Fix postrm script so that Mahara can be uninstalled

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Reads a file
 
5
 * <pre>
 
6
 *  * file : path or URI of the file to read (however reading from another website is not recommended for performance reasons)
 
7
 *  * assign : if set, the file will be saved in this variable instead of being output
 
8
 * </pre>
 
9
 * This software is provided 'as-is', without any express or implied warranty.
 
10
 * In no event will the authors be held liable for any damages arising from the use of this software.
 
11
 *
 
12
 * @author     Jordi Boggiano <j.boggiano@seld.be>
 
13
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 
14
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 
15
 * @link       http://dwoo.org/
 
16
 * @version    1.1.0
 
17
 * @date       2009-07-18
 
18
 * @package    Dwoo
 
19
 */
 
20
function Dwoo_Plugin_fetch(Dwoo $dwoo, $file, $assign = null)
 
21
{
 
22
        if ($file === '') {
 
23
                return;
 
24
        }
 
25
 
 
26
        if ($policy = $dwoo->getSecurityPolicy()) {
 
27
                while (true) {
 
28
                        if (preg_match('{^([a-z]+?)://}i', $file)) {
 
29
                                return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
 
30
                        }
 
31
 
 
32
                        $file = realpath($file);
 
33
                        $dirs = $policy->getAllowedDirectories();
 
34
                        foreach ($dirs as $dir=>$dummy) {
 
35
                                if (strpos($file, $dir) === 0) {
 
36
                                        break 2;
 
37
                                }
 
38
                        }
 
39
                        return $dwoo->triggerError('The security policy prevents you to read <em>'.$file.'</em>', E_USER_WARNING);
 
40
                }
 
41
        }
 
42
        $file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file);
 
43
 
 
44
        $out = file_get_contents($file);
 
45
 
 
46
        if ($assign === null) {
 
47
                return $out;
 
48
        }
 
49
        $dwoo->assignInScope($out, $assign);
 
50
}