1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : maintain.class.php |
---|
4 | * Project : piwigo-force-https |
---|
5 | * Descr : Plugin maintenance methods |
---|
6 | * |
---|
7 | * Created : 02.01.2015 |
---|
8 | * Updated : |
---|
9 | * Author : bonhommedeneige |
---|
10 | * |
---|
11 | * This program is free software: you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU General Public License as published by |
---|
13 | * the Free Software Foundation, either version 3 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * This program is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU General Public License |
---|
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | ************************************************/ |
---|
25 | |
---|
26 | /** |
---|
27 | Changelog : |
---|
28 | 1.4.0 (02.01.2015) : New maintenance class (compatibility with Piwigo 2.7.x) |
---|
29 | */ |
---|
30 | |
---|
31 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
32 | if (!defined('FORCE_HTTPS_PATH')) define('FORCE_HTTPS_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
33 | |
---|
34 | class Force_HTTPS_maintain extends PluginMaintain { |
---|
35 | /** |
---|
36 | * |
---|
37 | * @param unknown $plugin_version |
---|
38 | * @param unknown $errors |
---|
39 | */ |
---|
40 | function install($plugin_version, &$errors=array()) |
---|
41 | { |
---|
42 | $q = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) |
---|
43 | VALUES ("fhp_use_https", "false", "https usage status tag used by the piwigo-force-https plugin");'; |
---|
44 | pwg_query( $q ); |
---|
45 | |
---|
46 | $q = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) |
---|
47 | VALUES ("fhp_use_sts", "false", "HTTP Strict Transport Security (HSTS) usage status tag used by the piwigo-force-https plugin");'; |
---|
48 | pwg_query( $q ); |
---|
49 | |
---|
50 | $q = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) |
---|
51 | VALUES ("fhp_sts_maxage", "500", "max age duration (in seconds) used by the piwigo-force-https plugin");'; |
---|
52 | pwg_query( $q ); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * |
---|
57 | */ |
---|
58 | function uninstall() |
---|
59 | { |
---|
60 | if (is_dir(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'piwigo-force-https')) |
---|
61 | { |
---|
62 | $this->force_https_deltree(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'piwigo-force-https'); |
---|
63 | } |
---|
64 | $q = 'DELETE FROM '.CONFIG_TABLE.' WHERE param LIKE "fhp_%" LIMIT 6;'; |
---|
65 | pwg_query( $q ); |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * |
---|
70 | */ |
---|
71 | function deactivate() { |
---|
72 | |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * |
---|
77 | * @param unknown $plugin_version |
---|
78 | * @param unknown $errors |
---|
79 | */ |
---|
80 | function activate($plugin_version, &$errors=array()) |
---|
81 | { |
---|
82 | global $conf; |
---|
83 | |
---|
84 | if (!isset($conf['fhp_use_https'])) |
---|
85 | { |
---|
86 | plugin_install(); |
---|
87 | $this->install($plugin_version); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * |
---|
93 | * @param unknown $plugin_version |
---|
94 | * @param unknown $errors |
---|
95 | */ |
---|
96 | function update($old_version, $new_version, &$errors=array()) { |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | * |
---|
101 | * @param unknown $path |
---|
102 | */ |
---|
103 | private function force_https_deltree($path) |
---|
104 | { |
---|
105 | if (is_dir($path)) |
---|
106 | { |
---|
107 | $fh = opendir($path); |
---|
108 | while ($file = readdir($fh)) |
---|
109 | { |
---|
110 | if ($file != '.' and $file != '..') |
---|
111 | { |
---|
112 | $pathfile = $path . '/' . $file; |
---|
113 | if (is_dir($pathfile)) |
---|
114 | { |
---|
115 | force_https_deltree($pathfile); |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | @unlink($pathfile); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | closedir($fh); |
---|
124 | return @rmdir($path); |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | ?> |
---|