我正在运行 safesquid,它确实支持外部解析器,所以我用 python 编写了这个简单的 URL 重写代码,它还记录了初始请求......
#!/usr/bin/env python
import sys
def modify_url(line):
list = line.split(' ')
old_url = list[0]
new_url = '\n'
if old_url.endswith('.avi'):
new_url = 'http://www.yahoo.com'
else:
new_url = old_url
return new_url
def main():
while True:
line = sys.stdin.readline().strip()
log = open('/tmp/redirect.log', 'a')
log.write(line + "\n")
log.close()
new_url = modify_url(line)
sys.stdout.write(new_url)
sys.stdout.flush()
if __name__ == '__main__':
main()
我在 safesquid 上收到这些错误
2012 01 30 17:19:45 [225] request: request for web interface from 192.168.221.1
2012 01 30 17:19:45 [225] external: parsed with /opt/safesquid/safesquid/scripts/redirect.py
2012 01 30 17:19:45 [225] external: error: external parser sent null or invalid request headers
2012 01 30 17:19:45 [225] error: security: malformatted header received
2012 01 30 17:19:45 [225] external: parsed with /opt/safesquid/safesquid/scripts/redirect.py
2012 01 30 17:19:45 [225] external: error: external parser sent null or invalid request headers
另外,初始请求日志是空的,但文件很大,我猜它必须将“\n”附加到文件...
有什么想法我可以捕获来自 safesquid 的请求吗?