Last active
August 29, 2015 14:11
-
-
Save Programie/c0fadf0864bb241e30d9 to your computer and use it in GitHub Desktop.
A simple rewrite script for PS3 Downloads which can be used as redirect_program in Squid3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env php | |
| <?php | |
| /** | |
| * This is a simple rewrite script for use with Squid3. | |
| * | |
| * The primary use case for this script is to fetch any PKG URL which might be downloaded from the Playstation CDN and download them somewhere different. | |
| * This allows downloading big games on an always-on machine which takes less power than the Playstation. Or just download the file somewhere else where a fast internet connection is available. | |
| * | |
| * Just place any downloaded pkg-file into the directory configured in PKG_PATH and accessible via LOCAL_URL. Your Playstation will magically download the file from your own server. | |
| * | |
| * Requirements: | |
| * - Squid3 | |
| * - A webserver (e.g. Apache, nginx or lighttpd) | |
| * | |
| * Note: You have to point your webserver to the directory configured in PKG_PATH. | |
| * | |
| * Add the following line into your squid3.conf: | |
| * url_rewrite_program /path/to/this/script | |
| */ | |
| define("PKG_PATH", "/data/software/ps3");// Path to your downloaded .pkg files | |
| define("LOCAL_URL", "http://selfcoders.org/ps3pkg");// The local URL to which an already downloaded file should be rewritten | |
| while ($line = fgets(STDIN)) | |
| { | |
| list($url, $fqdn, $ident, $method) = explode(" ", $line); | |
| // Currently only GET is supported | |
| if ($method != "GET") | |
| { | |
| echo "\n"; | |
| continue; | |
| } | |
| $newUrl = ""; | |
| if (preg_match("|^http://zeus\.dl\.playstation\.net/cdn/(.*)/(.*)/(.*)\.pkg|", $url, $matches)) | |
| { | |
| $file = $matches[3] . ".pkg"; | |
| if (file_exists(PKG_PATH . "/" . $file)) | |
| { | |
| $newUrl = LOCAL_URL . "/" . $file; | |
| } | |
| else | |
| { | |
| file_put_contents(PKG_PATH . "/" . $file . ".txt", "Download " . $url . " to " . $file . "."); | |
| } | |
| } | |
| if (!$newUrl or $newUrl == $url) | |
| { | |
| echo "\n"; | |
| continue; | |
| } | |
| file_put_contents("/var/log/squid3/squid-rewrite.log", sprintf("[%s] %s -> %s\n", date("c"), $url, $newUrl), FILE_APPEND); | |
| echo "OK rewrite-url=" . $newUrl . "\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment