]>
Commit | Line | Data |
---|---|---|
2e28269b V |
1 | <?php |
2 | /** | |
3 | * Shaarli (application) utilities | |
4 | */ | |
5 | class ApplicationUtils | |
6 | { | |
7 | ||
c9cf2715 V |
8 | /** |
9 | * Checks the PHP version to ensure Shaarli can run | |
10 | * | |
11 | * @param string $minVersion minimum PHP required version | |
12 | * @param string $curVersion current PHP version (use PHP_VERSION) | |
13 | * | |
14 | * @throws Exception the PHP version is not supported | |
15 | */ | |
16 | public static function checkPHPVersion($minVersion, $curVersion) | |
17 | { | |
18 | if (version_compare($curVersion, $minVersion) < 0) { | |
19 | throw new Exception( | |
20 | 'Your PHP version is obsolete!' | |
21 | .' Shaarli requires at least PHP '.$minVersion.', and thus cannot run.' | |
22 | .' Your PHP version has known security vulnerabilities and should be' | |
23 | .' updated as soon as possible.' | |
24 | ); | |
25 | } | |
26 | } | |
27 | ||
2e28269b V |
28 | /** |
29 | * Checks Shaarli has the proper access permissions to its resources | |
30 | * | |
31 | * @param array $globalConfig The $GLOBALS['config'] array | |
32 | * | |
33 | * @return array A list of the detected configuration issues | |
34 | */ | |
35 | public static function checkResourcePermissions($globalConfig) | |
36 | { | |
37 | $errors = array(); | |
38 | ||
39 | // Check script and template directories are readable | |
40 | foreach (array( | |
41 | 'application', | |
42 | 'inc', | |
43 | 'plugins', | |
44 | $globalConfig['RAINTPL_TPL'] | |
45 | ) as $path) { | |
46 | if (! is_readable(realpath($path))) { | |
47 | $errors[] = '"'.$path.'" directory is not readable'; | |
48 | } | |
49 | } | |
50 | ||
51 | // Check cache and data directories are readable and writeable | |
52 | foreach (array( | |
53 | $globalConfig['CACHEDIR'], | |
54 | $globalConfig['DATADIR'], | |
55 | $globalConfig['PAGECACHE'], | |
56 | $globalConfig['RAINTPL_TMP'] | |
57 | ) as $path) { | |
58 | if (! is_readable(realpath($path))) { | |
59 | $errors[] = '"'.$path.'" directory is not readable'; | |
60 | } | |
61 | if (! is_writable(realpath($path))) { | |
62 | $errors[] = '"'.$path.'" directory is not writable'; | |
63 | } | |
64 | } | |
65 | ||
66 | // Check configuration files are readable and writeable | |
67 | foreach (array( | |
68 | $globalConfig['CONFIG_FILE'], | |
69 | $globalConfig['DATASTORE'], | |
70 | $globalConfig['IPBANS_FILENAME'], | |
71 | $globalConfig['LOG_FILE'], | |
72 | $globalConfig['UPDATECHECK_FILENAME'] | |
73 | ) as $path) { | |
74 | if (! is_file(realpath($path))) { | |
75 | # the file may not exist yet | |
76 | continue; | |
77 | } | |
78 | ||
79 | if (! is_readable(realpath($path))) { | |
80 | $errors[] = '"'.$path.'" file is not readable'; | |
81 | } | |
82 | if (! is_writable(realpath($path))) { | |
83 | $errors[] = '"'.$path.'" file is not writable'; | |
84 | } | |
85 | } | |
86 | ||
87 | return $errors; | |
88 | } | |
89 | } |