12
12
BACKLOG = 50 # how many pending connections queue will hold
13
13
MAX_DATA_RECV = 999999 # max number of bytes we receive at once
14
14
DEBUG = True # set to True to see the debug msgs
15
- BLOCKED = [] # just an example. Remove with [""] for no blocking at all.
15
+ BLOCKED = [] # just an example. Remove with [""] for no blocking at all.
16
16
17
17
#**************************************
18
18
#********* MAIN PROGRAM ***************
@@ -21,14 +21,15 @@ def main():
21
21
22
22
# check the length of command running
23
23
if (len (sys .argv )< 2 ):
24
- print "usage: proxy <port>"
25
- return sys .stdout
24
+ print "No port given, using :8080 (http-alt)"
25
+ port = 8080
26
+ else :
27
+ port = int (sys .argv [1 ]) # port from argument
26
28
27
29
# host and port info.
28
30
host = '' # blank for localhost
29
- port = int (sys .argv [1 ]) # port from argument
30
31
31
- print "Proxy Server Running on " ,host ,":" ,sys . argv [ 1 ]
32
+ print "Proxy Server Running on " ,host ,":" ,port
32
33
33
34
try :
34
35
# create a socket
@@ -56,6 +57,15 @@ def main():
56
57
s .close ()
57
58
#************** END MAIN PROGRAM ***************
58
59
60
+ def printout (type ,request ,address ):
61
+ if "Block" in type or "Blacklist" in type :
62
+ colornum = 91
63
+ elif "Request" in type :
64
+ colornum = 92
65
+ elif "Reset" in type :
66
+ colornum = 93
67
+
68
+ print "\033 [" ,colornum ,"m" ,address [0 ],"\t " ,type ,"\t " ,request ,"\033 [0m"
59
69
60
70
#*******************************************
61
71
#********* PROXY_THREAD FUNC ***************
@@ -74,10 +84,12 @@ def proxy_thread(conn, client_addr):
74
84
75
85
for i in range (0 ,len (BLOCKED )):
76
86
if BLOCKED [i ] in url :
77
- print "\033 [91mBlocked: " ,first_line ,"\033 [0m"
87
+ printout ("Blacklisted" ,first_line ,client_addr )
88
+ conn .close ()
78
89
sys .exit (1 )
79
90
80
- print "\033 [92mRequest: " ,first_line ,"\033 [0m"
91
+
92
+ printout ("Request" ,first_line ,client_addr )
81
93
# print "URL:",url
82
94
# print
83
95
@@ -126,7 +138,7 @@ def proxy_thread(conn, client_addr):
126
138
s .close ()
127
139
if conn :
128
140
conn .close ()
129
- print " \033 [93mPeer Reset: " ,first_line ," \033 [0m"
141
+ printout ( "Peer Reset" ,first_line ,client_addr )
130
142
sys .exit (1 )
131
143
#********** END PROXY_THREAD ***********
132
144
0 commit comments