forked from TheBlueMatt/dnsseed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fill-dns.php
executable file
·40 lines (38 loc) · 1017 Bytes
/
fill-dns.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/php
<?php
require("config.php");
require("global.php");
$file = fopen($CONFIG['BIND_RECORD_FILE'], "r+");
$headerfile = fopen($CONFIG['BIND_HEADER_FILE'], "r");
if(flock($file, LOCK_EX)) {
$i = 0;
$serial = 0;
while (($line = fgets($file)) !== false && $i < 11) {
if (strpos($line, "; Serial") !== false) {
sscanf($line, "\t\t\t%i\t\t; Serial\n", $serial);
$serial++;
break;
}
$i++;
}
fseek($file, 0);
ftruncate($file, 0);
while (($line = fgets($headerfile)) !== false) {
if (strpos($line, "; Serial") !== false)
fwrite($file, "\t\t\t".$serial."\t\t; Serial\n");
else
fwrite($file, $line);
}
fclose($headerfile);
connect_to_db();
$result = get_list_of_nodes_for_dns();
$result = init_results($result);
$row = get_assoc_result_row($result);
while (!empty($row)) {
fwrite($file, $CONFIG['DOMAIN_NAME'] . ".\t".$CONFIG['RECORD_TTL']."\tIN\tA\t" . long2ip($row['ipv4']) . "\n");
$row = get_assoc_result_row($result);
}
flock($file, LOCK_UN);
fclose($file);
}
?>