diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-14 17:07:11 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-14 17:07:11 +0000 |
commit | a0a19cebadfd63a7d9e99d09a8f23ec03a32f18a (patch) | |
tree | 30983594fa32af4241fb7d09221a354ef8829749 /src/gns | |
parent | 90b3fa120fe253da2c391e8e56c703d46a118625 (diff) | |
download | gnunet-a0a19cebadfd63a7d9e99d09a8f23ec03a32f18a.tar.gz gnunet-a0a19cebadfd63a7d9e99d09a8f23ec03a32f18a.zip |
-proxy magic, interceptor fix
Diffstat (limited to 'src/gns')
-rw-r--r-- | src/gns/gnunet-service-gns_interceptor.c | 3 | ||||
-rw-r--r-- | src/gns/proxy/proxy.py | 25 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c index 1a14eb96e..069975fc9 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c | |||
@@ -107,7 +107,6 @@ reply_to_dns(void* cls, uint32_t rd_count, | |||
107 | 107 | ||
108 | if (rd[i].record_type == ilh->query->type) | 108 | if (rd[i].record_type == ilh->query->type) |
109 | { | 109 | { |
110 | num_answers++; | ||
111 | answer_records[i].name = ilh->query->name; | 110 | answer_records[i].name = ilh->query->name; |
112 | answer_records[i].type = rd[i].record_type; | 111 | answer_records[i].type = rd[i].record_type; |
113 | answer_records[i].data.raw.data_len = rd[i].data_size; | 112 | answer_records[i].data.raw.data_len = rd[i].data_size; |
@@ -279,6 +278,8 @@ handle_dns_request(void *cls, | |||
279 | if (*(tldoffset-i) == '.') | 278 | if (*(tldoffset-i) == '.') |
280 | break; | 279 | break; |
281 | } | 280 | } |
281 | |||
282 | i--; | ||
282 | 283 | ||
283 | if ((i==strlen(GNUNET_GNS_TLD)-1) | 284 | if ((i==strlen(GNUNET_GNS_TLD)-1) |
284 | && (0 == strcmp(tldoffset-i, GNUNET_GNS_TLD))) | 285 | && (0 == strcmp(tldoffset-i, GNUNET_GNS_TLD))) |
diff --git a/src/gns/proxy/proxy.py b/src/gns/proxy/proxy.py index ffa47ee9f..7a73c4797 100644 --- a/src/gns/proxy/proxy.py +++ b/src/gns/proxy/proxy.py | |||
@@ -22,7 +22,7 @@ Any help will be greatly appreciated. SUZUKI Hisao | |||
22 | 22 | ||
23 | __version__ = "0.2.1" | 23 | __version__ = "0.2.1" |
24 | 24 | ||
25 | import BaseHTTPServer, select, socket, SocketServer, urlparse, re | 25 | import BaseHTTPServer, select, socket, SocketServer, urlparse, re, string, os |
26 | 26 | ||
27 | class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | 27 | class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): |
28 | __base = BaseHTTPServer.BaseHTTPRequestHandler | 28 | __base = BaseHTTPServer.BaseHTTPRequestHandler |
@@ -31,6 +31,7 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
31 | server_version = "TinyHTTPProxy/" + __version__ | 31 | server_version = "TinyHTTPProxy/" + __version__ |
32 | rbufsize = 0 # self.rfile Be unbuffered | 32 | rbufsize = 0 # self.rfile Be unbuffered |
33 | host_port = () | 33 | host_port = () |
34 | to_replace = "" | ||
34 | 35 | ||
35 | def handle(self): | 36 | def handle(self): |
36 | (ip, port) = self.client_address | 37 | (ip, port) = self.client_address |
@@ -43,8 +44,18 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
43 | def _connect_to(self, netloc, soc): | 44 | def _connect_to(self, netloc, soc): |
44 | i = netloc.find(':') | 45 | i = netloc.find(':') |
45 | if i >= 0: | 46 | if i >= 0: |
47 | print 'calling gnunet-gns -a '+netloc[:i] | ||
48 | auth = os.popen("gnunet-gns -a "+netloc[:i]) | ||
49 | lines = auth.readlines() | ||
50 | print 'result: '+lines[0].split(" ")[-1].rstrip() | ||
51 | self.to_replace = lines[0].split(" ")[-1].rstrip() | ||
46 | self.host_port = netloc[:i], int(netloc[i+1:]) | 52 | self.host_port = netloc[:i], int(netloc[i+1:]) |
47 | else: | 53 | else: |
54 | print 'calling gnunet-gns -a '+netloc | ||
55 | auth = os.popen("gnunet-gns -a "+netloc) | ||
56 | lines = auth.readlines() | ||
57 | print 'result: '+lines[0].split(" ")[-1].rstrip() | ||
58 | self.to_replace = lines[0].split(" ")[-1].rstrip() | ||
48 | self.host_port = netloc, 80 | 59 | self.host_port = netloc, 80 |
49 | print "\t" "connect to %s:%d" % self.host_port | 60 | print "\t" "connect to %s:%d" % self.host_port |
50 | try: soc.connect(self.host_port) | 61 | try: soc.connect(self.host_port) |
@@ -70,6 +81,14 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
70 | soc.close() | 81 | soc.close() |
71 | self.connection.close() | 82 | self.connection.close() |
72 | 83 | ||
84 | def replace_and_shorten(self, mo): | ||
85 | full = string.replace(mo.group(1)+self.to_replace, 'a href="', "") | ||
86 | print 'calling gnunet-gns -s '+full | ||
87 | s = os.popen("gnunet-gns -s "+full) | ||
88 | lines = s.readlines() | ||
89 | print 'short: '+lines[0].split(" ")[-1].rstrip() | ||
90 | return 'a href="'+lines[0].split(" ")[-1].rstrip() | ||
91 | |||
73 | def do_GET(self): | 92 | def do_GET(self): |
74 | (scm, netloc, path, params, query, fragment) = urlparse.urlparse( | 93 | (scm, netloc, path, params, query, fragment) = urlparse.urlparse( |
75 | self.path, 'http') | 94 | self.path, 'http') |
@@ -116,8 +135,8 @@ class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): | |||
116 | if (re.match("(\w+\.)*gnunet", self.host_port[0])): | 135 | if (re.match("(\w+\.)*gnunet", self.host_port[0])): |
117 | arr = self.host_port[0].split('.') | 136 | arr = self.host_port[0].split('.') |
118 | arr.pop(0) | 137 | arr.pop(0) |
119 | data = re.sub(r'(a href="http://(\w+\.)*)(\+)', | 138 | data = re.sub('(a href="http://(\w+\.)*)(\+)', |
120 | r'\1'+'.'.join(arr), data) | 139 | self.replace_and_shorten, data) |
121 | print data | 140 | print data |
122 | out.send(data) | 141 | out.send(data) |
123 | count = 0 | 142 | count = 0 |