forked from poppyred/1.6.x
/
exec.pdns.import.php
executable file
·88 lines (68 loc) · 2.56 KB
/
exec.pdns.import.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
include_once(dirname(__FILE__) . '/ressources/class.mysql.inc');
include_once(dirname(__FILE__) . '/ressources/class.ldap.inc');
include_once(dirname(__FILE__) . '/ressources/class.ccurl.inc');
include_once(dirname(__FILE__) . '/framework/class.unix.inc');
include_once(dirname(__FILE__).'/framework/frame.class.inc');
include_once(dirname(__FILE__) . '/ressources/class.pdns.inc');
$GLOBALS["SHOWKEYS"]=false;
if(preg_match("#schedule-id=([0-9]+)#",implode(" ",$argv),$re)){$GLOBALS["SCHEDULE_ID"]=$re[1];}
if(is_array($argv)){if(preg_match("#--verbose#",implode(" ",$argv))){$GLOBALS["VERBOSE"]=true; ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);}}
if(preg_match("#--showkeys#",implode(" ",$argv))){$GLOBALS["SHOWKEYS"]=true;}
if($argv[1]=="--import"){import($argv[2],$argv[3]);exit;}
function import($fileenc,$domain){
$domain=trim($domain);
if(preg_match("#--#", $domain)){$domain=null;}
$q=new mysql();
$q->BuildTables();
$filename=base64_decode($fileenc);
if(!is_file($filename)){
echo "$filename, no such file...\n";
return;
}
echo "$filename, Open file\n";
$f=file($filename);
$F=0;
$S=0;
while (list ($index, $line) = each ($f) ){
$line=trim($line);
$line=str_replace("\r", "", $line);$line=str_replace("\n", "", $line);$line=str_replace("\r\n", "", $line);
if($line==null){continue;}
if(substr($line, 0,1)=="#"){continue;}
$posDieze=strpos($line, "#");
if($posDieze>0){
if($posDieze<5){continue;}
}
$Obs=substr($line, $posDieze,strlen($line));
$line=str_replace($Obs, "", $line);
$Obs=trim(utf8_encode($Obs));
if(strlen($Obs)>2){$Obs=trim(str_replace("#", "", $Obs));}
if(!preg_match("#^([0-9\.]+)\s+(.+?)$#", $line,$re)){continue;}
$IP=trim($re[1]);
$domainname=$domain;
$hostname=trim(strtolower($re[2]));
if(strpos($hostname, " ")>0){
$tze=explode(" ",$hostname);
while (list ($a, $b) = each ($tze) ){if(trim($b)==null){continue;}$tzf[]=$b;}
if(strlen($tzf[0])>2){$hostname=$tzf[0];}
}
$netbiosname=$hostname;
if(strpos($hostname, ".")>0){
$tb=explode(".",$hostname);
$netbiosname=$tb[0];
unset($tb[0]);
$domainname=trim(@implode(".", $tb));
}
$host=$netbiosname.".".$domainname;
$pdns=new pdns($domainname);
if(!$pdns->EditIPName($netbiosname, $IP, "A",null,$Obs)){
echo "Item [{$re[1]}] - `{$host}` ($Obs) failed\n";
$F++;
}else{
echo "Item [{$re[1]}] - `{$host}` ($Obs) Success\n";
$S++;
}
}
echo "Success: $S item(s), Failed: $F item(s)\n";
}