#!/usr/bin/php $data) { if ($certbot==$suffix || substr($certbot,-strlen($suffix)-1)==(".".$suffix)) { // ^matching or \.matching if (strlen($suffix)>$length) { $length=strlen($suffix); $domain=$suffix; $server=$data["server"]; $token=$data["token"]; } } } if (!$domain) { echo "FATAL: the domain $certbot is NOT available through AlternC api. Please check your configuration file\n"; exit(1); } // now let's split what is domain and what is SUB :) if ($domain==$certbot) { $sub=""; } else { $sub=".".substr($certbot,0,-strlen($domain)-1); } // API call, list subdomains: $s=file_get_contents($server."/api/rest/domain/get?token=".$token."&dom=".$domain); if (!($result=json_decode($s,true)) || !is_array($result["content"])) { echo "FATAL: error while calling get API on $server, returned string\n$s\n"; exit(1); } $id=0; foreach($result["content"]["sub"] as $onesub) { if ($onesub["name"]=="_acme-challenge".$sub && strtolower($onesub["type"])=="txt" && $onesub["dest"]==$value) { $id=$onesub["id"]; break; } } if (!$id) { echo "ERROR: found nothing to cleanup, maybe a mistake ? \n"; exit(0); } echo "removing subdomain on AlternC server $server, id $id\n"; $s=file_get_contents($server."/api/rest/subdomain/del_by_id?token=".$token."&dom=".$domain."&id=".$id); if (!$result=@json_decode($s,true) || $result["content"]!=true) { echo "FATAL: error while calling del_by_id API on $server, returned string\n$s\n"; exit(1); } exit(0);