##Purge Akamai via SOAP by parsing out activated pages from an AEM/CQ Replication Agent.
Since Production Akamai could not be flushed globally we needed a job which could flush only today's Author activated pages.
<?php | |
#$url=split("\r\n",trim($_GET['url'])); | |
if(isset($_GET['url']) && $_GET['url']!='todays_urls' && $_GET['url']!='todays_dam') { $url=split(",",trim($_GET['url'])); } | |
else { | |
$input=fopen("http://admin:CUT@CUT/etc/replication/agents.author/akamai-agent.log.html", "rb",false); | |
//$input=fopen("temp.out", 'r'); | |
$output=fopen("output.out", 'wb'); | |
#Instead of parsing the stream directly lets put it to file first as a just in case of leaving prod connection too logn... | |
stream_copy_to_stream($input, $output); | |
fclose($input); | |
fclose($output); | |
$domainList=array( | |
'af' => 'http://www.sample.com', | |
'zw' => 'http://www.sample2.com' | |
); | |
$PREVURL=array(); | |
$fh=fopen("output.out", 'r'); | |
while (!feof($fh)) { | |
$line = fgets($fh); | |
if (strpos($line,'Skip') && isset($_GET['url']) && $_GET['url']=='todays_dam') { | |
//if (strpos($line,'Skip')) { | |
//echo $line; | |
$x=preg_split('/.*Skip/',$line); | |
$DAM[]=trim(substr($x[1],0,-5)); | |
} elseif (strpos($line,'ACTIVATE')) { | |
$x=preg_split('/\(ACTIVATE\) of /',$line); | |
$dirtyURL=trim(substr($x[1],0,-51)).'.html'; | |
$slashExploded=explode('/',$dirtyURL); | |
$domain=$domainList[$slashExploded[2]]; | |
$URL=$domain.substr($dirtyURL,11); | |
if (stripos($URL, 'http://')===0) { | |
$PREVURL[]=$URL; | |
} else { | |
//echo 'Skipping: '.$URL; | |
} | |
} | |
} | |
$buildURL=array(); | |
if(isset($DAM) && is_array($DAM)) { | |
//if(is_array($DAM)) { | |
foreach($DAM as $url) { | |
foreach($domainList as $domain) { | |
$buildURL[]=$domain.$url; | |
} | |
} | |
$url=$buildURL; | |
} else { | |
$url=$PREVURL; | |
} | |
} | |
$urlArray=array(); | |
$strContent=''; | |
foreach($url as $k=>$v) { | |
$urlArray[]=$v; | |
if ($k%30==0 && $k>1) { | |
$strContent.=Akamai($urlArray)."\n"; | |
unset($urlArray); | |
} | |
} | |
$strContent.=Akamai($urlArray)."\n"; | |
sleep(10); | |
echo "<br/><hr/><br/>"; | |
echo $strContent; | |
exit; | |
function Akamai($urlArray) { | |
$strContent='<div id="requestContainer">'; | |
$username='CUT'; | |
$password='CUT'; | |
$email=$_GET['email']; | |
#$opt=array('action' => 'remove', 'type' => 'arl'); | |
$opt=array('action=remove','domain=production','type=arl','email-notification='.$email); /*type arl or cpcode*/ | |
$client = new SoapClient('https://ccuapi.akamai.com/ccuapi-axis.wsdl', | |
array( | |
'proxy_host' => "165.72.254.22", | |
'proxy_port' => 8080 | |
) | |
); | |
try { | |
$purgeResult = $client->purgeRequest($username, $password, '', $opt, $urlArray); | |
#var_dump($client->__getFunctions()); | |
#var_dump($client->__getTypes()); | |
} | |
catch(SoapFault $e){ | |
$strContent.="Exception\n"; | |
//var_dump($e); | |
} | |
foreach($urlArray as $k=>$v) { | |
$strContent.='<span style="color:#fff;">Purging: </span><span style="color:#ccc;font-weight:900;">'.htmlentities($v).'</span><br/>'; | |
} | |
if($purgeResult->resultMsg == 'Success.') { | |
$strContent.='<div style="margin-left:10px;color:green;">Success confirmation email will be sent from Akamai</div>'; | |
$strContent.='<div style="color:yellow;margin-left:10px;">Verification ID: '.$purgeResult->sessionID.'</div>'; | |
} else { | |
$strContent.='<div style="color:red;">**** Failed: '.$purgeResult->resultMsg.'</div>'; | |
} | |
#var_dump($client->__getLastRequest()); | |
$strContent.="</div>"; | |
return $strContent; | |
} | |
?> |