michaelmr

WHMCS CozaEPP bulk disalbe of auto-renew

Feb 21st, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.50 KB | None | 0 0
  1. <?php
  2. ## Tool to bulk disable registrar "AutoRenew: True" //
  3. ## Everything Web CC - Used AllWorldIT's sync script and modified to suit
  4.  
  5. # This file brings in a few constants we need
  6. require_once dirname(__FILE__).'/../../../dbconnect.php';
  7.  
  8. # Setup include dir
  9. $include_path = ROOTDIR.'/modules/registrars/cozaepp';
  10. set_include_path($include_path.PATH_SEPARATOR.get_include_path());
  11.  
  12. # Include EPP stuff we need
  13. require_once 'cozaepp.php';
  14.  
  15. # Additional functions we need
  16. require_once ROOTDIR.'/includes/functions.php';
  17.  
  18. # Include registrar functions aswell
  19. require_once ROOTDIR.'/includes/registrarfunctions.php';
  20.  
  21. # We need pear for the error handling
  22. require_once "PEAR.php";
  23.  
  24. # Grab module parameters
  25. $params = getregistrarconfigoptions('cozaepp');
  26.  
  27. echo "COZA-EPP Disable Registrar Auto-renew\n";
  28. echo "--------------------------------------\n";
  29.  
  30. # Request balance from registrar
  31. if (PEAR::isError($client = _cozaepp_Client())) {
  32.     echo "ERROR: ".$client->getMessage()."\n";
  33.     die();
  34. }
  35.  
  36. # Domain passed as argument?
  37. if (isset($argv, $argv[1])) {
  38.     $queryresult = mysql_query("SELECT domain FROM tbldomains WHERE domain = '".mysql_escape_string(trim($argv[1]))."' and registrar = 'cozaepp' AND status = 'Active'");
  39. } else {
  40. # No? Let's do them all
  41.     $queryresult = mysql_query("SELECT domain FROM tbldomains WHERE registrar = 'cozaepp' AND status = 'Active'");     
  42. }
  43. # If you want to do it on domains that are cancelled - not just active - you can remove the "AND status = 'Active' above (note: both queries have it)
  44.  
  45. while ($data = mysql_fetch_array($queryresult)) {
  46.     $domains[] = trim(strtolower($data['domain']));
  47. }
  48.  
  49. # Loop with each one
  50. foreach ($domains as $domain) {
  51.     sleep(1);
  52.    
  53.     # Get domain info
  54.     $output = $client->request('
  55.         <epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  56.         xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
  57.           <command>
  58.             <info>
  59.               <domain:info xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"
  60.         xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
  61.                 <domain:name hosts="all">'.$domain.'</domain:name>
  62.               </domain:info>
  63.             </info>
  64.             <extension>
  65.               <cozadomain:info xmlns:cozadomain="http://co.za/epp/extensions/cozadomain-1-0"
  66.         xsi:schemaLocation="http://co.za/epp/extensions/cozadomain-1-0 coza-domain-1.0.xsd">
  67.               </cozadomain:info>
  68.             </extension>
  69.           </command>
  70.         </epp> 
  71.     ');
  72.    
  73.     $doc= new DOMDocument();
  74.     $doc->loadXML($output);
  75.     $coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
  76.     if ($coderes == '1000') {
  77.         # Is autorenew enabled?
  78.         if ($doc->getElementsByTagName('autorenew') && $doc->getElementsByTagName('autorenew')->item(0) && strtolower(trim($doc->getElementsByTagName('autorenew')->item(0)->nodeValue)) != "false") {
  79.             sleep(1);
  80.             # Disable autorenew via update
  81.             $output = $client->request('
  82.                 <epp:epp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0"
  83.                 xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xmlns:cozadomain="http://co.za/epp/extensions/cozadomain-1-0"
  84.                 xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
  85.                   <epp:command>
  86.                     <epp:update>
  87.                       <domain:update xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
  88.                         <domain:name>'.$domain.'</domain:name>
  89.                       </domain:update>
  90.                     </epp:update>
  91.                     <epp:extension>
  92.                       <cozadomain:update xsi:schemaLocation="http://co.za/epp/extensions/cozadomain-1-0 coza-domain-1.0.xsd">
  93.                       <cozadomain:chg><cozadomain:autorenew>false</cozadomain:autorenew></cozadomain:chg></cozadomain:update>
  94.                     </epp:extension>
  95.                   </epp:command>
  96.                 </epp:epp>                             
  97.             ');
  98.        
  99.             $doc= new DOMDocument();
  100.             $doc->loadXML($output);
  101.             $coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
  102.             if($coderes == '1001') {
  103.                 if($doc->getElementsByTagName('msg')) {
  104.                     if($doc->getElementsByTagName('msg')->item(0)) {
  105.                         echo "- ".$domain." results: ".$doc->getElementsByTagName('msg')->item(0)->nodeValue."\n";
  106.                     } else {
  107.                         $status = "$domain response error\n";
  108.                         continue;
  109.                     }
  110.                 }
  111.             } else {
  112.                 echo "Domain renew status update on $domain not successful: "._cozaepp_message($coderes)."\n";
  113.                 continue;
  114.             }
  115.         } else {
  116.             echo "- ".$domain." already has auto-renew disabled.\n";
  117.             continue;
  118.         }
  119.     } else {
  120.         echo "Domain info on $domain not successful: "._cozaepp_message($coderes)."\n";
  121.         continue;
  122.     }
  123.    
  124. }
  125.  
  126.  
  127. ?>
Advertisement
Add Comment
Please, Sign In to add comment