1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | class c13y_internal |
---|
25 | { |
---|
26 | function c13y_internal() |
---|
27 | { |
---|
28 | add_event_handler('list_check_integrity', array(&$this, 'c13y_version')); |
---|
29 | add_event_handler('list_check_integrity', array(&$this, 'c13y_exif')); |
---|
30 | add_event_handler('list_check_integrity', array(&$this, 'c13y_user')); |
---|
31 | } |
---|
32 | |
---|
33 | /** |
---|
34 | * Check version |
---|
35 | * |
---|
36 | * @param c13y object |
---|
37 | * @return void |
---|
38 | */ |
---|
39 | function c13y_version($c13y) |
---|
40 | { |
---|
41 | global $conf; |
---|
42 | |
---|
43 | $check_list = array(); |
---|
44 | |
---|
45 | $check_list[] = array('type' => 'PHP', 'current' => phpversion(), 'required' => REQUIRED_PHP_VERSION); |
---|
46 | |
---|
47 | $db_version = pwg_get_db_version(); |
---|
48 | $check_list[] = array('type' => $conf['dblayer'], |
---|
49 | 'current' => $db_version, |
---|
50 | 'required' => constant('REQUIRED_'.str_replace('-', '_', strtoupper($conf['dblayer'])).'_VERSION') |
---|
51 | ); |
---|
52 | |
---|
53 | foreach ($check_list as $elem) |
---|
54 | { |
---|
55 | if (version_compare($elem['current'], $elem['required'], '<')) |
---|
56 | { |
---|
57 | $c13y->add_anomaly( |
---|
58 | sprintf(l10n('The version of %s [%s] installed is not compatible with the version required [%s]'), $elem['type'], $elem['current'], $elem['required']), |
---|
59 | null, |
---|
60 | null, |
---|
61 | l10n('You need to upgrade your system to take full advantage of the application else the application will not work correctly, or not at all') |
---|
62 | .'<br>'. |
---|
63 | $c13y->get_htlm_links_more_info()); |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * Check exif |
---|
70 | * |
---|
71 | * @param c13y object |
---|
72 | * @return void |
---|
73 | */ |
---|
74 | function c13y_exif($c13y) |
---|
75 | { |
---|
76 | global $conf; |
---|
77 | |
---|
78 | foreach (array('show_exif', 'use_exif') as $value) |
---|
79 | { |
---|
80 | if (($conf[$value]) and (!function_exists('read_exif_data'))) |
---|
81 | { |
---|
82 | $c13y->add_anomaly( |
---|
83 | sprintf(l10n('%s value is not correct file because exif are not supported'), '$conf[\''.$value.'\']'), |
---|
84 | null, |
---|
85 | null, |
---|
86 | sprintf(l10n('%s must be to set to false in your local/config/config.inc.php file'), '$conf[\''.$value.'\']') |
---|
87 | .'<br>'. |
---|
88 | $c13y->get_htlm_links_more_info()); |
---|
89 | } |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * Check user |
---|
95 | * |
---|
96 | * @param c13y object |
---|
97 | * @return void |
---|
98 | */ |
---|
99 | function c13y_user($c13y) |
---|
100 | { |
---|
101 | global $conf; |
---|
102 | |
---|
103 | $c13y_users = array(); |
---|
104 | $c13y_users[$conf['guest_id']] = array( |
---|
105 | 'status' => 'guest', |
---|
106 | 'l10n_non_existent' => 'Main "guest" user does not exist', |
---|
107 | 'l10n_bad_status' => 'Main "guest" user status is incorrect'); |
---|
108 | |
---|
109 | if ($conf['guest_id'] != $conf['default_user_id']) |
---|
110 | { |
---|
111 | $c13y_users[$conf['default_user_id']] = array( |
---|
112 | 'password' => null, |
---|
113 | 'l10n_non_existent' => 'Default user does not exist'); |
---|
114 | } |
---|
115 | |
---|
116 | $c13y_users[$conf['webmaster_id']] = array( |
---|
117 | 'status' => 'webmaster', |
---|
118 | 'l10n_non_existent' => 'Main "webmaster" user does not exist', |
---|
119 | 'l10n_bad_status' => 'Main "webmaster" user status is incorrect'); |
---|
120 | |
---|
121 | $query = ' |
---|
122 | select u.'.$conf['user_fields']['id'].' as id, ui.status |
---|
123 | from '.USERS_TABLE.' as u |
---|
124 | left join '.USER_INFOS_TABLE.' as ui |
---|
125 | on u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
126 | where |
---|
127 | u.'.$conf['user_fields']['id'].' in ('.implode(',', array_keys($c13y_users)).') |
---|
128 | ;'; |
---|
129 | |
---|
130 | |
---|
131 | $status = array(); |
---|
132 | |
---|
133 | $result = pwg_query($query); |
---|
134 | while ($row = pwg_db_fetch_assoc($result)) |
---|
135 | { |
---|
136 | $status[$row['id']] = $row['status']; |
---|
137 | } |
---|
138 | |
---|
139 | foreach ($c13y_users as $id => $data) |
---|
140 | { |
---|
141 | if (!array_key_exists($id, $status)) |
---|
142 | { |
---|
143 | $c13y->add_anomaly(l10n($data['l10n_non_existent']), 'c13y_correction_user', |
---|
144 | array('id' => $id, 'action' => 'creation')); |
---|
145 | } |
---|
146 | else |
---|
147 | if (!empty($data['status']) and $status[$id] != $data['status']) |
---|
148 | { |
---|
149 | $c13y->add_anomaly(l10n($data['l10n_bad_status']), 'c13y_correction_user', |
---|
150 | array('id' => $id, 'action' => 'status')); |
---|
151 | } |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * Do correction user |
---|
157 | * |
---|
158 | * @param user_id, action |
---|
159 | * @return boolean true if ok else false |
---|
160 | */ |
---|
161 | function c13y_correction_user($id, $action) |
---|
162 | { |
---|
163 | global $conf, $page; |
---|
164 | |
---|
165 | $result = false; |
---|
166 | |
---|
167 | if (!empty($id)) |
---|
168 | { |
---|
169 | switch ($action) |
---|
170 | { |
---|
171 | case 'creation': |
---|
172 | if ($id == $conf['guest_id']) |
---|
173 | { |
---|
174 | $name = 'guest'; |
---|
175 | $password = null; |
---|
176 | } |
---|
177 | else if ($id == $conf['default_user_id']) |
---|
178 | { |
---|
179 | $name = 'guest'; |
---|
180 | $password = null; |
---|
181 | } |
---|
182 | else if ($id == $conf['webmaster_id']) |
---|
183 | { |
---|
184 | $name = 'webmaster'; |
---|
185 | $password = generate_key(6); |
---|
186 | } |
---|
187 | |
---|
188 | if (isset($name)) |
---|
189 | { |
---|
190 | $name_ok = false; |
---|
191 | while (!$name_ok) |
---|
192 | { |
---|
193 | $name_ok = (get_userid($name) === false); |
---|
194 | if (!$name_ok) |
---|
195 | { |
---|
196 | $name .= generate_key(1); |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | $inserts = array( |
---|
201 | array( |
---|
202 | 'id' => $id, |
---|
203 | 'username' => addslashes($name), |
---|
204 | 'password' => $password |
---|
205 | ), |
---|
206 | ); |
---|
207 | mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts); |
---|
208 | |
---|
209 | create_user_infos($id); |
---|
210 | |
---|
211 | $page['infos'][] = sprintf(l10n('User "%s" created with "%s" like password'), $name, $password); |
---|
212 | |
---|
213 | $result = true; |
---|
214 | } |
---|
215 | break; |
---|
216 | case 'status': |
---|
217 | if ($id == $conf['guest_id']) |
---|
218 | { |
---|
219 | $status = 'guest'; |
---|
220 | } |
---|
221 | else if ($id == $conf['default_user_id']) |
---|
222 | { |
---|
223 | $status = 'guest'; |
---|
224 | } |
---|
225 | else if ($id == $conf['webmaster_id']) |
---|
226 | { |
---|
227 | $status = 'webmaster'; |
---|
228 | } |
---|
229 | |
---|
230 | if (isset($status)) |
---|
231 | { |
---|
232 | $updates = array( |
---|
233 | array( |
---|
234 | 'user_id' => $id, |
---|
235 | 'status' => $status |
---|
236 | ), |
---|
237 | ); |
---|
238 | mass_updates(USER_INFOS_TABLE, |
---|
239 | array('primary' => array('user_id'),'update' => array('status')), |
---|
240 | $updates); |
---|
241 | |
---|
242 | $page['infos'][] = sprintf(l10n('Status of user "%s" updated'), get_username($id)); |
---|
243 | |
---|
244 | $result = true; |
---|
245 | } |
---|
246 | break; |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | return $result; |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | ?> |
---|