diff --git a/release/iana-data.db b/release/iana-data.db new file mode 100644 index 0000000..b0e13c1 Binary files /dev/null and b/release/iana-data.db differ diff --git a/src/main.php b/src/main.php index 5fe65c2..6a3220a 100644 --- a/src/main.php +++ b/src/main.php @@ -15,33 +15,6 @@ writeFile($release_path . 'tld-list.txt', implode(PHP_EOL, $tlds) . PHP_EOL); // Analyse all TLDs from html files $data = getTldsInfo($tlds, $html_path . 'tlds/'); -// $str = $data['.to']['admin_contact']['org']; -// echo preg_replace('/[\s]+/', ' ', $str); -// echo $str; -// exit; - -// var_dump($data['.com']); -// exit; -foreach ($data as $index => $row) { - // if ($row['admin_contact']['voice'] === false) { - // echo $index . ' -> ' . implode(' | ', $row['manager']['addr']) . PHP_EOL; - // if (count($row['nameserver']) === 0) { continue; } - // echo $row['website'] . PHP_EOL; - // echo $row['whois'] . PHP_EOL; - // echo $row['last_updated'] . PHP_EOL; - // echo $row['regist_date'] . PHP_EOL; - // echo $index . ' -> ' . $row['tech_contact']['name'] . PHP_EOL; - // echo $index . ' -> ' . $row['tech_contact']['org'] . PHP_EOL; - // echo $index . ' -> ' . implode(' | ', $row['tech_contact']['addr']) . PHP_EOL; - // echo $index . ' -> ' . $row['tech_contact']['email'] . PHP_EOL; - // echo $index . ' -> ' . $row['tech_contact']['voice'] . PHP_EOL; - // echo $index . ' -> ' . $row['tech_contact']['fax'] . PHP_EOL; - - // } -} - -// return; - // Output data by json format writeFile($release_path . 'all-data.json', json_encode($data)); @@ -52,7 +25,42 @@ foreach ($data as $index => $row) { $whoisStr .= $index . ',' . $row['whois'] . PHP_EOL; } } -writeFile('../release/whois-server.csv', $whoisStr); +writeFile($release_path . 'whois-server.csv', $whoisStr); + +// Output into sqlite3 database +$init_sql =<<exec($init_sql); + +$insert_sql = 'INSERT INTO data '; +$insert_sql .= '(tld,type,manager,admin_contact,tech_contact,nameserver,website,whois,last_updated,regist_date) '; +$insert_sql .= 'VALUES ('; +foreach ($data as $tld => $info) { + $sql = $insert_sql . '\'' . $tld . '\','; + foreach ($info as $index => $field) { + if ($index === 'manager' || $index === 'admin_contact' || $index === 'tech_contact' || $index === 'nameserver') { + $field = base64_encode(json_encode($field)); + } + $sql .= '\'' . $field . '\''; + if ($index !== 'regist_date') { + $sql .= ','; + } + } + $db->exec($sql . ');'); +} function writeFile($filename, $data) { $file = fopen($filename, 'w'); @@ -60,4 +68,13 @@ function writeFile($filename, $data) { fclose($file); } +class tldDB extends SQLite3 { + public function __construct($filename) { + $this->open($filename); + } + public function __destruct() { + $this->close(); + } +} + ?>