9,7 → 9,7 |
define('CONF_FILE', '/usr/local/etc/alcasar.conf'); |
define('ETHERS_FILE', '/usr/local/etc/alcasar-ethers'); |
define('ETHERS_INFO_FILE', '/usr/local/etc/alcasar-ethers-info'); |
define('DNS_LOCAL_FILE', '/usr/local/etc/alcasar-dns-name'); |
define('DNS_LOCAL_FILE', '/etc/hosts'); |
define('LETS_ENCRYPT_FILE', '/usr/local/etc/alcasar-letsencrypt'); |
$conf_files = [CONF_FILE, ETHERS_FILE, ETHERS_INFO_FILE, DNS_LOCAL_FILE, LETS_ENCRYPT_FILE]; |
|
223,29 → 223,23 |
$tab = file(DNS_LOCAL_FILE); |
if ($tab) { // the file isn't empty |
$insert = true; |
foreach ($tab as $line) { // verify that host or IP address doesn't exist |
if (preg_match('/^address/', $line)) { |
$field = explode('/', $line); |
$host_name = trim($field[1]); |
$ip_addr = trim($field[2]); |
if (strcasecmp($add_host, $host_name) === 0) { |
$insert = false; |
break; |
} |
if (strcmp($add_ip, $ip_addr) === 0) { |
$insert = false; |
break; |
} |
foreach ($tab as $line) { // verify that host or IP address doesn't already exist |
$field = explode('\t', $line); |
$host_name = trim($field[1]); |
$ip_addr = trim($field[2]); |
if (strcasecmp($add_host, $host_name) === 0) { |
$insert = false; |
break; |
} |
} |
if (strcmp($add_ip, $ip_addr) === 0) { |
$insert = false; |
break; |
} |
} |
if ($insert) { |
$line1 = 'address=/'.$add_host.'/'.$add_ip."\n"; |
$explode_ip = explode('.', $add_ip); |
$reverse_ip = implode('.', array_reverse($explode_ip)); |
$line2 = 'ptr-record='.$reverse_ip.'.in-addr.arpa,'.$add_host."\n"; |
$line1 = $add_ip.'\t'.$add_host."\n"; |
$pointeur=fopen(DNS_LOCAL_FILE, 'a'); |
fwrite($pointeur, $line1); |
fwrite($pointeur, $line2); |
fclose($pointeur); |
exec('sudo /usr/bin/systemctl restart dnsmasq'); |
exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist'); |