/
gensql.php
executable file
·55 lines (44 loc) · 1.14 KB
/
gensql.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/php
<?php
if(!isset($_SERVER['argv'][1])) {
echo "Specify domain ID plx ;-)\n";
exit(1);
} else {
$DOMAINID = $_SERVER['argv'][1];
}
$DEBUG = true;
function dout($text) {
global $DEBUG;
if($DEBUG) echo $text;
}
$INPUTFILE = 'http://www.ea3hkb.com/wp-content/uploads/YSFHosts.txt';
echo "Loading YSF servers...";
$LINES = file($INPUTFILE);
echo "done.\n";
$SERVERS = array();
//var_dump($LINES);
foreach($LINES as $i=>$line) {
//var_dump($line);
if(preg_match('/^(\xefbbbf)?#/', $line)) {
dout("INPUT: Comment line index[$i]\n");
continue;
}
$line = trim($line);
if(empty($line)) {
dout("INPUT: Empty line index[$i]\n");
continue;
}
$hits = preg_split('/\s+/', $line);
if(is_numeric($hits[1])) {
$SERVERS[] = $hits;
}
}
printf("DELETE FROM rr where zone = %d and name = '_ysf._udp' and type = 'SRV';\n", $DOMAINID);
foreach($SERVERS as $server) {
printf(
"INSERT INTO rr (`zone`, `name`, `type`, `data`, `ttl`) VALUES (%d, '_ysf._udp', 'SRV', '10 0 %d %s.', 300);\n",
$DOMAINID,
$server[1],
$server[0]
);
}