My solution was to use javascript to alter the torrent link to send its url to my server for download rather than trying to open it. A php script on the server could then download that url to the torrents folder. With both scripts in place and the permissions of the torrents folder modified to allow apache to write files, all I have to do is run the javascript as a bookmarklet before clicking the torrent link, and click the link to download the torrent file. The modified link will pass this url to the script to download it on the server.
Bookmarklet: torrent
PHP:
<?php
if (!($_SERVER['PHP_AUTH_USER'] == "username" && $_SERVER['PHP_AUTH_PW'] == "password")) {
header('WWW-Authenticate: Basic realm="torrent"');
header('HTTP/1.0 401 Unauthorized');
} else {
passthru('curl -H "Referer: '.$_SERVER['$HTTP_REFERER'].'" -H "User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-us) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10" -o /path/to/monitored/torrents/folder/remote.torrent "'.$_SERVER['QUERY_STRING'].'"');
}
?><script type="text/javascript">history.back()</script>
Modifications required:
- script url in bookmarklet
- username in php script
- password in php script
- torrents folder path in php script