<?php
require 'sql.php';
unlink('/root/novo_dns/tsdns_settings.ini');
$select_tsdns = mysql_query("Select * from tsdns where enabled=1 limit 1000");
	file_put_contents ('/root/novo_dns/tsdns_settings.ini' ,'#'.mysql_num_rows($select_tsdns)."\r\n" ,FILE_APPEND );
while($fetch_tsdns = mysql_fetch_assoc($select_tsdns)){
	$ip = $fetch_tsdns['ipaddress'];
	$domain = $fetch_tsdns['domain_id'];
	$select_ips = mysql_query("Select inet_ntoa(ipaddress) as ip from ips where id='$ip'");
	$select_domains = mysql_query("Select * from domains where id='$domain'");
	$fetch_ips = mysql_fetch_assoc($select_ips);
	$fetch_domains = mysql_fetch_assoc($select_domains);
	$data = $fetch_tsdns['hostname'].'.'.$fetch_domains['dominio'].'='.$fetch_ips['ip'].':'.$fetch_tsdns['port'];
	file_put_contents ( '/root/novo_dns/tsdns_settings.ini' , $data."\r\n" ,FILE_APPEND );
}
$select_tsdns = mysql_query("Select * from tsdns where enabled=0 limit 1000");
file_put_contents ('/root/novo_dns/tsdns_settings.ini' ,'#'.mysql_num_rows($select_tsdns)."\r\n" ,FILE_APPEND );
echo mysql_num_rows($select_tsdns);
while($fetch_tsdns = mysql_fetch_assoc($select_tsdns)){
	$ip = $fetch_tsdns['ipaddress'];
	$domain = $fetch_tsdns['domain_id'];
	$select_domains = mysql_query("Select * from domains where id='$domain'");
	$fetch_domains = mysql_fetch_assoc($select_domains);
	$data = $fetch_tsdns['hostname'].'.'.$fetch_domains['dominio'].'=104.207.141.148:3000';#Redirecionamos tudo para o TS suspendo patrocinado pelo joao
	file_put_contents ('/root/novo_dns/tsdns_settings.ini' , $data."\r\n" ,FILE_APPEND );
}
file_put_contents ('/root/novo_dns/tsdns_settings.ini' , "*=167.114.71.230:9989\r\n" ,FILE_APPEND );
shell_exec("/root/novo_dns/tsdnsserver_linux_amd64 --update")
?>
