@@ -18,42 +18,42 @@ discard block |
||
18 | 18 | global $k; |
19 | 19 | //ENGLISH |
20 | 20 | $english_vals = array( |
21 | - array('at_modification',"Modification"), |
|
22 | - array('at_creation',"Creation"), |
|
23 | - array('at_delete',"Deletion"), |
|
24 | - array('at_pw',"Password changed."), |
|
25 | - array('at_category',"Group"), |
|
26 | - array('at_personnel',"Personnal"), |
|
27 | - array('at_description',"Description"), |
|
28 | - array('at_url',"Url"), |
|
29 | - array('at_login',"Login"), |
|
30 | - array('at_label',"Label") |
|
21 | + array('at_modification', "Modification"), |
|
22 | + array('at_creation', "Creation"), |
|
23 | + array('at_delete', "Deletion"), |
|
24 | + array('at_pw', "Password changed."), |
|
25 | + array('at_category', "Group"), |
|
26 | + array('at_personnel', "Personnal"), |
|
27 | + array('at_description', "Description"), |
|
28 | + array('at_url', "Url"), |
|
29 | + array('at_login', "Login"), |
|
30 | + array('at_label', "Label") |
|
31 | 31 | ); |
32 | 32 | //FRENCH |
33 | 33 | $french_vals = array( |
34 | - array('at_modification',"Modification"), |
|
35 | - array('at_creation',"Création"), |
|
36 | - array('at_delete',"Suppression"), |
|
37 | - array('at_pw',"Mot de passe changé."), |
|
38 | - array('at_category',"Group"), |
|
39 | - array('at_personnel',"Personnel"), |
|
40 | - array('at_description',"Description."), |
|
41 | - array('at_url',"Url"), |
|
42 | - array('at_login',"Login"), |
|
43 | - array('at_label',"Label") |
|
34 | + array('at_modification', "Modification"), |
|
35 | + array('at_creation', "Création"), |
|
36 | + array('at_delete', "Suppression"), |
|
37 | + array('at_pw', "Mot de passe changé."), |
|
38 | + array('at_category', "Group"), |
|
39 | + array('at_personnel', "Personnel"), |
|
40 | + array('at_description', "Description."), |
|
41 | + array('at_url', "Url"), |
|
42 | + array('at_login', "Login"), |
|
43 | + array('at_label', "Label") |
|
44 | 44 | ); |
45 | 45 | //SPANISH |
46 | 46 | $spanish_vals = array( |
47 | - array('at_modification',"Modificacion"), |
|
48 | - array('at_creation',"Creacion"), |
|
49 | - array('at_delete',"Borrado"), |
|
50 | - array('at_pw',"Contraseéa cambiada."), |
|
51 | - array('at_category',"Grupo"), |
|
52 | - array('at_personnel',"Personal"), |
|
53 | - array('at_description',"Descripcion."), |
|
54 | - array('at_url',"Url"), |
|
55 | - array('at_login',"Login"), |
|
56 | - array('at_label',"Etiqueta") |
|
47 | + array('at_modification', "Modificacion"), |
|
48 | + array('at_creation', "Creacion"), |
|
49 | + array('at_delete', "Borrado"), |
|
50 | + array('at_pw', "Contraseéa cambiada."), |
|
51 | + array('at_category', "Grupo"), |
|
52 | + array('at_personnel', "Personal"), |
|
53 | + array('at_description', "Descripcion."), |
|
54 | + array('at_url', "Url"), |
|
55 | + array('at_login', "Login"), |
|
56 | + array('at_label', "Etiqueta") |
|
57 | 57 | ); |
58 | 58 | |
59 | 59 | changeDB(); |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data['action']."'"); |
80 | 80 | $found = true; |
81 | 81 | } else |
82 | - if ($lang[1] == trim(substr($data['raison'],0,strpos($data['raison'],":"))) && !empty($data['raison'])) { |
|
83 | - $data1= mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['pre']."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'")); |
|
84 | - mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]." ".substr($data['raison'],strpos($data['raison'],":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'"); |
|
82 | + if ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) { |
|
83 | + $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['pre']."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'")); |
|
84 | + mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]." ".substr($data['raison'], strpos($data['raison'], ":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'"); |
|
85 | 85 | $found = true; |
86 | 86 | } |
87 | 87 | } |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data['action']."'"); |
99 | 99 | $found = true; |
100 | 100 | } else |
101 | - if ($lang[1] == trim(substr($data['raison'],0,strpos($data['raison'],":"))) && !empty($data['raison'])) { |
|
102 | - $data1= mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['pre']."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'")); |
|
103 | - mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]." ".substr($data['raison'],strpos($data['raison'],":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'"); |
|
101 | + if ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) { |
|
102 | + $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['pre']."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'")); |
|
103 | + mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]." ".substr($data['raison'], strpos($data['raison'], ":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'"); |
|
104 | 104 | $found = true; |
105 | 105 | } |
106 | 106 | } |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data['action']."'"); |
118 | 118 | $found = true; |
119 | 119 | } else |
120 | - if ($lang[1] == trim(substr($data['raison'],0,strpos($data['raison'],":"))) && !empty($data['raison'])) { |
|
121 | - $data1= mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['pre']."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'")); |
|
122 | - mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]." ".substr($data['raison'],strpos($data['raison'],":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'"); |
|
120 | + if ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) { |
|
121 | + $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['pre']."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'")); |
|
122 | + mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]." ".substr($data['raison'], strpos($data['raison'], ":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'"); |
|
123 | 123 | $found = true; |
124 | 124 | } |
125 | 125 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | function getSettingValue($val) |
41 | 41 | { |
42 | 42 | $val = trim(strstr($val, "=")); |
43 | - return trim(str_replace('"', '', substr($val, 1, strpos($val, ";")-1))); |
|
43 | + return trim(str_replace('"', '', substr($val, 1, strpos($val, ";") - 1))); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | ################ |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | global $dbTmp; |
52 | 52 | $exists = false; |
53 | 53 | $columns = mysqli_query($dbTmp, "show columns from $db"); |
54 | - while ($c = mysqli_fetch_assoc( $columns)) { |
|
54 | + while ($c = mysqli_fetch_assoc($columns)) { |
|
55 | 55 | if ($c['Field'] == $column) { |
56 | 56 | $exists = true; |
57 | 57 | return true; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | -function addIndexIfNotExist($table, $index, $sql ) { |
|
67 | +function addIndexIfNotExist($table, $index, $sql) { |
|
68 | 68 | global $dbTmp; |
69 | 69 | |
70 | 70 | $mysqli_result = mysqli_query($dbTmp, "SHOW INDEX FROM $table WHERE key_name LIKE \"$index\""); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | // if index does not exist, then add it |
74 | 74 | if (!$res) { |
75 | - $res = mysqli_query($dbTmp, "ALTER TABLE `$table` " . $sql); |
|
75 | + $res = mysqli_query($dbTmp, "ALTER TABLE `$table` ".$sql); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return $res; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | // if yes, then don't execute re-encryption |
129 | 129 | $_SESSION['tp_defuse_installed'] = false; |
130 | 130 | $columns = mysqli_query($dbTmp, "show columns from ".$_SESSION['pre']."items"); |
131 | -while ($c = mysqli_fetch_assoc( $columns)) { |
|
131 | +while ($c = mysqli_fetch_assoc($columns)) { |
|
132 | 132 | if ($c['Field'] === "encryption_type") { |
133 | 133 | $_SESSION['tp_defuse_installed'] = true; |
134 | 134 | } |
@@ -137,49 +137,49 @@ discard block |
||
137 | 137 | |
138 | 138 | ## Populate table MISC |
139 | 139 | $val = array( |
140 | - array('admin', 'max_latest_items', '10',0), |
|
141 | - array('admin', 'enable_favourites', '1',0), |
|
142 | - array('admin', 'show_last_items', '1',0), |
|
143 | - array('admin', 'enable_pf_feature', '0',0), |
|
144 | - array('admin', 'menu_type', 'context',0), |
|
145 | - array('admin', 'log_connections', '0',0), |
|
146 | - array('admin', 'time_format', 'H:i:s',0), |
|
147 | - array('admin', 'date_format', 'd/m/Y',0), |
|
148 | - array('admin', 'duplicate_folder', '0',0), |
|
149 | - array('admin', 'duplicate_item', '0',0), |
|
150 | - array('admin', 'item_duplicate_in_same_folder', '0',0), |
|
151 | - array('admin', 'number_of_used_pw', '3',0), |
|
152 | - array('admin', 'manager_edit', '1',0), |
|
153 | - array('admin', 'cpassman_dir', '',0), |
|
154 | - array('admin', 'cpassman_url', '',0), |
|
155 | - array('admin', 'favicon', '',0), |
|
156 | - array('admin', 'activate_expiration', '0',0), |
|
157 | - array('admin', 'pw_life_duration','30',0), |
|
140 | + array('admin', 'max_latest_items', '10', 0), |
|
141 | + array('admin', 'enable_favourites', '1', 0), |
|
142 | + array('admin', 'show_last_items', '1', 0), |
|
143 | + array('admin', 'enable_pf_feature', '0', 0), |
|
144 | + array('admin', 'menu_type', 'context', 0), |
|
145 | + array('admin', 'log_connections', '0', 0), |
|
146 | + array('admin', 'time_format', 'H:i:s', 0), |
|
147 | + array('admin', 'date_format', 'd/m/Y', 0), |
|
148 | + array('admin', 'duplicate_folder', '0', 0), |
|
149 | + array('admin', 'duplicate_item', '0', 0), |
|
150 | + array('admin', 'item_duplicate_in_same_folder', '0', 0), |
|
151 | + array('admin', 'number_of_used_pw', '3', 0), |
|
152 | + array('admin', 'manager_edit', '1', 0), |
|
153 | + array('admin', 'cpassman_dir', '', 0), |
|
154 | + array('admin', 'cpassman_url', '', 0), |
|
155 | + array('admin', 'favicon', '', 0), |
|
156 | + array('admin', 'activate_expiration', '0', 0), |
|
157 | + array('admin', 'pw_life_duration', '30', 0), |
|
158 | 158 | //array('admin', 'maintenance_mode','1',1), |
159 | - array('admin', 'cpassman_version',$k['version'],1), |
|
160 | - array('admin', 'ldap_mode','0',0), |
|
161 | - array('admin','ldap_type','0',0), |
|
162 | - array('admin','ldap_suffix','0',0), |
|
163 | - array('admin','ldap_domain_dn','0',0), |
|
164 | - array('admin','ldap_domain_controler','0',0), |
|
165 | - array('admin','ldap_user_attribute','0',0), |
|
166 | - array('admin','ldap_ssl','0',0), |
|
167 | - array('admin','ldap_tls','0',0), |
|
168 | - array('admin','ldap_elusers','0',0), |
|
169 | - array('admin', 'richtext',0,0), |
|
170 | - array('admin', 'allow_print',0,0), |
|
171 | - array('admin', 'roles_allowed_to_print',0,0), |
|
172 | - array('admin', 'show_description',1,0), |
|
173 | - array('admin', 'anyone_can_modify',0,0), |
|
174 | - array('admin', 'anyone_can_modify_bydefault',0,0), |
|
175 | - array('admin', 'nb_bad_authentication',0,0), |
|
176 | - array('admin', 'restricted_to',0,0), |
|
177 | - array('admin', 'restricted_to_roles',0,0), |
|
178 | - array('admin', 'utf8_enabled',1,0), |
|
179 | - array('admin', 'custom_logo','',0), |
|
180 | - array('admin', 'custom_login_text','',0), |
|
181 | - array('admin', 'log_accessed', '1',1), |
|
182 | - array('admin', 'default_language', 'english',0), |
|
159 | + array('admin', 'cpassman_version', $k['version'], 1), |
|
160 | + array('admin', 'ldap_mode', '0', 0), |
|
161 | + array('admin', 'ldap_type', '0', 0), |
|
162 | + array('admin', 'ldap_suffix', '0', 0), |
|
163 | + array('admin', 'ldap_domain_dn', '0', 0), |
|
164 | + array('admin', 'ldap_domain_controler', '0', 0), |
|
165 | + array('admin', 'ldap_user_attribute', '0', 0), |
|
166 | + array('admin', 'ldap_ssl', '0', 0), |
|
167 | + array('admin', 'ldap_tls', '0', 0), |
|
168 | + array('admin', 'ldap_elusers', '0', 0), |
|
169 | + array('admin', 'richtext', 0, 0), |
|
170 | + array('admin', 'allow_print', 0, 0), |
|
171 | + array('admin', 'roles_allowed_to_print', 0, 0), |
|
172 | + array('admin', 'show_description', 1, 0), |
|
173 | + array('admin', 'anyone_can_modify', 0, 0), |
|
174 | + array('admin', 'anyone_can_modify_bydefault', 0, 0), |
|
175 | + array('admin', 'nb_bad_authentication', 0, 0), |
|
176 | + array('admin', 'restricted_to', 0, 0), |
|
177 | + array('admin', 'restricted_to_roles', 0, 0), |
|
178 | + array('admin', 'utf8_enabled', 1, 0), |
|
179 | + array('admin', 'custom_logo', '', 0), |
|
180 | + array('admin', 'custom_login_text', '', 0), |
|
181 | + array('admin', 'log_accessed', '1', 1), |
|
182 | + array('admin', 'default_language', 'english', 0), |
|
183 | 183 | array( |
184 | 184 | 'admin', |
185 | 185 | 'send_stats', |
@@ -195,16 +195,16 @@ discard block |
||
195 | 195 | 'admin', |
196 | 196 | 'path_to_upload_folder', |
197 | 197 | strrpos($_SERVER['DOCUMENT_ROOT'], "/") == 1 ? |
198 | - (strlen($_SERVER['DOCUMENT_ROOT'])-1).substr( |
|
198 | + (strlen($_SERVER['DOCUMENT_ROOT']) - 1).substr( |
|
199 | 199 | $_SERVER['PHP_SELF'], |
200 | 200 | 0, |
201 | - strlen($_SERVER['PHP_SELF'])-25 |
|
201 | + strlen($_SERVER['PHP_SELF']) - 25 |
|
202 | 202 | ).'/upload' |
203 | 203 | : |
204 | 204 | $_SERVER['DOCUMENT_ROOT'].substr( |
205 | 205 | $_SERVER['PHP_SELF'], |
206 | 206 | 0, |
207 | - strlen($_SERVER['PHP_SELF'])-25 |
|
207 | + strlen($_SERVER['PHP_SELF']) - 25 |
|
208 | 208 | ).'/upload', |
209 | 209 | 0 |
210 | 210 | ), |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | 'http://'.$_SERVER['HTTP_HOST'].substr( |
215 | 215 | $_SERVER['PHP_SELF'], |
216 | 216 | 0, |
217 | - strrpos($_SERVER['PHP_SELF'], '/')-8 |
|
217 | + strrpos($_SERVER['PHP_SELF'], '/') - 8 |
|
218 | 218 | ).'/upload', |
219 | 219 | 0 |
220 | 220 | ), |
@@ -224,16 +224,16 @@ discard block |
||
224 | 224 | 'admin', |
225 | 225 | 'path_to_files_folder', |
226 | 226 | strrpos($_SERVER['DOCUMENT_ROOT'], "/") == 1 ? |
227 | - (strlen($_SERVER['DOCUMENT_ROOT'])-1).substr( |
|
227 | + (strlen($_SERVER['DOCUMENT_ROOT']) - 1).substr( |
|
228 | 228 | $_SERVER['PHP_SELF'], |
229 | 229 | 0, |
230 | - strlen($_SERVER['PHP_SELF'])-25 |
|
230 | + strlen($_SERVER['PHP_SELF']) - 25 |
|
231 | 231 | ).'/files' |
232 | 232 | : |
233 | 233 | $_SERVER['DOCUMENT_ROOT'].substr( |
234 | 234 | $_SERVER['PHP_SELF'], |
235 | 235 | 0, |
236 | - strlen($_SERVER['PHP_SELF'])-25 |
|
236 | + strlen($_SERVER['PHP_SELF']) - 25 |
|
237 | 237 | ).'/files', |
238 | 238 | 0 |
239 | 239 | ), |
@@ -243,12 +243,12 @@ discard block |
||
243 | 243 | 'http://'.$_SERVER['HTTP_HOST'].substr( |
244 | 244 | $_SERVER['PHP_SELF'], |
245 | 245 | 0, |
246 | - strrpos($_SERVER['PHP_SELF'], '/')-8 |
|
246 | + strrpos($_SERVER['PHP_SELF'], '/') - 8 |
|
247 | 247 | ).'/files', |
248 | 248 | 0 |
249 | 249 | ), |
250 | - array('admin', 'pwd_maximum_length','40',0), |
|
251 | - array('admin', 'ga_website_name','TeamPass for ChangeMe',0), |
|
250 | + array('admin', 'pwd_maximum_length', '40', 0), |
|
251 | + array('admin', 'ga_website_name', 'TeamPass for ChangeMe', 0), |
|
252 | 252 | array('admin', 'email_smtp_server', @$_SESSION['smtp_server'], 0), |
253 | 253 | array('admin', 'email_smtp_auth', @$_SESSION['smtp_auth'], 0), |
254 | 254 | array('admin', 'email_auth_username', @$_SESSION['smtp_auth_username'], 0), |
@@ -259,43 +259,43 @@ discard block |
||
259 | 259 | array('admin', 'email_from_name', @$_SESSION['email_from_name'], 0), |
260 | 260 | array('admin', 'google_authentication', 0, 0), |
261 | 261 | array('admin', 'delay_item_edition', 0, 0), |
262 | - array('admin', 'allow_import',0,0), |
|
263 | - array('admin', 'proxy_port',0,0), |
|
264 | - array('admin', 'proxy_port',0,0), |
|
265 | - array('admin','upload_maxfilesize','10mb',0), |
|
262 | + array('admin', 'allow_import', 0, 0), |
|
263 | + array('admin', 'proxy_port', 0, 0), |
|
264 | + array('admin', 'proxy_port', 0, 0), |
|
265 | + array('admin', 'upload_maxfilesize', '10mb', 0), |
|
266 | 266 | array( |
267 | 267 | 'admin', |
268 | 268 | 'upload_docext', |
269 | 269 | 'doc,docx,dotx,xls,xlsx,xltx,rtf,csv,txt,pdf,ppt,pptx,pot,dotx,xltx', |
270 | 270 | 0 |
271 | 271 | ), |
272 | - array('admin','upload_imagesext','jpg,jpeg,gif,png',0), |
|
273 | - array('admin','upload_pkgext','7z,rar,tar,zip',0), |
|
274 | - array('admin','upload_otherext','sql,xml',0), |
|
275 | - array('admin','upload_imageresize_options','1',0), |
|
276 | - array('admin','upload_imageresize_width','800',0), |
|
277 | - array('admin','upload_imageresize_height','600',0), |
|
278 | - array('admin','upload_imageresize_quality','90',0), |
|
279 | - array('admin','enable_send_email_on_user_login','0', 0), |
|
280 | - array('admin','enable_user_can_create_folders','0', 0), |
|
281 | - array('admin','insert_manual_entry_item_history','0', 0), |
|
282 | - array('admin','enable_kb','0', 0), |
|
283 | - array('admin','enable_email_notification_on_item_shown','0', 0), |
|
284 | - array('admin','enable_email_notification_on_user_pw_change','0', 0), |
|
285 | - array('admin','enable_sts','0', 0), |
|
286 | - array('admin','encryptClientServer','1', 0), |
|
287 | - array('admin','use_md5_password_as_salt','0', 0), |
|
288 | - array('admin','api','0', 0), |
|
272 | + array('admin', 'upload_imagesext', 'jpg,jpeg,gif,png', 0), |
|
273 | + array('admin', 'upload_pkgext', '7z,rar,tar,zip', 0), |
|
274 | + array('admin', 'upload_otherext', 'sql,xml', 0), |
|
275 | + array('admin', 'upload_imageresize_options', '1', 0), |
|
276 | + array('admin', 'upload_imageresize_width', '800', 0), |
|
277 | + array('admin', 'upload_imageresize_height', '600', 0), |
|
278 | + array('admin', 'upload_imageresize_quality', '90', 0), |
|
279 | + array('admin', 'enable_send_email_on_user_login', '0', 0), |
|
280 | + array('admin', 'enable_user_can_create_folders', '0', 0), |
|
281 | + array('admin', 'insert_manual_entry_item_history', '0', 0), |
|
282 | + array('admin', 'enable_kb', '0', 0), |
|
283 | + array('admin', 'enable_email_notification_on_item_shown', '0', 0), |
|
284 | + array('admin', 'enable_email_notification_on_user_pw_change', '0', 0), |
|
285 | + array('admin', 'enable_sts', '0', 0), |
|
286 | + array('admin', 'encryptClientServer', '1', 0), |
|
287 | + array('admin', 'use_md5_password_as_salt', '0', 0), |
|
288 | + array('admin', 'api', '0', 0), |
|
289 | 289 | array('admin', 'subfolder_rights_as_parent', '0', 0), |
290 | 290 | array('admin', 'show_only_accessible_folders', '0', 0), |
291 | 291 | array('admin', 'enable_suggestion', '0', 0), |
292 | 292 | array('admin', 'email_server_url', '', 0), |
293 | - array('admin','otv_expiration_period','7', 0), |
|
294 | - array('admin','default_session_expiration_time','60', 0), |
|
295 | - array('admin','duo','0', 0), |
|
296 | - array('admin','enable_server_password_change','0', 0), |
|
297 | - array('admin','bck_script_path', $_SESSION['abspath']."/backups", 0), |
|
298 | - array('admin','bck_script_filename', 'bck_cpassman', 0) |
|
293 | + array('admin', 'otv_expiration_period', '7', 0), |
|
294 | + array('admin', 'default_session_expiration_time', '60', 0), |
|
295 | + array('admin', 'duo', '0', 0), |
|
296 | + array('admin', 'enable_server_password_change', '0', 0), |
|
297 | + array('admin', 'bck_script_path', $_SESSION['abspath']."/backups", 0), |
|
298 | + array('admin', 'bck_script_filename', 'bck_cpassman', 0) |
|
299 | 299 | ); |
300 | 300 | $res1 = "na"; |
301 | 301 | foreach ($val as $elem) { |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | ); |
606 | 606 | |
607 | 607 | // Clean timestamp for users table |
608 | -mysqli_query($dbTmp,"UPDATE ".$_SESSION['pre']."users SET timestamp = ''"); |
|
608 | +mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."users SET timestamp = ''"); |
|
609 | 609 | |
610 | 610 | ## Alter nested_tree table |
611 | 611 | $res2 = addColumnIfNotExist( |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | ); |
700 | 700 | |
701 | 701 | ## TABLE CACHE |
702 | -mysqli_query($dbTmp,"DROP TABLE IF EXISTS `".$_SESSION['pre']."cache`"); |
|
702 | +mysqli_query($dbTmp, "DROP TABLE IF EXISTS `".$_SESSION['pre']."cache`"); |
|
703 | 703 | $res8 = mysqli_query($dbTmp, |
704 | 704 | "CREATE TABLE IF NOT EXISTS `".$_SESSION['pre']."cache` ( |
705 | 705 | `id` int(12) NOT NULL, |
@@ -722,7 +722,7 @@ discard block |
||
722 | 722 | INNER JOIN ".$_SESSION['pre']."log_items as l ON (l.id_item = i.id) |
723 | 723 | AND l.action = 'at_creation' |
724 | 724 | WHERE i.inactif=0"; |
725 | - $rows = mysqli_query($dbTmp,$sql); |
|
725 | + $rows = mysqli_query($dbTmp, $sql); |
|
726 | 726 | while ($reccord = mysqli_fetch_array($rows)) { |
727 | 727 | //Get all TAGS |
728 | 728 | $tags = ""; |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | if (!empty($itemTags)) { |
735 | 735 | foreach ($itemTags as $itemTag) { |
736 | 736 | if (!empty($itemTag['tag'])) { |
737 | - $tags .= $itemTag['tag']. " "; |
|
737 | + $tags .= $itemTag['tag']." "; |
|
738 | 738 | } |
739 | 739 | } |
740 | 740 | } |
@@ -868,7 +868,7 @@ discard block |
||
868 | 868 | ); |
869 | 869 | |
870 | 870 | //Drop old table |
871 | - mysqli_query($dbTmp,"DROP TABLE ".$_SESSION['pre']."functions"); |
|
871 | + mysqli_query($dbTmp, "DROP TABLE ".$_SESSION['pre']."functions"); |
|
872 | 872 | } elseif ($tableFunctionExists == false) { |
873 | 873 | echo '[{"finish":"1", "msg":"", "error":"An error appears on table ROLES! '.addslashes(mysqli_error($dbTmp)).'"}]'; |
874 | 874 | mysqli_close($dbTmp); |
@@ -962,9 +962,9 @@ discard block |
||
962 | 962 | exit(); |
963 | 963 | } |
964 | 964 | $resTmp = mysqli_fetch_row( |
965 | - mysqli_query($dbTmp,"SELECT COUNT(*) FROM ".$_SESSION['pre']."languages") |
|
965 | + mysqli_query($dbTmp, "SELECT COUNT(*) FROM ".$_SESSION['pre']."languages") |
|
966 | 966 | ); |
967 | -mysqli_query($dbTmp,"TRUNCATE TABLE ".$_SESSION['pre']."languages"); |
|
967 | +mysqli_query($dbTmp, "TRUNCATE TABLE ".$_SESSION['pre']."languages"); |
|
968 | 968 | mysqli_query($dbTmp, |
969 | 969 | "INSERT IGNORE INTO `".$_SESSION['pre']."languages` |
970 | 970 | (`id`, `name`, `label`, `code`, `flag`) VALUES |
@@ -89,9 +89,12 @@ |
||
89 | 89 | AND table_name = '$tablename'" |
90 | 90 | ); |
91 | 91 | |
92 | - if ($res > 0) return true; |
|
93 | - else return false; |
|
94 | -} |
|
92 | + if ($res > 0) { |
|
93 | + return true; |
|
94 | + } else { |
|
95 | + return false; |
|
96 | + } |
|
97 | + } |
|
95 | 98 | |
96 | 99 | //define pbkdf2 iteration count |
97 | 100 | @define('ITCOUNT', '2072'); |
@@ -7,6 +7,9 @@ |
||
7 | 7 | ################ |
8 | 8 | ## Function permits to get the value from a line |
9 | 9 | ################ |
10 | +/** |
|
11 | + * @param string $val |
|
12 | + */ |
|
10 | 13 | function getSettingValue($val) |
11 | 14 | { |
12 | 15 | $val = trim(strstr($val, "=")); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | function getSettingValue($val) |
55 | 55 | { |
56 | 56 | $val = trim(strstr($val, "=")); |
57 | - return trim(str_replace('"', '', substr($val, 1, strpos($val, ";")-1))); |
|
57 | + return trim(str_replace('"', '', substr($val, 1, strpos($val, ";") - 1))); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | ################ |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | global $dbTmp; |
66 | 66 | $exists = false; |
67 | 67 | $columns = mysqli_query($dbTmp, "show columns from $db"); |
68 | - while ($c = mysqli_fetch_assoc( $columns)) { |
|
68 | + while ($c = mysqli_fetch_assoc($columns)) { |
|
69 | 69 | if ($c['Field'] == $column) { |
70 | 70 | $exists = true; |
71 | 71 | return true; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | -function addIndexIfNotExist($table, $index, $sql ) { |
|
81 | +function addIndexIfNotExist($table, $index, $sql) { |
|
82 | 82 | global $dbTmp; |
83 | 83 | |
84 | 84 | $mysqli_result = mysqli_query($dbTmp, "SHOW INDEX FROM $table WHERE key_name LIKE \"$index\""); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | // if index does not exist, then add it |
88 | 88 | if (!$res) { |
89 | - $res = mysqli_query($dbTmp, "ALTER TABLE `$table` " . $sql); |
|
89 | + $res = mysqli_query($dbTmp, "ALTER TABLE `$table` ".$sql); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | return $res; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | // change to 0 if auto_update_pwd_next_date empty in ITEMS table |
251 | 251 | $result = mysqli_query($dbTmp, "SELECT id FROM `".$_SESSION['pre']."items` WHERE auto_update_pwd_next_date = ''"); |
252 | -while($row = mysqli_fetch_assoc($result)) { |
|
252 | +while ($row = mysqli_fetch_assoc($result)) { |
|
253 | 253 | mysqli_query($dbTmp, |
254 | 254 | "UPDATE `".$_SESSION['pre']."items` |
255 | 255 | SET `auto_update_pwd_next_date` = '0' |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | // "The file $csrfp_file already exist. A copy has been created.<br />"; |
284 | 284 | } |
285 | 285 | } |
286 | - unlink($csrfp_file); // delete existing csrfp.config file |
|
287 | - copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file |
|
286 | + unlink($csrfp_file); // delete existing csrfp.config file |
|
287 | + copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file |
|
288 | 288 | $data = file_get_contents("../includes/libraries/csrfp/libs/csrfp.config.php"); |
289 | 289 | $newdata = str_replace('"CSRFP_TOKEN" => ""', '"CSRFP_TOKEN" => "'.bin2hex(openssl_random_pseudo_bytes(25)).'"', $data); |
290 | 290 | $newdata = str_replace('"tokenLength" => "25"', '"tokenLength" => "50"', $newdata); |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | \$SETTINGS = array ("; |
314 | 314 | |
315 | 315 | $result = mysqli_query($dbTmp, "SELECT * FROM `".$_SESSION['pre']."misc` WHERE type = 'admin'"); |
316 | - while($row = mysqli_fetch_assoc($result)) { |
|
316 | + while ($row = mysqli_fetch_assoc($result)) { |
|
317 | 317 | // append new setting in config file |
318 | 318 | $config_text .= " |
319 | 319 | '".$row['intitule']."' => '".$row['valeur']."',"; |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | |
334 | 334 | // clean duplicate ldap_object_class from bad update script version |
335 | 335 | $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `".$_SESSION['pre']."misc` WHERE type = 'admin' AND intitule = 'ldap_object_class'")); |
336 | -if ($tmp[0] > 1 ) { |
|
336 | +if ($tmp[0] > 1) { |
|
337 | 337 | mysqli_query($dbTmp, "DELETE FROM `".$_SESSION['pre']."misc` WHERE type = 'admin' AND intitule = 'ldap_object_class' AND `valeur` = 0"); |
338 | 338 | } |
339 | 339 | // add new setting - ldap_object_class |
@@ -346,10 +346,10 @@ discard block |
||
346 | 346 | $tmp_googlecount = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `".$_SESSION['pre']."misc` WHERE type = 'admin' AND intitule = 'google_authentication'")); |
347 | 347 | $tmp_twocount = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `".$_SESSION['pre']."misc` WHERE type = 'admin' AND intitule = '2factors_authentication'")); |
348 | 348 | |
349 | -if ($tmp_googlecount[0] > 0 ) { |
|
349 | +if ($tmp_googlecount[0] > 0) { |
|
350 | 350 | mysqli_query($dbTmp, "DELETE FROM `".$_SESSION['pre']."misc` WHERE type = 'admin' AND intitule = '2factors_authentication'"); |
351 | 351 | } else { |
352 | - if ($tmp_twocount[0] > 0 ) { |
|
352 | + if ($tmp_twocount[0] > 0) { |
|
353 | 353 | mysqli_query($dbTmp, "UPDATE `".$_SESSION['pre']."misc` SET intitule = 'google_authentication' WHERE intitule = '2factors_authentication' "); |
354 | 354 | } else { |
355 | 355 | mysqli_query($dbTmp, "INSERT INTO `".$_SESSION['pre']."misc` VALUES ('admin', 'google_authentication', '0')"); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | FROM `".$_SESSION['pre']."nested_tree` |
366 | 366 | WHERE personal_folder = '1' AND nlevel = '1' AND parent_id = '0'" |
367 | 367 | ); |
368 | -while($row = mysqli_fetch_assoc($result)) { |
|
368 | +while ($row = mysqli_fetch_assoc($result)) { |
|
369 | 369 | // only change non numeric folder title |
370 | 370 | if (!is_numeric($row['title'])) { |
371 | 371 | mysqli_query( |
@@ -7,6 +7,9 @@ |
||
7 | 7 | ################ |
8 | 8 | ## Function permits to get the value from a line |
9 | 9 | ################ |
10 | +/** |
|
11 | + * @param string $val |
|
12 | + */ |
|
10 | 13 | function getSettingValue($val) |
11 | 14 | { |
12 | 15 | $val = trim(strstr($val, "=")); |
@@ -89,9 +89,12 @@ |
||
89 | 89 | AND table_name = '$tablename'" |
90 | 90 | ); |
91 | 91 | |
92 | - if ($res > 0) return true; |
|
93 | - else return false; |
|
94 | -} |
|
92 | + if ($res > 0) { |
|
93 | + return true; |
|
94 | + } else { |
|
95 | + return false; |
|
96 | + } |
|
97 | + } |
|
95 | 98 | |
96 | 99 | //define pbkdf2 iteration count |
97 | 100 | @define('ITCOUNT', '2072'); |
@@ -101,8 +101,12 @@ |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | // temp data |
104 | - if (!isset($record['login'])) $record['login'] = ""; |
|
105 | - if (!isset($resNT['renewal_period'])) $resNT['renewal_period'] = "0"; |
|
104 | + if (!isset($record['login'])) { |
|
105 | + $record['login'] = ""; |
|
106 | + } |
|
107 | + if (!isset($resNT['renewal_period'])) { |
|
108 | + $resNT['renewal_period'] = "0"; |
|
109 | + } |
|
106 | 110 | |
107 | 111 | // store data |
108 | 112 | $res = mysqli_query($dbTmp, |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | function getSettingValue($val) |
35 | 35 | { |
36 | 36 | $val = trim(strstr($val, "=")); |
37 | - return trim(str_replace('"', '', substr($val, 1, strpos($val, ";")-1))); |
|
37 | + return trim(str_replace('"', '', substr($val, 1, strpos($val, ";") - 1))); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | ################ |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | global $dbTmp; |
46 | 46 | $exists = false; |
47 | 47 | $columns = mysqli_query($dbTmp, "show columns from $db"); |
48 | - while ($c = mysqli_fetch_assoc( $columns)) { |
|
48 | + while ($c = mysqli_fetch_assoc($columns)) { |
|
49 | 49 | if ($c['Field'] == $column) { |
50 | 50 | $exists = true; |
51 | 51 | return true; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | -function addIndexIfNotExist($table, $index, $sql ) { |
|
61 | +function addIndexIfNotExist($table, $index, $sql) { |
|
62 | 62 | global $dbTmp; |
63 | 63 | |
64 | 64 | $mysqli_result = mysqli_query($dbTmp, "SHOW INDEX FROM $table WHERE key_name LIKE \"$index\""); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | // if index does not exist, then add it |
68 | 68 | if (!$res) { |
69 | - $res = mysqli_query($dbTmp, "ALTER TABLE `$table` " . $sql); |
|
69 | + $res = mysqli_query($dbTmp, "ALTER TABLE `$table` ".$sql); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return $res; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | // if yes, then don't execute re-encryption |
153 | 153 | $_SESSION['tp_defuse_installed'] = false; |
154 | 154 | $columns = mysqli_query($dbTmp, "show columns from ".$_SESSION['pre']."items"); |
155 | -while ($c = mysqli_fetch_assoc( $columns)) { |
|
155 | +while ($c = mysqli_fetch_assoc($columns)) { |
|
156 | 156 | if ($c['Field'] === "encryption_type") { |
157 | 157 | $_SESSION['tp_defuse_installed'] = true; |
158 | 158 | } |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | // do clean of users table |
212 | 212 | $fieldsToUpdate = ['groupes_visibles', 'fonction_id', 'groupes_interdits']; |
213 | 213 | $result = mysqli_query($dbTmp, "SELECT id, groupes_visibles, fonction_id, groupes_interdits FROM `".$_SESSION['pre']."users`"); |
214 | -while($row = mysqli_fetch_assoc($result)) { |
|
214 | +while ($row = mysqli_fetch_assoc($result)) { |
|
215 | 215 | // check if field contains , instead of ; |
216 | - foreach($fieldsToUpdate as $field) { |
|
216 | + foreach ($fieldsToUpdate as $field) { |
|
217 | 217 | $tmp = cleanFields($row[$field]); |
218 | 218 | if ($tmp !== $row[$field]) { |
219 | 219 | mysqli_query($dbTmp, |
@@ -334,9 +334,9 @@ discard block |
||
334 | 334 | if (!isset($_SESSION['tp_defuse_installed']) || $_SESSION['tp_defuse_installed'] === false) { |
335 | 335 | $filename = "../includes/config/settings.php"; |
336 | 336 | $settingsFile = file($filename); |
337 | - while (list($key,$val) = each($settingsFile)) { |
|
338 | - if (substr_count($val, 'require_once "')>0 && substr_count($val, 'sk.php')>0) { |
|
339 | - $_SESSION['sk_file'] = substr($val, 14, strpos($val, '";')-14); |
|
337 | + while (list($key, $val) = each($settingsFile)) { |
|
338 | + if (substr_count($val, 'require_once "') > 0 && substr_count($val, 'sk.php') > 0) { |
|
339 | + $_SESSION['sk_file'] = substr($val, 14, strpos($val, '";') - 14); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | $dbTmp, |
381 | 381 | "SELECT id FROM `".$_SESSION['pre']."users`" |
382 | 382 | ); |
383 | - while($row_user = mysqli_fetch_assoc($result)) { |
|
383 | + while ($row_user = mysqli_fetch_assoc($result)) { |
|
384 | 384 | $result_items = mysqli_query( |
385 | 385 | $dbTmp, |
386 | 386 | "SELECT i.id AS item_id |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$_SESSION['pre']."misc` WHERE type = 'admin' AND intitule = 'send_stats_time'")); |
455 | 455 | if ($tmp === "0") { |
456 | 456 | mysqli_query($dbTmp, |
457 | - "INSERT INTO `".$_SESSION['pre']."misc` (`type`, `intitule`, `valeur`) VALUES ('admin', 'send_stats_time', '".(time()-2592000)."')" |
|
457 | + "INSERT INTO `".$_SESSION['pre']."misc` (`type`, `intitule`, `valeur`) VALUES ('admin', 'send_stats_time', '".(time() - 2592000)."')" |
|
458 | 458 | ); |
459 | 459 | } |
460 | 460 |
@@ -83,16 +83,27 @@ |
||
83 | 83 | AND table_name = '$tablename'" |
84 | 84 | ); |
85 | 85 | |
86 | - if ($res > 0) return true; |
|
87 | - else return false; |
|
88 | -} |
|
86 | + if ($res > 0) { |
|
87 | + return true; |
|
88 | + } else { |
|
89 | + return false; |
|
90 | + } |
|
91 | + } |
|
89 | 92 | |
90 | 93 | function cleanFields($txt) { |
91 | 94 | $tmp = str_replace(",", ";", trim($txt)); |
92 | - if (empty($tmp)) return $tmp; |
|
93 | - if ($tmp === ";") return ""; |
|
94 | - if (strpos($tmp, ';') === 0) $tmp = substr($tmp, 1); |
|
95 | - if (substr($tmp, -1) !== ";") $tmp = $tmp.";"; |
|
95 | + if (empty($tmp)) { |
|
96 | + return $tmp; |
|
97 | + } |
|
98 | + if ($tmp === ";") { |
|
99 | + return ""; |
|
100 | + } |
|
101 | + if (strpos($tmp, ';') === 0) { |
|
102 | + $tmp = substr($tmp, 1); |
|
103 | + } |
|
104 | + if (substr($tmp, -1) !== ";") { |
|
105 | + $tmp = $tmp.";"; |
|
106 | + } |
|
96 | 107 | return $tmp; |
97 | 108 | } |
98 | 109 |
@@ -7,6 +7,9 @@ |
||
7 | 7 | ################ |
8 | 8 | ## Function permits to get the value from a line |
9 | 9 | ################ |
10 | +/** |
|
11 | + * @param string $val |
|
12 | + */ |
|
10 | 13 | function getSettingValue($val) |
11 | 14 | { |
12 | 15 | $val = trim(strstr($val, "=")); |
@@ -18,8 +18,8 @@ |
||
18 | 18 | <body> |
19 | 19 | <?php |
20 | 20 | // define root path |
21 | -$abs_path = rtrim($_SERVER['DOCUMENT_ROOT'], '/') . substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF']) - 20); |
|
22 | -if( isset($_SERVER['HTTPS'] ) ) { |
|
21 | +$abs_path = rtrim($_SERVER['DOCUMENT_ROOT'], '/').substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF']) - 20); |
|
22 | +if (isset($_SERVER['HTTPS'])) { |
|
23 | 23 | $protocol = 'https://'; |
24 | 24 | } else { |
25 | 25 | $protocol = 'http://'; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | $dbgDuo = fopen("upgrade.log", "a"); |
45 | 45 | $finish = false; |
46 | -$next = ($_POST['nb']+$_POST['start']); |
|
46 | +$next = ($_POST['nb'] + $_POST['start']); |
|
47 | 47 | |
48 | 48 | |
49 | 49 | $dbTmp = mysqli_connect( |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $pw = decrypt($data['pw']); |
94 | 94 | if (empty($pw)) { |
95 | 95 | // used protocol is #1 |
96 | - $pw = decryptOld($data['pw']); // decrypt using protocol #1 |
|
96 | + $pw = decryptOld($data['pw']); // decrypt using protocol #1 |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // get key for this pw |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | // does tables KEYS exists |
134 | - if(mysqli_num_rows(mysqli_query("SHOW TABLES LIKE '".$_SESSION['pre']."keys'")) == 1) { |
|
134 | + if (mysqli_num_rows(mysqli_query("SHOW TABLES LIKE '".$_SESSION['pre']."keys'")) == 1) { |
|
135 | 135 | $table_keys_exists = 1; |
136 | 136 | } else { |
137 | 137 | $table_keys_exists = 0; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | fputs($dbgDuo, "\n/ step1 : ".$pw); |
163 | 163 | if (empty($pw)) { |
164 | 164 | // used protocol is #1 |
165 | - $pw = decryptOld(trim($reason[1])); // decrypt using protocol #1 |
|
165 | + $pw = decryptOld(trim($reason[1])); // decrypt using protocol #1 |
|
166 | 166 | fputs($dbgDuo, " / step2 : ".$pw); |
167 | 167 | } |
168 | 168 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | |
186 | 186 | // store new encryption |
187 | 187 | if (isUTF8($pw) && !empty($pw)) { |
188 | - $encrypt = cryption_phpCrypt($pw , SALT, "", "encrypt"); |
|
188 | + $encrypt = cryption_phpCrypt($pw, SALT, "", "encrypt"); |
|
189 | 189 | fputs($dbgDuo, " / Final : ".$encrypt['string']); |
190 | 190 | mysqli_query($dbTmp, |
191 | 191 | "UPDATE ".$_SESSION['pre']."log_items |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | |
218 | 218 | while ($record = mysqli_fetch_array($resData)) { |
219 | 219 | $tmpData = substr(decrypt($record['data']), strlen($record['rndKey'])); |
220 | - if (isUTF8($tmpData ) && !empty($tmpData )) { |
|
221 | - $encrypt = cryption_phpCrypt($tmpData , SALT, "", "encrypt"); |
|
220 | + if (isUTF8($tmpData) && !empty($tmpData)) { |
|
221 | + $encrypt = cryption_phpCrypt($tmpData, SALT, "", "encrypt"); |
|
222 | 222 | |
223 | 223 | // store Password |
224 | 224 | $resData_tmp2 = mysqli_query($dbTmp, |
@@ -214,16 +214,16 @@ discard block |
||
214 | 214 | { |
215 | 215 | |
216 | 216 | /** |
217 | - * Encrypt a text using AES encryption in Counter mode of operation |
|
218 | - * - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf |
|
219 | - * |
|
220 | - * Unicode multi-byte character safe |
|
221 | - * |
|
222 | - * @param plaintext source text to be encrypted |
|
223 | - * @param password the password to use to generate a key |
|
224 | - * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
225 | - * @return encrypted text |
|
226 | - */ |
|
217 | + * Encrypt a text using AES encryption in Counter mode of operation |
|
218 | + * - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf |
|
219 | + * |
|
220 | + * Unicode multi-byte character safe |
|
221 | + * |
|
222 | + * @param plaintext source text to be encrypted |
|
223 | + * @param password the password to use to generate a key |
|
224 | + * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
225 | + * @return encrypted text |
|
226 | + */ |
|
227 | 227 | public static function encrypt($plaintext, $password, $nBits) |
228 | 228 | { |
229 | 229 | $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
@@ -298,13 +298,13 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
301 | - * Decrypt a text encrypted by AES in counter mode of operation |
|
302 | - * |
|
303 | - * @param ciphertext source text to be decrypted |
|
304 | - * @param password the password to use to generate a key |
|
305 | - * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
306 | - * @return decrypted text |
|
307 | - */ |
|
301 | + * Decrypt a text encrypted by AES in counter mode of operation |
|
302 | + * |
|
303 | + * @param ciphertext source text to be decrypted |
|
304 | + * @param password the password to use to generate a key |
|
305 | + * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
306 | + * @return decrypted text |
|
307 | + */ |
|
308 | 308 | public static function decrypt($ciphertext, $password, $nBits) |
309 | 309 | { |
310 | 310 | $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
@@ -20,17 +20,17 @@ discard block |
||
20 | 20 | public static function cipher($input, $w) |
21 | 21 | { |
22 | 22 | // main cipher function [é5.1] |
23 | - $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
|
24 | - $Nr = count($w)/$Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys |
|
23 | + $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
|
24 | + $Nr = count($w) / $Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys |
|
25 | 25 | |
26 | - $state = array(); // initialise 4xNb byte-array 'state' with input [é3.4] |
|
27 | - for ($i=0; $i<4*$Nb; $i++) { |
|
28 | - $state[$i%4][floor($i/4)] = $input[$i]; |
|
26 | + $state = array(); // initialise 4xNb byte-array 'state' with input [é3.4] |
|
27 | + for ($i = 0; $i < 4 * $Nb; $i++) { |
|
28 | + $state[$i % 4][floor($i / 4)] = $input[$i]; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | $state = self::addRoundKey($state, $w, 0, $Nb); |
32 | 32 | |
33 | - for ($round=1; $round<$Nr; $round++) { // apply Nr rounds |
|
33 | + for ($round = 1; $round < $Nr; $round++) { // apply Nr rounds |
|
34 | 34 | $state = self::subBytes($state, $Nb); |
35 | 35 | $state = self::shiftRows($state, $Nb); |
36 | 36 | $state = self::mixColumns($state, $Nb); |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | $state = self::shiftRows($state, $Nb); |
42 | 42 | $state = self::addRoundKey($state, $w, $Nr, $Nb); |
43 | 43 | |
44 | - $output = array(4*$Nb); // convert state to 1-d array before returning [é3.4] |
|
45 | - for ($i=0; $i<4*$Nb; $i++) { |
|
46 | - $output[$i] = $state[$i%4][floor($i/4)]; |
|
44 | + $output = array(4 * $Nb); // convert state to 1-d array before returning [é3.4] |
|
45 | + for ($i = 0; $i < 4 * $Nb; $i++) { |
|
46 | + $output[$i] = $state[$i % 4][floor($i / 4)]; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | return $output; |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | private static function addRoundKey($state, $w, $rnd, $Nb) |
53 | 53 | { |
54 | 54 | // xor Round Key into state S [é5.1.4] |
55 | - for ($r=0; $r<4; $r++) { |
|
56 | - for ($c=0; $c<$Nb; $c++) { |
|
57 | - $state[$r][$c] ^= $w[$rnd*4+$c][$r]; |
|
55 | + for ($r = 0; $r < 4; $r++) { |
|
56 | + for ($c = 0; $c < $Nb; $c++) { |
|
57 | + $state[$r][$c] ^= $w[$rnd * 4 + $c][$r]; |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | private static function subBytes($s, $Nb) |
65 | 65 | { |
66 | 66 | // apply SBox to state S [é5.1.1] |
67 | - for ($r=0; $r<4; $r++) { |
|
68 | - for ($c=0; $c<$Nb; $c++) { |
|
67 | + for ($r = 0; $r < 4; $r++) { |
|
68 | + for ($c = 0; $c < $Nb; $c++) { |
|
69 | 69 | $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
70 | 70 | } |
71 | 71 | } |
@@ -77,26 +77,26 @@ discard block |
||
77 | 77 | { |
78 | 78 | // shift row r of state S left by r bytes [é5.1.2] |
79 | 79 | $t = array(4); |
80 | - for ($r=1; $r<4; $r++) { |
|
81 | - for ($c=0; $c<4; $c++) { |
|
82 | - $t[$c] = $s[$r][($c+$r)%$Nb]; // shift into temp copy |
|
80 | + for ($r = 1; $r < 4; $r++) { |
|
81 | + for ($c = 0; $c < 4; $c++) { |
|
82 | + $t[$c] = $s[$r][($c + $r) % $Nb]; // shift into temp copy |
|
83 | 83 | } |
84 | - for ($c=0; $c<4; $c++) { |
|
85 | - $s[$r][$c] = $t[$c]; // and copy back |
|
84 | + for ($c = 0; $c < 4; $c++) { |
|
85 | + $s[$r][$c] = $t[$c]; // and copy back |
|
86 | 86 | } |
87 | 87 | } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES): |
88 | - return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf |
|
88 | + return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | private static function mixColumns($s, $Nb) |
92 | 92 | { |
93 | 93 | // combine bytes of each col of state S [é5.1.3] |
94 | - for ($c=0; $c<4; $c++) { |
|
95 | - $a = array(4); // 'a' is a copy of the current column from 's' |
|
96 | - $b = array(4); // 'b' is aé{02} in GF(2^8) |
|
97 | - for ($i=0; $i<4; $i++) { |
|
94 | + for ($c = 0; $c < 4; $c++) { |
|
95 | + $a = array(4); // 'a' is a copy of the current column from 's' |
|
96 | + $b = array(4); // 'b' is aé{02} in GF(2^8) |
|
97 | + for ($i = 0; $i < 4; $i++) { |
|
98 | 98 | $a[$i] = $s[$i][$c]; |
99 | - $b[$i] = $s[$i][$c]&0x80 ? $s[$i][$c]<<1 ^ 0x011b : $s[$i][$c]<<1; |
|
99 | + $b[$i] = $s[$i][$c] & 0x80 ? $s[$i][$c] << 1 ^ 0x011b : $s[$i][$c] << 1; |
|
100 | 100 | } |
101 | 101 | // a[n] ^ b[n] is aé{03} in GF(2^8) |
102 | 102 | $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3 |
@@ -118,33 +118,33 @@ discard block |
||
118 | 118 | public static function keyExpansion($key) |
119 | 119 | { |
120 | 120 | // generate Key Schedule from Cipher Key [é5.2] |
121 | - $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
|
122 | - $Nk = count($key)/4; // key length (in words): 4/6/8 for 128/192/256-bit keys |
|
123 | - $Nr = $Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys |
|
121 | + $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
|
122 | + $Nk = count($key) / 4; // key length (in words): 4/6/8 for 128/192/256-bit keys |
|
123 | + $Nr = $Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys |
|
124 | 124 | |
125 | 125 | $w = array(); |
126 | 126 | $temp = array(); |
127 | 127 | |
128 | - for ($i=0; $i<$Nk; $i++) { |
|
129 | - $r = array($key[4*$i], $key[4*$i+1], $key[4*$i+2], $key[4*$i+3]); |
|
128 | + for ($i = 0; $i < $Nk; $i++) { |
|
129 | + $r = array($key[4 * $i], $key[4 * $i + 1], $key[4 * $i + 2], $key[4 * $i + 3]); |
|
130 | 130 | $w[$i] = $r; |
131 | 131 | } |
132 | 132 | |
133 | - for ($i=$Nk; $i<($Nb*($Nr+1)); $i++) { |
|
133 | + for ($i = $Nk; $i < ($Nb * ($Nr + 1)); $i++) { |
|
134 | 134 | $w[$i] = array(); |
135 | - for ($t=0; $t<4; $t++) { |
|
136 | - $temp[$t] = $w[$i-1][$t]; |
|
135 | + for ($t = 0; $t < 4; $t++) { |
|
136 | + $temp[$t] = $w[$i - 1][$t]; |
|
137 | 137 | } |
138 | 138 | if ($i % $Nk == 0) { |
139 | 139 | $temp = self::subWord(self::rotWord($temp)); |
140 | - for ($t=0; $t<4; $t++) { |
|
141 | - $temp[$t] ^= self::$rCon[$i/$Nk][$t]; |
|
140 | + for ($t = 0; $t < 4; $t++) { |
|
141 | + $temp[$t] ^= self::$rCon[$i / $Nk][$t]; |
|
142 | 142 | } |
143 | - } elseif ($Nk > 6 && $i%$Nk == 4) { |
|
143 | + } elseif ($Nk > 6 && $i % $Nk == 4) { |
|
144 | 144 | $temp = self::subWord($temp); |
145 | 145 | } |
146 | - for ($t=0; $t<4; $t++) { |
|
147 | - $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t]; |
|
146 | + for ($t = 0; $t < 4; $t++) { |
|
147 | + $w[$i][$t] = $w[$i - $Nk][$t] ^ $temp[$t]; |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | private static function subWord($w) |
155 | 155 | { |
156 | 156 | // apply SBox to 4-byte word w |
157 | - for ($i=0; $i<4; $i++) { |
|
157 | + for ($i = 0; $i < 4; $i++) { |
|
158 | 158 | $w[$i] = self::$sBox[$w[$i]]; |
159 | 159 | } |
160 | 160 | |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | { |
166 | 166 | // rotate 4-byte word w left by one byte |
167 | 167 | $tmp = $w[0]; |
168 | - for ($i=0; $i<3; $i++) { |
|
169 | - $w[$i] = $w[$i+1]; |
|
168 | + for ($i = 0; $i < 3; $i++) { |
|
169 | + $w[$i] = $w[$i + 1]; |
|
170 | 170 | } |
171 | 171 | $w[3] = $tmp; |
172 | 172 | |
@@ -175,22 +175,22 @@ discard block |
||
175 | 175 | |
176 | 176 | // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [é5.1.1] |
177 | 177 | private static $sBox = array( |
178 | - 0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76, |
|
179 | - 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0, |
|
180 | - 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15, |
|
181 | - 0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75, |
|
182 | - 0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84, |
|
183 | - 0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf, |
|
184 | - 0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8, |
|
185 | - 0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2, |
|
186 | - 0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73, |
|
187 | - 0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb, |
|
188 | - 0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79, |
|
189 | - 0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08, |
|
190 | - 0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a, |
|
191 | - 0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e, |
|
192 | - 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf, |
|
193 | - 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16 |
|
178 | + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, |
|
179 | + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, |
|
180 | + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, |
|
181 | + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, |
|
182 | + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, |
|
183 | + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, |
|
184 | + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, |
|
185 | + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, |
|
186 | + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, |
|
187 | + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, |
|
188 | + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, |
|
189 | + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, |
|
190 | + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, |
|
191 | + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, |
|
192 | + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, |
|
193 | + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 |
|
194 | 194 | ); |
195 | 195 | |
196 | 196 | // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [é5.2] |
@@ -226,72 +226,72 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public static function encrypt($plaintext, $password, $nBits) |
228 | 228 | { |
229 | - $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
|
230 | - if (!($nBits==128 || $nBits==192 || $nBits==256)) { |
|
231 | - return ''; // standard allows 128/192/256 bit keys |
|
229 | + $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
|
230 | + if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) { |
|
231 | + return ''; // standard allows 128/192/256 bit keys |
|
232 | 232 | } |
233 | 233 | // note PHP (5) gives us plaintext and password in UTF8 encoding! |
234 | 234 | |
235 | 235 | // use AES itself to encrypt password to get cipher key (using plain password as source for |
236 | 236 | // key expansion) - gives us well encrypted key |
237 | - $nBytes = $nBits/8; // no bytes in key |
|
237 | + $nBytes = $nBits / 8; // no bytes in key |
|
238 | 238 | $pwBytes = array(); |
239 | - for ($i=0; $i<$nBytes; $i++) { |
|
239 | + for ($i = 0; $i < $nBytes; $i++) { |
|
240 | 240 | $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff; |
241 | 241 | } |
242 | 242 | $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes)); |
243 | - $key = array_merge($key, array_slice($key, 0, $nBytes-16)); // expand key to 16/24/32 bytes long |
|
243 | + $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long |
|
244 | 244 | |
245 | 245 | // initialise counter block (NIST SP800-38A §B.2): millisecond time-stamp for nonce in |
246 | 246 | // 1st 8 bytes, block counter in 2nd 8 bytes |
247 | 247 | $counterBlock = array(); |
248 | - $nonce = floor(microtime(true)*1000); // timestamp: milliseconds since 1-Jan-1970 |
|
249 | - $nonceSec = floor($nonce/1000); |
|
250 | - $nonceMs = $nonce%1000; |
|
248 | + $nonce = floor(microtime(true) * 1000); // timestamp: milliseconds since 1-Jan-1970 |
|
249 | + $nonceSec = floor($nonce / 1000); |
|
250 | + $nonceMs = $nonce % 1000; |
|
251 | 251 | // encode nonce with seconds in 1st 4 bytes, and (repeated) ms part filling 2nd 4 bytes |
252 | - for ($i=0; $i<4; $i++) { |
|
253 | - $counterBlock[$i] = self::urs($nonceSec, $i*8) & 0xff; |
|
252 | + for ($i = 0; $i < 4; $i++) { |
|
253 | + $counterBlock[$i] = self::urs($nonceSec, $i * 8) & 0xff; |
|
254 | 254 | } |
255 | - for ($i=0; $i<4; $i++) { |
|
256 | - $counterBlock[$i+4] = $nonceMs & 0xff; |
|
255 | + for ($i = 0; $i < 4; $i++) { |
|
256 | + $counterBlock[$i + 4] = $nonceMs & 0xff; |
|
257 | 257 | } |
258 | 258 | // and convert it to a string to go on the front of the ciphertext |
259 | 259 | $ctrTxt = ''; |
260 | - for ($i=0; $i<8; $i++) { |
|
260 | + for ($i = 0; $i < 8; $i++) { |
|
261 | 261 | $ctrTxt .= chr($counterBlock[$i]); |
262 | 262 | } |
263 | 263 | |
264 | 264 | // generate key schedule - an expansion of the key into distinct Key Rounds for each round |
265 | 265 | $keySchedule = Aes::keyExpansion($key); |
266 | 266 | |
267 | - $blockCount = ceil(strlen($plaintext)/$blockSize); |
|
268 | - $ciphertxt = array(); // ciphertext as array of strings |
|
267 | + $blockCount = ceil(strlen($plaintext) / $blockSize); |
|
268 | + $ciphertxt = array(); // ciphertext as array of strings |
|
269 | 269 | |
270 | - for ($b=0; $b<$blockCount; $b++) { |
|
270 | + for ($b = 0; $b < $blockCount; $b++) { |
|
271 | 271 | // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
272 | 272 | // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB) |
273 | - for ($c=0; $c<4; $c++) { |
|
274 | - $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
273 | + for ($c = 0; $c < 4; $c++) { |
|
274 | + $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff; |
|
275 | 275 | } |
276 | - for ($c=0; $c<4; $c++) { |
|
277 | - $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8); |
|
276 | + for ($c = 0; $c < 4; $c++) { |
|
277 | + $counterBlock[15 - $c - 4] = self::urs($b / 0x100000000, $c * 8); |
|
278 | 278 | } |
279 | 279 | |
280 | - $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block -- |
|
280 | + $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block -- |
|
281 | 281 | |
282 | 282 | // block size is reduced on final block |
283 | - $blockLength = $b<$blockCount-1 ? $blockSize : (strlen($plaintext)-1)%$blockSize+1; |
|
283 | + $blockLength = $b < $blockCount - 1 ? $blockSize : (strlen($plaintext) - 1) % $blockSize + 1; |
|
284 | 284 | $cipherByte = array(); |
285 | 285 | |
286 | - for ($i=0; $i<$blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte -- |
|
287 | - $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b*$blockSize+$i, 1)); |
|
286 | + for ($i = 0; $i < $blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte -- |
|
287 | + $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b * $blockSize + $i, 1)); |
|
288 | 288 | $cipherByte[$i] = chr($cipherByte[$i]); |
289 | 289 | } |
290 | - $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext |
|
290 | + $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | // implode is more efficient than repeated string concatenation |
294 | - $ciphertext = $ctrTxt . implode('', $ciphertxt); |
|
294 | + $ciphertext = $ctrTxt.implode('', $ciphertxt); |
|
295 | 295 | $ciphertext = base64_encode($ciphertext); |
296 | 296 | |
297 | 297 | return $ciphertext; |
@@ -307,25 +307,25 @@ discard block |
||
307 | 307 | */ |
308 | 308 | public static function decrypt($ciphertext, $password, $nBits) |
309 | 309 | { |
310 | - $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
|
311 | - if (!($nBits==128 || $nBits==192 || $nBits==256)) { |
|
312 | - return ''; // standard allows 128/192/256 bit keys |
|
310 | + $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
|
311 | + if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) { |
|
312 | + return ''; // standard allows 128/192/256 bit keys |
|
313 | 313 | } |
314 | 314 | $ciphertext = base64_decode($ciphertext); |
315 | 315 | |
316 | 316 | // use AES to encrypt password (mirroring encrypt routine) |
317 | - $nBytes = $nBits/8; // no bytes in key |
|
317 | + $nBytes = $nBits / 8; // no bytes in key |
|
318 | 318 | $pwBytes = array(); |
319 | - for ($i=0; $i<$nBytes; $i++) { |
|
319 | + for ($i = 0; $i < $nBytes; $i++) { |
|
320 | 320 | $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff; |
321 | 321 | } |
322 | 322 | $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes)); |
323 | - $key = array_merge($key, array_slice($key, 0, $nBytes-16)); // expand key to 16/24/32 bytes long |
|
323 | + $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long |
|
324 | 324 | |
325 | 325 | // recover nonce from 1st element of ciphertext |
326 | 326 | $counterBlock = array(); |
327 | 327 | $ctrTxt = substr($ciphertext, 0, 8); |
328 | - for ($i=0; $i<8; $i++) { |
|
328 | + for ($i = 0; $i < 8; $i++) { |
|
329 | 329 | $counterBlock[$i] = ord(substr($ctrTxt, $i, 1)); |
330 | 330 | } |
331 | 331 | |
@@ -333,29 +333,29 @@ discard block |
||
333 | 333 | $keySchedule = Aes::keyExpansion($key); |
334 | 334 | |
335 | 335 | // separate ciphertext into blocks (skipping past initial 8 bytes) |
336 | - $nBlocks = ceil((strlen($ciphertext)-8) / $blockSize); |
|
336 | + $nBlocks = ceil((strlen($ciphertext) - 8) / $blockSize); |
|
337 | 337 | $ct = array(); |
338 | - for ($b=0; $b<$nBlocks; $b++) { |
|
339 | - $ct[$b] = substr($ciphertext, 8+$b*$blockSize, 16); |
|
338 | + for ($b = 0; $b < $nBlocks; $b++) { |
|
339 | + $ct[$b] = substr($ciphertext, 8 + $b * $blockSize, 16); |
|
340 | 340 | } |
341 | - $ciphertext = $ct; // ciphertext is now array of block-length strings |
|
341 | + $ciphertext = $ct; // ciphertext is now array of block-length strings |
|
342 | 342 | |
343 | 343 | // plaintext will get generated block-by-block into array of block-length strings |
344 | 344 | $plaintxt = array(); |
345 | 345 | |
346 | - for ($b=0; $b<$nBlocks; $b++) { |
|
346 | + for ($b = 0; $b < $nBlocks; $b++) { |
|
347 | 347 | // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
348 | - for ($c=0; $c<4; $c++) { |
|
349 | - $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
348 | + for ($c = 0; $c < 4; $c++) { |
|
349 | + $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff; |
|
350 | 350 | } |
351 | - for ($c=0; $c<4; $c++) { |
|
352 | - $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff; |
|
351 | + for ($c = 0; $c < 4; $c++) { |
|
352 | + $counterBlock[15 - $c - 4] = self::urs(($b + 1) / 0x100000000 - 1, $c * 8) & 0xff; |
|
353 | 353 | } |
354 | 354 | |
355 | - $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block |
|
355 | + $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block |
|
356 | 356 | |
357 | 357 | $plaintxtByte = array(); |
358 | - for ($i=0; $i<strlen($ciphertext[$b]); $i++) { |
|
358 | + for ($i = 0; $i < strlen($ciphertext[$b]); $i++) { |
|
359 | 359 | // -- xor plaintext with ciphered counter byte-by-byte -- |
360 | 360 | $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b], $i, 1)); |
361 | 361 | $plaintxtByte[$i] = chr($plaintxtByte[$i]); |
@@ -379,12 +379,12 @@ discard block |
||
379 | 379 | private static function urs($a, $b) |
380 | 380 | { |
381 | 381 | $a &= 0xffffffff; |
382 | - $b &= 0x1f; // (bounds check) |
|
383 | - if ($a&0x80000000 && $b>0) { // if left-most bit set |
|
384 | - $a = ($a>>1) & 0x7fffffff; // right-shift one bit & clear left-most bit |
|
385 | - $a = $a >> ($b-1); // remaining right-shifts |
|
382 | + $b &= 0x1f; // (bounds check) |
|
383 | + if ($a & 0x80000000 && $b > 0) { // if left-most bit set |
|
384 | + $a = ($a >> 1) & 0x7fffffff; // right-shift one bit & clear left-most bit |
|
385 | + $a = $a >> ($b - 1); // remaining right-shifts |
|
386 | 386 | } else { // otherwise |
387 | - $a = ($a>>$b); // use normal right-shift |
|
387 | + $a = ($a >> $b); // use normal right-shift |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | return $a; |
@@ -49,6 +49,10 @@ discard block |
||
49 | 49 | return $output; |
50 | 50 | } |
51 | 51 | |
52 | + /** |
|
53 | + * @param integer $rnd |
|
54 | + * @param integer $Nb |
|
55 | + */ |
|
52 | 56 | private static function addRoundKey($state, $w, $rnd, $Nb) |
53 | 57 | { |
54 | 58 | // xor Round Key into state S [é5.1.4] |
@@ -61,6 +65,9 @@ discard block |
||
61 | 65 | return $state; |
62 | 66 | } |
63 | 67 | |
68 | + /** |
|
69 | + * @param integer $Nb |
|
70 | + */ |
|
64 | 71 | private static function subBytes($s, $Nb) |
65 | 72 | { |
66 | 73 | // apply SBox to state S [é5.1.1] |
@@ -73,6 +80,9 @@ discard block |
||
73 | 80 | return $s; |
74 | 81 | } |
75 | 82 | |
83 | + /** |
|
84 | + * @param integer $Nb |
|
85 | + */ |
|
76 | 86 | private static function shiftRows($s, $Nb) |
77 | 87 | { |
78 | 88 | // shift row r of state S left by r bytes [é5.1.2] |
@@ -88,6 +98,9 @@ discard block |
||
88 | 98 | return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf |
89 | 99 | } |
90 | 100 | |
101 | + /** |
|
102 | + * @param integer $Nb |
|
103 | + */ |
|
91 | 104 | private static function mixColumns($s, $Nb) |
92 | 105 | { |
93 | 106 | // combine bytes of each col of state S [é5.1.3] |
@@ -219,10 +232,10 @@ discard block |
||
219 | 232 | * |
220 | 233 | * Unicode multi-byte character safe |
221 | 234 | * |
222 | - * @param plaintext source text to be encrypted |
|
235 | + * @param plaintext string text to be encrypted |
|
223 | 236 | * @param password the password to use to generate a key |
224 | - * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
225 | - * @return encrypted text |
|
237 | + * @param nBits integer of bits to be used in the key (128, 192, or 256) |
|
238 | + * @return string text |
|
226 | 239 | */ |
227 | 240 | public static function encrypt($plaintext, $password, $nBits) |
228 | 241 | { |
@@ -302,8 +315,8 @@ discard block |
||
302 | 315 | * |
303 | 316 | * @param ciphertext source text to be decrypted |
304 | 317 | * @param password the password to use to generate a key |
305 | - * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
306 | - * @return decrypted text |
|
318 | + * @param nBits integer of bits to be used in the key (128, 192, or 256) |
|
319 | + * @return string text |
|
307 | 320 | */ |
308 | 321 | public static function decrypt($ciphertext, $password, $nBits) |
309 | 322 | { |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $_SESSION['port'] |
41 | 41 | ); |
42 | 42 | // are files encrypted? get the setting ongoing in teampass |
43 | -$set = mysqli_fetch_row(mysqli_query($dbTmp,"SELECT valeur FROM ".$_SESSION['pre']."misc WHERE type='admin' AND intitule='enable_attachment_encryption'")); |
|
43 | +$set = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT valeur FROM ".$_SESSION['pre']."misc WHERE type='admin' AND intitule='enable_attachment_encryption'")); |
|
44 | 44 | $enable_attachment_encryption = $set[0]; |
45 | 45 | |
46 | 46 | // if no encryption then stop |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | // get path to upload |
54 | -$set = mysqli_fetch_row(mysqli_query($dbTmp,"SELECT valeur FROM ".$_SESSION['pre']."misc WHERE type='admin' AND intitule='path_to_upload_folder'")); |
|
54 | +$set = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT valeur FROM ".$_SESSION['pre']."misc WHERE type='admin' AND intitule='path_to_upload_folder'")); |
|
55 | 55 | $path_to_upload_folder = $set[0]; |
56 | 56 | |
57 | 57 | // get previous saltkey |
58 | -$set = mysqli_fetch_row(mysqli_query($dbTmp,"SELECT valeur FROM ".$_SESSION['pre']."misc WHERE type='admin' AND intitule='saltkey_ante_2127'")); |
|
58 | +$set = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT valeur FROM ".$_SESSION['pre']."misc WHERE type='admin' AND intitule='saltkey_ante_2127'")); |
|
59 | 59 | $saltkey_ante_2127 = $set[0]; |
60 | 60 | |
61 | 61 |