|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2018 Justin Kuenzel (jukusoft.com) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Project: JuKuCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 22.04.2018 |
|
25
|
|
|
* Time: 11:51 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
class FilePermissionsInstaller extends PluginInstaller_Plugin { |
|
29
|
|
|
|
|
30
|
|
|
public function install(Plugin $plugin, array $install_json): bool { |
|
31
|
|
|
if (isset($install_json['chmod'])) { |
|
32
|
|
|
$files = $install_json['chmod']; |
|
33
|
|
|
|
|
34
|
|
|
foreach ($files as $file=>$chmod_value) { |
|
35
|
|
|
if (strpos($file, "..") !== FALSE) { |
|
36
|
|
|
throw new IllegalArgumentException("Its not allowed that chmod file path in install.json of plugin '" . $plugin->getName() . "' contains '..' in path."); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$file_path = ROOT_PATH . $file; |
|
40
|
|
|
|
|
41
|
|
|
if (!file_exists($file_path)) { |
|
42
|
|
|
//create directory |
|
43
|
|
|
throw new IllegalStateException("directory '" . htmlentities($file_path) . "' doesnt exists."); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (strlen($chmod_value) != 3) { |
|
47
|
|
|
throw new IllegalArgumentException("Exception in install.json of plugin '" . $plugin->getName() . "': chmod value has to be a length of 3 characters (like 755)."); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$chmod_value = "0" . $chmod_value; |
|
51
|
|
|
|
|
52
|
|
|
if(!chmod($file_path, $chmod_value)) { |
|
|
|
|
|
|
53
|
|
|
throw new IllegalStateException("Cannot change file permissions of directory '". $file_path . "' (plugin: " . $plugin->getName() . "."); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function uninstall(Plugin $plugin, array $install_json): bool { |
|
60
|
|
|
//dont do anything |
|
61
|
|
|
return true; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function upgrade(Plugin $plugin, array $install_json): bool { |
|
65
|
|
|
return $this->install($plugin, $install_json); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
?> |
|
|
|
|
|
|
70
|
|
|
|