From 01744f46f687d541f5d02eac4c8daa9b06c689ac Mon Sep 17 00:00:00 2001 From: spiralvoice Date: Sun, 24 Oct 2010 12:04:23 +0000 Subject: [PATCH] patch #7318 --- distrib/ChangeLog | 1 + src/networks/donkey/donkeyClient.ml | 144 +++++-------------------------- src/networks/donkey/donkeyInteractive.ml | 6 +- 3 files changed, 27 insertions(+), 124 deletions(-) diff --git a/distrib/ChangeLog b/distrib/ChangeLog index 135b661b..0ac0a189 100644 --- a/distrib/ChangeLog +++ b/distrib/ChangeLog @@ -15,6 +15,7 @@ ChangeLog ========= 2010/10/24 +7318: EDK/Emule captcha: Use Base64 functions (ygrek) 7357: configure: fix quoting of arguments (ygrek) 2010/10/23 diff --git a/src/networks/donkey/donkeyClient.ml b/src/networks/donkey/donkeyClient.ml index e8962106..756a9bff 100644 --- a/src/networks/donkey/donkeyClient.ml +++ b/src/networks/donkey/donkeyClient.ml @@ -1135,6 +1135,18 @@ let check_stolen_hash c sock md4 = if !!ban_identity_thieves then ban_client c sock "is probably using stolen client hashes" +let string_of_client_addr c = + try + match c.client_source.DonkeySources.source_sock with + | Connection sock -> + (Ip.to_string (peer_ip sock) ^ ":" ^ string_of_int (peer_port sock)) + | _ -> + raise Not_found + with _ -> + match c.client_kind with + | Direct_address (ip,port) -> ((Ip.to_string ip) ^ ":" ^ string_of_int port) + | Indirect_address _ | Invalid_address _ -> "Indirect" + let client_to_client for_files c t sock = let module M = DonkeyProtoClient in @@ -1935,134 +1947,24 @@ end else *) (* FIXME: add logging *) (* !say_hook c s *) private_message_from (as_client c) s; - - let cip = - ( - try - - match c.client_source.DonkeySources.source_sock with - Connection sock -> - (Ip.to_string (peer_ip sock) ^ ":" ^ string_of_int (peer_port sock)) - | _ -> (match c.client_kind with - Direct_address (ip,port) -> - ((Ip.to_string ip) ^ ":" ^ string_of_int port) - | Indirect_address _ | Invalid_address _ -> "Indirect" - ) - - with _ -> - - try - match c.client_kind with - Direct_address (ip,port) -> - ((Ip.to_string ip) ^ ":" ^ string_of_int port) - | Indirect_address _ | Invalid_address _ -> "Indirect" - with _ -> "" - ) - in + let cip = string_of_client_addr c in log_chat_message cip (client_num c) c.client_name s; - | M.EmuleCaptchaReq t -> - let buf = Buffer.create 4096 in - let len = String.length t in - let b64_map = [| - 'A'; 'B'; 'C'; 'D'; 'E'; 'F'; 'G'; 'H'; 'I'; 'J'; 'K'; 'L'; 'M'; 'N'; 'O'; 'P'; - 'Q'; 'R'; 'S'; 'T'; 'U'; 'V'; 'W'; 'X'; 'Y'; 'Z'; 'a'; 'b'; 'c'; 'd'; 'e'; 'f'; - 'g'; 'h'; 'i'; 'j'; 'k'; 'l'; 'm'; 'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't'; 'u'; 'v'; - 'w'; 'x'; 'y'; 'z'; '0'; '1'; '2'; '3'; '4'; '5'; '6'; '7'; '8'; '9'; '+'; '/'|] in - - for i = 0 to (len / 3) - 1 do - let c1 = int_of_char t.[i*3] in - let c2 = int_of_char t.[i*3+1] in - let c3 = int_of_char t.[i*3+2] in - let n1 = c1 lsr 2 in - let n2 = ((c1 land 3) lsl 4) lor (c2 lsr 4) in - let n3 = ((c2 land 0xf) lsl 2) lor (c3 lsr 6) in - let n4 = c3 land 63 in - Printf.bprintf buf "%c%c%c%c" b64_map.(n1) b64_map.(n2) b64_map.(n3) b64_map.(n4); - done; - if (len mod 3) = 1 then ( - let i = len - 2 in - let c1 = int_of_char t.[i] in - let c2 = int_of_char t.[i+1] in - let n1 = ((c1 land 0xf) lsl 2) lor (c2 lsr 6) in - let n2 = c2 land 63 in - Printf.bprintf buf "%c%c==" b64_map.(n1) b64_map.(n2) - ) - else if (len mod 3) = 2 then ( - let i = len - 3 in - let c1 = int_of_char t.[i] in - let c2 = int_of_char t.[i+1] in - let c3 = int_of_char t.[i+2] in - let n1 = ((c1 land 3) lsl 4) lor (c2 lsr 4) in - let n2 = ((c2 land 0xf) lsl 2) lor (c3 lsr 6) in - let n3 = c3 land 63 in - Printf.bprintf buf "%c%c%c=" b64_map.(n1) b64_map.(n2) b64_map.(n3) - ); - - let b64data = Buffer.contents buf in - let cip = - ( - try - - match c.client_source.DonkeySources.source_sock with - Connection sock -> - (Ip.to_string (peer_ip sock) ^ ":" ^ string_of_int (peer_port sock)) - | _ -> (match c.client_kind with - Direct_address (ip,port) -> - ((Ip.to_string ip) ^ ":" ^ string_of_int port) - | Indirect_address _ | Invalid_address _ -> "Indirect" - ) - - with _ -> - - try - match c.client_kind with - Direct_address (ip,port) -> - ((Ip.to_string ip) ^ ":" ^ string_of_int port) - | Indirect_address _ | Invalid_address _ -> "Indirect" - with _ -> "" - ) - in - log_chat_message cip (client_num c) c.client_name ("data:image/bmp;base64," ^ b64data) - + let b64data = Base64.encode t in + let cip = string_of_client_addr c in + log_chat_message cip (client_num c) c.client_name ("data:image/bmp;base64," ^ b64data) | M.EmuleCaptchaRes t -> - let cip = - ( - try - - match c.client_source.DonkeySources.source_sock with - Connection sock -> - (Ip.to_string (peer_ip sock) ^ ":" ^ string_of_int (peer_port sock)) - | _ -> (match c.client_kind with - Direct_address (ip,port) -> - ((Ip.to_string ip) ^ ":" ^ string_of_int port) - | Indirect_address _ | Invalid_address _ -> "Indirect" - ) - - with _ -> - - try - match c.client_kind with - Direct_address (ip,port) -> - ((Ip.to_string ip) ^ ":" ^ string_of_int port) - | Indirect_address _ | Invalid_address _ -> "Indirect" - with _ -> "" - ) + let msg = match t with + | 0 -> _s "You have correctly solved the captcha and your message was sent." + | 1 -> _s "Wrong answer to the captcha, so your message was not sent. You will only be sent 3 captchas. Try sending another message to receive another captcha challenge." + | 2 -> _s "3 captchas have already been sent to you. Fail." + | _ -> _s "Unknown captcha state!?" in - log_chat_message cip (client_num c) c.client_name ( - if t = 0 then - "You have correctly solved the captcha and your message was sent." - else if t = 1 then - "Wrong answer to the captcha, so your message was not sent. You will only be sent 3 captchas. Try sending another message to receive another captcha challenge." - else if t = 2 then - "3 captchas have already been sent to you. Fail." - else - "Unknown captcha state!?" - ) + let cip = string_of_client_addr c in + log_chat_message cip (client_num c) c.client_name msg - | M.QueryChunkMd4Req t when !CommonGlobals.has_upload = 0 -> let file = find_file t in diff --git a/src/networks/donkey/donkeyInteractive.ml b/src/networks/donkey/donkeyInteractive.ml index ab4e5bd6..c252e451 100644 --- a/src/networks/donkey/donkeyInteractive.ml +++ b/src/networks/donkey/donkeyInteractive.ml @@ -1194,7 +1194,7 @@ let _ = } ) -let string_of_client_addr c = +let string_of_client_ip c = try match c.client_source.DonkeySources.source_sock with Connection sock -> (Ip.to_string (peer_ip sock)) | _ -> "" @@ -1212,7 +1212,7 @@ let get_ips_cc_cn c = (Ip.to_string real_ip),cc,cn | _ -> let cc,cn = Geoip.unknown_country in - (string_of_client_addr c),cc,cn + (string_of_client_ip c),cc,cn with _ -> ("X","??","Country Error") @@ -1808,7 +1808,7 @@ let _ = (shorten c.client_name 20) (match c.client_kind with Direct_address (ip,port) -> (Ip.to_string ip) - | _ -> (string_of_client_addr c)); + | _ -> (string_of_client_ip c)); Printf.bprintf buf "\n%14sDown : %-10s Uploaded: %-10s Ratio: %s%1.1f (%s)\n" "" (Int64.to_string c.client_total_downloaded) (Int64.to_string c.client_total_uploaded) -- 2.11.4.GIT