pdo; $util = new App\Utils; $STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen`, `approved`, `initial`, `disabled` FROM hosts"); $hosts = $STH->fetchAll(PDO::FETCH_ASSOC); // for automatic approving $approffs = date ("Y-m-d H:i:s", strtotime ("-" . $options["approvedelay"] . " hour")); // approval offset $apprseen = date ("Y-m-d H:i:s", strtotime ("-" . $options["approveseen"] . " hour")); // approval maxseen offset $newregoffs = date ("Y-m-d H:i:s", strtotime ("-" . $options["newdays"] . " day")); // 7 $newseenlim = date ("Y-m-d H:i:s", strtotime ("-" . $options["delnewdays"] . " day")); // 3 $oldseenlim = date ("Y-m-d H:i:s", strtotime ("-" . $options["delolddays"] . " day")); // 30 $export_full = $export_live = $export_init = []; $export_addr_full = $export_addr_live = $export_addr_init = []; foreach ($hosts as $host) { /* Convert UFT-8 domains to Punycode */ $domain = $util->isASCII ($host["host"]) ? $host["host"] : idn_to_ascii ($host["host"]); array_push($export_full, $domain . "=" . $host["base64"]); array_push($export_addr_full, $domain . "," . $host["base32"]); if ( ($options["approval"] == false || $host["approved"] == 1) && ($host["disabled"] == 0 || ( ($host["add_date"] > $newregoffs && $host["last_seen"] > $newseenlim) || ($host["add_date"] < $newregoffs && $host["last_seen"] > $oldseenlim) ) ) ) { array_push($export_live, $domain . "=" . $host["base64"]); array_push($export_addr_live, $domain . "," . $host["base32"]); if ($host["initial"] == 1) { array_push($export_init, $domain . "=" . $host["base64"]); array_push($export_addr_init, $domain . "," . $host["base32"]); } if ($host["disabled"] == 1) { $pdo->exec ("UPDATE `hosts` SET `disabled` = 0 WHERE `host` = '" . $host["host"] . "'"); } } else if ( $host["approved"] == 0 && ( ($host["add_date"] < $approffs && $host["last_seen"] > $apprseen) // if host were registered more then X days ago and seen lesser than X hours ago ) ) { $pdo->exec ("UPDATE `hosts` SET `approved` = 1 WHERE `host` = '" . $host["host"] . "'"); array_push($export_live, $domain . "=" . $host["base64"]); array_push($export_addr_live, $domain . "," . $host["base32"]); } if ( $host["disabled"] == 0 && ($host["add_date"] > $newregoffs && $host["last_seen"] < $newseenlim) || ($host["add_date"] < $newregoffs && $host["last_seen"] < $oldseenlim) ) { $pdo->exec ("UPDATE `hosts` SET `disabled` = 1 WHERE `host` = '" . $host["host"] . "'"); } } $STH = null; $pdo = null; /* Sort records */ sort ($export_full); sort ($export_addr_full); // sort ($export_live); sort ($export_addr_live); // sort ($export_init); sort ($export_addr_init); /* Export all records */ $f = fopen (__DIR__ . "/public/export/hosts-all.txt", "w"); foreach ($export_full as $l) { $toWrite = print_r ($l, true); fwrite ($f, $toWrite . "\n"); } fclose ($f); $f = fopen (__DIR__ . "/public/export/addresses-all.csv", "w"); foreach ($export_addr_full as $l) { $toWrite = print_r ($l, true); fwrite ($f, $toWrite . "\n"); } fclose ($f); /* Export alive records */ $f = fopen (__DIR__ . "/public/export/hosts.txt", "w"); foreach ($export_live as $l) { $toWrite = print_r ($l, true); fwrite ($f, $toWrite . "\n"); } fclose ($f); $f = fopen (__DIR__ . "/public/export/addresses.csv", "w"); foreach ($export_addr_live as $l) { $toWrite = print_r ($l, true); fwrite ($f, $toWrite . "\n"); } fclose ($f); /* Export initial records */ $f = fopen (__DIR__ . "/public/export/hosts-basic.txt", "w"); foreach ($export_init as $l) { $toWrite = print_r ($l, true); fwrite ($f, $toWrite . "\n"); } fclose ($f); $f = fopen (__DIR__ . "/public/export/addresses-basic.csv", "w"); foreach ($export_addr_init as $l) { $toWrite = print_r ($l, true); fwrite ($f, $toWrite . "\n"); } fclose ($f);