| version 1.12, 2015/08/27 06:16:20 |
version 1.13, 2017/09/16 09:36:22 |
|
|
| * |
* |
| * 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'; |
| |
|
|
|
| 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; |
| |
|
|
|
| && $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(); |
|
|
| } |
} |
| $this->_cleanImport(); |
$this->_cleanImport(); |
| $this->_writeImportWithLoadData($filename, $changed_date); |
$this->_writeImportWithLoadData($filename, $changed_date); |
| |
$this->_importedNameserversReorder(); |
| return true; |
return true; |
| } /* }}} */ |
} /* }}} */ |
| |
|
|
|
| |
|
| 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) { |
|
|
| 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; |
| } |
} |
| |
|
|
|
| $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); |
|
|
| $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) /* {{{ */ |
|
|
| 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(*)' |