Skip to content

Instantly share code, notes, and snippets.

@SmugZombie
Last active May 19, 2016 23:55
Show Gist options
  • Save SmugZombie/4df56af9a0c919e3b7f0906a80de80c3 to your computer and use it in GitHub Desktop.
Save SmugZombie/4df56af9a0c919e3b7f0906a80de80c3 to your computer and use it in GitHub Desktop.
?php
// Simple Proxy script created to manage Cisco Devices in a different vlan. Uses Basic Auth
// github.com/smugzombie
$username = "";
$password = "";
$url = $_GET['url'];
if(!$url){ echo "<form action='/proxy/' method='get'>URL: <input type='text' name='url'/> <button>Go</button></form>"; return;}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
curl_close($ch);
function prepend_proxy($matches) {
global $url;
$url = rtrim($url, '/');
$prepend = $matches[2] ? $matches[2] : $url;
$prepend = 'index.php?url='. $prepend;
return $matches[1] . $prepend . $matches[3];
}
echo preg_replace_callback('|(href=[\'"]?)(https?://)?([^\'"\s]+[\'"]?)|i','prepend_proxy',$result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment