#!/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: echo "adding subdomain on AlternC server $server for domain $domain & sub $sub\n"; $s=file_get_contents($server."/api/rest/subdomain/set?token=".$token."&dom=".$domain."&sub=_acme-challenge".$sub."&type=TXT&dest=".urlencode($value)."&urgent=1"); if (!$result=@json_decode($s,true) || $result["content"]!=true) { echo "FATAL: error while calling set API on $server, returned string\n$s\n"; exit(1); } // wait for a few seconds for the information to propagate to DNS through update_domaines & others... sleep(10); exit(0);