]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | /** | |
3 | * Shaarli (application) utilities | |
4 | */ | |
5 | class ApplicationUtils | |
6 | { | |
7 | ||
8 | /** | |
9 | * Checks Shaarli has the proper access permissions to its resources | |
10 | * | |
11 | * @param array $globalConfig The $GLOBALS['config'] array | |
12 | * | |
13 | * @return array A list of the detected configuration issues | |
14 | */ | |
15 | public static function checkResourcePermissions($globalConfig) | |
16 | { | |
17 | $errors = array(); | |
18 | ||
19 | // Check script and template directories are readable | |
20 | foreach (array( | |
21 | 'application', | |
22 | 'inc', | |
23 | 'plugins', | |
24 | $globalConfig['RAINTPL_TPL'] | |
25 | ) as $path) { | |
26 | if (! is_readable(realpath($path))) { | |
27 | $errors[] = '"'.$path.'" directory is not readable'; | |
28 | } | |
29 | } | |
30 | ||
31 | // Check cache and data directories are readable and writeable | |
32 | foreach (array( | |
33 | $globalConfig['CACHEDIR'], | |
34 | $globalConfig['DATADIR'], | |
35 | $globalConfig['PAGECACHE'], | |
36 | $globalConfig['RAINTPL_TMP'] | |
37 | ) as $path) { | |
38 | if (! is_readable(realpath($path))) { | |
39 | $errors[] = '"'.$path.'" directory is not readable'; | |
40 | } | |
41 | if (! is_writable(realpath($path))) { | |
42 | $errors[] = '"'.$path.'" directory is not writable'; | |
43 | } | |
44 | } | |
45 | ||
46 | // Check configuration files are readable and writeable | |
47 | foreach (array( | |
48 | $globalConfig['CONFIG_FILE'], | |
49 | $globalConfig['DATASTORE'], | |
50 | $globalConfig['IPBANS_FILENAME'], | |
51 | $globalConfig['LOG_FILE'], | |
52 | $globalConfig['UPDATECHECK_FILENAME'] | |
53 | ) as $path) { | |
54 | if (! is_file(realpath($path))) { | |
55 | # the file may not exist yet | |
56 | continue; | |
57 | } | |
58 | ||
59 | if (! is_readable(realpath($path))) { | |
60 | $errors[] = '"'.$path.'" file is not readable'; | |
61 | } | |
62 | if (! is_writable(realpath($path))) { | |
63 | $errors[] = '"'.$path.'" file is not writable'; | |
64 | } | |
65 | } | |
66 | ||
67 | return $errors; | |
68 | } | |
69 | } |