## duplo:/etc/zorp/policy.py
# test zorp config

from Zorp.Core import *
from Zorp.Http import *
from Zorp.AnyPy import *

Zorp.firewall_name = 'zorp@duplo'

InetZone("local", "127.0.0.0/8",
	 inbound_services=["*"],
	 outbound_services=["*"])

class IntraHttp(HttpProxy):
	def config(self):
		HttpProxy.config(self)
		self.transparent_mode = TRUE
		self.permit_enchunking = FALSE
		self.request_stack["POST"] = (HTTP_STK_DATA, MagicProxy)
		

# zorp_http instance
def zorp_http():
	Service("intra_http", IntraHttp, router=DirectedRouter(SockAddrInet('127.0.0.1',80)))
	Listener(SockAddrInet("127.0.0.1", 50080), "intra_http")

class MagicProxy(AbstractAnyPyProxy):
	def config(self):
		AbstractAnyPyProxy.config(self)

	def proxyThread(self):
		client = self.session.client_stream
		server = self.session.server_stream

		buf = client.read(128)

		while buf:
			log("http.info", 2, "read data: *%s*" % (buf.__str__()));
			log("http.info", 2, "read data length *%d*" % (len(buf.__str__())));
			try:
				server.write(buf)
				log("http.info", 2, "(written data: *%s*)" % (buf.__str__()));
				buf = client.read(128)
			except IOError, e:
				log("http.info", 2, "exception: %s" % (e.__str__()));
				break

		log("http.info", 2, "DEBUG: MagicProxy END")

