Changeset 4951
- Timestamp:
- May 27, 2009, 12:07:18 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/Path.java
r4892 r4951 23 23 package net.sf.basedb.core; 24 24 25 import java.io.UnsupportedEncodingException; 26 import java.net.URLEncoder; 25 27 import java.util.regex.Pattern; 26 28 … … 283 285 return sb.toString(); 284 286 } 287 288 /** 289 Get this Path's URL-string encoded with a given 290 character encoding. 291 292 @param enc The encoding to use. UTF-8 is used is this is null. 293 @return The encoded URL-string. 294 @throws UnsupportedEncodingException If the give encoding is not supported 295 @since 2.11.1 296 */ 297 public String toURLString(String enc) 298 throws UnsupportedEncodingException 299 { 300 StringBuilder sb = new StringBuilder(); 301 enc = (enc == null || enc.length() == 0) ? "UTF-8" : enc; 302 if (userlogin != null) 303 { 304 sb.append("~").append(URLEncoder.encode(userlogin, enc)); 305 } 306 for (String directory : directories) 307 { 308 sb.append("/").append(URLEncoder.encode(directory, enc)); 309 } 310 if (filename != null && getType() == Type.FILE) 311 { 312 sb.append("/").append(URLEncoder.encode(filename, enc)); 313 } 314 if (sb.length() == 0) sb.append("/"); // For the root directory 315 return sb.toString(); 316 } 285 317 286 318 /** -
trunk/src/core/net/sf/basedb/core/SessionControl.java
r4889 r4951 313 313 The client application should use the challenge as follows: 314 314 <ol> 315 <li>Calculate the MD5 of the real password315 <li>Calculate the MD5 of the real UTF-8 encoded password 316 316 <li>Concatenate this with the challenge with a colon inbetween: 317 317 <code>MD5:challenge</code> … … 352 352 353 353 @param login The login of the user 354 @param password The password for the user354 @param password The UTF-8 encoded password for the user 355 355 @param comment A comment for the login, which will show in the {@link Session} 356 356 @param encryptedPassword A flag indicating if the password has been encrypted -
trunk/src/core/net/sf/basedb/util/MD5.java
r4889 r4951 37 37 public class MD5 38 38 { 39 /** 40 Calculates the MD5 hash of an UTF-8 encoded string. 41 */ 39 42 public static String getHashString(String in) 40 43 { … … 42 45 { 43 46 MessageDigest md5 = MessageDigest.getInstance("MD5"); 44 BigInteger result = new BigInteger(1, md5.digest(in.getBytes( )));47 BigInteger result = new BigInteger(1, md5.digest(in.getBytes("UTF-8"))); 45 48 return leftPad(result.toString(16), '0', 32); 46 49 } -
trunk/www/filemanager/directories/list_directories.jsp
r4889 r4951 103 103 final Directory userHome = user.getHomeDirectory(); 104 104 final boolean readDirectories = sc.hasPermission(Permission.READ, Item.DIRECTORY); 105 final Directory root = Directory.getById(dc, SystemItems.getId(readDirectories ? Directory.ROOT : Directory.HOME)); 106 Directory current = directoryId != 0 ? Directory.getById(dc, directoryId) : null; 105 final Directory root = Directory.getById(dc, SystemItems.getId(readDirectories ? Directory.ROOT : Directory.HOME)); 106 107 Directory current = null; 108 // Try to get current/last visited directory. If not successful, use default directory. 109 try 110 { 111 current = directoryId != 0 ? Directory.getById(dc, directoryId) : null; 112 } 113 catch (Throwable ex){} 107 114 if (current == null) current = userHome; 108 115 if (current == null) current = root; -
trunk/www/filemanager/files/index.jsp
r4889 r4951 465 465 dc = sc.newDbControl(); 466 466 File f = File.getById(dc, cc.getId()); 467 redirect = root + "filemanager/files/view/-"+ID+"-"+ HTML.urlEncode(f.getPath().toString());467 redirect = root + "filemanager/files/view/-"+ID+"-"+ f.getPath().toURLString("UTF-8"); 468 468 dc.close(); 469 469 } -
trunk/www/filemanager/index.jsp
r4889 r4951 89 89 dc = sc.newDbControl(); 90 90 File f = File.getById(dc, cc.getId()); 91 redirect = root + "filemanager/files/view/-"+ID+"-"+ HTML.urlEncode(f.getPath().toString());91 redirect = root + "filemanager/files/view/-"+ID+"-"+ f.getPath().toURLString("UTF-8"); 92 92 dc.close(); 93 93 } -
trunk/www/include/scripts/md5.js
r2306 r4951 2 2 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message 3 3 * Digest Algorithm, as defined in RFC 1321. 4 * Version 2. 1 Copyright (C) Paul Johnston 1999 - 2002.4 * Version 2.2-alpha Copyright (C) Paul Johnston 1999 - 2009 5 5 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet 6 6 * Distributed under the BSD License … … 12 12 * the server-side, but the defaults work in most cases. 13 13 */ 14 var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ 15 var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ 16 var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ 14 var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ 15 var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ 17 16 18 17 /* … … 20 19 * They take string arguments and return either hex or base-64 encoded strings 21 20 */ 22 function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));} 23 function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));} 24 function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));} 25 function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); } 26 function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); } 27 function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); } 21 function hex_md5(s) { return rstr2hex(rstr_md5(str2rstr_utf8(s))); } 22 function b64_md5(s) { return rstr2b64(rstr_md5(str2rstr_utf8(s))); } 23 function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); } 24 function hex_hmac_md5(k, d) 25 { return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); } 26 function b64_hmac_md5(k, d) 27 { return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); } 28 function any_hmac_md5(k, d, e) 29 { return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e); } 28 30 29 31 /* … … 32 34 function md5_vm_test() 33 35 { 34 return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; 35 } 36 37 /* 38 * Calculate the MD5 of an array of little-endian words, and a bit length 39 */ 40 function core_md5(x, len) 36 return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72"; 37 } 38 39 /* 40 * Calculate the MD5 of a raw string 41 */ 42 function rstr_md5(s) 43 { 44 return binl2rstr(binl_md5(rstr2binl(s), s.length * 8)); 45 } 46 47 /* 48 * Calculate the HMAC-MD5, of a key and some data (raw strings) 49 */ 50 function rstr_hmac_md5(key, data) 51 { 52 var bkey = rstr2binl(key); 53 if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8); 54 55 var ipad = Array(16), opad = Array(16); 56 for(var i = 0; i < 16; i++) 57 { 58 ipad[i] = bkey[i] ^ 0x36363636; 59 opad[i] = bkey[i] ^ 0x5C5C5C5C; 60 } 61 62 var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8); 63 return binl2rstr(binl_md5(opad.concat(hash), 512 + 128)); 64 } 65 66 /* 67 * Convert a raw string to a hex string 68 */ 69 function rstr2hex(input) 70 { 71 try { hexcase } catch(e) { hexcase=0; } 72 var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 73 var output = ""; 74 var x; 75 for(var i = 0; i < input.length; i++) 76 { 77 x = input.charCodeAt(i); 78 output += hex_tab.charAt((x >>> 4) & 0x0F) 79 + hex_tab.charAt( x & 0x0F); 80 } 81 return output; 82 } 83 84 /* 85 * Convert a raw string to a base-64 string 86 */ 87 function rstr2b64(input) 88 { 89 try { b64pad } catch(e) { b64pad=''; } 90 var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 91 var output = ""; 92 var len = input.length; 93 for(var i = 0; i < len; i += 3) 94 { 95 var triplet = (input.charCodeAt(i) << 16) 96 | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0) 97 | (i + 2 < len ? input.charCodeAt(i+2) : 0); 98 for(var j = 0; j < 4; j++) 99 { 100 if(i * 8 + j * 6 > input.length * 8) output += b64pad; 101 else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F); 102 } 103 } 104 return output; 105 } 106 107 /* 108 * Convert a raw string to an arbitrary string encoding 109 */ 110 function rstr2any(input, encoding) 111 { 112 var divisor = encoding.length; 113 var i, j, q, x, quotient; 114 115 /* Convert to an array of 16-bit big-endian values, forming the dividend */ 116 var dividend = Array(Math.ceil(input.length / 2)); 117 for(i = 0; i < dividend.length; i++) 118 { 119 dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1); 120 } 121 122 /* 123 * Repeatedly perform a long division. The binary array forms the dividend, 124 * the length of the encoding is the divisor. Once computed, the quotient 125 * forms the dividend for the next step. All remainders are stored for later 126 * use. 127 */ 128 var full_length = Math.ceil(input.length * 8 / 129 (Math.log(encoding.length) / Math.log(2))); 130 var remainders = Array(full_length); 131 for(j = 0; j < full_length; j++) 132 { 133 quotient = Array(); 134 x = 0; 135 for(i = 0; i < dividend.length; i++) 136 { 137 x = (x << 16) + dividend[i]; 138 q = Math.floor(x / divisor); 139 x -= q * divisor; 140 if(quotient.length > 0 || q > 0) 141 quotient[quotient.length] = q; 142 } 143 remainders[j] = x; 144 dividend = quotient; 145 } 146 147 /* Convert the remainders to the output string */ 148 var output = ""; 149 for(i = remainders.length - 1; i >= 0; i--) 150 output += encoding.charAt(remainders[i]); 151 152 return output; 153 } 154 155 /* 156 * Encode a string as utf-8. 157 * For efficiency, this assumes the input is valid utf-16. 158 */ 159 function str2rstr_utf8(input) 160 { 161 var output = ""; 162 var i = -1; 163 var x, y; 164 165 while(++i < input.length) 166 { 167 /* Decode utf-16 surrogate pairs */ 168 x = input.charCodeAt(i); 169 y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; 170 if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) 171 { 172 x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); 173 i++; 174 } 175 176 /* Encode output as utf-8 */ 177 if(x <= 0x7F) 178 output += String.fromCharCode(x); 179 else if(x <= 0x7FF) 180 output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), 181 0x80 | ( x & 0x3F)); 182 else if(x <= 0xFFFF) 183 output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 184 0x80 | ((x >>> 6 ) & 0x3F), 185 0x80 | ( x & 0x3F)); 186 else if(x <= 0x1FFFFF) 187 output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 188 0x80 | ((x >>> 12) & 0x3F), 189 0x80 | ((x >>> 6 ) & 0x3F), 190 0x80 | ( x & 0x3F)); 191 } 192 return output; 193 } 194 195 /* 196 * Encode a string as utf-16 197 */ 198 function str2rstr_utf16le(input) 199 { 200 var output = ""; 201 for(var i = 0; i < input.length; i++) 202 output += String.fromCharCode( input.charCodeAt(i) & 0xFF, 203 (input.charCodeAt(i) >>> 8) & 0xFF); 204 return output; 205 } 206 207 function str2rstr_utf16be(input) 208 { 209 var output = ""; 210 for(var i = 0; i < input.length; i++) 211 output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, 212 input.charCodeAt(i) & 0xFF); 213 return output; 214 } 215 216 /* 217 * Convert a raw string to an array of little-endian words 218 * Characters >255 have their high-byte silently ignored. 219 */ 220 function rstr2binl(input) 221 { 222 var output = Array(input.length >> 2); 223 for(var i = 0; i < output.length; i++) 224 output[i] = 0; 225 for(var i = 0; i < input.length * 8; i += 8) 226 output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32); 227 return output; 228 } 229 230 /* 231 * Convert an array of little-endian words to a string 232 */ 233 function binl2rstr(input) 234 { 235 var output = ""; 236 for(var i = 0; i < input.length * 32; i += 8) 237 output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF); 238 return output; 239 } 240 241 /* 242 * Calculate the MD5 of an array of little-endian words, and a bit length. 243 */ 244 function binl_md5(x, len) 41 245 { 42 246 /* append padding */ … … 130 334 } 131 335 return Array(a, b, c, d); 132 133 336 } 134 337 … … 155 358 { 156 359 return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); 157 }158 159 /*160 * Calculate the HMAC-MD5, of a key and some data161 */162 function core_hmac_md5(key, data)163 {164 var bkey = str2binl(key);165 if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);166 167 var ipad = Array(16), opad = Array(16);168 for(var i = 0; i < 16; i++)169 {170 ipad[i] = bkey[i] ^ 0x36363636;171 opad[i] = bkey[i] ^ 0x5C5C5C5C;172 }173 174 var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);175 return core_md5(opad.concat(hash), 512 + 128);176 360 } 177 361 … … 194 378 return (num << cnt) | (num >>> (32 - cnt)); 195 379 } 196 197 /*198 * Convert a string to an array of little-endian words199 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.200 */201 function str2binl(str)202 {203 var bin = Array();204 var mask = (1 << chrsz) - 1;205 for(var i = 0; i < str.length * chrsz; i += chrsz)206 bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);207 return bin;208 }209 210 /*211 * Convert an array of little-endian words to a string212 */213 function binl2str(bin)214 {215 var str = "";216 var mask = (1 << chrsz) - 1;217 for(var i = 0; i < bin.length * 32; i += chrsz)218 str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);219 return str;220 }221 222 /*223 * Convert an array of little-endian words to a hex string.224 */225 function binl2hex(binarray)226 {227 var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";228 var str = "";229 for(var i = 0; i < binarray.length * 4; i++)230 {231 str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +232 hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);233 }234 return str;235 }236 237 /*238 * Convert an array of little-endian words to a base-64 string239 */240 function binl2b64(binarray)241 {242 var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";243 var str = "";244 for(var i = 0; i < binarray.length * 4; i += 3)245 {246 var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16)247 | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )248 | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);249 for(var j = 0; j < 4; j++)250 {251 if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;252 else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);253 }254 }255 return str;256 } -
trunk/www/views/experiments/spotdata/index.jsp
r4889 r4951 135 135 { 136 136 // Run an export plugin in a list context 137 ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);137 ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext); 138 138 dc = sc.newDbControl(); 139 139 if (bas != null) dc.reattachItem(bas); … … 144 144 dc.close(); 145 145 cc.setQuery(query); 146 redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"& context_type=LIST&title=Export+spot+data";146 redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+subContext+"&context_type=LIST&title=Export+spot+data"; 147 147 } 148 148 else if ("CreateReporterList".equals(cmd))
Note: See TracChangeset
for help on using the changeset viewer.