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

Last change on this file since 30991 was 30991, checked in by bonhommedeneige, 9 years ago

Updated files for Piwigo 2.7 compatibility

File size: 2.9 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.4.0 (02.01.2015) : Deprecated file, will now use maintain.class.php for plugin maintenance.
29 1.3.0 (05.03.2014) : Renamed deltree function to force_https_deltree to avoid multiple declarations of
30                      function accross multiple plugins. Piwigo 2.6 compatibility
31 1.2.0 (05.05.2013) : No change
32 1.1.0 (04.05.2013) : Added HSTS security settings
33                      Modified default values at initialization (disabled by default)
34 1.0.0 (02.05.2013) : Initial version
35*/
36
37if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
38if (!defined('FORCE_HTTPS_PATH')) define('FORCE_HTTPS_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
39
40function plugin_install()
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
55function plugin_uninstall()
56{
57        if (is_dir(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'piwigo-force-https'))
58        {
59                force_https_deltree(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'piwigo-force-https');
60        }
61        $q = 'DELETE FROM '.CONFIG_TABLE.' WHERE param LIKE "fhp_%" LIMIT 6;';
62        pwg_query( $q );
63}
64
65function plugin_activate()
66{
67        global $conf;
68
69        if (!isset($conf['fhp_use_https']))
70        {
71                plugin_install();
72        }
73}
74
75function force_https_deltree($path)
76{
77        if (is_dir($path))
78        {
79                $fh = opendir($path);
80                while ($file = readdir($fh))
81                {
82                        if ($file != '.' and $file != '..')
83                        {
84                                $pathfile = $path . '/' . $file;
85                                if (is_dir($pathfile))
86                                {
87                                        force_https_deltree($pathfile);
88                                }
89                                else
90                                {
91                                        @unlink($pathfile);
92                                }
93                        }
94                }
95                closedir($fh);
96                return @rmdir($path);
97        }
98}
99?>
Note: See TracBrowser for help on using the repository browser.