Skip to content

Instantly share code, notes, and snippets.

@agramajo
Created October 22, 2019 16:45
Show Gist options
  • Save agramajo/586685fc69c249f73428a327255d7d35 to your computer and use it in GitHub Desktop.
Save agramajo/586685fc69c249f73428a327255d7d35 to your computer and use it in GitHub Desktop.
<?php
header( 'Content-Type: text/html' );
header( 'Cache-Control: no-cache' );
$password = 'xxx';
$hostname = 'https://xxx.com';
function purgeURL( $hostname, $port, $purgeHOST, $purgeURL )
{
$finalURL = sprintf( "%s%s", $hostname, $purgeURL );
$output = "PURGE $purgeHOST$purgeURL\n";
$curlOptionList = array(
CURLOPT_CUSTOMREQUEST => 'PURGE',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
CURLOPT_URL => $finalURL,
CURLOPT_CONNECTTIMEOUT_MS => 2000,
CURLOPT_HTTPHEADER => array("Host: $purgeHOST"),
CURLOPT_VERBOSE => true
);
$curlHandler = curl_init();
curl_setopt_array( $curlHandler, $curlOptionList );
$output .= curl_exec( $curlHandler );
curl_close( $curlHandler );
return $output;
}
?>
<form id="foo" method=post>
password <input type=password name=password size=10>
host <input type=text value=test.urgente24.com name=host>
url <input type=text value=/ name=url>
home? <input type=checkbox value=1 name=home>
<button id="btn1">Purgar</button>
</form>
<div id="msg"></div>
<script>
$(document).ready(function(){
$("#foo").submit(function(){
$("#msg").html('Cargando...');
var values = $("#foo").serialize();
$.ajax({
type: "POST",
url: "purge.php",
data: values,
success: function(data){ $("#msg").html(values); }
});
});
});
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<?php
if (isset($_POST['host'])) {
if ($_POST['password'] == $password) {
$output = purgeURL( $hostname, $port, $_POST['host'], $_POST['url'] );
if ($_POST['home']) {
$output .= purgeURL( $hostname, $port, $_POST['host'], '/' );
}
} else {
$output = 'Password incorrecto';
}
echo "<pre>$output</pre>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment