Hi, what you want, I already have for years. And is used in production already, of course. But I do _not_ sell the soure code. I only license am appliance, based on traffic volume.
My solution is a proxy itself, so squid is not necessary, but is useful for certain optimizations.
Usually, my clients only inject the "container" code for the ads, and ads themselves are served by openx/revive adserver. Feel free to ask me for a demo video.