Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, October 15, 2026

Diff for scripts/php/sk-nic/SK-NIC.php between version 1.12 and 1.13

version 1.12, 2015/08/27 06:16:20 version 1.13, 2017/09/16 09:36:22
Line 10 
Line 10 
  *   *
  * Changelog:   * Changelog:
  * 2007-03-09 - created   * 2007-03-09 - created
  *   * 2017-09-12 - implemented new SK-NIC-EPP/CentralNic export
  */   */
   
 /* $Platon: scripts/php/sk-nic/SK-NIC.php,v 1.11 2011-08-11 08:53:09 nepto Exp $ */  /* $Platon: scripts/php/sk-nic/SK-NIC.php,v 1.12 2015/08/27 06:16:20 nepto Exp $ */
   
 require_once 'DB.php';  require_once 'DB.php';
   
Line 23  class SK_NIC
Line 23  class SK_NIC
         var $_dsn  = null;          var $_dsn  = null;
         var $_db   = null;          var $_db   = null;
   
         function SK_NIC($dsn, $options  = array('debug' => 10)) // {{{          public function __construct($dsn, $options  = array('debug' => 10)) // {{{
         {          {
                 $this->_dsn  = $dsn;                  $this->_dsn  = $dsn;
   
Line 37  class SK_NIC
Line 37  class SK_NIC
                         && $this->error($res);                          && $this->error($res);
         } // }}}          } // }}}
   
           function SK_NIC($dsn, $options  = array('debug' => 10)) // {{{
           {
                   self::__construct();
           } // }}}
   
         function _SK_NIC() // {{{ DESTRUCTOR          function _SK_NIC() // {{{ DESTRUCTOR
         {          {
                 $this->_db->disconnect();                  $this->_db->disconnect();
Line 97  class SK_NIC
Line 102  class SK_NIC
                 }                  }
                 $this->_cleanImport();                  $this->_cleanImport();
                 $this->_writeImportWithLoadData($filename, $changed_date);                  $this->_writeImportWithLoadData($filename, $changed_date);
                   $this->_importedNameserversReorder();
                 return true;                  return true;
         } /* }}} */          } /* }}} */
   
Line 116  class SK_NIC
Line 122  class SK_NIC
   
         function _cleanImport() /* {{{ */          function _cleanImport() /* {{{ */
         {          {
                 // $result = $this->_db->query('DELETE FROM sknic_domains_import');  
                 $result = $this->_db->query('TRUNCATE TABLE sknic_domains_import');                  $result = $this->_db->query('TRUNCATE TABLE sknic_domains_import');
                 DB::isError($result) && $this->error($result);                  DB::isError($result) && $this->error($result);
         } /* }}} */          } /* }}} */
   
           function _importedNameserversReorder() /* {{{ */
           {
                   $result = $this->_db->query('SELECT domain,ns1,ns2,ns3,ns4 FROM sknic_domains_import');
                   while ($row = $result->fetchRow()) {
                           $domain = $row['domain'];
                           unset($row['domain']);
                           usort($row, array($this, '_sortingFunction'));
                           $row = array_filter($row, function($value) { return $value !== ''; });
                           $query = sprintf('UPDATE sknic_domains_import SET ns1=%s,ns2=%s,ns3=%s,ns4=%s WHERE domain=%s',
                                           $this->_db->quote($row[0]),
                                           $this->_db->quote($row[1]),
                                           $this->_db->quote($row[2]),
                                           $this->_db->quote($row[3]),
                                           $this->_db->quote($domain));
                           $result2 = $this->_db->query($query);
                           DB::isError($result2) && $this->error($result2);
                   }
           } /* }}} */
   
           function _sortingFunction($a, $b) /* {{{ */
           {       /* Sorts by:
                    * 1. length - shorter hostname first
                    * 2. alphabeticaly
                    * Sorted exmaple:
                    * - ns.platon.sk
                    * - dns.platon.sk
                    * - ns.platon.org
                    * - dns.platon.org
                    */
                   $a_len = strlen($a);
                   $b_len = strlen($b);
                   if ($a_len == $b_len) {
                           return strcasecmp($a, $b);
                   }
                   if ($a_len == 0 || $b_len == 0) {
                           return $b_len - $a_len; // flip order if we have some empty values
                   }
                   return $a_len - $b_len;
           } /* }}} */
   
         function _writeImportWithInserts($filename, $changed_date) /* {{{ */          function _writeImportWithInserts($filename, $changed_date) /* {{{ */
         {          {
                 if (($f = fopen($filename, 'r')) == false) {                  if (($f = fopen($filename, 'r')) == false) {
Line 132  class SK_NIC
Line 177  class SK_NIC
                                 continue; /* line skipped */                                  continue; /* line skipped */
                         }                          }
   
                         @list($domain, $id_reg, $id_owner, $flag, $status,                          @list($domain, $id_reg, $id_owner, $status,
                                         $ns1, $ns2, $ns3, $ns4, $ico_owner, $dt_valid) = split(';', $line);                                          $ns1, $ns2, $ns3, $ns4, $dt_valid) = split(';', $line);
   
                         if (! preg_match('|^.+\....?.?$|', $domain)) {                          if (! preg_match('|^.+\....?.?$|', $domain)) {
                                 //echo 'skipping: ',$domain, "\n";                                  echo 'skipping: ',$domain, "\n";
                                 continue;                                  continue;
                         }                          }
   
Line 144  class SK_NIC
Line 189  class SK_NIC
                         $dt_valid = date('Y-m-d', $dt_valid);                          $dt_valid = date('Y-m-d', $dt_valid);
   
                         $query = sprintf('INSERT INTO sknic_domains_import'                          $query = sprintf('INSERT INTO sknic_domains_import'
                                         .' (domain,id_reg,id_owner,flag,status,ns1,ns2,ns3,ns4,ico_owner,dt_valid,dt_changed)'                                          .' (domain,status,id_reg,id_owner,ns1,ns2,ns3,ns4,dt_valid,dt_changed)'
                                         .' VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',                                          .' VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
                                         $this->_db->quote($domain), $this->_db->quote($id_reg), $this->_db->quote($id_owner),                                          $this->_db->quote($domain), $this->_db->quote($status),
                                         $this->_db->quote($flag), $this->_db->quote($status),                                          $this->_db->quote($id_reg), $this->_db->quote($id_owner),
                                         $this->_db->quote($ns1), $this->_db->quote($ns2),                                          $this->_db->quote($ns1), $this->_db->quote($ns2),
                                         $this->_db->quote($ns3), $this->_db->quote($ns4),                                          $this->_db->quote($ns3), $this->_db->quote($ns4),
                                         $this->_db->quote($ico_owner),  
                                         $this->_db->quote($dt_valid), $this->_db->quote($changed_date));                                          $this->_db->quote($dt_valid), $this->_db->quote($changed_date));
   
                         $result = $this->_db->query($query);                          $result = $this->_db->query($query);
Line 165  class SK_NIC
Line 209  class SK_NIC
                 $query = sprintf('load data local infile %s'                  $query = sprintf('load data local infile %s'
                                 .' into table sknic_domains_import'                                  .' into table sknic_domains_import'
                                 .' fields terminated by ";"'                                  .' fields terminated by ";"'
                                 .' ignore 11 lines'                                  .' (domain,id_reg,id_owner,status,ns1,ns2,ns3,ns4,@dt_valid)'
                                 .' (domain,id_reg,id_owner,flag,status,ns1,ns2,ns3,ns4,ico_owner,@dt_valid)'  
                                 .' SET dt_valid = STR_TO_DATE(@dt_valid, %s), dt_changed = %s',                                  .' SET dt_valid = STR_TO_DATE(@dt_valid, %s), dt_changed = %s',
                                 $this->_db->quote($filename),                                  $this->_db->quote($filename),
                                 $this->_db->quote($this->input_dt_format_sql),                                  $this->_db->quote($this->input_dt_format_sql),
                                 $this->_db->quote($changed_date));                                  $this->_db->quote($changed_date));
                 $result = $this->_db->query($query);                  $result = $this->_db->query($query);
                 DB::isError($result) && $this->error($result);                  DB::isError($result) && $this->error($result);
                   $query = 'DELETE FROM sknic_domains_import WHERE domain LIKE "-- %"';
                   $result = $this->_db->query($query);
                   DB::isError($result) && $this->error($result);
         } /* }}} */          } /* }}} */
   
         function _writeDomainHistory($rec, $deleted = 0) /* {{{ */          function _writeDomainHistory($rec, $deleted = 0) /* {{{ */
Line 306  class SK_NIC
Line 352  class SK_NIC
                 static $queries = array();                  static $queries = array();
                 if (count($queries) <= 0) {                  if (count($queries) <= 0) {
                         $queries[] = 'INSERT INTO sknic_domains_stats'                          $queries[] = 'INSERT INTO sknic_domains_stats'
                                 .' SELECT dt_changed, NULL, NULL, COUNT(*)'                                  .' SELECT dt_changed, "", "", COUNT(*)'
                                 .' FROM sknic_domains_import GROUP BY dt_changed';                                  .' FROM sknic_domains_import GROUP BY dt_changed';
                         $queries[] = 'INSERT INTO sknic_domains_stats'                          $queries[] = 'INSERT INTO sknic_domains_stats'
                                 .' SELECT dt_changed, "status", status, COUNT(*)'                                  .' SELECT dt_changed, "status", status, COUNT(*)'

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top