source: extensions/Password_Policy/maintain.inc.php @ 31835

Last change on this file since 31835 was 29339, checked in by Eric, 10 years ago

Next version will be 2.7.0 : Compatibility with Piwigo 2.7

File size: 4.0 KB
RevLine 
[25028]1<?php
2
3if(!defined('PP_PATH'))
4{
5  define('PP_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
6}
7
8include_once (PP_PATH.'include/functions.inc.php');
9
10load_language('plugin.lang', PP_PATH);
11
12
[29339]13function plugin_install($id, $version, &$errors)
[25028]14{
15        global $conf;
16
17  // Set current plugin version in config table
18  // ------------------------------------------
19  $plugin =  PPInfos(PP_PATH);
20  $version = $plugin['version'];
21
22/* ****************************************************************** */
23/* **************** BEGIN - Data preparation in vars **************** */
24/* ****************************************************************** */
25
26  // Default global parameters for PasswordPolicy conf
27  // -------------------------------------------------
28  $defaultPP = array(
29    'PPVersion'                   => $version, // PasswordPolicy History version
30    'PASSWORDENF'                 => 'false',
31    'PASSWORD_SCORE'              => '100',
32    'ADMINPASSWENF'               => 'false',
33    'PWDRESET'                    => 'false',
[25089]34    'LOGFAILBLOCK'                => 'false',
[25028]35    'NBLOGFAIL'                   => '0',
[25089]36    'USRLOCKEDTXT'                => l10n('PP_User_Account_Locked_Txt')
[25028]37  );
38
39/* **************************************************************** */
40/* **************** END - Data preparation in vars **************** */
41/* **************************************************************** */
42
43
44/* ***************************************************************************** */
45/* **************** BEGIN - Database actions and initialization **************** */
46/* ***************************************************************************** */
47
48  // Create PasswordPolicy conf if not already exists
49  // ------------------------------------------------
50        $query = '
51SELECT param
52  FROM '.CONFIG_TABLE.'
53WHERE param = "PasswordPolicy"
54;';
55  $count = pwg_db_num_rows(pwg_query($query));
56 
57  if ($count == 0)
58  {
59    $q = '
60INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
61VALUES ("PasswordPolicy","'.pwg_db_real_escape_string(serialize($defaultPP)).'","Password Policy parameters")
62  ;';
63    pwg_query($q);
64  }
65
66  // Piwigo's native tables modifications for password reset function - Add pwdreset column if not already exists
67  // ------------------------------------------------------------------------------------------------------------
68  $query = '
69SHOW COLUMNS FROM '.USERS_TABLE.'
70LIKE "PP_pwdreset"
71;';
72 
73  $result = pwg_query($query);
74
75  if(!pwg_db_fetch_row($result))
76  {
77    $q = '
78ALTER TABLE '.USERS_TABLE.'
79ADD PP_pwdreset enum("true","false")
80;';
81    pwg_query($q);
82  }
83
84  // Piwigo's native tables modifications for failed login attempts count
85  // --------------------------------------------------------------------
86  $query = '
87SHOW COLUMNS FROM '.USERS_TABLE.'
88LIKE "PP_loginfailcount"
89;';
90 
91  $result = pwg_query($query);
92
93  if(!pwg_db_fetch_row($result))
94  {
95    $q = '
96ALTER TABLE '.USERS_TABLE.'
[25089]97ADD PP_loginfailcount INT NOT NULL DEFAULT "0"
[25028]98;';
99    pwg_query($q);
100  }
101
102  // Piwigo's native tables modifications for locked accounts
103  // --------------------------------------------------------
104  $query = '
105SHOW COLUMNS FROM '.USERS_TABLE.'
106LIKE "PP_lock"
107;';
108 
109  $result = pwg_query($query);
110
111  if(!pwg_db_fetch_row($result))
112  {
113    $q = '
114ALTER TABLE '.USERS_TABLE.'
115ADD PP_lock enum("true","false")
116;';
117    pwg_query($q);
118  }
119/* *************************************************************************** */
120/* **************** END - Database actions and initialization **************** */
121/* *************************************************************************** */
122}
123
124
[29339]125function plugin_uninstall($id, $version, &$errors)
[25028]126{
127  global $conf;
128
129  if (isset($conf['PasswordPolicy']))
130  {
131    $q = '
132DELETE FROM '.CONFIG_TABLE.'
133WHERE param="PasswordPolicy"
134;';
135
136    pwg_query($q);
137  }
138
139  $q = '
140ALTER TABLE '.USERS_TABLE.'
141DROP PP_pwdreset
142;';
143  pwg_query($q);
144
145  $q = '
146ALTER TABLE '.USERS_TABLE.'
147DROP PP_loginfailcount
148;';
149  pwg_query($q);
150
151  $q = '
152ALTER TABLE '.USERS_TABLE.'
153DROP PP_lock
154;';
155  pwg_query($q);
156}
157?>
Note: See TracBrowser for help on using the repository browser.