changeset 1062:4eabca5d5703 draft

[quicktun.socks4a] bugfixes
author d3v11 <d3v11@d3v11.ano>
date Sun, 11 Nov 2012 04:07:07 +0000
parents 2f46efeae39a
children 2847a9ff2e6b
files contrib/quicktun.socks4a/quicktun.socks4a
diffstat 1 files changed, 21 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/quicktun.socks4a/quicktun.socks4a	Fri Nov 09 10:22:51 2012 +0000
+++ b/contrib/quicktun.socks4a/quicktun.socks4a	Sun Nov 11 04:07:07 2012 +0000
@@ -1,5 +1,14 @@
 #!/usr/bin/env python
-import               subprocess, socket, select, fcntl, sys, os
+import  subprocess, signal, socket, select, fcntl, time, sys, os
+
+def exit(sn,sf):
+  try:
+    tun.terminate                                             ()
+  except:
+    pass
+signal.signal                              (signal.SIGHUP, exit)
+signal.signal                              (signal.SIGINT, exit)
+signal.signal                              (signal.SIGTERM,exit)
 
 DEBUG          = os.getenv        ('DEBUG'         ,'1'        )
 TUN_MODE       = os.getenv        ('TUN_MODE'      ,'1'        )
@@ -16,8 +25,8 @@
 DST_ADDRESS    = os.getenv        ('DST_ADDRESS'   ,'127.0.0.3')
 DST_PORT       = os.getenv        ('DST_PORT'      ,'2998'     )
 
-SOCKS_ADDRESS  = os.getenv        ('LOCAL_ADDRESS' ,'127.0.0.1')
-SOCKS_PORT     = os.getenv        ('LOCAL_PORT'    ,'9050'     )
+SOCKS_ADDRESS  = os.getenv        ('SOCKS_ADDRESS' ,'127.0.0.1')
+SOCKS_PORT     = os.getenv        ('SOCKS_PORT'    ,'9050'     )
 
 udp            = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
 udp.setsockopt         (socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
@@ -28,12 +37,9 @@
 
 if REMOTE_FLOAT==0:
   tun          = subprocess.Popen                             (
-                 [ 'socat',
-                   'STDIO',
-                   'SOCKS4A:'
-                   +SOCKS_ADDRESS+':'+DST_ADDRESS+':'+DST_PORT
-                                     +',SOCKSPORT='+SOCKS_PORT,
-                 ],
+                 ['socat','STDIO','SOCKS4A:'+SOCKS_ADDRESS+':'
+                  +DST_ADDRESS+':'+DST_PORT+',SOCKSPORT='
+                                                  +SOCKS_PORT],
   stdout       = subprocess.PIPE,
   stdin        = subprocess.PIPE,                              )
   tun_stdout   = tun.stdout.fileno                            ()
@@ -44,13 +50,10 @@
 
 if REMOTE_FLOAT==1:
   tun          = subprocess.Popen                             (
-                 [ 'socat',
-                   'TCP-LISTEN:'
-                   +str(LOCAL_PORT)+',BIND='+LOCAL_ADDRESS
-                                                 +',REUSEADDR',
-                   'UDP-CONNECT:'+LOCAL_ADDRESS+':'
-                                              +str(LOCAL_PORT),
-                 ],
+                       ['socat','TCP-LISTEN:'+str(LOCAL_PORT)
+                        +',BIND='+LOCAL_ADDRESS+',REUSEADDR',
+                        'UDP-CONNECT:'+LOCAL_ADDRESS+':'+str(
+                                                  LOCAL_PORT)],
   stdout       = subprocess.PIPE,
   stdin        = subprocess.PIPE,                              )
   tun_stdout   = tun.stdout.fileno                            ()
@@ -65,6 +68,8 @@
 fcntl.fcntl               (tun_stdout,fcntl.F_SETFL,fcntl.fcntl
         (tun_stdout,fcntl.F_GETFL)&~os.O_NONBLOCK|os.O_NONBLOCK)
 
+time.sleep                                                   (4)
+
 tun            = subprocess.Popen                             (
                  [ '/usr/sbin/quicktun.'+PROTOCOL,
                  ],