1 | <?php |
---|
2 | |
---|
3 | if(!defined('PP_PATH')) |
---|
4 | { |
---|
5 | define('PP_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
6 | } |
---|
7 | |
---|
8 | include_once (PP_PATH.'include/functions.inc.php'); |
---|
9 | |
---|
10 | load_language('plugin.lang', PP_PATH); |
---|
11 | |
---|
12 | |
---|
13 | function plugin_install() |
---|
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', |
---|
34 | 'LOGFAILBLOCK' => 'false', |
---|
35 | 'NBLOGFAIL' => '0', |
---|
36 | 'USRLOCKEDTXT' => l10n('PP_User_Account_Locked_Txt') |
---|
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 = ' |
---|
51 | SELECT param |
---|
52 | FROM '.CONFIG_TABLE.' |
---|
53 | WHERE param = "PasswordPolicy" |
---|
54 | ;'; |
---|
55 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
56 | |
---|
57 | if ($count == 0) |
---|
58 | { |
---|
59 | $q = ' |
---|
60 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
61 | VALUES ("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 = ' |
---|
69 | SHOW COLUMNS FROM '.USERS_TABLE.' |
---|
70 | LIKE "PP_pwdreset" |
---|
71 | ;'; |
---|
72 | |
---|
73 | $result = pwg_query($query); |
---|
74 | |
---|
75 | if(!pwg_db_fetch_row($result)) |
---|
76 | { |
---|
77 | $q = ' |
---|
78 | ALTER TABLE '.USERS_TABLE.' |
---|
79 | ADD 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 = ' |
---|
87 | SHOW COLUMNS FROM '.USERS_TABLE.' |
---|
88 | LIKE "PP_loginfailcount" |
---|
89 | ;'; |
---|
90 | |
---|
91 | $result = pwg_query($query); |
---|
92 | |
---|
93 | if(!pwg_db_fetch_row($result)) |
---|
94 | { |
---|
95 | $q = ' |
---|
96 | ALTER TABLE '.USERS_TABLE.' |
---|
97 | ADD PP_loginfailcount INT NOT NULL DEFAULT "0" |
---|
98 | ;'; |
---|
99 | pwg_query($q); |
---|
100 | } |
---|
101 | |
---|
102 | // Piwigo's native tables modifications for locked accounts |
---|
103 | // -------------------------------------------------------- |
---|
104 | $query = ' |
---|
105 | SHOW COLUMNS FROM '.USERS_TABLE.' |
---|
106 | LIKE "PP_lock" |
---|
107 | ;'; |
---|
108 | |
---|
109 | $result = pwg_query($query); |
---|
110 | |
---|
111 | if(!pwg_db_fetch_row($result)) |
---|
112 | { |
---|
113 | $q = ' |
---|
114 | ALTER TABLE '.USERS_TABLE.' |
---|
115 | ADD PP_lock enum("true","false") |
---|
116 | ;'; |
---|
117 | pwg_query($q); |
---|
118 | } |
---|
119 | /* *************************************************************************** */ |
---|
120 | /* **************** END - Database actions and initialization **************** */ |
---|
121 | /* *************************************************************************** */ |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | function plugin_uninstall() |
---|
126 | { |
---|
127 | global $conf; |
---|
128 | |
---|
129 | if (isset($conf['PasswordPolicy'])) |
---|
130 | { |
---|
131 | $q = ' |
---|
132 | DELETE FROM '.CONFIG_TABLE.' |
---|
133 | WHERE param="PasswordPolicy" |
---|
134 | ;'; |
---|
135 | |
---|
136 | pwg_query($q); |
---|
137 | } |
---|
138 | |
---|
139 | $q = ' |
---|
140 | ALTER TABLE '.USERS_TABLE.' |
---|
141 | DROP PP_pwdreset |
---|
142 | ;'; |
---|
143 | pwg_query($q); |
---|
144 | |
---|
145 | $q = ' |
---|
146 | ALTER TABLE '.USERS_TABLE.' |
---|
147 | DROP PP_loginfailcount |
---|
148 | ;'; |
---|
149 | pwg_query($q); |
---|
150 | |
---|
151 | $q = ' |
---|
152 | ALTER TABLE '.USERS_TABLE.' |
---|
153 | DROP PP_lock |
---|
154 | ;'; |
---|
155 | pwg_query($q); |
---|
156 | } |
---|
157 | ?> |
---|