79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
-
+
-
-
-
+
+
+
+
|
self._log = Logger()
self._log.info('started\n')
self._request = re.compile('^([0-9]+)\ (http|ftp):\/\/([-\w.:]+)\/([^ ]*)\ ([0-9.]+)\/(-|[\w\.]+)\ (-|\w+)\ (-|GET|HEAD|POST).*$')
def process(self, id, site, ip_address, url_path, line = None):
self._log.info('trying {}\n'.format(site))
result = self._db.check(site, ip_address)
reply = '-'
reply = None
for row in result:
if row != None and row[0] != None:
if row[1] != None:
self._log.info('trying regexp "{}" versus "{}"\n'.format(row[1], url_path))
try:
if re.compile(row[1]).match(url_path):
reply = row[0].format(url_path)
break
else:
continue
except:
self._log.info("can't compile regexp")
else:
reply = row[0].format(url_path)
break
self.writeline('{} {}\n'.format(id, reply))
if reply != None:
self.writeline('{} {}\n'.format(id, reply))
return(True)
self.writeline('{}\n'.format(id))
def check(self, line):
request = self._request.match(line)
if request:
id = request.group(1)
#proto = request.group(2)
site = request.group(3)
|