@@ -173,6 +173,7 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @param string $text The string to pad |
175 | 175 | * @param integer The number of bytes to pad |
176 | + * @param integer $bytes |
|
176 | 177 | * @return boolean Returns true |
177 | 178 | */ |
178 | 179 | private static function ansiX923Pad(&$text, $bytes) |
@@ -217,6 +218,7 @@ discard block |
||
217 | 218 | * |
218 | 219 | * @param string $text The string to pad |
219 | 220 | * @param integer The number of bytes to pad |
221 | + * @param integer $bytes |
|
220 | 222 | * @return boolean Returns true |
221 | 223 | */ |
222 | 224 | private static function iso10126Pad(&$text, $bytes) |
@@ -261,6 +263,7 @@ discard block |
||
261 | 263 | * |
262 | 264 | * @param string $text The string to pad |
263 | 265 | * @param integer The number of bytes to pad |
266 | + * @param integer $bytes |
|
264 | 267 | * @return boolean Returns true |
265 | 268 | */ |
266 | 269 | private static function pkcs7Pad(&$text, $bytes) |
@@ -296,6 +299,7 @@ discard block |
||
296 | 299 | * |
297 | 300 | * @param string $text The string to pad |
298 | 301 | * @param integer The number of bytes to pad |
302 | + * @param integer $bytes |
|
299 | 303 | * @return boolean Returns true |
300 | 304 | */ |
301 | 305 | private static function iso7816Pad(&$text, $bytes) |
@@ -39,290 +39,290 @@ |
||
39 | 39 | */ |
40 | 40 | class Padding |
41 | 41 | { |
42 | - /** |
|
43 | - * Constructor |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function __construct() { } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Destructor |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function __destruct() { } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * Returns a string padded using the specified padding scheme |
|
60 | - * |
|
61 | - * @param string $text The string to pad |
|
62 | - * @param integer $bytes The number of bytes to pad |
|
63 | - * @param integer $type One of the predefined padding types |
|
64 | - * @return boolean True on success, false on error |
|
65 | - */ |
|
66 | - public static function pad(&$text, $bytes, $type = PHP_Crypt::ZERO) |
|
67 | - { |
|
68 | - // if the size of padding is not greater than 1 |
|
69 | - // just return true, no padding will be done |
|
70 | - if(!($bytes > 0)) |
|
71 | - return true; |
|
72 | - |
|
73 | - switch($type) |
|
74 | - { |
|
75 | - case PHP_Crypt::PAD_ZERO: |
|
76 | - return self::zeroPad($text, $bytes); |
|
77 | - break; |
|
78 | - case PHP_Crypt::PAD_ANSI_X923: |
|
79 | - return self::ansiX923Pad($text, $bytes); |
|
80 | - break; |
|
81 | - case PHP_Crypt::PAD_ISO_10126: |
|
82 | - return self::iso10126Pad($text, $bytes); |
|
83 | - break; |
|
84 | - case PHP_Crypt::PAD_PKCS7: |
|
85 | - return self::pkcs7Pad($text, $bytes); |
|
86 | - break; |
|
87 | - case PHP_Crypt::PAD_ISO_7816_4: |
|
88 | - return self::iso7816Pad($text, $bytes); |
|
89 | - break; |
|
90 | - default: |
|
91 | - trigger_error("$type is not a valid padding type.", E_USER_NOTICE); |
|
92 | - return self::zeroPad($text, $bytes); |
|
93 | - } |
|
94 | - |
|
95 | - return true; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Strips padding from a string |
|
101 | - * |
|
102 | - * @param string $text The string strip padding from |
|
103 | - * @param integer $type One of the predefined padding types |
|
104 | - * @return boolean True on success, false on error |
|
105 | - */ |
|
106 | - public static function strip(&$text, $type = PHP_Crypt::ZERO) |
|
107 | - { |
|
108 | - switch($type) |
|
109 | - { |
|
110 | - case PHP_Crypt::PAD_ZERO: |
|
111 | - return self::zeroStrip($text); |
|
112 | - break; |
|
113 | - case PHP_Crypt::PAD_ANSI_X923: |
|
114 | - return self::ansiX923Strip($text); |
|
115 | - break; |
|
116 | - case PHP_Crypt::PAD_ISO_10126: |
|
117 | - return self::iso10126Strip($text); |
|
118 | - break; |
|
119 | - case PHP_Crypt::PAD_PKCS7: |
|
120 | - return self::pkcs7Strip($text); |
|
121 | - break; |
|
122 | - case PHP_Crypt::PAD_ISO_7816_4: |
|
123 | - return self::iso7816Strip($text); |
|
124 | - break; |
|
125 | - default: |
|
126 | - trigger_error("$type is not a valid padding type.", E_USER_NOTICE); |
|
127 | - return self::zeroStrip($text); |
|
128 | - } |
|
129 | - |
|
130 | - return true; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * Pads a string with null bytes |
|
136 | - * |
|
137 | - * @param string $text The string to be padded |
|
138 | - * @param integer $bytes The number of bytes to pad |
|
139 | - * @return boolean Returns true |
|
140 | - */ |
|
141 | - private static function zeroPad(&$text, $bytes) |
|
142 | - { |
|
143 | - $len = $bytes + strlen($text); |
|
144 | - $text = str_pad($text, $len, chr(0), STR_PAD_RIGHT); |
|
145 | - return true; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * Strips null padding off a string |
|
151 | - * NOTE: This is generally a bad idea as there is no way |
|
152 | - * to distinguish a null byte that is not padding from |
|
153 | - * a null byte that is padding. Stripping null padding should |
|
154 | - * be handled by the developer at the application level. |
|
155 | - * |
|
156 | - * @param string $text The string with null padding to strip |
|
157 | - * @return boolean Returns true |
|
158 | - */ |
|
159 | - private static function zeroStrip(&$text) |
|
160 | - { |
|
161 | - // with NULL byte padding, we should not strip off the |
|
162 | - // null bytes, instead leave this to the developer at the |
|
163 | - // application level |
|
164 | - //$text = preg_replace('/\0+$/', '', $text); |
|
165 | - return true; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Pads a string using ANSI X.923 |
|
171 | - * Adds null padding to the string, except for the last byte |
|
172 | - * which indicates the number of bytes padded |
|
173 | - * |
|
174 | - * @param string $text The string to pad |
|
175 | - * @param integer The number of bytes to pad |
|
176 | - * @return boolean Returns true |
|
177 | - */ |
|
178 | - private static function ansiX923Pad(&$text, $bytes) |
|
179 | - { |
|
180 | - $len = $bytes + strlen($text); |
|
181 | - $text = str_pad($text, ($len-1), "\0", STR_PAD_RIGHT); |
|
182 | - $text .= chr($bytes); |
|
183 | - return true; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Strips ANSI X.923 padding from a string |
|
189 | - * |
|
190 | - * @param string $text The string to strip padding from |
|
191 | - * @return boolean Returns true |
|
192 | - */ |
|
193 | - private static function ansiX923Strip(&$text) |
|
194 | - { |
|
195 | - $pos = strlen($text) - 1; |
|
196 | - $c = ord($text[$pos]); |
|
197 | - |
|
198 | - if($c == 0) |
|
199 | - return true; |
|
200 | - else if($c == 1) |
|
201 | - $text = substr($text, 0, -1); |
|
202 | - else |
|
203 | - { |
|
204 | - // the total null bytes are 1 less than the value of the final byte |
|
205 | - $nc = $c - 1; |
|
206 | - $text = preg_replace('/\0{'.$nc.'}'.preg_quote(chr($c)).'$/', "", $text); |
|
207 | - } |
|
208 | - |
|
209 | - return true; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Pads a string using ISO 10126 |
|
215 | - * Adds random bytes to the end of the string, except for the last |
|
216 | - * byte which indicates the number of padded bytes |
|
217 | - * |
|
218 | - * @param string $text The string to pad |
|
219 | - * @param integer The number of bytes to pad |
|
220 | - * @return boolean Returns true |
|
221 | - */ |
|
222 | - private static function iso10126Pad(&$text, $bytes) |
|
223 | - { |
|
224 | - // create the random pad bytes, we do one less than |
|
225 | - // needed because the last byte is reserved for the |
|
226 | - // number of padded bytes |
|
227 | - for($i = 0; $i < ($bytes - 1); ++$i) |
|
228 | - $text .= chr(mt_rand(0, 255)); |
|
229 | - |
|
230 | - // add the byte to indicate the padding length |
|
231 | - $text .= chr($bytes); |
|
232 | - return true; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Strips ISO 10126 padding from a string |
|
238 | - * |
|
239 | - * @param string $text The string to strip padding from |
|
240 | - * @return boolean Returns true |
|
241 | - */ |
|
242 | - private static function iso10126Strip(&$text) |
|
243 | - { |
|
244 | - $pos = strlen($text) - 1; |
|
245 | - $c = ord($text[$pos]) * -1; |
|
246 | - |
|
247 | - // if we got a null byte at the end of the string, |
|
248 | - // just return |
|
249 | - if($c == 0) |
|
250 | - return true; |
|
251 | - |
|
252 | - $text = substr($text, 0, $c); |
|
253 | - return true; |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Pads a string using PKCS7 |
|
259 | - * Adds padding using the bytes with the value of the |
|
260 | - * number of bytes need for padding |
|
261 | - * |
|
262 | - * @param string $text The string to pad |
|
263 | - * @param integer The number of bytes to pad |
|
264 | - * @return boolean Returns true |
|
265 | - */ |
|
266 | - private static function pkcs7Pad(&$text, $bytes) |
|
267 | - { |
|
268 | - $len = $bytes + strlen($text); |
|
269 | - $text = str_pad($text, $len, chr($bytes), STR_PAD_RIGHT); |
|
270 | - return true; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * Strips PKCS7 padding from a string |
|
276 | - * |
|
277 | - * @param string $text The string to strip padding from |
|
278 | - * @return boolean Returns true |
|
279 | - */ |
|
280 | - private static function pkcs7Strip(&$text) |
|
281 | - { |
|
282 | - $pos = strlen($text) - 1; |
|
283 | - $c = ord($text[$pos]); |
|
284 | - |
|
285 | - if($c == 0) |
|
286 | - return true; |
|
287 | - |
|
288 | - $text = preg_replace('/'.preg_quote(chr($c)).'{'.$c.'}$/', "", $text); |
|
289 | - return true; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Pads a string using ISO/IEC 7816-4 |
|
295 | - * Adds byte 0x80 followed by null bytes to pad a string |
|
296 | - * |
|
297 | - * @param string $text The string to pad |
|
298 | - * @param integer The number of bytes to pad |
|
299 | - * @return boolean Returns true |
|
300 | - */ |
|
301 | - private static function iso7816Pad(&$text, $bytes) |
|
302 | - { |
|
303 | - $text .= chr(0x80); |
|
304 | - $len = $bytes + strlen($text); |
|
305 | - |
|
306 | - // if we are only padding one byte, then 0x80 is all we need |
|
307 | - // else we follow up with null bytes |
|
308 | - if($bytes > 1) |
|
309 | - $text = str_pad($text, ($len - 1), chr(0), STR_PAD_RIGHT); |
|
310 | - |
|
311 | - return true; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Strips ISO/IEC 7816-4 padding from a string |
|
317 | - * |
|
318 | - * @param string $text The string to strip padding from |
|
319 | - * @return boolean Returns true |
|
320 | - */ |
|
321 | - private static function iso7816Strip(&$text) |
|
322 | - { |
|
323 | - $c = chr(0x80); |
|
324 | - $text = preg_replace('/'.preg_quote($c).'\0*$/', '', $text); |
|
325 | - return true; |
|
326 | - } |
|
42 | + /** |
|
43 | + * Constructor |
|
44 | + * |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function __construct() { } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Destructor |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function __destruct() { } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * Returns a string padded using the specified padding scheme |
|
60 | + * |
|
61 | + * @param string $text The string to pad |
|
62 | + * @param integer $bytes The number of bytes to pad |
|
63 | + * @param integer $type One of the predefined padding types |
|
64 | + * @return boolean True on success, false on error |
|
65 | + */ |
|
66 | + public static function pad(&$text, $bytes, $type = PHP_Crypt::ZERO) |
|
67 | + { |
|
68 | + // if the size of padding is not greater than 1 |
|
69 | + // just return true, no padding will be done |
|
70 | + if(!($bytes > 0)) |
|
71 | + return true; |
|
72 | + |
|
73 | + switch($type) |
|
74 | + { |
|
75 | + case PHP_Crypt::PAD_ZERO: |
|
76 | + return self::zeroPad($text, $bytes); |
|
77 | + break; |
|
78 | + case PHP_Crypt::PAD_ANSI_X923: |
|
79 | + return self::ansiX923Pad($text, $bytes); |
|
80 | + break; |
|
81 | + case PHP_Crypt::PAD_ISO_10126: |
|
82 | + return self::iso10126Pad($text, $bytes); |
|
83 | + break; |
|
84 | + case PHP_Crypt::PAD_PKCS7: |
|
85 | + return self::pkcs7Pad($text, $bytes); |
|
86 | + break; |
|
87 | + case PHP_Crypt::PAD_ISO_7816_4: |
|
88 | + return self::iso7816Pad($text, $bytes); |
|
89 | + break; |
|
90 | + default: |
|
91 | + trigger_error("$type is not a valid padding type.", E_USER_NOTICE); |
|
92 | + return self::zeroPad($text, $bytes); |
|
93 | + } |
|
94 | + |
|
95 | + return true; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Strips padding from a string |
|
101 | + * |
|
102 | + * @param string $text The string strip padding from |
|
103 | + * @param integer $type One of the predefined padding types |
|
104 | + * @return boolean True on success, false on error |
|
105 | + */ |
|
106 | + public static function strip(&$text, $type = PHP_Crypt::ZERO) |
|
107 | + { |
|
108 | + switch($type) |
|
109 | + { |
|
110 | + case PHP_Crypt::PAD_ZERO: |
|
111 | + return self::zeroStrip($text); |
|
112 | + break; |
|
113 | + case PHP_Crypt::PAD_ANSI_X923: |
|
114 | + return self::ansiX923Strip($text); |
|
115 | + break; |
|
116 | + case PHP_Crypt::PAD_ISO_10126: |
|
117 | + return self::iso10126Strip($text); |
|
118 | + break; |
|
119 | + case PHP_Crypt::PAD_PKCS7: |
|
120 | + return self::pkcs7Strip($text); |
|
121 | + break; |
|
122 | + case PHP_Crypt::PAD_ISO_7816_4: |
|
123 | + return self::iso7816Strip($text); |
|
124 | + break; |
|
125 | + default: |
|
126 | + trigger_error("$type is not a valid padding type.", E_USER_NOTICE); |
|
127 | + return self::zeroStrip($text); |
|
128 | + } |
|
129 | + |
|
130 | + return true; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * Pads a string with null bytes |
|
136 | + * |
|
137 | + * @param string $text The string to be padded |
|
138 | + * @param integer $bytes The number of bytes to pad |
|
139 | + * @return boolean Returns true |
|
140 | + */ |
|
141 | + private static function zeroPad(&$text, $bytes) |
|
142 | + { |
|
143 | + $len = $bytes + strlen($text); |
|
144 | + $text = str_pad($text, $len, chr(0), STR_PAD_RIGHT); |
|
145 | + return true; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Strips null padding off a string |
|
151 | + * NOTE: This is generally a bad idea as there is no way |
|
152 | + * to distinguish a null byte that is not padding from |
|
153 | + * a null byte that is padding. Stripping null padding should |
|
154 | + * be handled by the developer at the application level. |
|
155 | + * |
|
156 | + * @param string $text The string with null padding to strip |
|
157 | + * @return boolean Returns true |
|
158 | + */ |
|
159 | + private static function zeroStrip(&$text) |
|
160 | + { |
|
161 | + // with NULL byte padding, we should not strip off the |
|
162 | + // null bytes, instead leave this to the developer at the |
|
163 | + // application level |
|
164 | + //$text = preg_replace('/\0+$/', '', $text); |
|
165 | + return true; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Pads a string using ANSI X.923 |
|
171 | + * Adds null padding to the string, except for the last byte |
|
172 | + * which indicates the number of bytes padded |
|
173 | + * |
|
174 | + * @param string $text The string to pad |
|
175 | + * @param integer The number of bytes to pad |
|
176 | + * @return boolean Returns true |
|
177 | + */ |
|
178 | + private static function ansiX923Pad(&$text, $bytes) |
|
179 | + { |
|
180 | + $len = $bytes + strlen($text); |
|
181 | + $text = str_pad($text, ($len-1), "\0", STR_PAD_RIGHT); |
|
182 | + $text .= chr($bytes); |
|
183 | + return true; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Strips ANSI X.923 padding from a string |
|
189 | + * |
|
190 | + * @param string $text The string to strip padding from |
|
191 | + * @return boolean Returns true |
|
192 | + */ |
|
193 | + private static function ansiX923Strip(&$text) |
|
194 | + { |
|
195 | + $pos = strlen($text) - 1; |
|
196 | + $c = ord($text[$pos]); |
|
197 | + |
|
198 | + if($c == 0) |
|
199 | + return true; |
|
200 | + else if($c == 1) |
|
201 | + $text = substr($text, 0, -1); |
|
202 | + else |
|
203 | + { |
|
204 | + // the total null bytes are 1 less than the value of the final byte |
|
205 | + $nc = $c - 1; |
|
206 | + $text = preg_replace('/\0{'.$nc.'}'.preg_quote(chr($c)).'$/', "", $text); |
|
207 | + } |
|
208 | + |
|
209 | + return true; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Pads a string using ISO 10126 |
|
215 | + * Adds random bytes to the end of the string, except for the last |
|
216 | + * byte which indicates the number of padded bytes |
|
217 | + * |
|
218 | + * @param string $text The string to pad |
|
219 | + * @param integer The number of bytes to pad |
|
220 | + * @return boolean Returns true |
|
221 | + */ |
|
222 | + private static function iso10126Pad(&$text, $bytes) |
|
223 | + { |
|
224 | + // create the random pad bytes, we do one less than |
|
225 | + // needed because the last byte is reserved for the |
|
226 | + // number of padded bytes |
|
227 | + for($i = 0; $i < ($bytes - 1); ++$i) |
|
228 | + $text .= chr(mt_rand(0, 255)); |
|
229 | + |
|
230 | + // add the byte to indicate the padding length |
|
231 | + $text .= chr($bytes); |
|
232 | + return true; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Strips ISO 10126 padding from a string |
|
238 | + * |
|
239 | + * @param string $text The string to strip padding from |
|
240 | + * @return boolean Returns true |
|
241 | + */ |
|
242 | + private static function iso10126Strip(&$text) |
|
243 | + { |
|
244 | + $pos = strlen($text) - 1; |
|
245 | + $c = ord($text[$pos]) * -1; |
|
246 | + |
|
247 | + // if we got a null byte at the end of the string, |
|
248 | + // just return |
|
249 | + if($c == 0) |
|
250 | + return true; |
|
251 | + |
|
252 | + $text = substr($text, 0, $c); |
|
253 | + return true; |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Pads a string using PKCS7 |
|
259 | + * Adds padding using the bytes with the value of the |
|
260 | + * number of bytes need for padding |
|
261 | + * |
|
262 | + * @param string $text The string to pad |
|
263 | + * @param integer The number of bytes to pad |
|
264 | + * @return boolean Returns true |
|
265 | + */ |
|
266 | + private static function pkcs7Pad(&$text, $bytes) |
|
267 | + { |
|
268 | + $len = $bytes + strlen($text); |
|
269 | + $text = str_pad($text, $len, chr($bytes), STR_PAD_RIGHT); |
|
270 | + return true; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * Strips PKCS7 padding from a string |
|
276 | + * |
|
277 | + * @param string $text The string to strip padding from |
|
278 | + * @return boolean Returns true |
|
279 | + */ |
|
280 | + private static function pkcs7Strip(&$text) |
|
281 | + { |
|
282 | + $pos = strlen($text) - 1; |
|
283 | + $c = ord($text[$pos]); |
|
284 | + |
|
285 | + if($c == 0) |
|
286 | + return true; |
|
287 | + |
|
288 | + $text = preg_replace('/'.preg_quote(chr($c)).'{'.$c.'}$/', "", $text); |
|
289 | + return true; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Pads a string using ISO/IEC 7816-4 |
|
295 | + * Adds byte 0x80 followed by null bytes to pad a string |
|
296 | + * |
|
297 | + * @param string $text The string to pad |
|
298 | + * @param integer The number of bytes to pad |
|
299 | + * @return boolean Returns true |
|
300 | + */ |
|
301 | + private static function iso7816Pad(&$text, $bytes) |
|
302 | + { |
|
303 | + $text .= chr(0x80); |
|
304 | + $len = $bytes + strlen($text); |
|
305 | + |
|
306 | + // if we are only padding one byte, then 0x80 is all we need |
|
307 | + // else we follow up with null bytes |
|
308 | + if($bytes > 1) |
|
309 | + $text = str_pad($text, ($len - 1), chr(0), STR_PAD_RIGHT); |
|
310 | + |
|
311 | + return true; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Strips ISO/IEC 7816-4 padding from a string |
|
317 | + * |
|
318 | + * @param string $text The string to strip padding from |
|
319 | + * @return boolean Returns true |
|
320 | + */ |
|
321 | + private static function iso7816Strip(&$text) |
|
322 | + { |
|
323 | + $c = chr(0x80); |
|
324 | + $text = preg_replace('/'.preg_quote($c).'\0*$/', '', $text); |
|
325 | + return true; |
|
326 | + } |
|
327 | 327 | } |
328 | 328 | ?> |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | { |
68 | 68 | // if the size of padding is not greater than 1 |
69 | 69 | // just return true, no padding will be done |
70 | - if(!($bytes > 0)) |
|
70 | + if (!($bytes > 0)) |
|
71 | 71 | return true; |
72 | 72 | |
73 | - switch($type) |
|
73 | + switch ($type) |
|
74 | 74 | { |
75 | 75 | case PHP_Crypt::PAD_ZERO: |
76 | 76 | return self::zeroPad($text, $bytes); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public static function strip(&$text, $type = PHP_Crypt::ZERO) |
107 | 107 | { |
108 | - switch($type) |
|
108 | + switch ($type) |
|
109 | 109 | { |
110 | 110 | case PHP_Crypt::PAD_ZERO: |
111 | 111 | return self::zeroStrip($text); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | private static function ansiX923Pad(&$text, $bytes) |
179 | 179 | { |
180 | 180 | $len = $bytes + strlen($text); |
181 | - $text = str_pad($text, ($len-1), "\0", STR_PAD_RIGHT); |
|
181 | + $text = str_pad($text, ($len - 1), "\0", STR_PAD_RIGHT); |
|
182 | 182 | $text .= chr($bytes); |
183 | 183 | return true; |
184 | 184 | } |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | $pos = strlen($text) - 1; |
196 | 196 | $c = ord($text[$pos]); |
197 | 197 | |
198 | - if($c == 0) |
|
198 | + if ($c == 0) |
|
199 | 199 | return true; |
200 | - else if($c == 1) |
|
200 | + else if ($c == 1) |
|
201 | 201 | $text = substr($text, 0, -1); |
202 | 202 | else |
203 | 203 | { |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | // create the random pad bytes, we do one less than |
225 | 225 | // needed because the last byte is reserved for the |
226 | 226 | // number of padded bytes |
227 | - for($i = 0; $i < ($bytes - 1); ++$i) |
|
227 | + for ($i = 0; $i < ($bytes - 1); ++$i) |
|
228 | 228 | $text .= chr(mt_rand(0, 255)); |
229 | 229 | |
230 | 230 | // add the byte to indicate the padding length |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | |
247 | 247 | // if we got a null byte at the end of the string, |
248 | 248 | // just return |
249 | - if($c == 0) |
|
249 | + if ($c == 0) |
|
250 | 250 | return true; |
251 | 251 | |
252 | 252 | $text = substr($text, 0, $c); |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | private static function pkcs7Pad(&$text, $bytes) |
267 | 267 | { |
268 | 268 | $len = $bytes + strlen($text); |
269 | - $text = str_pad($text, $len, chr($bytes), STR_PAD_RIGHT); |
|
269 | + $text = str_pad($text, $len, chr($bytes), STR_PAD_RIGHT); |
|
270 | 270 | return true; |
271 | 271 | } |
272 | 272 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $pos = strlen($text) - 1; |
283 | 283 | $c = ord($text[$pos]); |
284 | 284 | |
285 | - if($c == 0) |
|
285 | + if ($c == 0) |
|
286 | 286 | return true; |
287 | 287 | |
288 | 288 | $text = preg_replace('/'.preg_quote(chr($c)).'{'.$c.'}$/', "", $text); |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | |
306 | 306 | // if we are only padding one byte, then 0x80 is all we need |
307 | 307 | // else we follow up with null bytes |
308 | - if($bytes > 1) |
|
309 | - $text = str_pad($text, ($len - 1), chr(0), STR_PAD_RIGHT); |
|
308 | + if ($bytes > 1) |
|
309 | + $text = str_pad($text, ($len - 1), chr(0), STR_PAD_RIGHT); |
|
310 | 310 | |
311 | 311 | return true; |
312 | 312 | } |
@@ -67,8 +67,9 @@ discard block |
||
67 | 67 | { |
68 | 68 | // if the size of padding is not greater than 1 |
69 | 69 | // just return true, no padding will be done |
70 | - if(!($bytes > 0)) |
|
71 | - return true; |
|
70 | + if(!($bytes > 0)) { |
|
71 | + return true; |
|
72 | + } |
|
72 | 73 | |
73 | 74 | switch($type) |
74 | 75 | { |
@@ -195,11 +196,11 @@ discard block |
||
195 | 196 | $pos = strlen($text) - 1; |
196 | 197 | $c = ord($text[$pos]); |
197 | 198 | |
198 | - if($c == 0) |
|
199 | - return true; |
|
200 | - else if($c == 1) |
|
201 | - $text = substr($text, 0, -1); |
|
202 | - else |
|
199 | + if($c == 0) { |
|
200 | + return true; |
|
201 | + } else if($c == 1) { |
|
202 | + $text = substr($text, 0, -1); |
|
203 | + } else |
|
203 | 204 | { |
204 | 205 | // the total null bytes are 1 less than the value of the final byte |
205 | 206 | $nc = $c - 1; |
@@ -224,8 +225,9 @@ discard block |
||
224 | 225 | // create the random pad bytes, we do one less than |
225 | 226 | // needed because the last byte is reserved for the |
226 | 227 | // number of padded bytes |
227 | - for($i = 0; $i < ($bytes - 1); ++$i) |
|
228 | - $text .= chr(mt_rand(0, 255)); |
|
228 | + for($i = 0; $i < ($bytes - 1); ++$i) { |
|
229 | + $text .= chr(mt_rand(0, 255)); |
|
230 | + } |
|
229 | 231 | |
230 | 232 | // add the byte to indicate the padding length |
231 | 233 | $text .= chr($bytes); |
@@ -246,8 +248,9 @@ discard block |
||
246 | 248 | |
247 | 249 | // if we got a null byte at the end of the string, |
248 | 250 | // just return |
249 | - if($c == 0) |
|
250 | - return true; |
|
251 | + if($c == 0) { |
|
252 | + return true; |
|
253 | + } |
|
251 | 254 | |
252 | 255 | $text = substr($text, 0, $c); |
253 | 256 | return true; |
@@ -282,8 +285,9 @@ discard block |
||
282 | 285 | $pos = strlen($text) - 1; |
283 | 286 | $c = ord($text[$pos]); |
284 | 287 | |
285 | - if($c == 0) |
|
286 | - return true; |
|
288 | + if($c == 0) { |
|
289 | + return true; |
|
290 | + } |
|
287 | 291 | |
288 | 292 | $text = preg_replace('/'.preg_quote(chr($c)).'{'.$c.'}$/', "", $text); |
289 | 293 | return true; |
@@ -305,8 +309,9 @@ discard block |
||
305 | 309 | |
306 | 310 | // if we are only padding one byte, then 0x80 is all we need |
307 | 311 | // else we follow up with null bytes |
308 | - if($bytes > 1) |
|
309 | - $text = str_pad($text, ($len - 1), chr(0), STR_PAD_RIGHT); |
|
312 | + if($bytes > 1) { |
|
313 | + $text = str_pad($text, ($len - 1), chr(0), STR_PAD_RIGHT); |
|
314 | + } |
|
310 | 315 | |
311 | 316 | return true; |
312 | 317 | } |
@@ -97,8 +97,8 @@ |
||
97 | 97 | * @param string $key The key to use for the selected Cipher |
98 | 98 | * @param string $cipher The type of cipher to use |
99 | 99 | * @param string $mode The encrypt mode to use with the cipher |
100 | - * @param string $padding The padding type to use. Defaults to PAD_ZERO |
|
101 | - * @return void |
|
100 | + * @param integer $padding The padding type to use. Defaults to PAD_ZERO |
|
101 | + * @return string |
|
102 | 102 | */ |
103 | 103 | public function __construct($key, $cipher = self::CIPHER_AES_128, $mode = self::MODE_ECB, $padding = self::PAD_ZERO) |
104 | 104 | { |
@@ -35,423 +35,423 @@ |
||
35 | 35 | */ |
36 | 36 | class PHP_Crypt |
37 | 37 | { |
38 | - // Ciphers |
|
39 | - const CIPHER_3DES = "3DES"; |
|
40 | - const CIPHER_3WAY = "3-Way"; |
|
41 | - const CIPHER_AES_128 = "AES-128"; |
|
42 | - const CIPHER_AES_192 = "AES-192"; |
|
43 | - const CIPHER_AES_256 = "AES-256"; |
|
44 | - const CIPHER_ARC4 = "ARC4"; // Alternative RC4 |
|
45 | - const CIPHER_BLOWFISH = "Blowfish"; |
|
46 | - const CIPHER_CAST_128 = "CAST-128"; |
|
47 | - const CIPHER_CAST_256 = "CAST-256"; |
|
48 | - const CIPHER_DES = "DES"; |
|
49 | - const CIPHER_ENIGMA = "Enigma"; |
|
50 | - const CIPHER_GOST = "GOST"; |
|
51 | - const CIPHER_RC2 = "RC2"; |
|
52 | - const CIPHER_RIJNDAEL_128 = "Rijndael-128"; |
|
53 | - const CIPHER_RIJNDAEL_192 = "Rijndael-192"; |
|
54 | - const CIPHER_RIJNDAEL_256 = "Rijndael-256"; |
|
55 | - const CIPHER_SKIPJACK = "Skipjack"; |
|
56 | - const CIPHER_SIMPLEXOR = "SimpleXOR"; |
|
57 | - const CIPHER_VIGENERE = "Vigenere"; // historical |
|
58 | - |
|
59 | - // Modes |
|
60 | - const MODE_CBC = "CBC"; |
|
61 | - const MODE_CFB = "CFB"; // 8 bit cfb mode |
|
62 | - const MODE_CTR = "CTR"; |
|
63 | - const MODE_ECB = "ECB"; |
|
64 | - const MODE_NCFB = "NCFB"; // blocksize cfb mode |
|
65 | - const MODE_NOFB = "NOFB"; // blocksize ofb mode |
|
66 | - const MODE_OFB = "OFB"; // 8 bit ofb mode |
|
67 | - const MODE_PCBC = "PCBC"; |
|
68 | - const MODE_RAW = "Raw"; // raw encryption, with no mode |
|
69 | - const MODE_STREAM = "Stream"; // used only for stream ciphers |
|
70 | - |
|
71 | - // The source of random data used to create keys and IV's |
|
72 | - // Used for PHP_Crypt::createKey(), PHP_Crypt::createIV() |
|
73 | - const RAND = "rand"; // uses mt_rand(), windows & unix |
|
74 | - const RAND_DEV_RAND = "/dev/random"; // unix only |
|
75 | - const RAND_DEV_URAND= "/dev/urandom";// unix only |
|
76 | - const RAND_WIN_COM = "wincom"; // windows only, COM extension |
|
77 | - const RAND_DEFAULT_SZ = 32; // the default number of bytes returned |
|
78 | - |
|
79 | - // Padding types |
|
80 | - const PAD_ZERO = 0; |
|
81 | - const PAD_ANSI_X923 = 1; |
|
82 | - const PAD_ISO_10126 = 2; |
|
83 | - const PAD_PKCS7 = 3; |
|
84 | - const PAD_ISO_7816_4 = 4; |
|
85 | - |
|
86 | - |
|
87 | - /** @type object $cipher An instance of the cipher object selected */ |
|
88 | - private $cipher = null; |
|
89 | - |
|
90 | - /** @type object $mode An instance of the mode object selected */ |
|
91 | - private $mode = null; |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Constructor |
|
96 | - * |
|
97 | - * @param string $key The key to use for the selected Cipher |
|
98 | - * @param string $cipher The type of cipher to use |
|
99 | - * @param string $mode The encrypt mode to use with the cipher |
|
100 | - * @param string $padding The padding type to use. Defaults to PAD_ZERO |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - public function __construct($key, $cipher = self::CIPHER_AES_128, $mode = self::MODE_ECB, $padding = self::PAD_ZERO) |
|
104 | - { |
|
105 | - /* |
|
38 | + // Ciphers |
|
39 | + const CIPHER_3DES = "3DES"; |
|
40 | + const CIPHER_3WAY = "3-Way"; |
|
41 | + const CIPHER_AES_128 = "AES-128"; |
|
42 | + const CIPHER_AES_192 = "AES-192"; |
|
43 | + const CIPHER_AES_256 = "AES-256"; |
|
44 | + const CIPHER_ARC4 = "ARC4"; // Alternative RC4 |
|
45 | + const CIPHER_BLOWFISH = "Blowfish"; |
|
46 | + const CIPHER_CAST_128 = "CAST-128"; |
|
47 | + const CIPHER_CAST_256 = "CAST-256"; |
|
48 | + const CIPHER_DES = "DES"; |
|
49 | + const CIPHER_ENIGMA = "Enigma"; |
|
50 | + const CIPHER_GOST = "GOST"; |
|
51 | + const CIPHER_RC2 = "RC2"; |
|
52 | + const CIPHER_RIJNDAEL_128 = "Rijndael-128"; |
|
53 | + const CIPHER_RIJNDAEL_192 = "Rijndael-192"; |
|
54 | + const CIPHER_RIJNDAEL_256 = "Rijndael-256"; |
|
55 | + const CIPHER_SKIPJACK = "Skipjack"; |
|
56 | + const CIPHER_SIMPLEXOR = "SimpleXOR"; |
|
57 | + const CIPHER_VIGENERE = "Vigenere"; // historical |
|
58 | + |
|
59 | + // Modes |
|
60 | + const MODE_CBC = "CBC"; |
|
61 | + const MODE_CFB = "CFB"; // 8 bit cfb mode |
|
62 | + const MODE_CTR = "CTR"; |
|
63 | + const MODE_ECB = "ECB"; |
|
64 | + const MODE_NCFB = "NCFB"; // blocksize cfb mode |
|
65 | + const MODE_NOFB = "NOFB"; // blocksize ofb mode |
|
66 | + const MODE_OFB = "OFB"; // 8 bit ofb mode |
|
67 | + const MODE_PCBC = "PCBC"; |
|
68 | + const MODE_RAW = "Raw"; // raw encryption, with no mode |
|
69 | + const MODE_STREAM = "Stream"; // used only for stream ciphers |
|
70 | + |
|
71 | + // The source of random data used to create keys and IV's |
|
72 | + // Used for PHP_Crypt::createKey(), PHP_Crypt::createIV() |
|
73 | + const RAND = "rand"; // uses mt_rand(), windows & unix |
|
74 | + const RAND_DEV_RAND = "/dev/random"; // unix only |
|
75 | + const RAND_DEV_URAND= "/dev/urandom";// unix only |
|
76 | + const RAND_WIN_COM = "wincom"; // windows only, COM extension |
|
77 | + const RAND_DEFAULT_SZ = 32; // the default number of bytes returned |
|
78 | + |
|
79 | + // Padding types |
|
80 | + const PAD_ZERO = 0; |
|
81 | + const PAD_ANSI_X923 = 1; |
|
82 | + const PAD_ISO_10126 = 2; |
|
83 | + const PAD_PKCS7 = 3; |
|
84 | + const PAD_ISO_7816_4 = 4; |
|
85 | + |
|
86 | + |
|
87 | + /** @type object $cipher An instance of the cipher object selected */ |
|
88 | + private $cipher = null; |
|
89 | + |
|
90 | + /** @type object $mode An instance of the mode object selected */ |
|
91 | + private $mode = null; |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Constructor |
|
96 | + * |
|
97 | + * @param string $key The key to use for the selected Cipher |
|
98 | + * @param string $cipher The type of cipher to use |
|
99 | + * @param string $mode The encrypt mode to use with the cipher |
|
100 | + * @param string $padding The padding type to use. Defaults to PAD_ZERO |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + public function __construct($key, $cipher = self::CIPHER_AES_128, $mode = self::MODE_ECB, $padding = self::PAD_ZERO) |
|
104 | + { |
|
105 | + /* |
|
106 | 106 | * CIPHERS |
107 | 107 | */ |
108 | - switch($cipher) |
|
109 | - { |
|
110 | - case self::CIPHER_3DES: |
|
111 | - $this->cipher = new Cipher_3DES($key); |
|
112 | - break; |
|
108 | + switch($cipher) |
|
109 | + { |
|
110 | + case self::CIPHER_3DES: |
|
111 | + $this->cipher = new Cipher_3DES($key); |
|
112 | + break; |
|
113 | 113 | |
114 | - case self::CIPHER_3WAY: |
|
115 | - $this->cipher = new Cipher_3WAY($key); |
|
116 | - break; |
|
114 | + case self::CIPHER_3WAY: |
|
115 | + $this->cipher = new Cipher_3WAY($key); |
|
116 | + break; |
|
117 | 117 | |
118 | - case self::CIPHER_AES_128: |
|
119 | - $this->cipher = new Cipher_AES_128($key); |
|
120 | - break; |
|
118 | + case self::CIPHER_AES_128: |
|
119 | + $this->cipher = new Cipher_AES_128($key); |
|
120 | + break; |
|
121 | 121 | |
122 | - case self::CIPHER_AES_192: |
|
123 | - $this->cipher = new Cipher_AES_192($key); |
|
124 | - break; |
|
122 | + case self::CIPHER_AES_192: |
|
123 | + $this->cipher = new Cipher_AES_192($key); |
|
124 | + break; |
|
125 | 125 | |
126 | - case self::CIPHER_AES_256: |
|
127 | - $this->cipher = new Cipher_AES_256($key); |
|
128 | - break; |
|
126 | + case self::CIPHER_AES_256: |
|
127 | + $this->cipher = new Cipher_AES_256($key); |
|
128 | + break; |
|
129 | 129 | |
130 | - case self::CIPHER_ARC4: // an alternative to RC4 |
|
131 | - $this->cipher = new Cipher_ARC4($key); |
|
132 | - break; |
|
130 | + case self::CIPHER_ARC4: // an alternative to RC4 |
|
131 | + $this->cipher = new Cipher_ARC4($key); |
|
132 | + break; |
|
133 | 133 | |
134 | - case self::CIPHER_BLOWFISH: |
|
135 | - $this->cipher = new Cipher_Blowfish($key); |
|
136 | - break; |
|
134 | + case self::CIPHER_BLOWFISH: |
|
135 | + $this->cipher = new Cipher_Blowfish($key); |
|
136 | + break; |
|
137 | 137 | |
138 | - case self::CIPHER_CAST_128: |
|
139 | - $this->cipher = new Cipher_CAST_128($key); |
|
140 | - break; |
|
138 | + case self::CIPHER_CAST_128: |
|
139 | + $this->cipher = new Cipher_CAST_128($key); |
|
140 | + break; |
|
141 | 141 | |
142 | - case self::CIPHER_CAST_256: |
|
143 | - $this->cipher = new Cipher_CAST_256($key); |
|
144 | - break; |
|
142 | + case self::CIPHER_CAST_256: |
|
143 | + $this->cipher = new Cipher_CAST_256($key); |
|
144 | + break; |
|
145 | 145 | |
146 | - case self::CIPHER_DES: |
|
147 | - $this->cipher = new Cipher_DES($key); |
|
148 | - break; |
|
146 | + case self::CIPHER_DES: |
|
147 | + $this->cipher = new Cipher_DES($key); |
|
148 | + break; |
|
149 | 149 | |
150 | - case self::CIPHER_ENIGMA: |
|
151 | - $this->cipher = new Cipher_Enigma($key); |
|
152 | - break; |
|
150 | + case self::CIPHER_ENIGMA: |
|
151 | + $this->cipher = new Cipher_Enigma($key); |
|
152 | + break; |
|
153 | 153 | |
154 | - case self::CIPHER_GOST: |
|
155 | - $this->cipher = new Cipher_GOST($key); |
|
156 | - break; |
|
154 | + case self::CIPHER_GOST: |
|
155 | + $this->cipher = new Cipher_GOST($key); |
|
156 | + break; |
|
157 | 157 | |
158 | - case self::CIPHER_RC2: |
|
159 | - $this->cipher = new Cipher_RC2($key); |
|
160 | - break; |
|
158 | + case self::CIPHER_RC2: |
|
159 | + $this->cipher = new Cipher_RC2($key); |
|
160 | + break; |
|
161 | 161 | |
162 | - case self::CIPHER_RIJNDAEL_128: |
|
163 | - $this->cipher = new Cipher_Rijndael_128($key); |
|
164 | - break; |
|
162 | + case self::CIPHER_RIJNDAEL_128: |
|
163 | + $this->cipher = new Cipher_Rijndael_128($key); |
|
164 | + break; |
|
165 | 165 | |
166 | - case self::CIPHER_RIJNDAEL_192: |
|
167 | - $this->cipher = new Cipher_Rijndael_192($key); |
|
168 | - break; |
|
166 | + case self::CIPHER_RIJNDAEL_192: |
|
167 | + $this->cipher = new Cipher_Rijndael_192($key); |
|
168 | + break; |
|
169 | 169 | |
170 | - case self::CIPHER_RIJNDAEL_256: |
|
171 | - $this->cipher = new Cipher_Rijndael_256($key); |
|
172 | - break; |
|
170 | + case self::CIPHER_RIJNDAEL_256: |
|
171 | + $this->cipher = new Cipher_Rijndael_256($key); |
|
172 | + break; |
|
173 | 173 | |
174 | - case self::CIPHER_SIMPLEXOR: |
|
175 | - $this->cipher = new Cipher_Simple_XOR($key); |
|
176 | - break; |
|
174 | + case self::CIPHER_SIMPLEXOR: |
|
175 | + $this->cipher = new Cipher_Simple_XOR($key); |
|
176 | + break; |
|
177 | 177 | |
178 | - case self::CIPHER_SKIPJACK: |
|
179 | - $this->cipher = new Cipher_Skipjack($key); |
|
180 | - break; |
|
178 | + case self::CIPHER_SKIPJACK: |
|
179 | + $this->cipher = new Cipher_Skipjack($key); |
|
180 | + break; |
|
181 | 181 | |
182 | - case self::CIPHER_VIGENERE: |
|
183 | - $this->cipher = new Cipher_Vigenere($key); |
|
184 | - break; |
|
182 | + case self::CIPHER_VIGENERE: |
|
183 | + $this->cipher = new Cipher_Vigenere($key); |
|
184 | + break; |
|
185 | 185 | |
186 | - default: |
|
187 | - trigger_error("$cipher is not a valid cipher", E_USER_WARNING); |
|
188 | - } |
|
186 | + default: |
|
187 | + trigger_error("$cipher is not a valid cipher", E_USER_WARNING); |
|
188 | + } |
|
189 | 189 | |
190 | 190 | |
191 | - /* |
|
191 | + /* |
|
192 | 192 | * MODES |
193 | 193 | */ |
194 | - switch($mode) |
|
195 | - { |
|
196 | - case self::MODE_CBC: |
|
197 | - $this->mode = new Mode_CBC($this->cipher); |
|
198 | - break; |
|
199 | - |
|
200 | - case self::MODE_CFB: |
|
201 | - $this->mode = new Mode_CFB($this->cipher); |
|
202 | - break; |
|
203 | - |
|
204 | - case self::MODE_CTR: |
|
205 | - $this->mode = new Mode_CTR($this->cipher); |
|
206 | - break; |
|
207 | - |
|
208 | - case self::MODE_ECB: |
|
209 | - $this->mode = new Mode_ECB($this->cipher); |
|
210 | - break; |
|
211 | - |
|
212 | - case self::MODE_NCFB: |
|
213 | - $this->mode = new Mode_NCFB($this->cipher); |
|
214 | - break; |
|
215 | - |
|
216 | - case self::MODE_NOFB: |
|
217 | - $this->mode = new Mode_NOFB($this->cipher); |
|
218 | - break; |
|
219 | - |
|
220 | - case self::MODE_OFB: |
|
221 | - $this->mode = new Mode_OFB($this->cipher); |
|
222 | - break; |
|
223 | - |
|
224 | - case self::MODE_PCBC: |
|
225 | - $this->mode = new Mode_PCBC($this->cipher); |
|
226 | - break; |
|
227 | - |
|
228 | - case self::MODE_RAW: |
|
229 | - $this->mode = new Mode_RAW($this->cipher); |
|
230 | - break; |
|
231 | - |
|
232 | - case self::MODE_STREAM: |
|
233 | - $this->mode = new Mode_Stream($this->cipher); |
|
234 | - break; |
|
235 | - |
|
236 | - default: |
|
237 | - trigger_error("$mode is not a valid mode", E_USER_WARNING); |
|
238 | - } |
|
239 | - |
|
240 | - // set the default padding |
|
241 | - $this->padding($padding); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Destructor |
|
247 | - * |
|
248 | - * @return void |
|
249 | - */ |
|
250 | - public function __destruct() |
|
251 | - { |
|
252 | - |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * Encrypt a plain text message using the Mode and Cipher selected. |
|
258 | - * Some stream modes require this function to be called in a loop |
|
259 | - * which requires the use of $result parameter to retrieve |
|
260 | - * the decrypted data. |
|
261 | - * |
|
262 | - * @param string $text The plain text string |
|
263 | - * @return string The encrypted string |
|
264 | - */ |
|
265 | - public function encrypt($text) |
|
266 | - { |
|
267 | - // check that an iv is set, if required by the mode |
|
268 | - $this->mode->checkIV(); |
|
269 | - |
|
270 | - // the encryption is done inside the mode |
|
271 | - $this->mode->encrypt($text); |
|
272 | - return $text; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Decrypt an encrypted message using the Mode and Cipher selected. |
|
278 | - * Some stream modes require this function to be called in a loop |
|
279 | - * which requires the use of $result parameter to retrieve |
|
280 | - * the decrypted data. |
|
281 | - * |
|
282 | - * @param string $text The encrypted string |
|
283 | - * @return string The decrypted string |
|
284 | - */ |
|
285 | - public function decrypt($text) |
|
286 | - { |
|
287 | - // check that an iv is set, if required by the mode |
|
288 | - $this->mode->checkIV(); |
|
289 | - |
|
290 | - // the decryption is done inside the mode |
|
291 | - $this->mode->decrypt($text); |
|
292 | - return $text; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Return the cipher object being used |
|
298 | - * |
|
299 | - * @return object The Cipher object |
|
300 | - */ |
|
301 | - public function cipher() |
|
302 | - { |
|
303 | - return $this->cipher; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Return the mode object being used |
|
309 | - * |
|
310 | - * @return object The Mode object |
|
311 | - */ |
|
312 | - public function mode() |
|
313 | - { |
|
314 | - return $this->mode; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Returns the name of the cipher being used |
|
320 | - * |
|
321 | - * @return string The name of the cipher currently in use, |
|
322 | - * it will be one of the predefined phpCrypt cipher constants |
|
323 | - */ |
|
324 | - public function cipherName() |
|
325 | - { |
|
326 | - return $this->cipher->name(); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Return the name of the mode being used |
|
332 | - * |
|
333 | - * @return string The name of the mode in use, it will |
|
334 | - * be one of the predefined phpCrypt mode constants |
|
335 | - */ |
|
336 | - public function modeName() |
|
337 | - { |
|
338 | - return $this->mode->name(); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * Returns Ciphers required block size in bytes |
|
344 | - * |
|
345 | - * @return integer The cipher data block size, in bytes |
|
346 | - */ |
|
347 | - public function cipherBlockSize() |
|
348 | - { |
|
349 | - return $this->cipher->blockSize(); |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * Returns the cipher's required key size, in bytes |
|
355 | - * |
|
356 | - * @return integer The cipher's key size requirement, in bytes |
|
357 | - */ |
|
358 | - public function cipherKeySize() |
|
359 | - { |
|
360 | - return $this->cipher->keySize(); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * Sets and/or returns the key to be used. Normally you set |
|
366 | - * the key in the phpCrypt constructor. This can be usefully |
|
367 | - * if you need to change the key on the fly and don't want |
|
368 | - * to create a new instance of phpCrypt. |
|
369 | - * |
|
370 | - * If the $key parameter is not given, this function will simply |
|
371 | - * return the key currently in use. |
|
372 | - * |
|
373 | - * @param string $key Optional, The key to set |
|
374 | - * @return string The key being used |
|
375 | - */ |
|
376 | - public function cipherKey($key = "") |
|
377 | - { |
|
378 | - return $this->cipher->key($key); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * A helper function which will create a random key. Calls |
|
384 | - * Core::randBytes(). By default it will use PHP_Crypt::RAND for |
|
385 | - * the random source of bytes, and return a PHP_Crypt::RAND_DEFAULT_SZ |
|
386 | - * byte string. There are 4 ways to create a random byte string by |
|
387 | - * setting the $src parameter: |
|
388 | - * PHP_Crypt::RAND - Default, uses mt_rand() |
|
389 | - * PHP_Crypt::RAND_DEV_RAND - Unix only, uses /dev/random |
|
390 | - * PHP_Crypt::RAND_DEV_URAND - Unix only, uses /dev/urandom |
|
391 | - * PHP_Crypt::RAND_WIN_COM - Windows only, uses Microsoft's CAPICOM SDK |
|
392 | - * |
|
393 | - * @param string $src Optional, The source to use to create random bytes |
|
394 | - * @param integer $len Optional, The number of random bytes to return |
|
395 | - * @return string A random string of bytes |
|
396 | - */ |
|
397 | - public static function createKey($src = self::RAND, $len = self::RAND_DEFAULT_SZ) |
|
398 | - { |
|
399 | - return Core::randBytes($src, $len); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * Sets the IV to use. Note that you do not need to call |
|
405 | - * this function if creating an IV using createIV(). This |
|
406 | - * function is used when an IV has already been created |
|
407 | - * outside of phpCrypt and needs to be set. Alternatively |
|
408 | - * you can just pass the $iv parameter to the encrypt() |
|
409 | - * or decrypt() functions |
|
410 | - * |
|
411 | - * When the $iv parameter is not given, the function will |
|
412 | - * return the current IV being used. See createIV() if you |
|
413 | - * need to create an IV. |
|
414 | - * |
|
415 | - * @param string $iv Optional, The IV to use during Encryption/Decryption |
|
416 | - * @return void |
|
417 | - */ |
|
418 | - public function IV($iv = "") |
|
419 | - { |
|
420 | - return $this->mode->IV($iv); |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Creates an IV for the the Cipher selected, if one is required. |
|
426 | - * If you already have an IV to use, this function does not need |
|
427 | - * to be called, instead set it with setIV(). If you create an |
|
428 | - * IV with createIV(), you do not need to set it with setIV(), |
|
429 | - * as it is automatically set in this function |
|
430 | - * |
|
431 | - * $src values are: |
|
432 | - * PHP_Crypt::RAND - Default, uses mt_rand() |
|
433 | - * PHP_Crypt::RAND_DEV_RAND - Unix only, uses /dev/random |
|
434 | - * PHP_Crypt::RAND_DEV_URAND - Unix only, uses /dev/urandom |
|
435 | - * PHP_Crypt::RAND_WIN_COM - Windows only, uses Microsoft's CAPICOM SDK |
|
436 | - * |
|
437 | - * @param string $src Optional, how the IV is generated |
|
438 | - * @return string The IV that was created, and set for the mode |
|
439 | - */ |
|
440 | - public function createIV($src = self::RAND) |
|
441 | - { |
|
442 | - return $this->mode->createIV($src); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * Sets the type of padding to be used within the specified Mode |
|
448 | - * |
|
449 | - * @param string $type One of the predefined padding types |
|
450 | - * @return void |
|
451 | - */ |
|
452 | - public function padding($type = "") |
|
453 | - { |
|
454 | - return $this->mode->padding($type); |
|
455 | - } |
|
194 | + switch($mode) |
|
195 | + { |
|
196 | + case self::MODE_CBC: |
|
197 | + $this->mode = new Mode_CBC($this->cipher); |
|
198 | + break; |
|
199 | + |
|
200 | + case self::MODE_CFB: |
|
201 | + $this->mode = new Mode_CFB($this->cipher); |
|
202 | + break; |
|
203 | + |
|
204 | + case self::MODE_CTR: |
|
205 | + $this->mode = new Mode_CTR($this->cipher); |
|
206 | + break; |
|
207 | + |
|
208 | + case self::MODE_ECB: |
|
209 | + $this->mode = new Mode_ECB($this->cipher); |
|
210 | + break; |
|
211 | + |
|
212 | + case self::MODE_NCFB: |
|
213 | + $this->mode = new Mode_NCFB($this->cipher); |
|
214 | + break; |
|
215 | + |
|
216 | + case self::MODE_NOFB: |
|
217 | + $this->mode = new Mode_NOFB($this->cipher); |
|
218 | + break; |
|
219 | + |
|
220 | + case self::MODE_OFB: |
|
221 | + $this->mode = new Mode_OFB($this->cipher); |
|
222 | + break; |
|
223 | + |
|
224 | + case self::MODE_PCBC: |
|
225 | + $this->mode = new Mode_PCBC($this->cipher); |
|
226 | + break; |
|
227 | + |
|
228 | + case self::MODE_RAW: |
|
229 | + $this->mode = new Mode_RAW($this->cipher); |
|
230 | + break; |
|
231 | + |
|
232 | + case self::MODE_STREAM: |
|
233 | + $this->mode = new Mode_Stream($this->cipher); |
|
234 | + break; |
|
235 | + |
|
236 | + default: |
|
237 | + trigger_error("$mode is not a valid mode", E_USER_WARNING); |
|
238 | + } |
|
239 | + |
|
240 | + // set the default padding |
|
241 | + $this->padding($padding); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Destructor |
|
247 | + * |
|
248 | + * @return void |
|
249 | + */ |
|
250 | + public function __destruct() |
|
251 | + { |
|
252 | + |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * Encrypt a plain text message using the Mode and Cipher selected. |
|
258 | + * Some stream modes require this function to be called in a loop |
|
259 | + * which requires the use of $result parameter to retrieve |
|
260 | + * the decrypted data. |
|
261 | + * |
|
262 | + * @param string $text The plain text string |
|
263 | + * @return string The encrypted string |
|
264 | + */ |
|
265 | + public function encrypt($text) |
|
266 | + { |
|
267 | + // check that an iv is set, if required by the mode |
|
268 | + $this->mode->checkIV(); |
|
269 | + |
|
270 | + // the encryption is done inside the mode |
|
271 | + $this->mode->encrypt($text); |
|
272 | + return $text; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Decrypt an encrypted message using the Mode and Cipher selected. |
|
278 | + * Some stream modes require this function to be called in a loop |
|
279 | + * which requires the use of $result parameter to retrieve |
|
280 | + * the decrypted data. |
|
281 | + * |
|
282 | + * @param string $text The encrypted string |
|
283 | + * @return string The decrypted string |
|
284 | + */ |
|
285 | + public function decrypt($text) |
|
286 | + { |
|
287 | + // check that an iv is set, if required by the mode |
|
288 | + $this->mode->checkIV(); |
|
289 | + |
|
290 | + // the decryption is done inside the mode |
|
291 | + $this->mode->decrypt($text); |
|
292 | + return $text; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Return the cipher object being used |
|
298 | + * |
|
299 | + * @return object The Cipher object |
|
300 | + */ |
|
301 | + public function cipher() |
|
302 | + { |
|
303 | + return $this->cipher; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Return the mode object being used |
|
309 | + * |
|
310 | + * @return object The Mode object |
|
311 | + */ |
|
312 | + public function mode() |
|
313 | + { |
|
314 | + return $this->mode; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Returns the name of the cipher being used |
|
320 | + * |
|
321 | + * @return string The name of the cipher currently in use, |
|
322 | + * it will be one of the predefined phpCrypt cipher constants |
|
323 | + */ |
|
324 | + public function cipherName() |
|
325 | + { |
|
326 | + return $this->cipher->name(); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Return the name of the mode being used |
|
332 | + * |
|
333 | + * @return string The name of the mode in use, it will |
|
334 | + * be one of the predefined phpCrypt mode constants |
|
335 | + */ |
|
336 | + public function modeName() |
|
337 | + { |
|
338 | + return $this->mode->name(); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * Returns Ciphers required block size in bytes |
|
344 | + * |
|
345 | + * @return integer The cipher data block size, in bytes |
|
346 | + */ |
|
347 | + public function cipherBlockSize() |
|
348 | + { |
|
349 | + return $this->cipher->blockSize(); |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * Returns the cipher's required key size, in bytes |
|
355 | + * |
|
356 | + * @return integer The cipher's key size requirement, in bytes |
|
357 | + */ |
|
358 | + public function cipherKeySize() |
|
359 | + { |
|
360 | + return $this->cipher->keySize(); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * Sets and/or returns the key to be used. Normally you set |
|
366 | + * the key in the phpCrypt constructor. This can be usefully |
|
367 | + * if you need to change the key on the fly and don't want |
|
368 | + * to create a new instance of phpCrypt. |
|
369 | + * |
|
370 | + * If the $key parameter is not given, this function will simply |
|
371 | + * return the key currently in use. |
|
372 | + * |
|
373 | + * @param string $key Optional, The key to set |
|
374 | + * @return string The key being used |
|
375 | + */ |
|
376 | + public function cipherKey($key = "") |
|
377 | + { |
|
378 | + return $this->cipher->key($key); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * A helper function which will create a random key. Calls |
|
384 | + * Core::randBytes(). By default it will use PHP_Crypt::RAND for |
|
385 | + * the random source of bytes, and return a PHP_Crypt::RAND_DEFAULT_SZ |
|
386 | + * byte string. There are 4 ways to create a random byte string by |
|
387 | + * setting the $src parameter: |
|
388 | + * PHP_Crypt::RAND - Default, uses mt_rand() |
|
389 | + * PHP_Crypt::RAND_DEV_RAND - Unix only, uses /dev/random |
|
390 | + * PHP_Crypt::RAND_DEV_URAND - Unix only, uses /dev/urandom |
|
391 | + * PHP_Crypt::RAND_WIN_COM - Windows only, uses Microsoft's CAPICOM SDK |
|
392 | + * |
|
393 | + * @param string $src Optional, The source to use to create random bytes |
|
394 | + * @param integer $len Optional, The number of random bytes to return |
|
395 | + * @return string A random string of bytes |
|
396 | + */ |
|
397 | + public static function createKey($src = self::RAND, $len = self::RAND_DEFAULT_SZ) |
|
398 | + { |
|
399 | + return Core::randBytes($src, $len); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * Sets the IV to use. Note that you do not need to call |
|
405 | + * this function if creating an IV using createIV(). This |
|
406 | + * function is used when an IV has already been created |
|
407 | + * outside of phpCrypt and needs to be set. Alternatively |
|
408 | + * you can just pass the $iv parameter to the encrypt() |
|
409 | + * or decrypt() functions |
|
410 | + * |
|
411 | + * When the $iv parameter is not given, the function will |
|
412 | + * return the current IV being used. See createIV() if you |
|
413 | + * need to create an IV. |
|
414 | + * |
|
415 | + * @param string $iv Optional, The IV to use during Encryption/Decryption |
|
416 | + * @return void |
|
417 | + */ |
|
418 | + public function IV($iv = "") |
|
419 | + { |
|
420 | + return $this->mode->IV($iv); |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Creates an IV for the the Cipher selected, if one is required. |
|
426 | + * If you already have an IV to use, this function does not need |
|
427 | + * to be called, instead set it with setIV(). If you create an |
|
428 | + * IV with createIV(), you do not need to set it with setIV(), |
|
429 | + * as it is automatically set in this function |
|
430 | + * |
|
431 | + * $src values are: |
|
432 | + * PHP_Crypt::RAND - Default, uses mt_rand() |
|
433 | + * PHP_Crypt::RAND_DEV_RAND - Unix only, uses /dev/random |
|
434 | + * PHP_Crypt::RAND_DEV_URAND - Unix only, uses /dev/urandom |
|
435 | + * PHP_Crypt::RAND_WIN_COM - Windows only, uses Microsoft's CAPICOM SDK |
|
436 | + * |
|
437 | + * @param string $src Optional, how the IV is generated |
|
438 | + * @return string The IV that was created, and set for the mode |
|
439 | + */ |
|
440 | + public function createIV($src = self::RAND) |
|
441 | + { |
|
442 | + return $this->mode->createIV($src); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * Sets the type of padding to be used within the specified Mode |
|
448 | + * |
|
449 | + * @param string $type One of the predefined padding types |
|
450 | + * @return void |
|
451 | + */ |
|
452 | + public function padding($type = "") |
|
453 | + { |
|
454 | + return $this->mode->padding($type); |
|
455 | + } |
|
456 | 456 | } |
457 | 457 | ?> |
@@ -107,84 +107,84 @@ discard block |
||
107 | 107 | */ |
108 | 108 | switch($cipher) |
109 | 109 | { |
110 | - case self::CIPHER_3DES: |
|
111 | - $this->cipher = new Cipher_3DES($key); |
|
112 | - break; |
|
110 | + case self::CIPHER_3DES: |
|
111 | + $this->cipher = new Cipher_3DES($key); |
|
112 | + break; |
|
113 | 113 | |
114 | - case self::CIPHER_3WAY: |
|
115 | - $this->cipher = new Cipher_3WAY($key); |
|
116 | - break; |
|
114 | + case self::CIPHER_3WAY: |
|
115 | + $this->cipher = new Cipher_3WAY($key); |
|
116 | + break; |
|
117 | 117 | |
118 | - case self::CIPHER_AES_128: |
|
119 | - $this->cipher = new Cipher_AES_128($key); |
|
120 | - break; |
|
118 | + case self::CIPHER_AES_128: |
|
119 | + $this->cipher = new Cipher_AES_128($key); |
|
120 | + break; |
|
121 | 121 | |
122 | - case self::CIPHER_AES_192: |
|
123 | - $this->cipher = new Cipher_AES_192($key); |
|
124 | - break; |
|
122 | + case self::CIPHER_AES_192: |
|
123 | + $this->cipher = new Cipher_AES_192($key); |
|
124 | + break; |
|
125 | 125 | |
126 | - case self::CIPHER_AES_256: |
|
127 | - $this->cipher = new Cipher_AES_256($key); |
|
128 | - break; |
|
126 | + case self::CIPHER_AES_256: |
|
127 | + $this->cipher = new Cipher_AES_256($key); |
|
128 | + break; |
|
129 | 129 | |
130 | - case self::CIPHER_ARC4: // an alternative to RC4 |
|
131 | - $this->cipher = new Cipher_ARC4($key); |
|
132 | - break; |
|
130 | + case self::CIPHER_ARC4: // an alternative to RC4 |
|
131 | + $this->cipher = new Cipher_ARC4($key); |
|
132 | + break; |
|
133 | 133 | |
134 | - case self::CIPHER_BLOWFISH: |
|
135 | - $this->cipher = new Cipher_Blowfish($key); |
|
136 | - break; |
|
134 | + case self::CIPHER_BLOWFISH: |
|
135 | + $this->cipher = new Cipher_Blowfish($key); |
|
136 | + break; |
|
137 | 137 | |
138 | - case self::CIPHER_CAST_128: |
|
139 | - $this->cipher = new Cipher_CAST_128($key); |
|
140 | - break; |
|
138 | + case self::CIPHER_CAST_128: |
|
139 | + $this->cipher = new Cipher_CAST_128($key); |
|
140 | + break; |
|
141 | 141 | |
142 | - case self::CIPHER_CAST_256: |
|
143 | - $this->cipher = new Cipher_CAST_256($key); |
|
144 | - break; |
|
142 | + case self::CIPHER_CAST_256: |
|
143 | + $this->cipher = new Cipher_CAST_256($key); |
|
144 | + break; |
|
145 | 145 | |
146 | - case self::CIPHER_DES: |
|
147 | - $this->cipher = new Cipher_DES($key); |
|
148 | - break; |
|
146 | + case self::CIPHER_DES: |
|
147 | + $this->cipher = new Cipher_DES($key); |
|
148 | + break; |
|
149 | 149 | |
150 | - case self::CIPHER_ENIGMA: |
|
151 | - $this->cipher = new Cipher_Enigma($key); |
|
152 | - break; |
|
150 | + case self::CIPHER_ENIGMA: |
|
151 | + $this->cipher = new Cipher_Enigma($key); |
|
152 | + break; |
|
153 | 153 | |
154 | - case self::CIPHER_GOST: |
|
155 | - $this->cipher = new Cipher_GOST($key); |
|
156 | - break; |
|
154 | + case self::CIPHER_GOST: |
|
155 | + $this->cipher = new Cipher_GOST($key); |
|
156 | + break; |
|
157 | 157 | |
158 | - case self::CIPHER_RC2: |
|
159 | - $this->cipher = new Cipher_RC2($key); |
|
160 | - break; |
|
158 | + case self::CIPHER_RC2: |
|
159 | + $this->cipher = new Cipher_RC2($key); |
|
160 | + break; |
|
161 | 161 | |
162 | - case self::CIPHER_RIJNDAEL_128: |
|
163 | - $this->cipher = new Cipher_Rijndael_128($key); |
|
164 | - break; |
|
162 | + case self::CIPHER_RIJNDAEL_128: |
|
163 | + $this->cipher = new Cipher_Rijndael_128($key); |
|
164 | + break; |
|
165 | 165 | |
166 | - case self::CIPHER_RIJNDAEL_192: |
|
167 | - $this->cipher = new Cipher_Rijndael_192($key); |
|
168 | - break; |
|
166 | + case self::CIPHER_RIJNDAEL_192: |
|
167 | + $this->cipher = new Cipher_Rijndael_192($key); |
|
168 | + break; |
|
169 | 169 | |
170 | - case self::CIPHER_RIJNDAEL_256: |
|
171 | - $this->cipher = new Cipher_Rijndael_256($key); |
|
172 | - break; |
|
170 | + case self::CIPHER_RIJNDAEL_256: |
|
171 | + $this->cipher = new Cipher_Rijndael_256($key); |
|
172 | + break; |
|
173 | 173 | |
174 | - case self::CIPHER_SIMPLEXOR: |
|
175 | - $this->cipher = new Cipher_Simple_XOR($key); |
|
176 | - break; |
|
174 | + case self::CIPHER_SIMPLEXOR: |
|
175 | + $this->cipher = new Cipher_Simple_XOR($key); |
|
176 | + break; |
|
177 | 177 | |
178 | - case self::CIPHER_SKIPJACK: |
|
179 | - $this->cipher = new Cipher_Skipjack($key); |
|
180 | - break; |
|
178 | + case self::CIPHER_SKIPJACK: |
|
179 | + $this->cipher = new Cipher_Skipjack($key); |
|
180 | + break; |
|
181 | 181 | |
182 | - case self::CIPHER_VIGENERE: |
|
183 | - $this->cipher = new Cipher_Vigenere($key); |
|
184 | - break; |
|
182 | + case self::CIPHER_VIGENERE: |
|
183 | + $this->cipher = new Cipher_Vigenere($key); |
|
184 | + break; |
|
185 | 185 | |
186 | - default: |
|
187 | - trigger_error("$cipher is not a valid cipher", E_USER_WARNING); |
|
186 | + default: |
|
187 | + trigger_error("$cipher is not a valid cipher", E_USER_WARNING); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | |
@@ -193,48 +193,48 @@ discard block |
||
193 | 193 | */ |
194 | 194 | switch($mode) |
195 | 195 | { |
196 | - case self::MODE_CBC: |
|
197 | - $this->mode = new Mode_CBC($this->cipher); |
|
198 | - break; |
|
196 | + case self::MODE_CBC: |
|
197 | + $this->mode = new Mode_CBC($this->cipher); |
|
198 | + break; |
|
199 | 199 | |
200 | - case self::MODE_CFB: |
|
201 | - $this->mode = new Mode_CFB($this->cipher); |
|
202 | - break; |
|
200 | + case self::MODE_CFB: |
|
201 | + $this->mode = new Mode_CFB($this->cipher); |
|
202 | + break; |
|
203 | 203 | |
204 | - case self::MODE_CTR: |
|
205 | - $this->mode = new Mode_CTR($this->cipher); |
|
206 | - break; |
|
204 | + case self::MODE_CTR: |
|
205 | + $this->mode = new Mode_CTR($this->cipher); |
|
206 | + break; |
|
207 | 207 | |
208 | - case self::MODE_ECB: |
|
209 | - $this->mode = new Mode_ECB($this->cipher); |
|
210 | - break; |
|
208 | + case self::MODE_ECB: |
|
209 | + $this->mode = new Mode_ECB($this->cipher); |
|
210 | + break; |
|
211 | 211 | |
212 | - case self::MODE_NCFB: |
|
213 | - $this->mode = new Mode_NCFB($this->cipher); |
|
214 | - break; |
|
212 | + case self::MODE_NCFB: |
|
213 | + $this->mode = new Mode_NCFB($this->cipher); |
|
214 | + break; |
|
215 | 215 | |
216 | - case self::MODE_NOFB: |
|
217 | - $this->mode = new Mode_NOFB($this->cipher); |
|
218 | - break; |
|
216 | + case self::MODE_NOFB: |
|
217 | + $this->mode = new Mode_NOFB($this->cipher); |
|
218 | + break; |
|
219 | 219 | |
220 | - case self::MODE_OFB: |
|
221 | - $this->mode = new Mode_OFB($this->cipher); |
|
222 | - break; |
|
220 | + case self::MODE_OFB: |
|
221 | + $this->mode = new Mode_OFB($this->cipher); |
|
222 | + break; |
|
223 | 223 | |
224 | - case self::MODE_PCBC: |
|
225 | - $this->mode = new Mode_PCBC($this->cipher); |
|
226 | - break; |
|
224 | + case self::MODE_PCBC: |
|
225 | + $this->mode = new Mode_PCBC($this->cipher); |
|
226 | + break; |
|
227 | 227 | |
228 | - case self::MODE_RAW: |
|
229 | - $this->mode = new Mode_RAW($this->cipher); |
|
230 | - break; |
|
228 | + case self::MODE_RAW: |
|
229 | + $this->mode = new Mode_RAW($this->cipher); |
|
230 | + break; |
|
231 | 231 | |
232 | - case self::MODE_STREAM: |
|
233 | - $this->mode = new Mode_Stream($this->cipher); |
|
234 | - break; |
|
232 | + case self::MODE_STREAM: |
|
233 | + $this->mode = new Mode_Stream($this->cipher); |
|
234 | + break; |
|
235 | 235 | |
236 | - default: |
|
237 | - trigger_error("$mode is not a valid mode", E_USER_WARNING); |
|
236 | + default: |
|
237 | + trigger_error("$mode is not a valid mode", E_USER_WARNING); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | // set the default padding |
@@ -41,46 +41,46 @@ discard block |
||
41 | 41 | const CIPHER_AES_128 = "AES-128"; |
42 | 42 | const CIPHER_AES_192 = "AES-192"; |
43 | 43 | const CIPHER_AES_256 = "AES-256"; |
44 | - const CIPHER_ARC4 = "ARC4"; // Alternative RC4 |
|
44 | + const CIPHER_ARC4 = "ARC4"; // Alternative RC4 |
|
45 | 45 | const CIPHER_BLOWFISH = "Blowfish"; |
46 | 46 | const CIPHER_CAST_128 = "CAST-128"; |
47 | 47 | const CIPHER_CAST_256 = "CAST-256"; |
48 | 48 | const CIPHER_DES = "DES"; |
49 | - const CIPHER_ENIGMA = "Enigma"; |
|
50 | - const CIPHER_GOST = "GOST"; |
|
49 | + const CIPHER_ENIGMA = "Enigma"; |
|
50 | + const CIPHER_GOST = "GOST"; |
|
51 | 51 | const CIPHER_RC2 = "RC2"; |
52 | 52 | const CIPHER_RIJNDAEL_128 = "Rijndael-128"; |
53 | 53 | const CIPHER_RIJNDAEL_192 = "Rijndael-192"; |
54 | 54 | const CIPHER_RIJNDAEL_256 = "Rijndael-256"; |
55 | 55 | const CIPHER_SKIPJACK = "Skipjack"; |
56 | - const CIPHER_SIMPLEXOR = "SimpleXOR"; |
|
56 | + const CIPHER_SIMPLEXOR = "SimpleXOR"; |
|
57 | 57 | const CIPHER_VIGENERE = "Vigenere"; // historical |
58 | 58 | |
59 | 59 | // Modes |
60 | 60 | const MODE_CBC = "CBC"; |
61 | - const MODE_CFB = "CFB"; // 8 bit cfb mode |
|
61 | + const MODE_CFB = "CFB"; // 8 bit cfb mode |
|
62 | 62 | const MODE_CTR = "CTR"; |
63 | 63 | const MODE_ECB = "ECB"; |
64 | 64 | const MODE_NCFB = "NCFB"; // blocksize cfb mode |
65 | 65 | const MODE_NOFB = "NOFB"; // blocksize ofb mode |
66 | - const MODE_OFB = "OFB"; // 8 bit ofb mode |
|
66 | + const MODE_OFB = "OFB"; // 8 bit ofb mode |
|
67 | 67 | const MODE_PCBC = "PCBC"; |
68 | - const MODE_RAW = "Raw"; // raw encryption, with no mode |
|
68 | + const MODE_RAW = "Raw"; // raw encryption, with no mode |
|
69 | 69 | const MODE_STREAM = "Stream"; // used only for stream ciphers |
70 | 70 | |
71 | 71 | // The source of random data used to create keys and IV's |
72 | 72 | // Used for PHP_Crypt::createKey(), PHP_Crypt::createIV() |
73 | - const RAND = "rand"; // uses mt_rand(), windows & unix |
|
73 | + const RAND = "rand"; // uses mt_rand(), windows & unix |
|
74 | 74 | const RAND_DEV_RAND = "/dev/random"; // unix only |
75 | - const RAND_DEV_URAND= "/dev/urandom";// unix only |
|
76 | - const RAND_WIN_COM = "wincom"; // windows only, COM extension |
|
77 | - const RAND_DEFAULT_SZ = 32; // the default number of bytes returned |
|
75 | + const RAND_DEV_URAND = "/dev/urandom"; // unix only |
|
76 | + const RAND_WIN_COM = "wincom"; // windows only, COM extension |
|
77 | + const RAND_DEFAULT_SZ = 32; // the default number of bytes returned |
|
78 | 78 | |
79 | 79 | // Padding types |
80 | - const PAD_ZERO = 0; |
|
80 | + const PAD_ZERO = 0; |
|
81 | 81 | const PAD_ANSI_X923 = 1; |
82 | 82 | const PAD_ISO_10126 = 2; |
83 | - const PAD_PKCS7 = 3; |
|
83 | + const PAD_PKCS7 = 3; |
|
84 | 84 | const PAD_ISO_7816_4 = 4; |
85 | 85 | |
86 | 86 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | /* |
106 | 106 | * CIPHERS |
107 | 107 | */ |
108 | - switch($cipher) |
|
108 | + switch ($cipher) |
|
109 | 109 | { |
110 | 110 | case self::CIPHER_3DES: |
111 | 111 | $this->cipher = new Cipher_3DES($key); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | /* |
192 | 192 | * MODES |
193 | 193 | */ |
194 | - switch($mode) |
|
194 | + switch ($mode) |
|
195 | 195 | { |
196 | 196 | case self::MODE_CBC: |
197 | 197 | $this->mode = new Mode_CBC($this->cipher); |
@@ -443,6 +443,7 @@ |
||
443 | 443 | * @param int $id The ID of the current node to process |
444 | 444 | * @param int $level The nlevel to assign to the current node |
445 | 445 | * @param int &$n A reference to the running tally for the n-value |
446 | + * @param integer $n |
|
446 | 447 | */ |
447 | 448 | public function generateTreeData(&$arr, $id, $level, &$n) |
448 | 449 | { |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | $this->table = $table; |
36 | 36 | |
37 | 37 | $this->fields = array('id' => $idField, |
38 | - 'parent' => $parentField, |
|
39 | - 'sort' => $sortField |
|
38 | + 'parent' => $parentField, |
|
39 | + 'sort' => $sortField |
|
40 | 40 | ); |
41 | 41 | } |
42 | 42 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | public function getFields() |
50 | 50 | { |
51 | 51 | return array($this->fields['id'], $this->fields['parent'], $this->fields['sort'], |
52 | - 'nleft', 'nright', 'nlevel', 'personal_folder', 'renewal_period', 'bloquer_modification', 'bloquer_creation'); |
|
52 | + 'nleft', 'nright', 'nlevel', 'personal_folder', 'renewal_period', 'bloquer_modification', 'bloquer_creation'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -356,12 +356,12 @@ discard block |
||
356 | 356 | $idField = $this->fields['id']; |
357 | 357 | $parentField = $this->fields['parent']; |
358 | 358 | |
359 | - $query = sprintf( |
|
360 | - 'select %s from %s order by %s', |
|
361 | - join(',', $this->getFields()), |
|
362 | - $this->table, |
|
363 | - $this->fields['sort'] |
|
364 | - ); |
|
359 | + $query = sprintf( |
|
360 | + 'select %s from %s order by %s', |
|
361 | + join(',', $this->getFields()), |
|
362 | + $this->table, |
|
363 | + $this->fields['sort'] |
|
364 | + ); |
|
365 | 365 | |
366 | 366 | $result = mysqli_query($link, $query); |
367 | 367 |
@@ -50,6 +50,7 @@ |
||
50 | 50 | * genHash() |
51 | 51 | * |
52 | 52 | * Generate a hash for user login |
53 | + * @param string $password |
|
53 | 54 | */ |
54 | 55 | function bCrypt($password, $cost) |
55 | 56 | { |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | function chmod_r($dir, $dirPermissions, $filePermissions) { |
23 | 23 | $dp = opendir($dir); |
24 | 24 | $res = true; |
25 | - while($file = readdir($dp)) { |
|
25 | + while ($file = readdir($dp)) { |
|
26 | 26 | if (($file == ".") || ($file == "..")) |
27 | 27 | continue; |
28 | 28 | |
29 | 29 | $fullPath = $dir."/".$file; |
30 | 30 | |
31 | - if(is_dir($fullPath)) { |
|
31 | + if (is_dir($fullPath)) { |
|
32 | 32 | if ($res = @chmod($fullPath, $dirPermissions)) |
33 | 33 | $res = @chmod_r($fullPath, $dirPermissions, $filePermissions); |
34 | 34 | } else { |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | if (function_exists('openssl_random_pseudo_bytes')) { |
58 | 58 | $salt .= bin2hex(openssl_random_pseudo_bytes(11)); |
59 | 59 | } else { |
60 | - $chars='./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
61 | - for ($i=0; $i<22; $i++) { |
|
62 | - $salt.=$chars[mt_rand(0, 63)]; |
|
60 | + $chars = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
61 | + for ($i = 0; $i < 22; $i++) { |
|
62 | + $salt .= $chars[mt_rand(0, 63)]; |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | return crypt($password, $salt); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | switch ($_POST['type']) { |
70 | 70 | case "step_2": |
71 | 71 | //decrypt |
72 | - require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
72 | + require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
73 | 73 | $json = Encryption\Crypt\aesctr::decrypt($_POST['data'], "cpm", 128); |
74 | 74 | $data = json_decode($json, true); |
75 | 75 | $json = Encryption\Crypt\aesctr::decrypt($_POST['activity'], "cpm", 128); |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | $data = array_merge($data, array("task" => $json)); |
79 | 79 | |
80 | 80 | $abspath = str_replace('\\', '/', $data['root_path']); |
81 | - if (substr($abspath, strlen($abspath)-1) == "/") { |
|
82 | - $abspath = substr($abspath, 0, strlen($abspath)-1); |
|
81 | + if (substr($abspath, strlen($abspath) - 1) == "/") { |
|
82 | + $abspath = substr($abspath, 0, strlen($abspath) - 1); |
|
83 | 83 | } |
84 | 84 | $_SESSION['abspath'] = $abspath; |
85 | 85 | $_SESSION['url_path'] = $data['url_path']; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | if (isset($data['activity']) && $data['activity'] == "ini") { |
124 | - if (ini_get($data['task'])>=60) { |
|
124 | + if (ini_get($data['task']) >= 60) { |
|
125 | 125 | echo '[{"error" : "", "index" : "'.$_POST['index'].'"}]'; |
126 | 126 | } else { |
127 | 127 | echo '[{"error" : "PHP \"Maximum execution time\" is set to '.ini_get('max_execution_time').' seconds. Please try to set to 60s at least during installation.", "index" : "'.$_POST['index'].'", "multiple" : "'.$_POST['multiple'].'"}]'; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | case "step_3": |
134 | 134 | //decrypt |
135 | - require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
135 | + require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
136 | 136 | $json = Encryption\Crypt\aesctr::decrypt($_POST['data'], "cpm", 128); |
137 | 137 | $data = json_decode($json, true); |
138 | 138 | $json = Encryption\Crypt\aesctr::decrypt($_POST['db'], "cpm", 128); |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | ) CHARSET=utf8;" |
149 | 149 | ); |
150 | 150 | // store values |
151 | - foreach($data as $key=>$value) { |
|
151 | + foreach ($data as $key=>$value) { |
|
152 | 152 | $_SESSION[$key] = $value; |
153 | 153 | $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = '".$key."'")); |
154 | 154 | if ($tmp[0] == 0 || empty($tmp[0])) { |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | if ($tmp[0] == 0 || empty($tmp[0])) { |
162 | 162 | mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('url_path', '", empty($_SESSION['url_path']) ? $db['url_path'] : $_SESSION['url_path'], "');"); |
163 | 163 | } else { |
164 | - mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($_SESSION['url_path']) ? $db['url_path'] : $_SESSION['url_path'],"' WHERE `key` = 'url_path';"); |
|
164 | + mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($_SESSION['url_path']) ? $db['url_path'] : $_SESSION['url_path'], "' WHERE `key` = 'url_path';"); |
|
165 | 165 | } |
166 | 166 | $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = 'abspath'")); |
167 | 167 | if ($tmp[0] == 0 || empty($tmp[0])) { |
168 | - mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('abspath', '", empty($_SESSION['abspath']) ? $db['abspath'] : $_SESSION['abspath'],"');"); |
|
168 | + mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('abspath', '", empty($_SESSION['abspath']) ? $db['abspath'] : $_SESSION['abspath'], "');"); |
|
169 | 169 | } else { |
170 | - mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($_SESSION['abspath']) ? $db['abspath'] : $_SESSION['abspath'],"' WHERE `key` = 'abspath';"); |
|
170 | + mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($_SESSION['abspath']) ? $db['abspath'] : $_SESSION['abspath'], "' WHERE `key` = 'abspath';"); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | echo '[{"error" : "", "result" : "Connection is successful", "multiple" : ""}]'; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | case "step_4": |
181 | 181 | //decrypt |
182 | - require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
182 | + require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
183 | 183 | $json = Encryption\Crypt\aesctr::decrypt($_POST['data'], "cpm", 128); |
184 | 184 | $data = json_decode($json, true); |
185 | 185 | $json = Encryption\Crypt\aesctr::decrypt($_POST['db'], "cpm", 128); |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | $dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']); |
189 | 189 | |
190 | 190 | // prepare data |
191 | - foreach($data as $key=>$value) { |
|
192 | - $data[$key] = str_replace(array('"', '\'), array('""','\\\\'), $value); |
|
191 | + foreach ($data as $key=>$value) { |
|
192 | + $data[$key] = str_replace(array('"', '\'), array('""', '\\\\'), $value); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | // check skpath |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | } else { |
199 | 199 | $data['sk_path'] = str_replace("\", "/", $data['sk_path']); |
200 | 200 | } |
201 | - if (substr($data['sk_path'], strlen($data['sk_path'])-1) == "/" || substr($data['sk_path'], strlen($data['sk_path'])-1) == "\"") { |
|
202 | - $data['sk_path'] = substr($data['sk_path'], 0, strlen($data['sk_path'])-1); |
|
201 | + if (substr($data['sk_path'], strlen($data['sk_path']) - 1) == "/" || substr($data['sk_path'], strlen($data['sk_path']) - 1) == "\"") { |
|
202 | + $data['sk_path'] = substr($data['sk_path'], 0, strlen($data['sk_path']) - 1); |
|
203 | 203 | } |
204 | 204 | if (is_dir($data['sk_path'])) { |
205 | 205 | if (is_writable($data['sk_path'])) { |
206 | 206 | // store all variables in SESSION |
207 | - foreach($data as $key=>$value) { |
|
207 | + foreach ($data as $key=>$value) { |
|
208 | 208 | $_SESSION[$key] = $value; |
209 | 209 | $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = '".$key."'")); |
210 | 210 | if ($tmp[0] == 0 || empty($tmp[0])) { |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | |
226 | 226 | case "step_5": |
227 | 227 | //decrypt |
228 | - require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
228 | + require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
229 | 229 | $activity = Encryption\Crypt\aesctr::decrypt($_POST['activity'], "cpm", 128); |
230 | 230 | $task = Encryption\Crypt\aesctr::decrypt($_POST['task'], "cpm", 128); |
231 | 231 | $json = Encryption\Crypt\aesctr::decrypt($_POST['db'], "cpm", 128); |
@@ -341,97 +341,97 @@ discard block |
||
341 | 341 | array('admin', 'path_to_files_folder', $var['abspath'].'/files'), |
342 | 342 | array('admin', 'url_to_files_folder', $var['url_path'].'/files'), |
343 | 343 | array('admin', 'activate_expiration', '0'), |
344 | - array('admin','pw_life_duration','0'), |
|
345 | - array('admin','maintenance_mode','1'), |
|
346 | - array('admin','enable_sts','0'), |
|
347 | - array('admin','encryptClientServer','1'), |
|
348 | - array('admin','cpassman_version',$k['version']), |
|
349 | - array('admin','ldap_mode','0'), |
|
350 | - array('admin','ldap_type','0'), |
|
351 | - array('admin','ldap_suffix','0'), |
|
352 | - array('admin','ldap_domain_dn','0'), |
|
353 | - array('admin','ldap_domain_controler','0'), |
|
354 | - array('admin','ldap_user_attribute','0'), |
|
355 | - array('admin','ldap_ssl','0'), |
|
356 | - array('admin','ldap_tls','0'), |
|
357 | - array('admin','ldap_elusers','0'), |
|
358 | - array('admin','ldap_search_base','0'), |
|
359 | - array('admin','richtext','0'), |
|
360 | - array('admin','allow_print','0'), |
|
361 | - array('admin','roles_allowed_to_print','0'), |
|
362 | - array('admin','show_description','1'), |
|
363 | - array('admin','anyone_can_modify','0'), |
|
364 | - array('admin','anyone_can_modify_bydefault','0'), |
|
365 | - array('admin','nb_bad_authentication','0'), |
|
366 | - array('admin','utf8_enabled','1'), |
|
367 | - array('admin','restricted_to','0'), |
|
368 | - array('admin','restricted_to_roles','0'), |
|
369 | - array('admin','enable_send_email_on_user_login','0'), |
|
370 | - array('admin','enable_user_can_create_folders','0'), |
|
371 | - array('admin','insert_manual_entry_item_history','0'), |
|
372 | - array('admin','enable_kb','0'), |
|
373 | - array('admin','enable_email_notification_on_item_shown','0'), |
|
374 | - array('admin','enable_email_notification_on_user_pw_change','0'), |
|
375 | - array('admin','custom_logo',''), |
|
376 | - array('admin','custom_login_text',''), |
|
377 | - array('admin','default_language','english'), |
|
378 | - array('admin','send_stats', '0'), |
|
379 | - array('admin','send_statistics_items', 'stat_country;stat_users;stat_items;stat_items_shared;stat_folders;stat_folders_shared;stat_admins;stat_managers;stat_ro;stat_mysqlversion;stat_phpversion;stat_teampassversion;stat_languages;stat_kb;stat_suggestion;stat_customfields;stat_api;stat_2fa;stat_agses;stat_duo;stat_ldap;stat_syslog;stat_stricthttps;stat_fav;stat_pf;'), |
|
380 | - array('admin','send_stats_time', time()-2592000), |
|
381 | - array('admin','get_tp_info', '1'), |
|
382 | - array('admin','send_mail_on_user_login', '0'), |
|
344 | + array('admin', 'pw_life_duration', '0'), |
|
345 | + array('admin', 'maintenance_mode', '1'), |
|
346 | + array('admin', 'enable_sts', '0'), |
|
347 | + array('admin', 'encryptClientServer', '1'), |
|
348 | + array('admin', 'cpassman_version', $k['version']), |
|
349 | + array('admin', 'ldap_mode', '0'), |
|
350 | + array('admin', 'ldap_type', '0'), |
|
351 | + array('admin', 'ldap_suffix', '0'), |
|
352 | + array('admin', 'ldap_domain_dn', '0'), |
|
353 | + array('admin', 'ldap_domain_controler', '0'), |
|
354 | + array('admin', 'ldap_user_attribute', '0'), |
|
355 | + array('admin', 'ldap_ssl', '0'), |
|
356 | + array('admin', 'ldap_tls', '0'), |
|
357 | + array('admin', 'ldap_elusers', '0'), |
|
358 | + array('admin', 'ldap_search_base', '0'), |
|
359 | + array('admin', 'richtext', '0'), |
|
360 | + array('admin', 'allow_print', '0'), |
|
361 | + array('admin', 'roles_allowed_to_print', '0'), |
|
362 | + array('admin', 'show_description', '1'), |
|
363 | + array('admin', 'anyone_can_modify', '0'), |
|
364 | + array('admin', 'anyone_can_modify_bydefault', '0'), |
|
365 | + array('admin', 'nb_bad_authentication', '0'), |
|
366 | + array('admin', 'utf8_enabled', '1'), |
|
367 | + array('admin', 'restricted_to', '0'), |
|
368 | + array('admin', 'restricted_to_roles', '0'), |
|
369 | + array('admin', 'enable_send_email_on_user_login', '0'), |
|
370 | + array('admin', 'enable_user_can_create_folders', '0'), |
|
371 | + array('admin', 'insert_manual_entry_item_history', '0'), |
|
372 | + array('admin', 'enable_kb', '0'), |
|
373 | + array('admin', 'enable_email_notification_on_item_shown', '0'), |
|
374 | + array('admin', 'enable_email_notification_on_user_pw_change', '0'), |
|
375 | + array('admin', 'custom_logo', ''), |
|
376 | + array('admin', 'custom_login_text', ''), |
|
377 | + array('admin', 'default_language', 'english'), |
|
378 | + array('admin', 'send_stats', '0'), |
|
379 | + array('admin', 'send_statistics_items', 'stat_country;stat_users;stat_items;stat_items_shared;stat_folders;stat_folders_shared;stat_admins;stat_managers;stat_ro;stat_mysqlversion;stat_phpversion;stat_teampassversion;stat_languages;stat_kb;stat_suggestion;stat_customfields;stat_api;stat_2fa;stat_agses;stat_duo;stat_ldap;stat_syslog;stat_stricthttps;stat_fav;stat_pf;'), |
|
380 | + array('admin', 'send_stats_time', time() - 2592000), |
|
381 | + array('admin', 'get_tp_info', '1'), |
|
382 | + array('admin', 'send_mail_on_user_login', '0'), |
|
383 | 383 | array('cron', 'sending_emails', '0'), |
384 | - array('admin','nb_items_by_query', 'auto'), |
|
385 | - array('admin','enable_delete_after_consultation', '0'), |
|
386 | - array('admin','enable_personal_saltkey_cookie', '0'), |
|
387 | - array('admin','personal_saltkey_cookie_duration', '31'), |
|
388 | - array('admin','email_smtp_server', ''), |
|
389 | - array('admin','email_smtp_auth', ''), |
|
390 | - array('admin','email_auth_username', ''), |
|
391 | - array('admin','email_auth_pwd', ''), |
|
392 | - array('admin','email_port', ''), |
|
393 | - array('admin','email_security',''), |
|
394 | - array('admin','email_server_url', ''), |
|
395 | - array('admin','email_from', ''), |
|
396 | - array('admin','email_from_name', ''), |
|
397 | - array('admin','pwd_maximum_length', '40'), |
|
398 | - array('admin','google_authentication', '0'), |
|
399 | - array('admin','delay_item_edition', '0'), |
|
400 | - array('admin','allow_import','0'), |
|
401 | - array('admin','proxy_ip',''), |
|
402 | - array('admin','proxy_port',''), |
|
403 | - array('admin','upload_maxfilesize','10mb'), |
|
404 | - array('admin','upload_docext','doc,docx,dotx,xls,xlsx,xltx,rtf,csv,txt,pdf,ppt,pptx,pot,dotx,xltx'), |
|
405 | - array('admin','upload_imagesext','jpg,jpeg,gif,png'), |
|
406 | - array('admin','upload_pkgext','7z,rar,tar,zip'), |
|
407 | - array('admin','upload_otherext','sql,xml'), |
|
408 | - array('admin','upload_imageresize_options','1'), |
|
409 | - array('admin','upload_imageresize_width','800'), |
|
410 | - array('admin','upload_imageresize_height','600'), |
|
411 | - array('admin','upload_imageresize_quality','90'), |
|
412 | - array('admin','use_md5_password_as_salt','0'), |
|
413 | - array('admin','ga_website_name','TeamPass for ChangeMe'), |
|
414 | - array('admin','api','0'), |
|
415 | - array('admin','subfolder_rights_as_parent','0'), |
|
416 | - array('admin','show_only_accessible_folders','0'), |
|
417 | - array('admin','enable_suggestion','0'), |
|
418 | - array('admin','otv_expiration_period','7'), |
|
419 | - array('admin','default_session_expiration_time','60'), |
|
420 | - array('admin','duo','0'), |
|
421 | - array('admin','enable_server_password_change','0'), |
|
422 | - array('admin','ldap_object_class','0'), |
|
423 | - array('admin','bck_script_path', $var['abspath']."/backups"), |
|
424 | - array('admin','bck_script_filename', 'bck_teampass'), |
|
425 | - array('admin','syslog_enable','0'), |
|
426 | - array('admin','syslog_host','localhost'), |
|
427 | - array('admin','syslog_port','514'), |
|
428 | - array('admin','manager_move_item','0'), |
|
429 | - array('admin','create_item_without_password','0'), |
|
430 | - array('admin','otv_is_enabled','0'), |
|
431 | - array('admin','agses_authentication_enabled','0'), |
|
432 | - array('admin','item_extra_fields','0'), |
|
433 | - array('admin','saltkey_ante_2127','none'), |
|
434 | - array('admin','migration_to_2127','done') |
|
384 | + array('admin', 'nb_items_by_query', 'auto'), |
|
385 | + array('admin', 'enable_delete_after_consultation', '0'), |
|
386 | + array('admin', 'enable_personal_saltkey_cookie', '0'), |
|
387 | + array('admin', 'personal_saltkey_cookie_duration', '31'), |
|
388 | + array('admin', 'email_smtp_server', ''), |
|
389 | + array('admin', 'email_smtp_auth', ''), |
|
390 | + array('admin', 'email_auth_username', ''), |
|
391 | + array('admin', 'email_auth_pwd', ''), |
|
392 | + array('admin', 'email_port', ''), |
|
393 | + array('admin', 'email_security', ''), |
|
394 | + array('admin', 'email_server_url', ''), |
|
395 | + array('admin', 'email_from', ''), |
|
396 | + array('admin', 'email_from_name', ''), |
|
397 | + array('admin', 'pwd_maximum_length', '40'), |
|
398 | + array('admin', 'google_authentication', '0'), |
|
399 | + array('admin', 'delay_item_edition', '0'), |
|
400 | + array('admin', 'allow_import', '0'), |
|
401 | + array('admin', 'proxy_ip', ''), |
|
402 | + array('admin', 'proxy_port', ''), |
|
403 | + array('admin', 'upload_maxfilesize', '10mb'), |
|
404 | + array('admin', 'upload_docext', 'doc,docx,dotx,xls,xlsx,xltx,rtf,csv,txt,pdf,ppt,pptx,pot,dotx,xltx'), |
|
405 | + array('admin', 'upload_imagesext', 'jpg,jpeg,gif,png'), |
|
406 | + array('admin', 'upload_pkgext', '7z,rar,tar,zip'), |
|
407 | + array('admin', 'upload_otherext', 'sql,xml'), |
|
408 | + array('admin', 'upload_imageresize_options', '1'), |
|
409 | + array('admin', 'upload_imageresize_width', '800'), |
|
410 | + array('admin', 'upload_imageresize_height', '600'), |
|
411 | + array('admin', 'upload_imageresize_quality', '90'), |
|
412 | + array('admin', 'use_md5_password_as_salt', '0'), |
|
413 | + array('admin', 'ga_website_name', 'TeamPass for ChangeMe'), |
|
414 | + array('admin', 'api', '0'), |
|
415 | + array('admin', 'subfolder_rights_as_parent', '0'), |
|
416 | + array('admin', 'show_only_accessible_folders', '0'), |
|
417 | + array('admin', 'enable_suggestion', '0'), |
|
418 | + array('admin', 'otv_expiration_period', '7'), |
|
419 | + array('admin', 'default_session_expiration_time', '60'), |
|
420 | + array('admin', 'duo', '0'), |
|
421 | + array('admin', 'enable_server_password_change', '0'), |
|
422 | + array('admin', 'ldap_object_class', '0'), |
|
423 | + array('admin', 'bck_script_path', $var['abspath']."/backups"), |
|
424 | + array('admin', 'bck_script_filename', 'bck_teampass'), |
|
425 | + array('admin', 'syslog_enable', '0'), |
|
426 | + array('admin', 'syslog_host', 'localhost'), |
|
427 | + array('admin', 'syslog_port', '514'), |
|
428 | + array('admin', 'manager_move_item', '0'), |
|
429 | + array('admin', 'create_item_without_password', '0'), |
|
430 | + array('admin', 'otv_is_enabled', '0'), |
|
431 | + array('admin', 'agses_authentication_enabled', '0'), |
|
432 | + array('admin', 'item_extra_fields', '0'), |
|
433 | + array('admin', 'saltkey_ante_2127', 'none'), |
|
434 | + array('admin', 'migration_to_2127', 'done') |
|
435 | 435 | ); |
436 | 436 | foreach ($aMiscVal as $elem) { |
437 | 437 | //Check if exists before inserting |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | (`type`, `intitule`, `valeur`) VALUES |
449 | 449 | ('".$elem[0]."', '".$elem[1]."', '". |
450 | 450 | str_replace("'", "", $elem[2])."');" |
451 | - ); // or die(mysqli_error($dbTmp)) |
|
451 | + ); // or die(mysqli_error($dbTmp)) |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | // append new setting in config file |
@@ -843,10 +843,10 @@ discard block |
||
843 | 843 | $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$var['tbl_prefix']."users` WHERE login = 'admin'")); |
844 | 844 | if ($tmp === "0") { |
845 | 845 | $mysqli_result = mysqli_query($dbTmp, |
846 | - "INSERT INTO `".$var['tbl_prefix']."users` (`id`, `login`, `pw`, `admin`, `gestionnaire`, `personal_folder`, `groupes_visibles`, `email`, `encrypted_psk`) VALUES ('1', 'admin', '".bCrypt($var['admin_pwd'],'13' )."', '1', '0', '0', '', '', '')" |
|
846 | + "INSERT INTO `".$var['tbl_prefix']."users` (`id`, `login`, `pw`, `admin`, `gestionnaire`, `personal_folder`, `groupes_visibles`, `email`, `encrypted_psk`) VALUES ('1', 'admin', '".bCrypt($var['admin_pwd'], '13')."', '1', '0', '0', '', '', '')" |
|
847 | 847 | ); |
848 | 848 | } else { |
849 | - $mysqli_result = mysqli_query($dbTmp, "UPDATE `".$var['tbl_prefix']."users` SET `pw` = '".bCrypt($var['admin_pwd'],'13' )."' WHERE login = 'admin' AND id = '1'"); |
|
849 | + $mysqli_result = mysqli_query($dbTmp, "UPDATE `".$var['tbl_prefix']."users` SET `pw` = '".bCrypt($var['admin_pwd'], '13')."' WHERE login = 'admin' AND id = '1'"); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | // check that API doesn't exist |
@@ -878,13 +878,13 @@ discard block |
||
878 | 878 | |
879 | 879 | mysqli_close($dbTmp); |
880 | 880 | // Destroy session without writing to disk |
881 | - define('NODESTROY_SESSION','true'); |
|
881 | + define('NODESTROY_SESSION', 'true'); |
|
882 | 882 | session_destroy(); |
883 | 883 | break; |
884 | 884 | |
885 | 885 | case "step_6": |
886 | 886 | //decrypt |
887 | - require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
887 | + require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
888 | 888 | $activity = Encryption\Crypt\aesctr::decrypt($_POST['activity'], "cpm", 128); |
889 | 889 | $data_sent = Encryption\Crypt\aesctr::decrypt($_POST['data'], "cpm", 128); |
890 | 890 | $data_sent = json_decode($data_sent, true); |
@@ -995,9 +995,9 @@ discard block |
||
995 | 995 | if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { |
996 | 996 | // Change directory permissions |
997 | 997 | $result = chmod_r($_SESSION['abspath'], 0770, 0740); |
998 | - if ($result ) |
|
998 | + if ($result) |
|
999 | 999 | $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770); |
1000 | - if ($result) |
|
1000 | + if ($result) |
|
1001 | 1001 | $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770); |
1002 | 1002 | } |
1003 | 1003 | |
@@ -1039,8 +1039,8 @@ discard block |
||
1039 | 1039 | $events .= "The file $csrfp_file already exist. A copy has been created.<br />"; |
1040 | 1040 | } |
1041 | 1041 | } |
1042 | - unlink($csrfp_file); // delete existing csrfp.config file |
|
1043 | - copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file |
|
1042 | + unlink($csrfp_file); // delete existing csrfp.config file |
|
1043 | + copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file |
|
1044 | 1044 | $data = file_get_contents($csrfp_file); |
1045 | 1045 | $newdata = str_replace('"CSRFP_TOKEN" => ""', '"CSRFP_TOKEN" => "'.bin2hex(openssl_random_pseudo_bytes(25)).'"', $data); |
1046 | 1046 | $jsUrl = $data_sent['url_path'].'/includes/libraries/csrfp/js/csrfprotector.js'; |
@@ -1053,13 +1053,13 @@ discard block |
||
1053 | 1053 | |
1054 | 1054 | mysqli_close($dbTmp); |
1055 | 1055 | // Destroy session without writing to disk |
1056 | - define('NODESTROY_SESSION','true'); |
|
1056 | + define('NODESTROY_SESSION', 'true'); |
|
1057 | 1057 | session_destroy(); |
1058 | 1058 | break; |
1059 | 1059 | case "step_7": |
1060 | 1060 | |
1061 | 1061 | //decrypt |
1062 | - require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
1062 | + require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
1063 | 1063 | $activity = Encryption\Crypt\aesctr::decrypt($_POST['activity'], "cpm", 128); |
1064 | 1064 | $task = Encryption\Crypt\aesctr::decrypt($_POST['task'], "cpm", 128); |
1065 | 1065 | // launch |
@@ -1068,7 +1068,7 @@ discard block |
||
1068 | 1068 | if ($activity == "file") { |
1069 | 1069 | if ($task == "deleteInstall") { |
1070 | 1070 | function delTree($dir) { |
1071 | - $files = array_diff(scandir($dir), array('.','..')); |
|
1071 | + $files = array_diff(scandir($dir), array('.', '..')); |
|
1072 | 1072 | |
1073 | 1073 | foreach ($files as $file) { |
1074 | 1074 | (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file"); |
@@ -1076,7 +1076,7 @@ discard block |
||
1076 | 1076 | return rmdir($dir); |
1077 | 1077 | } |
1078 | 1078 | |
1079 | - $result=true; |
|
1079 | + $result = true; |
|
1080 | 1080 | $errorMsg = "Cannot delete installation directory"; |
1081 | 1081 | if (file_exists($_SESSION['abspath'].'/install')) { |
1082 | 1082 | // set the permissions on the install directory and delete |
@@ -1102,7 +1102,7 @@ discard block |
||
1102 | 1102 | // |
1103 | 1103 | mysqli_close($dbTmp); |
1104 | 1104 | // Destroy session without writing to disk |
1105 | - define('NODESTROY_SESSION','true'); |
|
1105 | + define('NODESTROY_SESSION', 'true'); |
|
1106 | 1106 | session_destroy(); |
1107 | 1107 | break; |
1108 | 1108 | } |
@@ -23,14 +23,16 @@ discard block |
||
23 | 23 | $dp = opendir($dir); |
24 | 24 | $res = true; |
25 | 25 | while($file = readdir($dp)) { |
26 | - if (($file == ".") || ($file == "..")) |
|
27 | - continue; |
|
26 | + if (($file == ".") || ($file == "..")) { |
|
27 | + continue; |
|
28 | + } |
|
28 | 29 | |
29 | 30 | $fullPath = $dir."/".$file; |
30 | 31 | |
31 | 32 | if(is_dir($fullPath)) { |
32 | - if ($res = @chmod($fullPath, $dirPermissions)) |
|
33 | - $res = @chmod_r($fullPath, $dirPermissions, $filePermissions); |
|
33 | + if ($res = @chmod($fullPath, $dirPermissions)) { |
|
34 | + $res = @chmod_r($fullPath, $dirPermissions, $filePermissions); |
|
35 | + } |
|
34 | 36 | } else { |
35 | 37 | $res = chmod($fullPath, $filePermissions); |
36 | 38 | } |
@@ -40,8 +42,9 @@ discard block |
||
40 | 42 | } |
41 | 43 | } |
42 | 44 | closedir($dp); |
43 | - if (is_dir($dir) && $res) |
|
44 | - $res = @chmod($dir, $dirPermissions); |
|
45 | + if (is_dir($dir) && $res) { |
|
46 | + $res = @chmod($dir, $dirPermissions); |
|
47 | + } |
|
45 | 48 | |
46 | 49 | return $res; |
47 | 50 | } |
@@ -995,10 +998,12 @@ discard block |
||
995 | 998 | if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { |
996 | 999 | // Change directory permissions |
997 | 1000 | $result = chmod_r($_SESSION['abspath'], 0770, 0740); |
998 | - if ($result ) |
|
999 | - $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770); |
|
1000 | - if ($result) |
|
1001 | - $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770); |
|
1001 | + if ($result ) { |
|
1002 | + $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770); |
|
1003 | + } |
|
1004 | + if ($result) { |
|
1005 | + $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770); |
|
1006 | + } |
|
1002 | 1007 | } |
1003 | 1008 | |
1004 | 1009 | if ($result === false) { |
@@ -40,6 +40,10 @@ discard block |
||
40 | 40 | return $output; |
41 | 41 | } |
42 | 42 | |
43 | + /** |
|
44 | + * @param integer $rnd |
|
45 | + * @param integer $Nb |
|
46 | + */ |
|
43 | 47 | private static function addRoundKey($state, $w, $rnd, $Nb) { // xor Round Key into state S [é5.1.4] |
44 | 48 | for ($r=0; $r<4; $r++) { |
45 | 49 | for ($c=0; $c<$Nb; $c++) $state[$r][$c] ^= $w[$rnd*4+$c][$r]; |
@@ -48,6 +52,9 @@ discard block |
||
48 | 52 | return $state; |
49 | 53 | } |
50 | 54 | |
55 | + /** |
|
56 | + * @param integer $Nb |
|
57 | + */ |
|
51 | 58 | private static function subBytes($s, $Nb) { // apply SBox to state S [é5.1.1] |
52 | 59 | for ($r=0; $r<4; $r++) { |
53 | 60 | for ($c=0; $c<$Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
@@ -56,6 +63,9 @@ discard block |
||
56 | 63 | return $s; |
57 | 64 | } |
58 | 65 | |
66 | + /** |
|
67 | + * @param integer $Nb |
|
68 | + */ |
|
59 | 69 | private static function shiftRows($s, $Nb) { // shift row r of state S left by r bytes [é5.1.2] |
60 | 70 | $t = array(4); |
61 | 71 | for ($r=1; $r<4; $r++) { |
@@ -65,6 +75,9 @@ discard block |
||
65 | 75 | return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf |
66 | 76 | } |
67 | 77 | |
78 | + /** |
|
79 | + * @param integer $Nb |
|
80 | + */ |
|
68 | 81 | private static function mixColumns($s, $Nb) { // combine bytes of each col of state S [é5.1.3] |
69 | 82 | for ($c=0; $c<4; $c++) { |
70 | 83 | $a = array(4); // 'a' is a copy of the current column from 's' |
@@ -6,15 +6,15 @@ discard block |
||
6 | 6 | |
7 | 7 | class Aes |
8 | 8 | { |
9 | - /** |
|
10 | - * AES Cipher function: encrypt 'input' with Rijndael algorithm |
|
11 | - * |
|
12 | - * @param input message as byte-array (16 bytes) |
|
13 | - * @param w key schedule as 2D byte-array (Nr+1 x Nb bytes) - |
|
14 | - * generated from the cipher key by keyExpansion() |
|
15 | - * @return ciphertext as byte-array (16 bytes) |
|
16 | - */ |
|
17 | - public static function cipher($input, $w) { // main cipher function [é5.1] |
|
9 | + /** |
|
10 | + * AES Cipher function: encrypt 'input' with Rijndael algorithm |
|
11 | + * |
|
12 | + * @param input message as byte-array (16 bytes) |
|
13 | + * @param w key schedule as 2D byte-array (Nr+1 x Nb bytes) - |
|
14 | + * generated from the cipher key by keyExpansion() |
|
15 | + * @return ciphertext as byte-array (16 bytes) |
|
16 | + */ |
|
17 | + public static function cipher($input, $w) { // main cipher function [é5.1] |
|
18 | 18 | $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
19 | 19 | $Nr = count($w)/$Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys |
20 | 20 | |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | $state = self::addRoundKey($state, $w, 0, $Nb); |
25 | 25 | |
26 | 26 | for ($round=1; $round<$Nr; $round++) { // apply Nr rounds |
27 | - $state = self::subBytes($state, $Nb); |
|
28 | - $state = self::shiftRows($state, $Nb); |
|
29 | - $state = self::mixColumns($state, $Nb); |
|
30 | - $state = self::addRoundKey($state, $w, $round, $Nb); |
|
27 | + $state = self::subBytes($state, $Nb); |
|
28 | + $state = self::shiftRows($state, $Nb); |
|
29 | + $state = self::mixColumns($state, $Nb); |
|
30 | + $state = self::addRoundKey($state, $w, $round, $Nb); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | $state = self::subBytes($state, $Nb); |
@@ -38,59 +38,59 @@ discard block |
||
38 | 38 | for ($i=0; $i<4*$Nb; $i++) $output[$i] = $state[$i%4][floor($i/4)]; |
39 | 39 | |
40 | 40 | return $output; |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - private static function addRoundKey($state, $w, $rnd, $Nb) { // xor Round Key into state S [é5.1.4] |
|
43 | + private static function addRoundKey($state, $w, $rnd, $Nb) { // xor Round Key into state S [é5.1.4] |
|
44 | 44 | for ($r=0; $r<4; $r++) { |
45 | - for ($c=0; $c<$Nb; $c++) $state[$r][$c] ^= $w[$rnd*4+$c][$r]; |
|
45 | + for ($c=0; $c<$Nb; $c++) $state[$r][$c] ^= $w[$rnd*4+$c][$r]; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | return $state; |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - private static function subBytes($s, $Nb) { // apply SBox to state S [é5.1.1] |
|
51 | + private static function subBytes($s, $Nb) { // apply SBox to state S [é5.1.1] |
|
52 | 52 | for ($r=0; $r<4; $r++) { |
53 | - for ($c=0; $c<$Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
|
53 | + for ($c=0; $c<$Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $s; |
57 | - } |
|
57 | + } |
|
58 | 58 | |
59 | - private static function shiftRows($s, $Nb) { // shift row r of state S left by r bytes [é5.1.2] |
|
59 | + private static function shiftRows($s, $Nb) { // shift row r of state S left by r bytes [é5.1.2] |
|
60 | 60 | $t = array(4); |
61 | 61 | for ($r=1; $r<4; $r++) { |
62 | - for ($c=0; $c<4; $c++) $t[$c] = $s[$r][($c+$r)%$Nb]; // shift into temp copy |
|
63 | - for ($c=0; $c<4; $c++) $s[$r][$c] = $t[$c]; // and copy back |
|
62 | + for ($c=0; $c<4; $c++) $t[$c] = $s[$r][($c+$r)%$Nb]; // shift into temp copy |
|
63 | + for ($c=0; $c<4; $c++) $s[$r][$c] = $t[$c]; // and copy back |
|
64 | 64 | } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES): |
65 | 65 | return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - private static function mixColumns($s, $Nb) { // combine bytes of each col of state S [é5.1.3] |
|
68 | + private static function mixColumns($s, $Nb) { // combine bytes of each col of state S [é5.1.3] |
|
69 | 69 | for ($c=0; $c<4; $c++) { |
70 | - $a = array(4); // 'a' is a copy of the current column from 's' |
|
71 | - $b = array(4); // 'b' is aé{02} in GF(2^8) |
|
72 | - for ($i=0; $i<4; $i++) { |
|
70 | + $a = array(4); // 'a' is a copy of the current column from 's' |
|
71 | + $b = array(4); // 'b' is aé{02} in GF(2^8) |
|
72 | + for ($i=0; $i<4; $i++) { |
|
73 | 73 | $a[$i] = $s[$i][$c]; |
74 | 74 | $b[$i] = $s[$i][$c]&0x80 ? $s[$i][$c]<<1 ^ 0x011b : $s[$i][$c]<<1; |
75 | - } |
|
76 | - // a[n] ^ b[n] is aé{03} in GF(2^8) |
|
77 | - $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3 |
|
78 | - $s[1][$c] = $a[0] ^ $b[1] ^ $a[2] ^ $b[2] ^ $a[3]; // a0 * 2*a1 + 3*a2 + a3 |
|
79 | - $s[2][$c] = $a[0] ^ $a[1] ^ $b[2] ^ $a[3] ^ $b[3]; // a0 + a1 + 2*a2 + 3*a3 |
|
80 | - $s[3][$c] = $a[0] ^ $b[0] ^ $a[1] ^ $a[2] ^ $b[3]; // 3*a0 + a1 + a2 + 2*a3 |
|
75 | + } |
|
76 | + // a[n] ^ b[n] is aé{03} in GF(2^8) |
|
77 | + $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3 |
|
78 | + $s[1][$c] = $a[0] ^ $b[1] ^ $a[2] ^ $b[2] ^ $a[3]; // a0 * 2*a1 + 3*a2 + a3 |
|
79 | + $s[2][$c] = $a[0] ^ $a[1] ^ $b[2] ^ $a[3] ^ $b[3]; // a0 + a1 + 2*a2 + 3*a3 |
|
80 | + $s[3][$c] = $a[0] ^ $b[0] ^ $a[1] ^ $a[2] ^ $b[3]; // 3*a0 + a1 + a2 + 2*a3 |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | return $s; |
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Key expansion for Rijndael cipher(): performs key expansion on cipher key |
|
88 | - * to generate a key schedule |
|
89 | - * |
|
90 | - * @param key cipher key byte-array (16 bytes) |
|
91 | - * @return key schedule as 2D byte-array (Nr+1 x Nb bytes) |
|
92 | - */ |
|
93 | - public static function keyExpansion($key) { // generate Key Schedule from Cipher Key [é5.2] |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Key expansion for Rijndael cipher(): performs key expansion on cipher key |
|
88 | + * to generate a key schedule |
|
89 | + * |
|
90 | + * @param key cipher key byte-array (16 bytes) |
|
91 | + * @return key schedule as 2D byte-array (Nr+1 x Nb bytes) |
|
92 | + */ |
|
93 | + public static function keyExpansion($key) { // generate Key Schedule from Cipher Key [é5.2] |
|
94 | 94 | $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
95 | 95 | $Nk = count($key)/4; // key length (in words): 4/6/8 for 128/192/256-bit keys |
96 | 96 | $Nr = $Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys |
@@ -99,41 +99,41 @@ discard block |
||
99 | 99 | $temp = array(); |
100 | 100 | |
101 | 101 | for ($i=0; $i<$Nk; $i++) { |
102 | - $r = array($key[4*$i], $key[4*$i+1], $key[4*$i+2], $key[4*$i+3]); |
|
103 | - $w[$i] = $r; |
|
102 | + $r = array($key[4*$i], $key[4*$i+1], $key[4*$i+2], $key[4*$i+3]); |
|
103 | + $w[$i] = $r; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | for ($i=$Nk; $i<($Nb*($Nr+1)); $i++) { |
107 | - $w[$i] = array(); |
|
108 | - for ($t=0; $t<4; $t++) $temp[$t] = $w[$i-1][$t]; |
|
109 | - if ($i % $Nk == 0) { |
|
107 | + $w[$i] = array(); |
|
108 | + for ($t=0; $t<4; $t++) $temp[$t] = $w[$i-1][$t]; |
|
109 | + if ($i % $Nk == 0) { |
|
110 | 110 | $temp = self::subWord(self::rotWord($temp)); |
111 | 111 | for ($t=0; $t<4; $t++) $temp[$t] ^= self::$rCon[$i/$Nk][$t]; |
112 | - } elseif ($Nk > 6 && $i%$Nk == 4) { |
|
112 | + } elseif ($Nk > 6 && $i%$Nk == 4) { |
|
113 | 113 | $temp = self::subWord($temp); |
114 | - } |
|
115 | - for ($t=0; $t<4; $t++) $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t]; |
|
114 | + } |
|
115 | + for ($t=0; $t<4; $t++) $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t]; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | return $w; |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | - private static function subWord($w) { // apply SBox to 4-byte word w |
|
121 | + private static function subWord($w) { // apply SBox to 4-byte word w |
|
122 | 122 | for ($i=0; $i<4; $i++) $w[$i] = self::$sBox[$w[$i]]; |
123 | 123 | |
124 | 124 | return $w; |
125 | - } |
|
125 | + } |
|
126 | 126 | |
127 | - private static function rotWord($w) { // rotate 4-byte word w left by one byte |
|
127 | + private static function rotWord($w) { // rotate 4-byte word w left by one byte |
|
128 | 128 | $tmp = $w[0]; |
129 | 129 | for ($i=0; $i<3; $i++) $w[$i] = $w[$i+1]; |
130 | 130 | $w[3] = $tmp; |
131 | 131 | |
132 | 132 | return $w; |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [é5.1.1] |
|
136 | - private static $sBox = array( |
|
135 | + // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [é5.1.1] |
|
136 | + private static $sBox = array( |
|
137 | 137 | 0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76, |
138 | 138 | 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0, |
139 | 139 | 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15, |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf, |
152 | 152 | 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16); |
153 | 153 | |
154 | - // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [é5.2] |
|
155 | - private static $rCon = array( |
|
154 | + // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [é5.2] |
|
155 | + private static $rCon = array( |
|
156 | 156 | array(0x00, 0x00, 0x00, 0x00), |
157 | 157 | array(0x01, 0x00, 0x00, 0x00), |
158 | 158 | array(0x02, 0x00, 0x00, 0x00), |
@@ -15,15 +15,15 @@ discard block |
||
15 | 15 | * @return ciphertext as byte-array (16 bytes) |
16 | 16 | */ |
17 | 17 | public static function cipher($input, $w) { // main cipher function [é5.1] |
18 | - $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
|
19 | - $Nr = count($w)/$Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys |
|
18 | + $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
|
19 | + $Nr = count($w) / $Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys |
|
20 | 20 | |
21 | - $state = array(); // initialise 4xNb byte-array 'state' with input [é3.4] |
|
22 | - for ($i=0; $i<4*$Nb; $i++) $state[$i%4][floor($i/4)] = $input[$i]; |
|
21 | + $state = array(); // initialise 4xNb byte-array 'state' with input [é3.4] |
|
22 | + for ($i = 0; $i < 4 * $Nb; $i++) $state[$i % 4][floor($i / 4)] = $input[$i]; |
|
23 | 23 | |
24 | 24 | $state = self::addRoundKey($state, $w, 0, $Nb); |
25 | 25 | |
26 | - for ($round=1; $round<$Nr; $round++) { // apply Nr rounds |
|
26 | + for ($round = 1; $round < $Nr; $round++) { // apply Nr rounds |
|
27 | 27 | $state = self::subBytes($state, $Nb); |
28 | 28 | $state = self::shiftRows($state, $Nb); |
29 | 29 | $state = self::mixColumns($state, $Nb); |
@@ -34,23 +34,23 @@ discard block |
||
34 | 34 | $state = self::shiftRows($state, $Nb); |
35 | 35 | $state = self::addRoundKey($state, $w, $Nr, $Nb); |
36 | 36 | |
37 | - $output = array(4*$Nb); // convert state to 1-d array before returning [é3.4] |
|
38 | - for ($i=0; $i<4*$Nb; $i++) $output[$i] = $state[$i%4][floor($i/4)]; |
|
37 | + $output = array(4 * $Nb); // convert state to 1-d array before returning [é3.4] |
|
38 | + for ($i = 0; $i < 4 * $Nb; $i++) $output[$i] = $state[$i % 4][floor($i / 4)]; |
|
39 | 39 | |
40 | 40 | return $output; |
41 | 41 | } |
42 | 42 | |
43 | 43 | private static function addRoundKey($state, $w, $rnd, $Nb) { // xor Round Key into state S [é5.1.4] |
44 | - for ($r=0; $r<4; $r++) { |
|
45 | - for ($c=0; $c<$Nb; $c++) $state[$r][$c] ^= $w[$rnd*4+$c][$r]; |
|
44 | + for ($r = 0; $r < 4; $r++) { |
|
45 | + for ($c = 0; $c < $Nb; $c++) $state[$r][$c] ^= $w[$rnd * 4 + $c][$r]; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | return $state; |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function subBytes($s, $Nb) { // apply SBox to state S [é5.1.1] |
52 | - for ($r=0; $r<4; $r++) { |
|
53 | - for ($c=0; $c<$Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
|
52 | + for ($r = 0; $r < 4; $r++) { |
|
53 | + for ($c = 0; $c < $Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $s; |
@@ -58,20 +58,20 @@ discard block |
||
58 | 58 | |
59 | 59 | private static function shiftRows($s, $Nb) { // shift row r of state S left by r bytes [é5.1.2] |
60 | 60 | $t = array(4); |
61 | - for ($r=1; $r<4; $r++) { |
|
62 | - for ($c=0; $c<4; $c++) $t[$c] = $s[$r][($c+$r)%$Nb]; // shift into temp copy |
|
63 | - for ($c=0; $c<4; $c++) $s[$r][$c] = $t[$c]; // and copy back |
|
61 | + for ($r = 1; $r < 4; $r++) { |
|
62 | + for ($c = 0; $c < 4; $c++) $t[$c] = $s[$r][($c + $r) % $Nb]; // shift into temp copy |
|
63 | + for ($c = 0; $c < 4; $c++) $s[$r][$c] = $t[$c]; // and copy back |
|
64 | 64 | } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES): |
65 | - return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf |
|
65 | + return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | private static function mixColumns($s, $Nb) { // combine bytes of each col of state S [é5.1.3] |
69 | - for ($c=0; $c<4; $c++) { |
|
70 | - $a = array(4); // 'a' is a copy of the current column from 's' |
|
71 | - $b = array(4); // 'b' is aé{02} in GF(2^8) |
|
72 | - for ($i=0; $i<4; $i++) { |
|
69 | + for ($c = 0; $c < 4; $c++) { |
|
70 | + $a = array(4); // 'a' is a copy of the current column from 's' |
|
71 | + $b = array(4); // 'b' is aé{02} in GF(2^8) |
|
72 | + for ($i = 0; $i < 4; $i++) { |
|
73 | 73 | $a[$i] = $s[$i][$c]; |
74 | - $b[$i] = $s[$i][$c]&0x80 ? $s[$i][$c]<<1 ^ 0x011b : $s[$i][$c]<<1; |
|
74 | + $b[$i] = $s[$i][$c] & 0x80 ? $s[$i][$c] << 1 ^ 0x011b : $s[$i][$c] << 1; |
|
75 | 75 | } |
76 | 76 | // a[n] ^ b[n] is aé{03} in GF(2^8) |
77 | 77 | $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3 |
@@ -91,42 +91,42 @@ discard block |
||
91 | 91 | * @return key schedule as 2D byte-array (Nr+1 x Nb bytes) |
92 | 92 | */ |
93 | 93 | public static function keyExpansion($key) { // generate Key Schedule from Cipher Key [é5.2] |
94 | - $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
|
95 | - $Nk = count($key)/4; // key length (in words): 4/6/8 for 128/192/256-bit keys |
|
96 | - $Nr = $Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys |
|
94 | + $Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES) |
|
95 | + $Nk = count($key) / 4; // key length (in words): 4/6/8 for 128/192/256-bit keys |
|
96 | + $Nr = $Nk + 6; // no of rounds: 10/12/14 for 128/192/256-bit keys |
|
97 | 97 | |
98 | 98 | $w = array(); |
99 | 99 | $temp = array(); |
100 | 100 | |
101 | - for ($i=0; $i<$Nk; $i++) { |
|
102 | - $r = array($key[4*$i], $key[4*$i+1], $key[4*$i+2], $key[4*$i+3]); |
|
101 | + for ($i = 0; $i < $Nk; $i++) { |
|
102 | + $r = array($key[4 * $i], $key[4 * $i + 1], $key[4 * $i + 2], $key[4 * $i + 3]); |
|
103 | 103 | $w[$i] = $r; |
104 | 104 | } |
105 | 105 | |
106 | - for ($i=$Nk; $i<($Nb*($Nr+1)); $i++) { |
|
106 | + for ($i = $Nk; $i < ($Nb * ($Nr + 1)); $i++) { |
|
107 | 107 | $w[$i] = array(); |
108 | - for ($t=0; $t<4; $t++) $temp[$t] = $w[$i-1][$t]; |
|
108 | + for ($t = 0; $t < 4; $t++) $temp[$t] = $w[$i - 1][$t]; |
|
109 | 109 | if ($i % $Nk == 0) { |
110 | 110 | $temp = self::subWord(self::rotWord($temp)); |
111 | - for ($t=0; $t<4; $t++) $temp[$t] ^= self::$rCon[$i/$Nk][$t]; |
|
112 | - } elseif ($Nk > 6 && $i%$Nk == 4) { |
|
111 | + for ($t = 0; $t < 4; $t++) $temp[$t] ^= self::$rCon[$i / $Nk][$t]; |
|
112 | + } elseif ($Nk > 6 && $i % $Nk == 4) { |
|
113 | 113 | $temp = self::subWord($temp); |
114 | 114 | } |
115 | - for ($t=0; $t<4; $t++) $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t]; |
|
115 | + for ($t = 0; $t < 4; $t++) $w[$i][$t] = $w[$i - $Nk][$t] ^ $temp[$t]; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | return $w; |
119 | 119 | } |
120 | 120 | |
121 | 121 | private static function subWord($w) { // apply SBox to 4-byte word w |
122 | - for ($i=0; $i<4; $i++) $w[$i] = self::$sBox[$w[$i]]; |
|
122 | + for ($i = 0; $i < 4; $i++) $w[$i] = self::$sBox[$w[$i]]; |
|
123 | 123 | |
124 | 124 | return $w; |
125 | 125 | } |
126 | 126 | |
127 | 127 | private static function rotWord($w) { // rotate 4-byte word w left by one byte |
128 | 128 | $tmp = $w[0]; |
129 | - for ($i=0; $i<3; $i++) $w[$i] = $w[$i+1]; |
|
129 | + for ($i = 0; $i < 3; $i++) $w[$i] = $w[$i + 1]; |
|
130 | 130 | $w[3] = $tmp; |
131 | 131 | |
132 | 132 | return $w; |
@@ -134,22 +134,22 @@ discard block |
||
134 | 134 | |
135 | 135 | // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [é5.1.1] |
136 | 136 | private static $sBox = array( |
137 | - 0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76, |
|
138 | - 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0, |
|
139 | - 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15, |
|
140 | - 0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75, |
|
141 | - 0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84, |
|
142 | - 0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf, |
|
143 | - 0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8, |
|
144 | - 0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2, |
|
145 | - 0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73, |
|
146 | - 0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb, |
|
147 | - 0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79, |
|
148 | - 0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08, |
|
149 | - 0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a, |
|
150 | - 0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e, |
|
151 | - 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf, |
|
152 | - 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16); |
|
137 | + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, |
|
138 | + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, |
|
139 | + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, |
|
140 | + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, |
|
141 | + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, |
|
142 | + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, |
|
143 | + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, |
|
144 | + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, |
|
145 | + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, |
|
146 | + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, |
|
147 | + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, |
|
148 | + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, |
|
149 | + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, |
|
150 | + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, |
|
151 | + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, |
|
152 | + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16); |
|
153 | 153 | |
154 | 154 | // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [é5.2] |
155 | 155 | private static $rCon = array( |
@@ -19,7 +19,9 @@ discard block |
||
19 | 19 | $Nr = count($w)/$Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys |
20 | 20 | |
21 | 21 | $state = array(); // initialise 4xNb byte-array 'state' with input [é3.4] |
22 | - for ($i=0; $i<4*$Nb; $i++) $state[$i%4][floor($i/4)] = $input[$i]; |
|
22 | + for ($i=0; $i<4*$Nb; $i++) { |
|
23 | + $state[$i%4][floor($i/4)] = $input[$i]; |
|
24 | + } |
|
23 | 25 | |
24 | 26 | $state = self::addRoundKey($state, $w, 0, $Nb); |
25 | 27 | |
@@ -35,14 +37,18 @@ discard block |
||
35 | 37 | $state = self::addRoundKey($state, $w, $Nr, $Nb); |
36 | 38 | |
37 | 39 | $output = array(4*$Nb); // convert state to 1-d array before returning [é3.4] |
38 | - for ($i=0; $i<4*$Nb; $i++) $output[$i] = $state[$i%4][floor($i/4)]; |
|
40 | + for ($i=0; $i<4*$Nb; $i++) { |
|
41 | + $output[$i] = $state[$i%4][floor($i/4)]; |
|
42 | + } |
|
39 | 43 | |
40 | 44 | return $output; |
41 | 45 | } |
42 | 46 | |
43 | 47 | private static function addRoundKey($state, $w, $rnd, $Nb) { // xor Round Key into state S [é5.1.4] |
44 | 48 | for ($r=0; $r<4; $r++) { |
45 | - for ($c=0; $c<$Nb; $c++) $state[$r][$c] ^= $w[$rnd*4+$c][$r]; |
|
49 | + for ($c=0; $c<$Nb; $c++) { |
|
50 | + $state[$r][$c] ^= $w[$rnd*4+$c][$r]; |
|
51 | + } |
|
46 | 52 | } |
47 | 53 | |
48 | 54 | return $state; |
@@ -50,7 +56,9 @@ discard block |
||
50 | 56 | |
51 | 57 | private static function subBytes($s, $Nb) { // apply SBox to state S [é5.1.1] |
52 | 58 | for ($r=0; $r<4; $r++) { |
53 | - for ($c=0; $c<$Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
|
59 | + for ($c=0; $c<$Nb; $c++) { |
|
60 | + $s[$r][$c] = self::$sBox[$s[$r][$c]]; |
|
61 | + } |
|
54 | 62 | } |
55 | 63 | |
56 | 64 | return $s; |
@@ -59,8 +67,14 @@ discard block |
||
59 | 67 | private static function shiftRows($s, $Nb) { // shift row r of state S left by r bytes [é5.1.2] |
60 | 68 | $t = array(4); |
61 | 69 | for ($r=1; $r<4; $r++) { |
62 | - for ($c=0; $c<4; $c++) $t[$c] = $s[$r][($c+$r)%$Nb]; // shift into temp copy |
|
63 | - for ($c=0; $c<4; $c++) $s[$r][$c] = $t[$c]; // and copy back |
|
70 | + for ($c=0; $c<4; $c++) { |
|
71 | + $t[$c] = $s[$r][($c+$r)%$Nb]; |
|
72 | + } |
|
73 | + // shift into temp copy |
|
74 | + for ($c=0; $c<4; $c++) { |
|
75 | + $s[$r][$c] = $t[$c]; |
|
76 | + } |
|
77 | + // and copy back |
|
64 | 78 | } // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES): |
65 | 79 | return $s; // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf |
66 | 80 | } |
@@ -105,28 +119,38 @@ discard block |
||
105 | 119 | |
106 | 120 | for ($i=$Nk; $i<($Nb*($Nr+1)); $i++) { |
107 | 121 | $w[$i] = array(); |
108 | - for ($t=0; $t<4; $t++) $temp[$t] = $w[$i-1][$t]; |
|
122 | + for ($t=0; $t<4; $t++) { |
|
123 | + $temp[$t] = $w[$i-1][$t]; |
|
124 | + } |
|
109 | 125 | if ($i % $Nk == 0) { |
110 | 126 | $temp = self::subWord(self::rotWord($temp)); |
111 | - for ($t=0; $t<4; $t++) $temp[$t] ^= self::$rCon[$i/$Nk][$t]; |
|
127 | + for ($t=0; $t<4; $t++) { |
|
128 | + $temp[$t] ^= self::$rCon[$i/$Nk][$t]; |
|
129 | + } |
|
112 | 130 | } elseif ($Nk > 6 && $i%$Nk == 4) { |
113 | 131 | $temp = self::subWord($temp); |
114 | 132 | } |
115 | - for ($t=0; $t<4; $t++) $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t]; |
|
133 | + for ($t=0; $t<4; $t++) { |
|
134 | + $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t]; |
|
135 | + } |
|
116 | 136 | } |
117 | 137 | |
118 | 138 | return $w; |
119 | 139 | } |
120 | 140 | |
121 | 141 | private static function subWord($w) { // apply SBox to 4-byte word w |
122 | - for ($i=0; $i<4; $i++) $w[$i] = self::$sBox[$w[$i]]; |
|
142 | + for ($i=0; $i<4; $i++) { |
|
143 | + $w[$i] = self::$sBox[$w[$i]]; |
|
144 | + } |
|
123 | 145 | |
124 | 146 | return $w; |
125 | 147 | } |
126 | 148 | |
127 | 149 | private static function rotWord($w) { // rotate 4-byte word w left by one byte |
128 | 150 | $tmp = $w[0]; |
129 | - for ($i=0; $i<3; $i++) $w[$i] = $w[$i+1]; |
|
151 | + for ($i=0; $i<3; $i++) { |
|
152 | + $w[$i] = $w[$i+1]; |
|
153 | + } |
|
130 | 154 | $w[3] = $tmp; |
131 | 155 | |
132 | 156 | return $w; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @param plaintext source text to be encrypted |
17 | 17 | * @param password the password to use to generate a key |
18 | 18 | * @param nBits number of bits to be used in the key (128, 192, or 256) |
19 | - * @return encrypted text |
|
19 | + * @return string text |
|
20 | 20 | */ |
21 | 21 | public static function encrypt($plaintext, $password, $nBits) |
22 | 22 | { |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param ciphertext source text to be decrypted |
85 | 85 | * @param password the password to use to generate a key |
86 | 86 | * @param nBits number of bits to be used in the key (128, 192, or 256) |
87 | - * @return decrypted text |
|
87 | + * @return string text |
|
88 | 88 | */ |
89 | 89 | public static function decrypt($ciphertext, $password, $nBits) |
90 | 90 | { |
@@ -7,19 +7,19 @@ discard block |
||
7 | 7 | |
8 | 8 | class AesCtr extends Aes |
9 | 9 | { |
10 | - /** |
|
11 | - * Encrypt a text using AES encryption in Counter mode of operation |
|
12 | - * - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf |
|
13 | - * |
|
14 | - * Unicode multi-byte character safe |
|
15 | - * |
|
16 | - * @param plaintext source text to be encrypted |
|
17 | - * @param password the password to use to generate a key |
|
18 | - * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
19 | - * @return encrypted text |
|
20 | - */ |
|
21 | - public static function encrypt($plaintext, $password, $nBits) |
|
22 | - { |
|
10 | + /** |
|
11 | + * Encrypt a text using AES encryption in Counter mode of operation |
|
12 | + * - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf |
|
13 | + * |
|
14 | + * Unicode multi-byte character safe |
|
15 | + * |
|
16 | + * @param plaintext source text to be encrypted |
|
17 | + * @param password the password to use to generate a key |
|
18 | + * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
19 | + * @return encrypted text |
|
20 | + */ |
|
21 | + public static function encrypt($plaintext, $password, $nBits) |
|
22 | + { |
|
23 | 23 | $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
24 | 24 | if (!($nBits==128 || $nBits==192 || $nBits==256)) return ''; // standard allows 128/192/256 bit keys |
25 | 25 | // note PHP (5) gives us plaintext and password in UTF8 encoding! |
@@ -53,22 +53,22 @@ discard block |
||
53 | 53 | $ciphertxt = array(); // ciphertext as array of strings |
54 | 54 | |
55 | 55 | for ($b=0; $b<$blockCount; $b++) { |
56 | - // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
|
57 | - // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB) |
|
58 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
59 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8); |
|
56 | + // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
|
57 | + // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB) |
|
58 | + for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
59 | + for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8); |
|
60 | 60 | |
61 | - $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block -- |
|
61 | + $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block -- |
|
62 | 62 | |
63 | - // block size is reduced on final block |
|
64 | - $blockLength = $b<$blockCount-1 ? $blockSize : (strlen($plaintext)-1)%$blockSize+1; |
|
65 | - $cipherByte = array(); |
|
63 | + // block size is reduced on final block |
|
64 | + $blockLength = $b<$blockCount-1 ? $blockSize : (strlen($plaintext)-1)%$blockSize+1; |
|
65 | + $cipherByte = array(); |
|
66 | 66 | |
67 | - for ($i=0; $i<$blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte -- |
|
67 | + for ($i=0; $i<$blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte -- |
|
68 | 68 | $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b*$blockSize+$i, 1)); |
69 | 69 | $cipherByte[$i] = chr($cipherByte[$i]); |
70 | - } |
|
71 | - $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext |
|
70 | + } |
|
71 | + $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // implode is more efficient than repeated string concatenation |
@@ -76,18 +76,18 @@ discard block |
||
76 | 76 | $ciphertext = base64_encode($ciphertext); |
77 | 77 | |
78 | 78 | return $ciphertext; |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Decrypt a text encrypted by AES in counter mode of operation |
|
83 | - * |
|
84 | - * @param ciphertext source text to be decrypted |
|
85 | - * @param password the password to use to generate a key |
|
86 | - * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
87 | - * @return decrypted text |
|
88 | - */ |
|
89 | - public static function decrypt($ciphertext, $password, $nBits) |
|
90 | - { |
|
81 | + /** |
|
82 | + * Decrypt a text encrypted by AES in counter mode of operation |
|
83 | + * |
|
84 | + * @param ciphertext source text to be decrypted |
|
85 | + * @param password the password to use to generate a key |
|
86 | + * @param nBits number of bits to be used in the key (128, 192, or 256) |
|
87 | + * @return decrypted text |
|
88 | + */ |
|
89 | + public static function decrypt($ciphertext, $password, $nBits) |
|
90 | + { |
|
91 | 91 | $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
92 | 92 | if (!($nBits==128 || $nBits==192 || $nBits==256)) return ''; // standard allows 128/192/256 bit keys |
93 | 93 | $ciphertext = base64_decode($ciphertext); |
@@ -117,47 +117,47 @@ discard block |
||
117 | 117 | $plaintxt = array(); |
118 | 118 | |
119 | 119 | for ($b=0; $b<$nBlocks; $b++) { |
120 | - // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
|
121 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
122 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff; |
|
120 | + // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
|
121 | + for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
122 | + for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff; |
|
123 | 123 | |
124 | - $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block |
|
124 | + $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block |
|
125 | 125 | |
126 | - $plaintxtByte = array(); |
|
127 | - for ($i=0; $i<strlen($ciphertext[$b]); $i++) { |
|
126 | + $plaintxtByte = array(); |
|
127 | + for ($i=0; $i<strlen($ciphertext[$b]); $i++) { |
|
128 | 128 | // -- xor plaintext with ciphered counter byte-by-byte -- |
129 | 129 | $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b],$i,1)); |
130 | 130 | $plaintxtByte[$i] = chr($plaintxtByte[$i]); |
131 | 131 | |
132 | - } |
|
133 | - $plaintxt[$b] = implode('', $plaintxtByte); |
|
132 | + } |
|
133 | + $plaintxt[$b] = implode('', $plaintxtByte); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | // join array of blocks into single plaintext string |
137 | 137 | $plaintext = implode('',$plaintxt); |
138 | 138 | |
139 | 139 | return $plaintext; |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | - /* |
|
142 | + /* |
|
143 | 143 | * Unsigned right shift function, since PHP has neither >>> operator nor unsigned ints |
144 | 144 | * |
145 | 145 | * @param a number to be shifted (32-bit integer) |
146 | 146 | * @param b number of bits to shift a to the right (0..31) |
147 | 147 | * @return a right-shifted and zero-filled by b bits |
148 | 148 | */ |
149 | - private static function urs($a, $b) |
|
150 | - { |
|
149 | + private static function urs($a, $b) |
|
150 | + { |
|
151 | 151 | $a &= 0xffffffff; $b &= 0x1f; // (bounds check) |
152 | 152 | if ($a&0x80000000 && $b>0) { // if left-most bit set |
153 | - $a = ($a>>1) & 0x7fffffff; // right-shift one bit & clear left-most bit |
|
154 | - $a = $a >> ($b-1); // remaining right-shifts |
|
153 | + $a = ($a>>1) & 0x7fffffff; // right-shift one bit & clear left-most bit |
|
154 | + $a = $a >> ($b-1); // remaining right-shifts |
|
155 | 155 | } else { // otherwise |
156 | - $a = ($a>>$b); // use normal right-shift |
|
156 | + $a = ($a>>$b); // use normal right-shift |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return $a; |
160 | - } |
|
160 | + } |
|
161 | 161 | |
162 | 162 | } |
163 | 163 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ |
@@ -20,55 +20,55 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public static function encrypt($plaintext, $password, $nBits) |
22 | 22 | { |
23 | - $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
|
24 | - if (!($nBits==128 || $nBits==192 || $nBits==256)) return ''; // standard allows 128/192/256 bit keys |
|
23 | + $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
|
24 | + if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys |
|
25 | 25 | // note PHP (5) gives us plaintext and password in UTF8 encoding! |
26 | 26 | |
27 | 27 | // use AES itself to encrypt password to get cipher key (using plain password as source for |
28 | 28 | // key expansion) - gives us well encrypted key |
29 | - $nBytes = $nBits/8; // no bytes in key |
|
29 | + $nBytes = $nBits / 8; // no bytes in key |
|
30 | 30 | $pwBytes = array(); |
31 | - for ($i=0; $i<$nBytes; $i++) $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
31 | + for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff; |
|
32 | 32 | $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes)); |
33 | - $key = array_merge($key, array_slice($key, 0, $nBytes-16)); // expand key to 16/24/32 bytes long |
|
33 | + $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long |
|
34 | 34 | |
35 | 35 | // initialise counter block (NIST SP800-38A §B.2): millisecond time-stamp for nonce in |
36 | 36 | // 1st 8 bytes, block counter in 2nd 8 bytes |
37 | 37 | $counterBlock = array(); |
38 | - $nonce = floor(microtime(true)*1000); // timestamp: milliseconds since 1-Jan-1970 |
|
39 | - $nonceSec = floor($nonce/1000); |
|
40 | - $nonceMs = $nonce%1000; |
|
38 | + $nonce = floor(microtime(true) * 1000); // timestamp: milliseconds since 1-Jan-1970 |
|
39 | + $nonceSec = floor($nonce / 1000); |
|
40 | + $nonceMs = $nonce % 1000; |
|
41 | 41 | // encode nonce with seconds in 1st 4 bytes, and (repeated) ms part filling 2nd 4 bytes |
42 | - for ($i=0; $i<4; $i++) $counterBlock[$i] = self::urs($nonceSec, $i*8) & 0xff; |
|
43 | - for ($i=0; $i<4; $i++) $counterBlock[$i+4] = $nonceMs & 0xff; |
|
42 | + for ($i = 0; $i < 4; $i++) $counterBlock[$i] = self::urs($nonceSec, $i * 8) & 0xff; |
|
43 | + for ($i = 0; $i < 4; $i++) $counterBlock[$i + 4] = $nonceMs & 0xff; |
|
44 | 44 | // and convert it to a string to go on the front of the ciphertext |
45 | 45 | $ctrTxt = ''; |
46 | - for ($i=0; $i<8; $i++) $ctrTxt .= chr($counterBlock[$i]); |
|
46 | + for ($i = 0; $i < 8; $i++) $ctrTxt .= chr($counterBlock[$i]); |
|
47 | 47 | |
48 | 48 | // generate key schedule - an expansion of the key into distinct Key Rounds for each round |
49 | 49 | $keySchedule = Aes::keyExpansion($key); |
50 | 50 | //print_r($keySchedule); |
51 | 51 | |
52 | - $blockCount = ceil(strlen($plaintext)/$blockSize); |
|
53 | - $ciphertxt = array(); // ciphertext as array of strings |
|
52 | + $blockCount = ceil(strlen($plaintext) / $blockSize); |
|
53 | + $ciphertxt = array(); // ciphertext as array of strings |
|
54 | 54 | |
55 | - for ($b=0; $b<$blockCount; $b++) { |
|
55 | + for ($b = 0; $b < $blockCount; $b++) { |
|
56 | 56 | // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
57 | 57 | // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB) |
58 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
59 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8); |
|
58 | + for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff; |
|
59 | + for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs($b / 0x100000000, $c * 8); |
|
60 | 60 | |
61 | - $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block -- |
|
61 | + $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block -- |
|
62 | 62 | |
63 | 63 | // block size is reduced on final block |
64 | - $blockLength = $b<$blockCount-1 ? $blockSize : (strlen($plaintext)-1)%$blockSize+1; |
|
64 | + $blockLength = $b < $blockCount - 1 ? $blockSize : (strlen($plaintext) - 1) % $blockSize + 1; |
|
65 | 65 | $cipherByte = array(); |
66 | 66 | |
67 | - for ($i=0; $i<$blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte -- |
|
68 | - $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b*$blockSize+$i, 1)); |
|
67 | + for ($i = 0; $i < $blockLength; $i++) { // -- xor plaintext with ciphered counter byte-by-byte -- |
|
68 | + $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b * $blockSize + $i, 1)); |
|
69 | 69 | $cipherByte[$i] = chr($cipherByte[$i]); |
70 | 70 | } |
71 | - $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext |
|
71 | + $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // implode is more efficient than repeated string concatenation |
@@ -88,45 +88,45 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public static function decrypt($ciphertext, $password, $nBits) |
90 | 90 | { |
91 | - $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
|
92 | - if (!($nBits==128 || $nBits==192 || $nBits==256)) return ''; // standard allows 128/192/256 bit keys |
|
91 | + $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
|
92 | + if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) return ''; // standard allows 128/192/256 bit keys |
|
93 | 93 | $ciphertext = base64_decode($ciphertext); |
94 | 94 | |
95 | 95 | // use AES to encrypt password (mirroring encrypt routine) |
96 | - $nBytes = $nBits/8; // no bytes in key |
|
96 | + $nBytes = $nBits / 8; // no bytes in key |
|
97 | 97 | $pwBytes = array(); |
98 | - for ($i=0; $i<$nBytes; $i++) $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
98 | + for ($i = 0; $i < $nBytes; $i++) $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff; |
|
99 | 99 | $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes)); |
100 | - $key = array_merge($key, array_slice($key, 0, $nBytes-16)); // expand key to 16/24/32 bytes long |
|
100 | + $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long |
|
101 | 101 | |
102 | 102 | // recover nonce from 1st element of ciphertext |
103 | 103 | $counterBlock = array(); |
104 | 104 | $ctrTxt = substr($ciphertext, 0, 8); |
105 | - for ($i=0; $i<8; $i++) $counterBlock[$i] = ord(substr($ctrTxt,$i,1)); |
|
105 | + for ($i = 0; $i < 8; $i++) $counterBlock[$i] = ord(substr($ctrTxt, $i, 1)); |
|
106 | 106 | |
107 | 107 | // generate key schedule |
108 | 108 | $keySchedule = Aes::keyExpansion($key); |
109 | 109 | |
110 | 110 | // separate ciphertext into blocks (skipping past initial 8 bytes) |
111 | - $nBlocks = ceil((strlen($ciphertext)-8) / $blockSize); |
|
111 | + $nBlocks = ceil((strlen($ciphertext) - 8) / $blockSize); |
|
112 | 112 | $ct = array(); |
113 | - for ($b=0; $b<$nBlocks; $b++) $ct[$b] = substr($ciphertext, 8+$b*$blockSize, 16); |
|
114 | - $ciphertext = $ct; // ciphertext is now array of block-length strings |
|
113 | + for ($b = 0; $b < $nBlocks; $b++) $ct[$b] = substr($ciphertext, 8 + $b * $blockSize, 16); |
|
114 | + $ciphertext = $ct; // ciphertext is now array of block-length strings |
|
115 | 115 | |
116 | 116 | // plaintext will get generated block-by-block into array of block-length strings |
117 | 117 | $plaintxt = array(); |
118 | 118 | |
119 | - for ($b=0; $b<$nBlocks; $b++) { |
|
119 | + for ($b = 0; $b < $nBlocks; $b++) { |
|
120 | 120 | // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
121 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
122 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff; |
|
121 | + for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff; |
|
122 | + for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs(($b + 1) / 0x100000000 - 1, $c * 8) & 0xff; |
|
123 | 123 | |
124 | - $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block |
|
124 | + $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block |
|
125 | 125 | |
126 | 126 | $plaintxtByte = array(); |
127 | - for ($i=0; $i<strlen($ciphertext[$b]); $i++) { |
|
127 | + for ($i = 0; $i < strlen($ciphertext[$b]); $i++) { |
|
128 | 128 | // -- xor plaintext with ciphered counter byte-by-byte -- |
129 | - $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b],$i,1)); |
|
129 | + $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b], $i, 1)); |
|
130 | 130 | $plaintxtByte[$i] = chr($plaintxtByte[$i]); |
131 | 131 | |
132 | 132 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | } |
135 | 135 | |
136 | 136 | // join array of blocks into single plaintext string |
137 | - $plaintext = implode('',$plaintxt); |
|
137 | + $plaintext = implode('', $plaintxt); |
|
138 | 138 | |
139 | 139 | return $plaintext; |
140 | 140 | } |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | */ |
149 | 149 | private static function urs($a, $b) |
150 | 150 | { |
151 | - $a &= 0xffffffff; $b &= 0x1f; // (bounds check) |
|
152 | - if ($a&0x80000000 && $b>0) { // if left-most bit set |
|
153 | - $a = ($a>>1) & 0x7fffffff; // right-shift one bit & clear left-most bit |
|
154 | - $a = $a >> ($b-1); // remaining right-shifts |
|
151 | + $a &= 0xffffffff; $b &= 0x1f; // (bounds check) |
|
152 | + if ($a & 0x80000000 && $b > 0) { // if left-most bit set |
|
153 | + $a = ($a >> 1) & 0x7fffffff; // right-shift one bit & clear left-most bit |
|
154 | + $a = $a >> ($b - 1); // remaining right-shifts |
|
155 | 155 | } else { // otherwise |
156 | - $a = ($a>>$b); // use normal right-shift |
|
156 | + $a = ($a >> $b); // use normal right-shift |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return $a; |
@@ -21,14 +21,19 @@ discard block |
||
21 | 21 | public static function encrypt($plaintext, $password, $nBits) |
22 | 22 | { |
23 | 23 | $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
24 | - if (!($nBits==128 || $nBits==192 || $nBits==256)) return ''; // standard allows 128/192/256 bit keys |
|
24 | + if (!($nBits==128 || $nBits==192 || $nBits==256)) { |
|
25 | + return ''; |
|
26 | + } |
|
27 | + // standard allows 128/192/256 bit keys |
|
25 | 28 | // note PHP (5) gives us plaintext and password in UTF8 encoding! |
26 | 29 | |
27 | 30 | // use AES itself to encrypt password to get cipher key (using plain password as source for |
28 | 31 | // key expansion) - gives us well encrypted key |
29 | 32 | $nBytes = $nBits/8; // no bytes in key |
30 | 33 | $pwBytes = array(); |
31 | - for ($i=0; $i<$nBytes; $i++) $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
34 | + for ($i=0; $i<$nBytes; $i++) { |
|
35 | + $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
36 | + } |
|
32 | 37 | $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes)); |
33 | 38 | $key = array_merge($key, array_slice($key, 0, $nBytes-16)); // expand key to 16/24/32 bytes long |
34 | 39 | |
@@ -39,11 +44,17 @@ discard block |
||
39 | 44 | $nonceSec = floor($nonce/1000); |
40 | 45 | $nonceMs = $nonce%1000; |
41 | 46 | // encode nonce with seconds in 1st 4 bytes, and (repeated) ms part filling 2nd 4 bytes |
42 | - for ($i=0; $i<4; $i++) $counterBlock[$i] = self::urs($nonceSec, $i*8) & 0xff; |
|
43 | - for ($i=0; $i<4; $i++) $counterBlock[$i+4] = $nonceMs & 0xff; |
|
47 | + for ($i=0; $i<4; $i++) { |
|
48 | + $counterBlock[$i] = self::urs($nonceSec, $i*8) & 0xff; |
|
49 | + } |
|
50 | + for ($i=0; $i<4; $i++) { |
|
51 | + $counterBlock[$i+4] = $nonceMs & 0xff; |
|
52 | + } |
|
44 | 53 | // and convert it to a string to go on the front of the ciphertext |
45 | 54 | $ctrTxt = ''; |
46 | - for ($i=0; $i<8; $i++) $ctrTxt .= chr($counterBlock[$i]); |
|
55 | + for ($i=0; $i<8; $i++) { |
|
56 | + $ctrTxt .= chr($counterBlock[$i]); |
|
57 | + } |
|
47 | 58 | |
48 | 59 | // generate key schedule - an expansion of the key into distinct Key Rounds for each round |
49 | 60 | $keySchedule = Aes::keyExpansion($key); |
@@ -55,8 +66,12 @@ discard block |
||
55 | 66 | for ($b=0; $b<$blockCount; $b++) { |
56 | 67 | // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
57 | 68 | // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB) |
58 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
59 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8); |
|
69 | + for ($c=0; $c<4; $c++) { |
|
70 | + $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
71 | + } |
|
72 | + for ($c=0; $c<4; $c++) { |
|
73 | + $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8); |
|
74 | + } |
|
60 | 75 | |
61 | 76 | $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block -- |
62 | 77 | |
@@ -89,20 +104,27 @@ discard block |
||
89 | 104 | public static function decrypt($ciphertext, $password, $nBits) |
90 | 105 | { |
91 | 106 | $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES |
92 | - if (!($nBits==128 || $nBits==192 || $nBits==256)) return ''; // standard allows 128/192/256 bit keys |
|
107 | + if (!($nBits==128 || $nBits==192 || $nBits==256)) { |
|
108 | + return ''; |
|
109 | + } |
|
110 | + // standard allows 128/192/256 bit keys |
|
93 | 111 | $ciphertext = base64_decode($ciphertext); |
94 | 112 | |
95 | 113 | // use AES to encrypt password (mirroring encrypt routine) |
96 | 114 | $nBytes = $nBits/8; // no bytes in key |
97 | 115 | $pwBytes = array(); |
98 | - for ($i=0; $i<$nBytes; $i++) $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
116 | + for ($i=0; $i<$nBytes; $i++) { |
|
117 | + $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff; |
|
118 | + } |
|
99 | 119 | $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes)); |
100 | 120 | $key = array_merge($key, array_slice($key, 0, $nBytes-16)); // expand key to 16/24/32 bytes long |
101 | 121 | |
102 | 122 | // recover nonce from 1st element of ciphertext |
103 | 123 | $counterBlock = array(); |
104 | 124 | $ctrTxt = substr($ciphertext, 0, 8); |
105 | - for ($i=0; $i<8; $i++) $counterBlock[$i] = ord(substr($ctrTxt,$i,1)); |
|
125 | + for ($i=0; $i<8; $i++) { |
|
126 | + $counterBlock[$i] = ord(substr($ctrTxt,$i,1)); |
|
127 | + } |
|
106 | 128 | |
107 | 129 | // generate key schedule |
108 | 130 | $keySchedule = Aes::keyExpansion($key); |
@@ -110,7 +132,9 @@ discard block |
||
110 | 132 | // separate ciphertext into blocks (skipping past initial 8 bytes) |
111 | 133 | $nBlocks = ceil((strlen($ciphertext)-8) / $blockSize); |
112 | 134 | $ct = array(); |
113 | - for ($b=0; $b<$nBlocks; $b++) $ct[$b] = substr($ciphertext, 8+$b*$blockSize, 16); |
|
135 | + for ($b=0; $b<$nBlocks; $b++) { |
|
136 | + $ct[$b] = substr($ciphertext, 8+$b*$blockSize, 16); |
|
137 | + } |
|
114 | 138 | $ciphertext = $ct; // ciphertext is now array of block-length strings |
115 | 139 | |
116 | 140 | // plaintext will get generated block-by-block into array of block-length strings |
@@ -118,8 +142,12 @@ discard block |
||
118 | 142 | |
119 | 143 | for ($b=0; $b<$nBlocks; $b++) { |
120 | 144 | // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes) |
121 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
122 | - for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff; |
|
145 | + for ($c=0; $c<4; $c++) { |
|
146 | + $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff; |
|
147 | + } |
|
148 | + for ($c=0; $c<4; $c++) { |
|
149 | + $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff; |
|
150 | + } |
|
123 | 151 | |
124 | 152 | $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block |
125 | 153 |
@@ -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, "=")); |
@@ -423,8 +423,8 @@ discard block |
||
423 | 423 | <h3>Step 2</h3> |
424 | 424 | <fieldset><legend>DataBase Informations</legend>'; |
425 | 425 | |
426 | - // check if all database info are available |
|
427 | - if ( |
|
426 | + // check if all database info are available |
|
427 | + if ( |
|
428 | 428 | isset($_SESSION['server']) && !empty($_SESSION['server']) |
429 | 429 | && isset($_SESSION['database']) && !empty($_SESSION['database']) |
430 | 430 | && isset($_SESSION['user']) && !empty($_SESSION['user']) |
@@ -437,15 +437,15 @@ discard block |
||
437 | 437 | The database information has been retreived from the settings file.<br> |
438 | 438 | If you need to change them, please edit file `/includes/config/settings.php` and relaunch the upgrade process. |
439 | 439 | </div>'; |
440 | - } else { |
|
440 | + } else { |
|
441 | 441 | echo ' |
442 | 442 | <div style=""> |
443 | 443 | The database information has not been retreived from the settings file.<br> |
444 | 444 | You need to adapt the file `/includes/config/settings.php` and relaunch the upgrade process. |
445 | 445 | </div>'; |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - echo ' |
|
448 | + echo ' |
|
449 | 449 | <a href="'.$protocol.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/') - 8).'/install/upgrade.php">Restart upgrade process</a> |
450 | 450 | </fieldset> |
451 | 451 | |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | </div>'; |
476 | 476 | |
477 | 477 | // teampass_version = 2.1.27 and no encrypt_key in db |
478 | - echo ' |
|
478 | + echo ' |
|
479 | 479 | <div id="no_encrypt_key" style="display:none;"> |
480 | 480 | <fieldset> |
481 | 481 | <legend>Database Origine</legend> |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | function getSettingValue($val) |
11 | 11 | { |
12 | 12 | $val = trim(strstr($val, "=")); |
13 | - return trim(str_replace('"', '', substr($val, 1, strpos($val, ";")-1))); |
|
13 | + return trim(str_replace('"', '', substr($val, 1, strpos($val, ";") - 1))); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | //get infos from SETTINGS.PHP file |
@@ -19,41 +19,41 @@ discard block |
||
19 | 19 | if (file_exists($filename)) { |
20 | 20 | //copy some constants from this existing file |
21 | 21 | $settings_file = file($filename); |
22 | - while (list($key,$val) = each($settings_file)) { |
|
23 | - if (substr_count($val,'charset')>0) { |
|
22 | + while (list($key, $val) = each($settings_file)) { |
|
23 | + if (substr_count($val, 'charset') > 0) { |
|
24 | 24 | $_SESSION['charset'] = getSettingValue($val); |
25 | - } elseif (substr_count($val,'@define(')>0 && substr_count($val, 'SALT')>0) { |
|
26 | - $_SESSION['encrypt_key'] = substr($val,17,strpos($val,"')")-17); |
|
27 | - } elseif (substr_count($val,'$smtp_server = ')>0) { |
|
25 | + } elseif (substr_count($val, '@define(') > 0 && substr_count($val, 'SALT') > 0) { |
|
26 | + $_SESSION['encrypt_key'] = substr($val, 17, strpos($val, "')") - 17); |
|
27 | + } elseif (substr_count($val, '$smtp_server = ') > 0) { |
|
28 | 28 | $_SESSION['smtp_server'] = getSettingValue($val); |
29 | - } elseif (substr_count($val,'$smtp_auth = ')>0) { |
|
29 | + } elseif (substr_count($val, '$smtp_auth = ') > 0) { |
|
30 | 30 | $_SESSION['smtp_auth'] = getSettingValue($val); |
31 | - } elseif (substr_count($val,'$smtp_port = ')>0) { |
|
31 | + } elseif (substr_count($val, '$smtp_port = ') > 0) { |
|
32 | 32 | $_SESSION['smtp_port'] = getSettingValue($val); |
33 | - } elseif (substr_count($val,'$smtp_security = ')>0) { |
|
33 | + } elseif (substr_count($val, '$smtp_security = ') > 0) { |
|
34 | 34 | $_SESSION['smtp_security'] = getSettingValue($val); |
35 | - } elseif (substr_count($val,'$smtp_auth_username = ')>0) { |
|
35 | + } elseif (substr_count($val, '$smtp_auth_username = ') > 0) { |
|
36 | 36 | $_SESSION['smtp_auth_username'] = getSettingValue($val); |
37 | - } elseif (substr_count($val,'$smtp_auth_password = ')>0) { |
|
37 | + } elseif (substr_count($val, '$smtp_auth_password = ') > 0) { |
|
38 | 38 | $_SESSION['smtp_auth_password'] = getSettingValue($val); |
39 | - } elseif (substr_count($val,'$email_from = ')>0) { |
|
39 | + } elseif (substr_count($val, '$email_from = ') > 0) { |
|
40 | 40 | $_SESSION['email_from'] = getSettingValue($val); |
41 | - } elseif (substr_count($val,'$email_from_name = ')>0) { |
|
41 | + } elseif (substr_count($val, '$email_from_name = ') > 0) { |
|
42 | 42 | $_SESSION['email_from_name'] = getSettingValue($val); |
43 | - } elseif (substr_count($val,'$server = ')>0) { |
|
43 | + } elseif (substr_count($val, '$server = ') > 0) { |
|
44 | 44 | $_SESSION['server'] = getSettingValue($val); |
45 | - } elseif (substr_count($val,'$user = ')>0) { |
|
45 | + } elseif (substr_count($val, '$user = ') > 0) { |
|
46 | 46 | $_SESSION['user'] = getSettingValue($val); |
47 | - } elseif (substr_count($val,'$pass = ')>0) { |
|
47 | + } elseif (substr_count($val, '$pass = ') > 0) { |
|
48 | 48 | $_SESSION['pass'] = getSettingValue($val); |
49 | - } elseif (substr_count($val,'$port = ')>0) { |
|
49 | + } elseif (substr_count($val, '$port = ') > 0) { |
|
50 | 50 | $_SESSION['port'] = getSettingValue($val); |
51 | - } elseif (substr_count($val,'$database = ')>0) { |
|
51 | + } elseif (substr_count($val, '$database = ') > 0) { |
|
52 | 52 | $_SESSION['database'] = getSettingValue($val); |
53 | - } elseif (substr_count($val,'$pre = ')>0) { |
|
53 | + } elseif (substr_count($val, '$pre = ') > 0) { |
|
54 | 54 | $_SESSION['pre'] = getSettingValue($val); |
55 | - } elseif (substr_count($val,'require_once "')>0 && substr_count($val, 'sk.php')>0) { |
|
56 | - $_SESSION['sk_path'] = substr($val,14,strpos($val,'";')-14); |
|
55 | + } elseif (substr_count($val, 'require_once "') > 0 && substr_count($val, 'sk.php') > 0) { |
|
56 | + $_SESSION['sk_path'] = substr($val, 14, strpos($val, '";') - 14); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | } |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | ) { |
64 | 64 | //copy some constants from this existing file |
65 | 65 | $skFile = file($_SESSION['sk_file']); |
66 | - while (list($key,$val) = each($skFile)) { |
|
67 | - if (substr_count($val, '@define(')>0) { |
|
68 | - $_SESSION['encrypt_key'] = substr($val, 17, strpos($val, "')")-17); |
|
66 | + while (list($key, $val) = each($skFile)) { |
|
67 | + if (substr_count($val, '@define(') > 0) { |
|
68 | + $_SESSION['encrypt_key'] = substr($val, 17, strpos($val, "')") - 17); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | } |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | |
311 | 311 | |
312 | 312 | //define root path |
313 | -$abs_path = rtrim($_SERVER['DOCUMENT_ROOT'], '/') . substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF'])-20); |
|
314 | -if( isset($_SERVER['HTTPS'] ) ) { |
|
313 | +$abs_path = rtrim($_SERVER['DOCUMENT_ROOT'], '/').substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF']) - 20); |
|
314 | +if (isset($_SERVER['HTTPS'])) { |
|
315 | 315 | $protocol = 'https://'; |
316 | 316 | } else { |
317 | 317 | $protocol = 'http://'; |
@@ -334,12 +334,12 @@ discard block |
||
334 | 334 | |
335 | 335 | //HIDDEN THINGS |
336 | 336 | echo ' |
337 | - <input type="hidden" id="step" name="step" value="', isset($_POST['step']) ? $_POST['step']:'', '" /> |
|
338 | - <input type="hidden" id="actual_cpm_version" name="actual_cpm_version" value="', isset($_POST['actual_cpm_version']) ? $_POST['actual_cpm_version']:'', '" /> |
|
339 | - <input type="hidden" id="cpm_isUTF8" name="cpm_isUTF8" value="', isset($_POST['cpm_isUTF8']) ? $_POST['cpm_isUTF8']:'', '" /> |
|
337 | + <input type="hidden" id="step" name="step" value="', isset($_POST['step']) ? $_POST['step'] : '', '" /> |
|
338 | + <input type="hidden" id="actual_cpm_version" name="actual_cpm_version" value="', isset($_POST['actual_cpm_version']) ? $_POST['actual_cpm_version'] : '', '" /> |
|
339 | + <input type="hidden" id="cpm_isUTF8" name="cpm_isUTF8" value="', isset($_POST['cpm_isUTF8']) ? $_POST['cpm_isUTF8'] : '', '" /> |
|
340 | 340 | <input type="hidden" name="menu_action" id="menu_action" value="" /> |
341 | 341 | <input type="hidden" name="user_granted" id="user_granted" value="" /> |
342 | - <input type="hidden" name="session_salt" id="session_salt" value="', (isset($_POST['session_salt']) && !empty($_POST['session_salt'])) ? $_POST['session_salt']:@$_SESSION['encrypt_key'], '" />'; |
|
342 | + <input type="hidden" name="session_salt" id="session_salt" value="', (isset($_POST['session_salt']) && !empty($_POST['session_salt'])) ? $_POST['session_salt'] : @$_SESSION['encrypt_key'], '" />'; |
|
343 | 343 | |
344 | 344 | if (!isset($_GET['step']) && !isset($_POST['step'])) { |
345 | 345 | //ETAPE O |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | echo '<br /><br /> |
572 | 572 | <label for="sk_path" style="width:300px;">Absolute path to SaltKey : |
573 | 573 | <img src="images/information-white.png" alt="" title="The SaltKey is stored in a file called sk.php. But for security reasons, this file should be stored in a folder outside the www folder of your server. So please, indicate here the path to this folder."> |
574 | - </label><input type="text" id="sk_path" name="sk_path" value="'.substr($_SESSION['sk_path'], 0, strlen($_SESSION['sk_path'])-7).'" size="75" /><br /> |
|
574 | + </label><input type="text" id="sk_path" name="sk_path" value="'.substr($_SESSION['sk_path'], 0, strlen($_SESSION['sk_path']) - 7).'" size="75" /><br /> |
|
575 | 575 | '; |
576 | 576 | } |
577 | 577 | echo ' |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | <div style="width:900px;margin:auto;margin-top:30px;"> |
603 | 603 | <div id="progressbar" style="float:left;margin-top:9px;"></div> |
604 | 604 | <div id="buttons_bottom"> |
605 | - <input type="button" id="but_next" target_id="'. (intval($_POST['step'])+1).'" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="NEXT" /> |
|
605 | + <input type="button" id="but_next" target_id="'. (intval($_POST['step']) + 1).'" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="NEXT" /> |
|
606 | 606 | </div> |
607 | 607 | </div>'; |
608 | 608 | } elseif ($_POST['step'] == 3 && $conversion_utf8 == true && $_SESSION['user_granted'] === "1") { |
@@ -610,22 +610,22 @@ discard block |
||
610 | 610 | <div style="width:900px;margin:auto;margin-top:30px;"> |
611 | 611 | <div id="progressbar" style="float:left;margin-top:9px;"></div> |
612 | 612 | <div id="buttons_bottom"> |
613 | - <input type="button" id="but_launch" onclick="Check(\'step'.$_POST['step'] .'\')" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="LAUNCH" /> |
|
614 | - <input type="button" id="but_next" target_id="'. (intval($_POST['step'])+1).'" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="NEXT" disabled="disabled" /> |
|
613 | + <input type="button" id="but_launch" onclick="Check(\'step'.$_POST['step'].'\')" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="LAUNCH" /> |
|
614 | + <input type="button" id="but_next" target_id="'. (intval($_POST['step']) + 1).'" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="NEXT" disabled="disabled" /> |
|
615 | 615 | </div> |
616 | 616 | </div>'; |
617 | 617 | } elseif ($_POST['step'] == 6 && $_SESSION['user_granted'] === "1") { |
618 | 618 | echo ' |
619 | 619 | <div style="margin-top:30px; text-align:center; width:100%; font-size:24px;"> |
620 | - <a href="#" onclick="javascript:window.location.href=\'', (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ? 'https' : 'http', '://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],'/')-8).'\';"><b>Open TeamPass</b></a> |
|
620 | + <a href="#" onclick="javascript:window.location.href=\'', (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ? 'https' : 'http', '://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/') - 8).'\';"><b>Open TeamPass</b></a> |
|
621 | 621 | </div>'; |
622 | 622 | } else { |
623 | 623 | echo ' |
624 | 624 | <div style="width:900px;margin:auto;margin-top:30px;"> |
625 | 625 | <div id="progressbar" style="float:left;margin-top:9px;"></div> |
626 | 626 | <div id="buttons_bottom"> |
627 | - <input type="button" id="but_launch" onclick="Check(\'step'.$_POST['step'] .'\')" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="LAUNCH" /> |
|
628 | - <input type="button" id="but_next" target_id="'. (intval($_POST['step'])+1).'" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="NEXT" disabled="disabled" /> |
|
627 | + <input type="button" id="but_launch" onclick="Check(\'step'.$_POST['step'].'\')" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="LAUNCH" /> |
|
628 | + <input type="button" id="but_next" target_id="'. (intval($_POST['step']) + 1).'" style="padding:3px;cursor:pointer;font-size:20px;" class="ui-state-default ui-corner-all" value="NEXT" disabled="disabled" /> |
|
629 | 629 | </div> |
630 | 630 | </div>'; |
631 | 631 | } |
@@ -39,6 +39,9 @@ |
||
39 | 39 | * |
40 | 40 | * Used to format the string ready for insertion in to the database |
41 | 41 | */ |
42 | +/** |
|
43 | + * @param string $crLFReplacement |
|
44 | + */ |
|
42 | 45 | function sanitiseString($str, $crLFReplacement) { |
43 | 46 | $str = preg_replace('#[\r\n]#', $crLFReplacement, $str); |
44 | 47 | $str = str_replace('\\', '\', $str); |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | 'id_tree' => $_POST['folder'], |
276 | 276 | 'login' => substr($item[1], 0, 200), |
277 | 277 | 'anyone_can_modify' => $_POST['import_csv_anyone_can_modify'] == "true" ? 1 : 0 |
278 | - ) |
|
278 | + ) |
|
279 | 279 | ); |
280 | 280 | $newId = DB::insertId(); |
281 | 281 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | array( |
288 | 288 | 'role_id' => $role['id'], |
289 | 289 | 'item_id' => $newId |
290 | - ) |
|
290 | + ) |
|
291 | 291 | ); |
292 | 292 | } |
293 | 293 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | 'date' => time(), |
301 | 301 | 'id_user' => $_SESSION['user_id'], |
302 | 302 | 'action' => 'at_creation' |
303 | - ) |
|
303 | + ) |
|
304 | 304 | ); |
305 | 305 | |
306 | 306 | if (empty($list)) { |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | 'timestamp' => time(), |
325 | 325 | 'tags' => '', |
326 | 326 | 'restricted_to' => '' |
327 | - ) |
|
327 | + ) |
|
328 | 328 | ); |
329 | 329 | } |
330 | 330 | echo '[{"items":"'.$list.'"}]'; |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | |
358 | 358 | /** |
359 | 359 | Recursive function that will permit to read each level of XML nodes |
360 | - */ |
|
360 | + */ |
|
361 | 361 | function recursiveKeepassXML($xmlRoot, $xmlLevel = 0) |
362 | 362 | { |
363 | 363 | global $meta, $root, $group, $name, $entry, $levelMin, $key, $title, $notes, $pw, $username, $url, |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | $keepassVersion = 2; |
516 | 516 | break; |
517 | 517 | } elseif ($root == true && $xmlLevel > $levelMin) { |
518 | - // error_log($nom.",".$elem." - "); |
|
518 | + // error_log($nom.",".$elem." - "); |
|
519 | 519 | //Check each node name and get data from some of them |
520 | 520 | if ($entry == true && $nom == "Key" && $elem == "Title") { |
521 | 521 | $title = true; |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | 'parent_id' => $parent_id, |
722 | 722 | 'title' => stripslashes($fold), |
723 | 723 | 'nlevel' => $folderLevel |
724 | - ) |
|
724 | + ) |
|
725 | 725 | ); |
726 | 726 | $id = DB::insertId(); |
727 | 727 | //Add complexity level => level is set to "medium" by default. |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | 'type' => 'complex', |
732 | 732 | 'intitule' => $id, |
733 | 733 | 'valeur' => $levelPwComplexity |
734 | - ) |
|
734 | + ) |
|
735 | 735 | ); |
736 | 736 | |
737 | 737 | //For each role to which the user depends on, add the folder just created. |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | 'role_id' => $role['id'], |
743 | 743 | 'folder_id' => $id, |
744 | 744 | 'type' => "W" |
745 | - ) |
|
745 | + ) |
|
746 | 746 | ); |
747 | 747 | } |
748 | 748 | |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | 'id_tree' => $folderId, |
872 | 872 | 'login' => substr(stripslashes($item[KP_USERNAME]), 0, 500), |
873 | 873 | 'anyone_can_modify' => $_POST['import_kps_anyone_can_modify'] == "true" ? 1 : 0 |
874 | - ) |
|
874 | + ) |
|
875 | 875 | ); |
876 | 876 | $newId = DB::insertId(); |
877 | 877 | |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | array( |
884 | 884 | 'role_id' => $role['id'], |
885 | 885 | 'item_id' => $newId |
886 | - ) |
|
886 | + ) |
|
887 | 887 | ); |
888 | 888 | } |
889 | 889 | } |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | 'id_user' => $_SESSION['user_id'], |
898 | 898 | 'action' => 'at_creation', |
899 | 899 | 'raison' => 'at_import' |
900 | - ) |
|
900 | + ) |
|
901 | 901 | ); |
902 | 902 | |
903 | 903 | //Add entry to cache table |
@@ -913,7 +913,7 @@ discard block |
||
913 | 913 | 'folder' => $data['title'], |
914 | 914 | 'author' => $_SESSION['user_id'], |
915 | 915 | 'timestamp' => time() |
916 | - ) |
|
916 | + ) |
|
917 | 917 | ); |
918 | 918 | |
919 | 919 | //show |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | set_time_limit(0); |
26 | 26 | |
27 | 27 | // Set some constants for program readability |
28 | -define('KP_PATH',0); |
|
29 | -define('KP_GROUP',1); |
|
30 | -define('KP_TITLE',2); |
|
31 | -define('KP_PASSWORD',3); |
|
32 | -define('KP_USERNAME',4); |
|
33 | -define('KP_URL',5); |
|
34 | -define('KP_UUID',6); |
|
35 | -define('KP_NOTES',7); |
|
28 | +define('KP_PATH', 0); |
|
29 | +define('KP_GROUP', 1); |
|
30 | +define('KP_TITLE', 2); |
|
31 | +define('KP_PASSWORD', 3); |
|
32 | +define('KP_USERNAME', 4); |
|
33 | +define('KP_URL', 5); |
|
34 | +define('KP_UUID', 6); |
|
35 | +define('KP_NOTES', 7); |
|
36 | 36 | |
37 | 37 | /* |
38 | 38 | * sanitiseString |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $size = 4096; |
99 | 99 | $separator = ","; |
100 | 100 | $enclosure = '"'; |
101 | - $fields_expected = array("Label","Login","Password","URL","Comments"); //requiered fields from CSV |
|
101 | + $fields_expected = array("Label", "Login", "Password", "URL", "Comments"); //requiered fields from CSV |
|
102 | 102 | $importation_possible = true; |
103 | 103 | $display = "<table>"; |
104 | 104 | $line_number = $prev_level = 0; |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | $login = addslashes($row['Login']); |
174 | 174 | $pw = str_replace('"', """, $row['Password']); |
175 | 175 | $url = addslashes($row['url']); |
176 | - $to_find = array ( "\"" , "'" ); |
|
177 | - $to_ins = array ( """ , "'"); |
|
176 | + $to_find = array("\"", "'"); |
|
177 | + $to_ins = array(""", "'"); |
|
178 | 178 | $comment = htmlentities(addslashes(str_replace($to_find, $to_ins, $row['Comments'])), ENT_QUOTES, 'UTF-8'); |
179 | 179 | |
180 | 180 | $continue_on_next_line = false; |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | $display .= '</table><div style=\"margin:10px 0 10px 0;\"><label><b>'.$LANG['import_to_folder'].'</b></label> <select id=\"import_items_to\" style=\"width:87%;\">'; |
205 | 205 | foreach ($tree as $t) { |
206 | 206 | if (in_array($t->id, $_SESSION['groupes_visibles'])) { |
207 | - $ident=""; |
|
208 | - for ($x=1; $x<$t->nlevel; $x++) { |
|
207 | + $ident = ""; |
|
208 | + for ($x = 1; $x < $t->nlevel; $x++) { |
|
209 | 209 | $ident .= " "; |
210 | 210 | } |
211 | 211 | if (isset($_POST['folder_id']) && $_POST['folder_id'] == $t->id) $selected = " selected"; |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | |
247 | 247 | foreach (explode('@_#sep#_@', mysqli_escape_string($link, stripslashes($listItems))) as $item) { |
248 | 248 | //For each item, insert into DB |
249 | - $item = explode('@|@', $item); //explode item to get all fields |
|
249 | + $item = explode('@|@', $item); //explode item to get all fields |
|
250 | 250 | |
251 | 251 | //Encryption key |
252 | 252 | if ($personalFolder == 1) { |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | $cacheFileNameFolder = $cacheFileName."_folders"; |
348 | 348 | $cacheFile = fopen($cacheFileName, "w"); |
349 | 349 | $cacheFileF = fopen($cacheFileNameFolder, "w"); |
350 | - $logFileName = "/keepassImport_" . date('YmdHis'); |
|
351 | - $cacheLogFile = fopen($_SESSION['settings']['path_to_files_folder'].$logFileName,'w'); |
|
350 | + $logFileName = "/keepassImport_".date('YmdHis'); |
|
351 | + $cacheLogFile = fopen($_SESSION['settings']['path_to_files_folder'].$logFileName, 'w'); |
|
352 | 352 | |
353 | 353 | //read xml file |
354 | 354 | if (file_exists("'".$_SESSION['settings']['path_to_files_folder']."/".$_POST['file'])."'") { |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | } |
424 | 424 | } |
425 | 425 | } |
426 | - $numGroups ++; |
|
426 | + $numGroups++; |
|
427 | 427 | } elseif ($entry == true && $nom == "title") { |
428 | 428 | $temparray[KP_TITLE] = sanitiseString($elem, ''); |
429 | 429 | } elseif ($entry == true && $nom == "username") { |
@@ -548,15 +548,15 @@ discard block |
||
548 | 548 | if ($levelInProgress == 3) { |
549 | 549 | $temparray[KP_PATH] = $temparray[KP_GROUP]; |
550 | 550 | } else { |
551 | - $temparray[KP_PATH] = substr($temparray[KP_PATH], 0, strrpos($temparray[KP_PATH], $foldersSeparator)+strlen($foldersSeparator)).$temparray[KP_GROUP]; |
|
551 | + $temparray[KP_PATH] = substr($temparray[KP_PATH], 0, strrpos($temparray[KP_PATH], $foldersSeparator) + strlen($foldersSeparator)).$temparray[KP_GROUP]; |
|
552 | 552 | } |
553 | 553 | } else { |
554 | - $diff = abs($xmlLevel-$levelInProgress)+1; |
|
554 | + $diff = abs($xmlLevel - $levelInProgress) + 1; |
|
555 | 555 | $tmp = explode($foldersSeparator, $temparray[KP_PATH]); |
556 | 556 | $temparray[KP_PATH] = ""; |
557 | - for ($x=0; $x<(count($tmp)-$diff); $x++) { |
|
557 | + for ($x = 0; $x < (count($tmp) - $diff); $x++) { |
|
558 | 558 | if (!empty($temparray[KP_PATH])) { |
559 | - $temparray[KP_PATH] = $temparray[KP_PATH]. $foldersSeparator.$tmp[$x]; |
|
559 | + $temparray[KP_PATH] = $temparray[KP_PATH].$foldersSeparator.$tmp[$x]; |
|
560 | 560 | } else { |
561 | 561 | $temparray[KP_PATH] = $tmp[$x]; |
562 | 562 | } |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | fwrite($cacheFileF, $temparray[KP_PATH]."\n"); |
574 | 574 | array_push($groupsArray, $temparray[KP_PATH]); |
575 | 575 | //increment number |
576 | - $numGroups ++; |
|
576 | + $numGroups++; |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | //Store actual level |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | } |
601 | 601 | } |
602 | 602 | |
603 | - fputs($cacheLogFile, date('H:i:s ') . "Writing XML File ".$_POST['file']."\n"); |
|
603 | + fputs($cacheLogFile, date('H:i:s ')."Writing XML File ".$_POST['file']."\n"); |
|
604 | 604 | |
605 | 605 | // Go through each node of XML file |
606 | 606 | recursiveKeepassXML($xml); |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | unlink($cacheFileNameFolder); |
615 | 615 | unlink($_SESSION['settings']['url_to_files_folder']."/".$_POST['file']); |
616 | 616 | |
617 | - fputs($cacheLogFile, date('H:i') . $LANG['import_error_no_read_possible_kp']."\n"); |
|
617 | + fputs($cacheLogFile, date('H:i').$LANG['import_error_no_read_possible_kp']."\n"); |
|
618 | 618 | |
619 | 619 | echo '[{"error":"not_kp_file" , "message":"'.$LANG['import_error_no_read_possible_kp'].'"}]'; |
620 | 620 | break; |
@@ -637,10 +637,10 @@ discard block |
||
637 | 637 | ################## |
638 | 638 | ## STARTING IMPORTING IF NO ERRORS OR NOT EMPTY |
639 | 639 | ################## |
640 | - if ($numItems>0 || $numGroups>0) { |
|
640 | + if ($numItems > 0 || $numGroups > 0) { |
|
641 | 641 | |
642 | - fputs($cacheLogFile, date('H:i:s ') . $LANG['nb_folders']. ' '.$numGroups."\n"); |
|
643 | - fputs($cacheLogFile, date('H:i:s ') . $LANG['nb_items'] . ' '. $numItems."\n"); |
|
642 | + fputs($cacheLogFile, date('H:i:s ').$LANG['nb_folders'].' '.$numGroups."\n"); |
|
643 | + fputs($cacheLogFile, date('H:i:s ').$LANG['nb_items'].' '.$numItems."\n"); |
|
644 | 644 | |
645 | 645 | $import_perso = false; |
646 | 646 | $itemsArray = array(); |
@@ -674,12 +674,12 @@ discard block |
||
674 | 674 | $cacheFileF = fopen($cacheFileNameFolder, "r"); |
675 | 675 | |
676 | 676 | //Create folders |
677 | - $i=1; |
|
677 | + $i = 1; |
|
678 | 678 | $level = 0; |
679 | 679 | $foldersArray = array(); |
680 | 680 | $nbFoldersImported = 0; |
681 | 681 | |
682 | - fputs($cacheLogFile, date('H:i:s ') . "Creating Folders\n"); |
|
682 | + fputs($cacheLogFile, date('H:i:s ')."Creating Folders\n"); |
|
683 | 683 | $results = "Folders\n\n"; |
684 | 684 | |
685 | 685 | while (!feof($cacheFileF)) { |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | |
693 | 693 | //get folder name |
694 | 694 | if (strrpos($folder, $foldersSeparator) > 0) { |
695 | - $fold = substr($folder, strrpos($folder, $foldersSeparator)+strlen($foldersSeparator)); |
|
695 | + $fold = substr($folder, strrpos($folder, $foldersSeparator) + strlen($foldersSeparator)); |
|
696 | 696 | //$parent_id = $foldersArray[$path[$folderLevel-2]]['id']; |
697 | 697 | $parent = implode($foldersSeparator, array_slice($path, 0, -1)); |
698 | 698 | $parent_id = $foldersArray[$parent]['id']; |
@@ -701,19 +701,19 @@ discard block |
||
701 | 701 | $parent_id = $_POST['destination']; //permits to select the folder destination |
702 | 702 | } |
703 | 703 | |
704 | - $fold=stripslashes($fold); |
|
704 | + $fold = stripslashes($fold); |
|
705 | 705 | //create folder - if not exists at the same level |
706 | 706 | DB::query( |
707 | 707 | "SELECT * FROM ".prefix_table("nested_tree")." |
708 | 708 | WHERE nlevel = %i AND title = %s AND parent_id = %i LIMIT 1", |
709 | - intval($folderLevel+$startPathLevel), |
|
709 | + intval($folderLevel + $startPathLevel), |
|
710 | 710 | $fold, |
711 | 711 | $parent_id |
712 | 712 | ); |
713 | - $results.= str_replace($foldersSeparator, '\\', $folder); |
|
713 | + $results .= str_replace($foldersSeparator, '\\', $folder); |
|
714 | 714 | $counter = DB::count(); |
715 | 715 | if ($counter == 0) { |
716 | - $results.= " - Inserting\n"; |
|
716 | + $results .= " - Inserting\n"; |
|
717 | 717 | //do query |
718 | 718 | DB::insert( |
719 | 719 | prefix_table("nested_tree"), |
@@ -754,12 +754,12 @@ discard block |
||
754 | 754 | //increment number of imported folders |
755 | 755 | $nbFoldersImported++; |
756 | 756 | } else { |
757 | - $results.= " - Skipped\n"; |
|
757 | + $results .= " - Skipped\n"; |
|
758 | 758 | //get folder actual ID |
759 | 759 | $data = DB::queryFirstRow( |
760 | 760 | "SELECT id FROM ".prefix_table("nested_tree")." |
761 | 761 | WHERE nlevel = %i AND title = %s AND parent_id = %i", |
762 | - intval($folderLevel+$startPathLevel), |
|
762 | + intval($folderLevel + $startPathLevel), |
|
763 | 763 | $fold, |
764 | 764 | $parent_id |
765 | 765 | ); |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | 'id' => $id |
774 | 774 | ); |
775 | 775 | |
776 | - $_SESSION['nb_folders'] ++; |
|
776 | + $_SESSION['nb_folders']++; |
|
777 | 777 | $i++; |
778 | 778 | } |
779 | 779 | } |
@@ -783,18 +783,18 @@ discard block |
||
783 | 783 | if ($nbFoldersImported == 0) { |
784 | 784 | //$text .= $LANG['none'].'<br />'; |
785 | 785 | } else { |
786 | - fputs($cacheLogFile, date('H:i:s ') . "Setting User Rights\n"); |
|
786 | + fputs($cacheLogFile, date('H:i:s ')."Setting User Rights\n"); |
|
787 | 787 | //Refresh the rights of actual user |
788 | 788 | identifyUserRights(implode(';', $_SESSION['groupes_visibles']).';'.$newId, $_SESSION['groupes_interdits'], $_SESSION['is_admin'], $_SESSION['fonction_id'], true); |
789 | 789 | |
790 | - fputs($cacheLogFile, date('H:i:s ') . "Rebuilding Tree\n"); |
|
790 | + fputs($cacheLogFile, date('H:i:s ')."Rebuilding Tree\n"); |
|
791 | 791 | //rebuild full tree |
792 | 792 | $tree->rebuild(); |
793 | 793 | } |
794 | 794 | //show |
795 | 795 | //$text .= '<br /><b>'.$LANG['importing_items'].':</b><br />'; |
796 | 796 | |
797 | - fputs($cacheLogFile, date('H:i:s ') . "Importing Items\n"); |
|
797 | + fputs($cacheLogFile, date('H:i:s ')."Importing Items\n"); |
|
798 | 798 | |
799 | 799 | // Now import ITEMS |
800 | 800 | $nbItemsImported = 0; |
@@ -819,18 +819,18 @@ discard block |
||
819 | 819 | |
820 | 820 | $count++; |
821 | 821 | if (!($count % 10)) { |
822 | - fputs($cacheLogFile, date('H:i:s ') . " Imported $count items (" . number_format(($count / $numItems) * 100, 1) . ")\n"); |
|
822 | + fputs($cacheLogFile, date('H:i:s ')." Imported $count items (".number_format(($count / $numItems) * 100, 1).")\n"); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | if (!empty($item[KP_TITLE])) { |
826 | 826 | //$count++; |
827 | 827 | //check if not exists |
828 | - $results .= str_replace($foldersSeparator,"\\",$item[KP_PATH]).'\\'.$item[KP_TITLE]; |
|
828 | + $results .= str_replace($foldersSeparator, "\\", $item[KP_PATH]).'\\'.$item[KP_TITLE]; |
|
829 | 829 | |
830 | 830 | $pw = $item[KP_PASSWORD]; |
831 | 831 | |
832 | 832 | //Get folder label |
833 | - if (count($foldersArray)==0 || empty($item[KP_PATH])) { |
|
833 | + if (count($foldersArray) == 0 || empty($item[KP_PATH])) { |
|
834 | 834 | $folderId = $_POST['destination']; |
835 | 835 | } else { |
836 | 836 | $folderId = $foldersArray[$item[KP_PATH]]['id']; |
@@ -938,10 +938,10 @@ discard block |
||
938 | 938 | $text .= '</div><br /><br /><b>'.$LANG['import_kp_finished'].'</b>'; |
939 | 939 | $text .= '<a href=\''.$_SESSION['settings']['url_to_files_folder'].'/'.$logFileName.'\' target=\'_blank\'>'.$LANG['pdf_download'].'</a>'; |
940 | 940 | |
941 | - fputs($cacheLogFile, date('H:i:s ') . "Import finished\n"); |
|
942 | - fputs($cacheLogFile, date('H:i:s ') . "Statistics\n"); |
|
943 | - fputs($cacheLogFile, date('H:i:s ') . "Folders imported: $nbFoldersImported\n"); |
|
944 | - fputs($cacheLogFile, date('H:i:s ') . "Items imported: $nbItemsImported\n\n".$results); |
|
941 | + fputs($cacheLogFile, date('H:i:s ')."Import finished\n"); |
|
942 | + fputs($cacheLogFile, date('H:i:s ')."Statistics\n"); |
|
943 | + fputs($cacheLogFile, date('H:i:s ')."Folders imported: $nbFoldersImported\n"); |
|
944 | + fputs($cacheLogFile, date('H:i:s ')."Items imported: $nbItemsImported\n\n".$results); |
|
945 | 945 | |
946 | 946 | //Delete cache file |
947 | 947 | fclose($cacheFileF); |
@@ -958,9 +958,9 @@ discard block |
||
958 | 958 | } |
959 | 959 | break; |
960 | 960 | } |
961 | -spl_autoload_register(function ($class) { |
|
962 | - $prefix = 'League\\Csv\\';echo "ici2"; |
|
963 | - $base_dir = __DIR__ . '/src/'; |
|
961 | +spl_autoload_register(function($class) { |
|
962 | + $prefix = 'League\\Csv\\'; echo "ici2"; |
|
963 | + $base_dir = __DIR__.'/src/'; |
|
964 | 964 | $len = strlen($prefix); |
965 | 965 | if (strncmp($prefix, $class, $len) !== 0) { |
966 | 966 | // no, move to the next registered autoloader |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | return; |
969 | 969 | } |
970 | 970 | $relative_class = substr($class, $len); |
971 | - $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
971 | + $file = $base_dir.str_replace('\\', '/', $relative_class).'.php'; |
|
972 | 972 | if (file_exists($file)) { |
973 | 973 | require $file; |
974 | 974 | } |
@@ -208,8 +208,11 @@ |
||
208 | 208 | for ($x=1; $x<$t->nlevel; $x++) { |
209 | 209 | $ident .= " "; |
210 | 210 | } |
211 | - if (isset($_POST['folder_id']) && $_POST['folder_id'] == $t->id) $selected = " selected"; |
|
212 | - else $selected = ""; |
|
211 | + if (isset($_POST['folder_id']) && $_POST['folder_id'] == $t->id) { |
|
212 | + $selected = " selected"; |
|
213 | + } else { |
|
214 | + $selected = ""; |
|
215 | + } |
|
213 | 216 | if ($prev_level != null && $prev_level < $t->nlevel) { |
214 | 217 | $display .= '<option value=\"'.$t->id.'\"'.$selected.'>'.$ident.str_replace(array("&", '"'), array("&", """), $t->title).'</option>'; |
215 | 218 | } elseif ($prev_level != null && $prev_level == $t->nlevel) { |
@@ -79,7 +79,6 @@ |
||
79 | 79 | // phpcrypt |
80 | 80 | require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/phpcrypt/phpCrypt.php'; |
81 | 81 | use PHP_Crypt\PHP_Crypt as PHP_Crypt; |
82 | -use PHP_Crypt\Cipher as Cipher; |
|
83 | 82 | |
84 | 83 | // prepare Encryption class calls |
85 | 84 | use \Defuse\Crypto\Crypto; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | 70 => array(70, $LANG['complex_level4']), |
51 | 51 | 80 => array(80, $LANG['complex_level5']), |
52 | 52 | 90 => array(90, $LANG['complex_level6']) |
53 | - ); |
|
53 | + ); |
|
54 | 54 | |
55 | 55 | //Class loader |
56 | 56 | require_once $_SESSION['settings']['cpassman_dir'].'/sources/SplClassLoader.php'; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | 'perso' => ($dataReceived['salt_key_set'] == 1 && isset($dataReceived['salt_key_set']) && $dataReceived['is_pf'] == 1 && isset($dataReceived['is_pf'])) ? '1' : '0', |
208 | 208 | 'anyone_can_modify' => (isset($dataReceived['anyone_can_modify']) && $dataReceived['anyone_can_modify'] == "on") ? '1' : '0', |
209 | 209 | 'complexity_level' => $dataReceived['complexity_level'] |
210 | - ) |
|
210 | + ) |
|
211 | 211 | ); |
212 | 212 | $newID = DB::insertId(); |
213 | 213 | $pw = $passwd['string']; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | 'del_enabled' => 1, // 0=deactivated;1=activated |
260 | 260 | 'del_type' => $date_stamp != false ? 2 : 1, // 1=counter;2=date |
261 | 261 | 'del_value' => $date_stamp != false ? $date_stamp : $dataReceived['to_be_deleted'] |
262 | - ) |
|
262 | + ) |
|
263 | 263 | ); |
264 | 264 | } |
265 | 265 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | array( |
272 | 272 | 'role_id' => $role, |
273 | 273 | 'item_id' => $newID |
274 | - ) |
|
274 | + ) |
|
275 | 275 | ); |
276 | 276 | } |
277 | 277 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | array( |
287 | 287 | 'item_id' => $newID, |
288 | 288 | 'tag' => strtolower($tag) |
289 | - ) |
|
289 | + ) |
|
290 | 290 | ); |
291 | 291 | } |
292 | 292 | } |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | prefix_table('files'), |
303 | 303 | array( |
304 | 304 | 'id_item' => $newID |
305 | - ), |
|
305 | + ), |
|
306 | 306 | "id=%i", $record['id'] |
307 | 307 | ); |
308 | 308 | } |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | "new_entry" => $html, |
391 | 391 | "array_items" => $itemsIDList, |
392 | 392 | "show_clipboard_small_icons" => (isset($_SESSION['settings']['copy_to_clipboard_small_icons']) && $_SESSION['settings']['copy_to_clipboard_small_icons'] == 1) ? 1 : 0 |
393 | - ); |
|
393 | + ); |
|
394 | 394 | } elseif (isset($_SESSION['settings']['duplicate_item']) && $_SESSION['settings']['duplicate_item'] == 0 && $itemExists == 1) { |
395 | 395 | $returnValues = array("error" => "item_exists"); |
396 | 396 | } |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | ) |
476 | 476 | || |
477 | 477 | (@in_array($_POST['id'], $_SESSION['list_folders_limited'][$_POST['folder_id']])) |
478 | - ) { |
|
478 | + ) { |
|
479 | 479 | |
480 | 480 | // is pwd empty? |
481 | 481 | if (empty($pw) && isset($_SESSION['user_settings']['create_item_without_password']) && $_SESSION['user_settings']['create_item_without_password'] !== "1") { |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | 'restricted_to' => $dataReceived['restricted_to'], |
564 | 564 | 'anyone_can_modify' => (isset($dataReceived['anyone_can_modify']) && $dataReceived['anyone_can_modify'] == "on") ? '1' : '0', |
565 | 565 | 'complexity_level' => $dataReceived['complexity_level'] |
566 | - ), |
|
566 | + ), |
|
567 | 567 | "id=%i", |
568 | 568 | $dataReceived['id'] |
569 | 569 | ); |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | 'del_enabled' => 1, |
689 | 689 | 'del_type' => is_numeric($dataReceived['to_be_deleted']) ? 1 : 2, |
690 | 690 | 'del_value' => is_numeric($dataReceived['to_be_deleted']) ? $dataReceived['to_be_deleted'] : dateToStamp($dataReceived['to_be_deleted']) |
691 | - ) |
|
691 | + ) |
|
692 | 692 | ); |
693 | 693 | // update LOG |
694 | 694 | logItems($dataReceived['id'], $label, $_SESSION['user_id'], 'at_modification', $_SESSION['login'], 'at_automatic_del : '.$dataReceived['to_be_deleted']); |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | array( |
703 | 703 | 'del_type' => is_numeric($dataReceived['to_be_deleted']) ? 1 : 2, |
704 | 704 | 'del_value' => is_numeric($dataReceived['to_be_deleted']) ? $dataReceived['to_be_deleted'] : dateToStamp($dataReceived['to_be_deleted']) |
705 | - ), |
|
705 | + ), |
|
706 | 706 | "item_id = %i", |
707 | 707 | $dataReceived['id'] |
708 | 708 | ); |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | array( |
773 | 773 | 'role_id' => $role, |
774 | 774 | 'item_id' => $dataReceived['id'] |
775 | - ) |
|
775 | + ) |
|
776 | 776 | ); |
777 | 777 | $dataTmp = DB::queryfirstrow("SELECT title FROM ".prefix_table("roles_title")." WHERE id= ".$role); |
778 | 778 | if (empty($listOfRestricted)) { |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | ), |
955 | 955 | 'receivers' => $mailing, |
956 | 956 | 'status' => '' |
957 | - ) |
|
957 | + ) |
|
958 | 958 | ); |
959 | 959 | } |
960 | 960 | |
@@ -970,7 +970,7 @@ discard block |
||
970 | 970 | "list_of_restricted" => $listOfRestricted, |
971 | 971 | "tags" => $return_tags, |
972 | 972 | "error" => "" |
973 | - ); |
|
973 | + ); |
|
974 | 974 | } else { |
975 | 975 | echo prepareExchangedData(array("error" => "ERR_NOT_ALLOWED_TO_EDIT"), "encode"); |
976 | 976 | break; |
@@ -1157,7 +1157,7 @@ discard block |
||
1157 | 1157 | 'extension' => $record['extension'], |
1158 | 1158 | 'type' => $record['type'], |
1159 | 1159 | 'file' => $record['file'] |
1160 | - ) |
|
1160 | + ) |
|
1161 | 1161 | ); |
1162 | 1162 | } |
1163 | 1163 | |
@@ -1169,7 +1169,7 @@ discard block |
||
1169 | 1169 | array( |
1170 | 1170 | 'item_id' => $newID, |
1171 | 1171 | 'role_id' => $record['role_id'] |
1172 | - ) |
|
1172 | + ) |
|
1173 | 1173 | ); |
1174 | 1174 | } |
1175 | 1175 | |
@@ -1181,7 +1181,7 @@ discard block |
||
1181 | 1181 | array( |
1182 | 1182 | 'item_id' => $newID, |
1183 | 1183 | 'tag' => $record['tag'] |
1184 | - ) |
|
1184 | + ) |
|
1185 | 1185 | ); |
1186 | 1186 | } |
1187 | 1187 | |
@@ -1548,14 +1548,14 @@ discard block |
||
1548 | 1548 | $pre."automatic_del", |
1549 | 1549 | array( |
1550 | 1550 | 'del_value' => $dataDelete['del_value'] - 1 |
1551 | - ), |
|
1551 | + ), |
|
1552 | 1552 | "item_id = %i", |
1553 | 1553 | $_POST['id'] |
1554 | 1554 | ); |
1555 | 1555 | // store value |
1556 | 1556 | $arrData['to_be_deleted'] = $dataDelete['del_value'] - 1; |
1557 | 1557 | } elseif ($dataDelete['del_type'] == 1 && $dataDelete['del_value'] <= 1 || $dataDelete['del_type'] == 2 && $dataDelete['del_value'] < time() |
1558 | - ) |
|
1558 | + ) |
|
1559 | 1559 | { |
1560 | 1560 | $arrData['show_details'] = 0; |
1561 | 1561 | // delete item |
@@ -1565,7 +1565,7 @@ discard block |
||
1565 | 1565 | prefix_table("items"), |
1566 | 1566 | array( |
1567 | 1567 | 'inactif' => '1', |
1568 | - ), |
|
1568 | + ), |
|
1569 | 1569 | "id = %i", |
1570 | 1570 | $_POST['id'] |
1571 | 1571 | ); |
@@ -1595,7 +1595,7 @@ discard block |
||
1595 | 1595 | 'body' => str_replace(array('#tp_item_author#', '#tp_user#', '#tp_item#'), array(" ".addslashes($arrData['author']), addslashes($_SESSION['login']), addslashes($dataItem['label'])), $LANG['email_on_open_notification_mail']), |
1596 | 1596 | 'receivers' => $listNotificationEmails, |
1597 | 1597 | 'status' => '' |
1598 | - ) |
|
1598 | + ) |
|
1599 | 1599 | ); |
1600 | 1600 | //} |
1601 | 1601 | } else { |
@@ -1744,7 +1744,7 @@ discard block |
||
1744 | 1744 | prefix_table("users"), |
1745 | 1745 | array( |
1746 | 1746 | 'latest_items' => implode(';', $_SESSION['latest_items']) |
1747 | - ), |
|
1747 | + ), |
|
1748 | 1748 | "id=".$_SESSION['user_id'] |
1749 | 1749 | ); |
1750 | 1750 | } |
@@ -1788,7 +1788,7 @@ discard block |
||
1788 | 1788 | prefix_table("items"), |
1789 | 1789 | array( |
1790 | 1790 | 'inactif' => '1', |
1791 | - ), |
|
1791 | + ), |
|
1792 | 1792 | "id = %i", |
1793 | 1793 | $_POST['id'] |
1794 | 1794 | ); |
@@ -1869,7 +1869,7 @@ discard block |
||
1869 | 1869 | prefix_table("nested_tree"), |
1870 | 1870 | array( |
1871 | 1871 | 'title' => $title |
1872 | - ), |
|
1872 | + ), |
|
1873 | 1873 | 'id=%s', |
1874 | 1874 | $dataReceived['folder'] |
1875 | 1875 | ); |
@@ -1878,7 +1878,7 @@ discard block |
||
1878 | 1878 | prefix_table("misc"), |
1879 | 1879 | array( |
1880 | 1880 | 'valeur' => $dataReceived['complexity'] |
1881 | - ), |
|
1881 | + ), |
|
1882 | 1882 | 'intitule = %s AND type = %s', |
1883 | 1883 | $dataReceived['folder'], |
1884 | 1884 | "complex" |
@@ -1949,7 +1949,7 @@ discard block |
||
1949 | 1949 | prefix_table("nested_tree"), |
1950 | 1950 | array( |
1951 | 1951 | 'parent_id' => $dataReceived['target_folder_id'] |
1952 | - ), |
|
1952 | + ), |
|
1953 | 1953 | 'id=%s', |
1954 | 1954 | $dataReceived['source_folder_id'] |
1955 | 1955 | ); |
@@ -1970,7 +1970,7 @@ discard block |
||
1970 | 1970 | prefix_table("nested_tree"), |
1971 | 1971 | array( |
1972 | 1972 | 'parent_id' => $_POST['destination'] |
1973 | - ), |
|
1973 | + ), |
|
1974 | 1974 | 'id = %i', |
1975 | 1975 | $_POST['source'] |
1976 | 1976 | ); |
@@ -2586,7 +2586,7 @@ discard block |
||
2586 | 2586 | $_SESSION['is_admin'] == 1 |
2587 | 2587 | || ($_SESSION['user_manager'] == 1) |
2588 | 2588 | || ( |
2589 | - isset($_SESSION['settings']['enable_user_can_create_folders']) |
|
2589 | + isset($_SESSION['settings']['enable_user_can_create_folders']) |
|
2590 | 2590 | && $_SESSION['settings']['enable_user_can_create_folders'] == 1 |
2591 | 2591 | ) |
2592 | 2592 | || ( |
@@ -2762,7 +2762,7 @@ discard block |
||
2762 | 2762 | prefix_table("users"), |
2763 | 2763 | array( |
2764 | 2764 | 'favourites' => implode(';', $_SESSION['favourites']) |
2765 | - ), |
|
2765 | + ), |
|
2766 | 2766 | 'id = %i', |
2767 | 2767 | $_SESSION['user_id'] |
2768 | 2768 | ); |
@@ -2771,7 +2771,7 @@ discard block |
||
2771 | 2771 | $_SESSION['favourites_tab'][$_POST['id']] = array( |
2772 | 2772 | 'label' => $data['label'], |
2773 | 2773 | 'url' => 'index.php?page=items&group='.$data['id_tree'].'&id='.$_POST['id'] |
2774 | - ); |
|
2774 | + ); |
|
2775 | 2775 | } elseif ($_POST['action'] == 0) { |
2776 | 2776 | // delete from session |
2777 | 2777 | foreach ($_SESSION['favourites'] as $key => $value) { |
@@ -2832,7 +2832,7 @@ discard block |
||
2832 | 2832 | prefix_table("items"), |
2833 | 2833 | array( |
2834 | 2834 | 'id_tree' => $_POST['folder_id'] |
2835 | - ), |
|
2835 | + ), |
|
2836 | 2836 | "id=%i", |
2837 | 2837 | $_POST['item_id'] |
2838 | 2838 | ); |
@@ -2939,7 +2939,7 @@ discard block |
||
2939 | 2939 | prefix_table("items"), |
2940 | 2940 | array( |
2941 | 2941 | 'id_tree' => $_POST['folder_id'] |
2942 | - ), |
|
2942 | + ), |
|
2943 | 2943 | "id=%i", |
2944 | 2944 | $item_id |
2945 | 2945 | ); |
@@ -3051,7 +3051,7 @@ discard block |
||
3051 | 3051 | prefix_table("items"), |
3052 | 3052 | array( |
3053 | 3053 | 'inactif' => '1', |
3054 | - ), |
|
3054 | + ), |
|
3055 | 3055 | "id = %i", |
3056 | 3056 | $item_id |
3057 | 3057 | ); |
@@ -3132,7 +3132,7 @@ discard block |
||
3132 | 3132 | prefix_table("items"), |
3133 | 3133 | array( |
3134 | 3134 | 'notification' => empty($data['notification']) ? $_POST['user_id'].";" : $data['notification'].$_POST['user_id'] |
3135 | - ), |
|
3135 | + ), |
|
3136 | 3136 | "id=%i", |
3137 | 3137 | $_POST['item_id'] |
3138 | 3138 | ); |
@@ -3145,7 +3145,7 @@ discard block |
||
3145 | 3145 | prefix_table("items"), |
3146 | 3146 | array( |
3147 | 3147 | 'notification' => empty($data['notification']) ? $_POST['user_id'] : $data['notification'].";".$_POST['user_id'] |
3148 | - ), |
|
3148 | + ), |
|
3149 | 3149 | "id=%i", |
3150 | 3150 | $_POST['item_id'] |
3151 | 3151 | ); |
@@ -3280,7 +3280,7 @@ discard block |
||
3280 | 3280 | 'timestamp' => time(), |
3281 | 3281 | 'originator' => intval($_SESSION['user_id']), |
3282 | 3282 | 'code' => $otv_code |
3283 | - ) |
|
3283 | + ) |
|
3284 | 3284 | ); |
3285 | 3285 | $newID = DB::insertId(); |
3286 | 3286 |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $aes->register(); |
78 | 78 | |
79 | 79 | // phpcrypt |
80 | -require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/phpcrypt/phpCrypt.php'; |
|
80 | +require_once $_SESSION['settings']['cpassman_dir'].'/includes/libraries/phpcrypt/phpCrypt.php'; |
|
81 | 81 | use PHP_Crypt\PHP_Crypt as PHP_Crypt; |
82 | 82 | use PHP_Crypt\Cipher as Cipher; |
83 | 83 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | if (isset($_SESSION['settings']['item_extra_fields']) && $_SESSION['settings']['item_extra_fields'] == 1) { |
217 | 217 | foreach (explode("_|_", $dataReceived['fields']) as $field) { |
218 | 218 | $field_data = explode("~~", $field); |
219 | - if (count($field_data)>1 && !empty($field_data[1])) { |
|
219 | + if (count($field_data) > 1 && !empty($field_data[1])) { |
|
220 | 220 | // should we encrypt the data |
221 | 221 | $dataTmp = DB::queryFirstRow("SELECT encrypted_data |
222 | 222 | FROM ".prefix_table("categories")." |
@@ -344,8 +344,8 @@ discard block |
||
344 | 344 | $html = '<li class="item_draggable' |
345 | 345 | .'" id="'.$newID.'" style="margin-left:-30px;">' |
346 | 346 | .'<span style="cursor:hand;" class="grippy"><i class="fa fa-sm fa-arrows mi-grey-1"></i> </span>' |
347 | - .$expirationFlag.'<i class="fa fa-sm fa-warning mi-yellow"></i> ' . |
|
348 | - ' <a id="fileclass'.$newID.'" class="file" onclick="AfficherDetailsItem(\''.$newID.'\', \'0\', \'\', \'\', \'\', \'\', \'\')" ondblclick="AfficherDetailsItem(\''.$newID.'\', \'0\', \'\', \'\', \'\', true, \'\')">' . |
|
347 | + .$expirationFlag.'<i class="fa fa-sm fa-warning mi-yellow"></i> '. |
|
348 | + ' <a id="fileclass'.$newID.'" class="file" onclick="AfficherDetailsItem(\''.$newID.'\', \'0\', \'\', \'\', \'\', \'\', \'\')" ondblclick="AfficherDetailsItem(\''.$newID.'\', \'0\', \'\', \'\', \'\', true, \'\')">'. |
|
349 | 349 | stripslashes($dataReceived['label']); |
350 | 350 | if (!empty($dataReceived['description']) && isset($_SESSION['settings']['show_description']) && $_SESSION['settings']['show_description'] == 1) { |
351 | 351 | $html .= ' <font size=2px>['.strip_tags(stripslashes(substr(cleanString($dataReceived['description']), 0, 30))).']</font>'; |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | if (isset($_SESSION['settings']['item_extra_fields']) && $_SESSION['settings']['item_extra_fields'] == 1) { |
572 | 572 | foreach (explode("_|_", $dataReceived['fields']) as $field) { |
573 | 573 | $field_data = explode("~~", $field); |
574 | - if (count($field_data)>1 && !empty($field_data[1])) { |
|
574 | + if (count($field_data) > 1 && !empty($field_data[1])) { |
|
575 | 575 | $dataTmpCat = DB::queryFirstRow( |
576 | 576 | "SELECT c.title AS title, i.data AS data, i.data_iv AS data_iv, i.encryption_type AS encryption_type, c.encrypted_data AS encrypted_data |
577 | 577 | FROM ".prefix_table("categories_items")." AS i |
@@ -856,12 +856,12 @@ discard block |
||
856 | 856 | foreach ($rows as $record) { |
857 | 857 | $reason = explode(':', $record['raison']); |
858 | 858 | if (empty($history)) { |
859 | - $history = date($_SESSION['settings']['date_format']." ".$_SESSION['settings']['time_format'], $record['date'])." - ".$record['login']." - ".$LANG[$record['action']] . |
|
860 | - " - ".(!empty($record['raison']) ? (count($reason) > 1 ? $LANG[trim($reason[0])].' : '.$reason[1] : $LANG[trim($reason[0])]):''); |
|
859 | + $history = date($_SESSION['settings']['date_format']." ".$_SESSION['settings']['time_format'], $record['date'])." - ".$record['login']." - ".$LANG[$record['action']]. |
|
860 | + " - ".(!empty($record['raison']) ? (count($reason) > 1 ? $LANG[trim($reason[0])].' : '.$reason[1] : $LANG[trim($reason[0])]) : ''); |
|
861 | 861 | } else { |
862 | - $history .= "<br />".date($_SESSION['settings']['date_format']." ".$_SESSION['settings']['time_format'], $record['date'])." - " . |
|
863 | - $record['login']." - ".$LANG[$record['action']]." - " . |
|
864 | - (!empty($record['raison']) ? (count($reason) > 1 ? $LANG[trim($reason[0])].' => '.$reason[1] : ($record['action'] != "at_manual" ? $LANG[trim($reason[0])] : trim($reason[0]))):''); |
|
862 | + $history .= "<br />".date($_SESSION['settings']['date_format']." ".$_SESSION['settings']['time_format'], $record['date'])." - ". |
|
863 | + $record['login']." - ".$LANG[$record['action']]." - ". |
|
864 | + (!empty($record['raison']) ? (count($reason) > 1 ? $LANG[trim($reason[0])].' => '.$reason[1] : ($record['action'] != "at_manual" ? $LANG[trim($reason[0])] : trim($reason[0]))) : ''); |
|
865 | 865 | } |
866 | 866 | } |
867 | 867 | // decrypt PW |
@@ -960,9 +960,9 @@ discard block |
||
960 | 960 | |
961 | 961 | // Prepare some stuff to return |
962 | 962 | $arrData = array( |
963 | - "files" => $files,//str_replace('"', '"', $files), |
|
963 | + "files" => $files, //str_replace('"', '"', $files), |
|
964 | 964 | "history" => str_replace('"', '"', $history), |
965 | - "files_edit" => $filesEdit,//str_replace('"', '"', $filesEdit), |
|
965 | + "files_edit" => $filesEdit, //str_replace('"', '"', $filesEdit), |
|
966 | 966 | "id_tree" => $dataItem['id_tree'], |
967 | 967 | "id" => $dataItem['id'], |
968 | 968 | "reload_page" => $reloadPage, |
@@ -1041,7 +1041,7 @@ discard block |
||
1041 | 1041 | // previous is public folder and personal one |
1042 | 1042 | else if ($originalRecord['perso'] === "0" && $dataDestination['personal_folder'] === "1") { |
1043 | 1043 | // check if PSK is set |
1044 | - if (!isset($_SESSION['user_settings']['session_psk']) || empty($_SESSION['user_settings']['session_psk'])){ |
|
1044 | + if (!isset($_SESSION['user_settings']['session_psk']) || empty($_SESSION['user_settings']['session_psk'])) { |
|
1045 | 1045 | $returnValues = '[{"error" : "no_psk"}, {"error_text" : "'.addslashes($LANG['alert_message_personal_sk_missing']).'"}]'; |
1046 | 1046 | echo $returnValues; |
1047 | 1047 | break; |
@@ -1067,7 +1067,7 @@ discard block |
||
1067 | 1067 | } else if ($originalRecord['perso'] === "1" && $dataDestination['personal_folder'] === "1") { |
1068 | 1068 | // previous is public folder and personal one |
1069 | 1069 | // check if PSK is set |
1070 | - if (!isset($_SESSION['user_settings']['session_psk']) || empty($_SESSION['user_settings']['session_psk'])){ |
|
1070 | + if (!isset($_SESSION['user_settings']['session_psk']) || empty($_SESSION['user_settings']['session_psk'])) { |
|
1071 | 1071 | $returnValues = '[{"error" : "no_psk"}, {"error_text" : "'.addslashes($LANG['alert_message_personal_sk_missing']).'"}]'; |
1072 | 1072 | echo $returnValues; |
1073 | 1073 | break; |
@@ -1471,12 +1471,12 @@ discard block |
||
1471 | 1471 | DB::update( |
1472 | 1472 | prefix_table("items"), |
1473 | 1473 | array( |
1474 | - 'viewed_no' => $dataItem['viewed_no']+1, |
|
1474 | + 'viewed_no' => $dataItem['viewed_no'] + 1, |
|
1475 | 1475 | ), |
1476 | 1476 | "id = %i", |
1477 | 1477 | $_POST['id'] |
1478 | 1478 | ); |
1479 | - $arrData['viewed_no'] = $dataItem['viewed_no']+1; |
|
1479 | + $arrData['viewed_no'] = $dataItem['viewed_no'] + 1; |
|
1480 | 1480 | |
1481 | 1481 | // get fields |
1482 | 1482 | $fieldsTmp = $arrCatList = ""; |
@@ -1821,7 +1821,7 @@ discard block |
||
1821 | 1821 | } |
1822 | 1822 | // check that title is not numeric |
1823 | 1823 | if (is_numeric($title) === true) { |
1824 | - echo '[{"error" : "ERR_TITLE_ONLY_WITH_NUMBERS"}]';; |
|
1824 | + echo '[{"error" : "ERR_TITLE_ONLY_WITH_NUMBERS"}]'; ; |
|
1825 | 1825 | break; |
1826 | 1826 | } |
1827 | 1827 | |
@@ -1864,7 +1864,7 @@ discard block |
||
1864 | 1864 | "SELECT title, parent_id, personal_folder FROM ".prefix_table("nested_tree")." WHERE id = %i", |
1865 | 1865 | $dataReceived['folder'] |
1866 | 1866 | ); |
1867 | - if ( $tmp['parent_id'] != 0 || $tmp['title'] != $_SESSION['user_id'] || $tmp['personal_folder'] != 1 ) { |
|
1867 | + if ($tmp['parent_id'] != 0 || $tmp['title'] != $_SESSION['user_id'] || $tmp['personal_folder'] != 1) { |
|
1868 | 1868 | DB::update( |
1869 | 1869 | prefix_table("nested_tree"), |
1870 | 1870 | array( |
@@ -1942,7 +1942,7 @@ discard block |
||
1942 | 1942 | break; |
1943 | 1943 | }*/ |
1944 | 1944 | |
1945 | - if ( $tmp_source['parent_id'] != 0 || $tmp_source['title'] != $_SESSION['user_id'] || $tmp_source['personal_folder'] != 1 || $tmp_target['title'] != $_SESSION['user_id'] || $tmp_target['personal_folder'] != 1) { |
|
1945 | + if ($tmp_source['parent_id'] != 0 || $tmp_source['title'] != $_SESSION['user_id'] || $tmp_source['personal_folder'] != 1 || $tmp_target['title'] != $_SESSION['user_id'] || $tmp_target['personal_folder'] != 1) { |
|
1946 | 1946 | |
1947 | 1947 | // moving SOURCE folder |
1948 | 1948 | DB::update( |
@@ -2010,7 +2010,7 @@ discard block |
||
2010 | 2010 | if (in_array($elem->id, $_SESSION['groupes_visibles'])) { |
2011 | 2011 | $arboHtml_tmp .= ' style="cursor:pointer;" onclick="ListerItems('.$elem->id.', \'\', 0)"'; |
2012 | 2012 | } |
2013 | - $arboHtml_tmp .= '>'. htmlspecialchars(stripslashes($elem->title), ENT_QUOTES). '</a>'; |
|
2013 | + $arboHtml_tmp .= '>'.htmlspecialchars(stripslashes($elem->title), ENT_QUOTES).'</a>'; |
|
2014 | 2014 | if (empty($arboHtml)) { |
2015 | 2015 | $arboHtml = $arboHtml_tmp; |
2016 | 2016 | } else { |
@@ -2109,12 +2109,12 @@ discard block |
||
2109 | 2109 | INNER JOIN ".prefix_table("log_items")." AS l ON (i.id = l.id_item) |
2110 | 2110 | WHERE %l |
2111 | 2111 | GROUP BY i.id, l.date, l.id_user, l.action |
2112 | - ORDER BY i.label ASC, l.date DESC".$query_limit,// |
|
2112 | + ORDER BY i.label ASC, l.date DESC".$query_limit, // |
|
2113 | 2113 | $where |
2114 | 2114 | ); |
2115 | 2115 | } else { |
2116 | 2116 | $items_to_display_once = "max"; |
2117 | - $where->add('i.inactif=%i',0); |
|
2117 | + $where->add('i.inactif=%i', 0); |
|
2118 | 2118 | |
2119 | 2119 | $rows = DB::query( |
2120 | 2120 | "SELECT i.id AS id, MIN(i.restricted_to) AS restricted_to, MIN(i.perso) AS perso, |
@@ -2396,7 +2396,7 @@ discard block |
||
2396 | 2396 | // Build array with items |
2397 | 2397 | array_push($itemsIDList, array($record['id'], $pw, $record['login'], $displayItem)); |
2398 | 2398 | |
2399 | - $i ++; |
|
2399 | + $i++; |
|
2400 | 2400 | } |
2401 | 2401 | $idManaged = $record['id']; |
2402 | 2402 | } |
@@ -2524,12 +2524,12 @@ discard block |
||
2524 | 2524 | |
2525 | 2525 | if (isset($_POST['item_id']) && !empty($_POST['item_id'])) { |
2526 | 2526 | // Lock Item (if already locked), go back and warn |
2527 | - $dataTmp = DB::queryFirstRow("SELECT timestamp, user_id FROM ".prefix_table("items_edition")." WHERE item_id = %i", $_POST['item_id']);//echo ">".$dataTmp[0]; |
|
2527 | + $dataTmp = DB::queryFirstRow("SELECT timestamp, user_id FROM ".prefix_table("items_edition")." WHERE item_id = %i", $_POST['item_id']); //echo ">".$dataTmp[0]; |
|
2528 | 2528 | |
2529 | 2529 | // If token is taken for this Item and delay is passed then delete it. |
2530 | 2530 | if (isset($_SESSION['settings']['delay_item_edition']) && |
2531 | 2531 | $_SESSION['settings']['delay_item_edition'] > 0 && !empty($dataTmp['timestamp']) && |
2532 | - round(abs(time()-$dataTmp['timestamp']) / 60, 2) > $_SESSION['settings']['delay_item_edition'] |
|
2532 | + round(abs(time() - $dataTmp['timestamp']) / 60, 2) > $_SESSION['settings']['delay_item_edition'] |
|
2533 | 2533 | ) { |
2534 | 2534 | DB::delete(prefix_table("items_edition"), "item_id = %i", $_POST['item_id']); |
2535 | 2535 | //reload the previous data |
@@ -2705,7 +2705,7 @@ discard block |
||
2705 | 2705 | // Delete from FILES table |
2706 | 2706 | DB::delete(prefix_table("files"), "id = %i", $_POST['file_id']); |
2707 | 2707 | // Update the log |
2708 | - logItems($data['id_item'], $dataItem['label'], $_SESSION['user_id'], 'at_modification', $_SESSION['login'],'at_del_file : '.$data['name']); |
|
2708 | + logItems($data['id_item'], $dataItem['label'], $_SESSION['user_id'], 'at_modification', $_SESSION['login'], 'at_del_file : '.$data['name']); |
|
2709 | 2709 | // Delete file from server |
2710 | 2710 | @unlink($_SESSION['settings']['path_to_upload_folder']."/".$data['file']); |
2711 | 2711 | } |
@@ -2745,7 +2745,7 @@ discard block |
||
2745 | 2745 | "SELECT description FROM ".prefix_table("items")." WHERE id=%i", $_POST['id_item'] |
2746 | 2746 | ); |
2747 | 2747 | // Clean up the string |
2748 | - echo json_encode(array("description" => strip_tags($dataItem['description'])), JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP); |
|
2748 | + echo json_encode(array("description" => strip_tags($dataItem['description'])), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); |
|
2749 | 2749 | break; |
2750 | 2750 | |
2751 | 2751 | /* |
@@ -3293,7 +3293,7 @@ discard block |
||
3293 | 3293 | $_SESSION['settings']['otv_expiration_period'] = 7; |
3294 | 3294 | } |
3295 | 3295 | $url = $_SESSION['settings']['cpassman_url']."/index.php?otv=true&".http_build_query($otv_session); |
3296 | - $exp_date = date($_SESSION['settings']['date_format']." ".$_SESSION['settings']['time_format'], time() + (intval($_SESSION['settings']['otv_expiration_period'])*86400)); |
|
3296 | + $exp_date = date($_SESSION['settings']['date_format']." ".$_SESSION['settings']['time_format'], time() + (intval($_SESSION['settings']['otv_expiration_period']) * 86400)); |
|
3297 | 3297 | |
3298 | 3298 | echo json_encode( |
3299 | 3299 | array( |
@@ -3323,7 +3323,7 @@ discard block |
||
3323 | 3323 | |
3324 | 3324 | // prepare image info |
3325 | 3325 | $image_code = $file_info['file']; |
3326 | - $extension = substr($_POST['title'], strrpos($_POST['title'], '.')+1); |
|
3326 | + $extension = substr($_POST['title'], strrpos($_POST['title'], '.') + 1); |
|
3327 | 3327 | $file_to_display = $_SESSION['settings']['url_to_upload_folder'].'/'.$image_code; |
3328 | 3328 | $file_suffix = ""; |
3329 | 3329 | |
@@ -3610,7 +3610,7 @@ discard block |
||
3610 | 3610 | $fldTitle = str_replace("&", "&", $folder->title); |
3611 | 3611 | |
3612 | 3612 | // rename personal folder with user login |
3613 | - if ($folder->title == $_SESSION['user_id'] && $folder->nlevel == 1 ) { |
|
3613 | + if ($folder->title == $_SESSION['user_id'] && $folder->nlevel == 1) { |
|
3614 | 3614 | $fldTitle = $_SESSION['login']; |
3615 | 3615 | } |
3616 | 3616 | |
@@ -3738,7 +3738,7 @@ discard block |
||
3738 | 3738 | '<td rowspan="2" style="width:40px;"><img src="'.$avatar.'" style="border-radius:20px; height:35px;"></td>'. |
3739 | 3739 | '<td colspan="2" style="font-size:11px;"><i>'.$LANG['by'].' '.$record['login'].' '.$LANG['at'].' '.date($_SESSION['settings']['date_format'].' '.$_SESSION['settings']['time_format'], $record['date']).'</i></td></tr>'. |
3740 | 3740 | '<tr style="border-bottom:3px solid #C9C9C9;"><td style="width:100px;"><b>'.$LANG[$record['action']].'</b></td>'. |
3741 | - '<td style="">' . (!empty($record['raison']) && $record['action'] !== "at_creation" ? (count($reason) > 1 ? $LANG[trim($reason[0])].' : '.handleBackslash($reason[1]) : ($record['action'] == "at_manual" ? $reason[0] : $LANG[trim($reason[0])])) : '') . '</td>'. |
|
3741 | + '<td style="">'.(!empty($record['raison']) && $record['action'] !== "at_creation" ? (count($reason) > 1 ? $LANG[trim($reason[0])].' : '.handleBackslash($reason[1]) : ($record['action'] == "at_manual" ? $reason[0] : $LANG[trim($reason[0])])) : '').'</td>'. |
|
3742 | 3742 | '</tr>'. |
3743 | 3743 | '<tr></tr>'; |
3744 | 3744 | } |
@@ -543,8 +543,11 @@ discard block |
||
543 | 543 | ) |
544 | 544 | ); |
545 | 545 | // prepare display |
546 | - if (empty($tags)) $return_tags = "<span class='round-grey pointer tip' title='".addslashes($LANG['list_items_with_tag'])."' onclick='searchItemsWithTags(\"".strtolower($tag)."\")'><i class='fa fa-tag fa-sm'></i> <span class=\"item_tag\">".strtolower($tag)."</span></span>"; |
|
547 | - else $return_tags .= " <span class='round-grey pointer tip' title='".addslashes($LANG['list_items_with_tag'])."' onclick='searchItemsWithTags(\"".strtolower($tag)."\")'><i class='fa fa-tag fa-sm'></i> <span class=\"item_tag\">".strtolower($tag)."</span></span>"; |
|
546 | + if (empty($tags)) { |
|
547 | + $return_tags = "<span class='round-grey pointer tip' title='".addslashes($LANG['list_items_with_tag'])."' onclick='searchItemsWithTags(\"".strtolower($tag)."\")'><i class='fa fa-tag fa-sm'></i> <span class=\"item_tag\">".strtolower($tag)."</span></span>"; |
|
548 | + } else { |
|
549 | + $return_tags .= " <span class='round-grey pointer tip' title='".addslashes($LANG['list_items_with_tag'])."' onclick='searchItemsWithTags(\"".strtolower($tag)."\")'><i class='fa fa-tag fa-sm'></i> <span class=\"item_tag\">".strtolower($tag)."</span></span>"; |
|
550 | + } |
|
548 | 551 | } |
549 | 552 | } |
550 | 553 | |
@@ -765,8 +768,11 @@ discard block |
||
765 | 768 | // add roles for item |
766 | 769 | foreach (array_filter(explode(';', $dataReceived['restricted_to_roles'])) as $role) { |
767 | 770 | $role = explode("role_", $role); |
768 | - if (count($role) > 1) $role = $role[1]; |
|
769 | - else $role = $role[0]; |
|
771 | + if (count($role) > 1) { |
|
772 | + $role = $role[1]; |
|
773 | + } else { |
|
774 | + $role = $role[0]; |
|
775 | + } |
|
770 | 776 | DB::insert( |
771 | 777 | prefix_table('restriction_to_roles'), |
772 | 778 | array( |
@@ -1314,8 +1320,11 @@ discard block |
||
1314 | 1320 | $tags = ""; |
1315 | 1321 | $rows = DB::query("SELECT tag FROM ".prefix_table("tags")." WHERE item_id=%i", $_POST['id']); |
1316 | 1322 | foreach ($rows as $record) { |
1317 | - if (empty($tags)) $tags = "<span style='' class='round-grey pointer tip' title='".addslashes($LANG['list_items_with_tag'])."' onclick='searchItemsWithTags(\"".$record['tag']."\")'><i class='fa fa-tag fa-sm'></i> <span class=\"item_tag\">".$record['tag']."</span></span>"; |
|
1318 | - else $tags .= " <span style='' class='round-grey pointer tip' title='".addslashes($LANG['list_items_with_tag'])."' onclick='searchItemsWithTags(\"".$record['tag']."\")'><i class='fa fa-tag fa-sm'></i> <span class=\"item_tag\">".$record['tag']."</span></span>"; |
|
1323 | + if (empty($tags)) { |
|
1324 | + $tags = "<span style='' class='round-grey pointer tip' title='".addslashes($LANG['list_items_with_tag'])."' onclick='searchItemsWithTags(\"".$record['tag']."\")'><i class='fa fa-tag fa-sm'></i> <span class=\"item_tag\">".$record['tag']."</span></span>"; |
|
1325 | + } else { |
|
1326 | + $tags .= " <span style='' class='round-grey pointer tip' title='".addslashes($LANG['list_items_with_tag'])."' onclick='searchItemsWithTags(\"".$record['tag']."\")'><i class='fa fa-tag fa-sm'></i> <span class=\"item_tag\">".$record['tag']."</span></span>"; |
|
1327 | + } |
|
1319 | 1328 | } |
1320 | 1329 | |
1321 | 1330 | // TODO -> improve this check |
@@ -1423,8 +1432,11 @@ discard block |
||
1423 | 1432 | $_POST['id'] |
1424 | 1433 | ); |
1425 | 1434 | foreach ($rows as $record) { |
1426 | - if (empty($tmp)) $tmp = "<a class='round-grey' href='".$_SESSION['settings']['cpassman_url']."/index.php?page=kb&id=".$record['id']."'><i class='fa fa-map-pin fa-sm'></i> ".$record['label']."</a>"; |
|
1427 | - else $tmp .= " <a class='round-grey' href='".$_SESSION['settings']['cpassman_url']."/index.php?page=kb&id=".$record['id']."'><i class='fa fa-map-pin fa-sm'></i> ".$record['label']."</a>"; |
|
1435 | + if (empty($tmp)) { |
|
1436 | + $tmp = "<a class='round-grey' href='".$_SESSION['settings']['cpassman_url']."/index.php?page=kb&id=".$record['id']."'><i class='fa fa-map-pin fa-sm'></i> ".$record['label']."</a>"; |
|
1437 | + } else { |
|
1438 | + $tmp .= " <a class='round-grey' href='".$_SESSION['settings']['cpassman_url']."/index.php?page=kb&id=".$record['id']."'><i class='fa fa-map-pin fa-sm'></i> ".$record['label']."</a>"; |
|
1439 | + } |
|
1428 | 1440 | } |
1429 | 1441 | $arrData['links_to_kbs'] = $tmp; |
1430 | 1442 | } |
@@ -2063,9 +2075,13 @@ discard block |
||
2063 | 2075 | $role, |
2064 | 2076 | $_POST['id'] |
2065 | 2077 | ); |
2066 | - if ($access['type'] == "R") array_push($arrTmp, 1); |
|
2067 | - else if ($access['type'] == "W") array_push($arrTmp, 0); |
|
2068 | - else array_push($arrTmp, 3); |
|
2078 | + if ($access['type'] == "R") { |
|
2079 | + array_push($arrTmp, 1); |
|
2080 | + } else if ($access['type'] == "W") { |
|
2081 | + array_push($arrTmp, 0); |
|
2082 | + } else { |
|
2083 | + array_push($arrTmp, 3); |
|
2084 | + } |
|
2069 | 2085 | } |
2070 | 2086 | $accessLevel = min($arrTmp); |
2071 | 2087 | //echo $_POST['id']." - ".$accessLevel." - "; |