Extract the opt out iframe from index.php

I am running a “customly hardened” installation of piwik. (the dashboard (index.php) is accessible under a completly different Domain) And for each (bigger) project I plan to create an extra subdomain exposing only piwik.php and piwik.js.
I NEED to give my visitors the option to opt out so I have to embed the opt out iframe.
The problem is: The iframe calls the index.php which is NOT accessible by the public tracking subdomain.
My dashboard is only accessible when connected via a tunnel of some sort or in the companys network via a non public “domain”.
Exposing the index.php to the “crowd” means my whole security concept would be for nothing…
Is there a way to extract this function from the index.php and put it in the piwik.php or a separate file?
If I get this right, there is only a cookie generated and nothing saved in the database, right? so I should be able to re implement this on my own? without a connection to piwik? also I need to to set the cookie from the url where the tracking happens otherwise this whole opt out thing would be useless, right?