source: extensions/Force_HTTPS/maintain.inc.php @ 30249

Last change on this file since 30249 was 27560, checked in by bonhommedeneige, 11 years ago

Version 1.3.0 - Piwigo 2.6 compatibility

File size: 2.8 KB
Line 
1<?php
2/***********************************************
3* File      :   maintain.inc.php
4* Project   :   piwigo-force-https
5* Descr     :   Install / Uninstall method
6*
7* Created   :   02.05.2013
8* Updated   :   05.03.2014
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/**
27Changelog :
28 1.3.0 (05.03.2014) : Renamed deltree function to force_https_deltree to avoid multiple declarations of
29                      function accross multiple plugins. Piwigo 2.6 compatibility
30 1.2.0 (05.05.2013) : No change
31 1.1.0 (04.05.2013) : Added HSTS security settings
32                      Modified default values at initialization (disabled by default)
33 1.0.0 (02.05.2013) : Initial version
34*/
35
36if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
37if (!defined('FORCE_HTTPS_PATH')) define('FORCE_HTTPS_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
38
39function plugin_install()
40{
41        $q = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
42                VALUES ("fhp_use_https", "false", "https usage status tag used by the piwigo-force-https plugin");';
43        pwg_query( $q );
44       
45        $q = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
46                VALUES ("fhp_use_sts", "false", "HTTP Strict Transport Security (HSTS) usage status tag used by the piwigo-force-https plugin");';
47        pwg_query( $q );
48       
49        $q = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
50                VALUES ("fhp_sts_maxage", "500", "max age duration (in seconds) used by the piwigo-force-https plugin");';
51        pwg_query( $q );
52}
53
54function plugin_uninstall()
55{
56        if (is_dir(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'piwigo-force-https'))
57        {
58                force_https_deltree(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'piwigo-force-https');
59        }
60        $q = 'DELETE FROM '.CONFIG_TABLE.' WHERE param LIKE "fhp_%" LIMIT 6;';
61        pwg_query( $q );
62}
63
64function plugin_activate()
65{
66        global $conf;
67
68        if (!isset($conf['fhp_use_https']))
69        {
70                plugin_install();
71        }
72}
73
74function force_https_deltree($path)
75{
76        if (is_dir($path))
77        {
78                $fh = opendir($path);
79                while ($file = readdir($fh))
80                {
81                        if ($file != '.' and $file != '..')
82                        {
83                                $pathfile = $path . '/' . $file;
84                                if (is_dir($pathfile))
85                                {
86                                        force_https_deltree($pathfile);
87                                }
88                                else
89                                {
90                                        @unlink($pathfile);
91                                }
92                        }
93                }
94                closedir($fh);
95                return @rmdir($path);
96        }
97}
98?>
Note: See TracBrowser for help on using the repository browser.