set_dns_record.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) Roman Dmitiriev, rnd@rajven.ru
  4. #
  5. use utf8;
  6. use English;
  7. use base;
  8. use FindBin '$Bin';
  9. no if $] >= 5.018, warnings => "experimental::smartmatch";
  10. use lib "$Bin/";
  11. use strict;
  12. use DBI;
  13. use Time::Local;
  14. use Net::Patricia;
  15. use NetAddr::IP;
  16. use Data::Dumper;
  17. use eyelib::config;
  18. use eyelib::main;
  19. use eyelib::mysql;
  20. use eyelib::net_utils;
  21. use File::Basename;
  22. use File::Path;
  23. my $h_name = $ARGV[0];
  24. my $ip = $ARGV[1];
  25. my $reverse = $ARGV[2] || '0';
  26. exit if (!$h_name and !$ip);
  27. my $ad_zone = get_option($dbh,33);
  28. my $ad_dns = get_option($dbh,3);
  29. my $subnets_dhcp = get_subnets_ref($dbh);
  30. my $enable_ad_dns_update = ($ad_zone and $ad_dns);
  31. my $subnet = GetSubNet($ip);
  32. log_debug("Subnet: $subnet");
  33. log_debug("DNS update flags - zone: $ad_zone dns: $ad_dns config: $update_hostname_from_dhcp subnet: $subnets_dhcp->{$subnet}->{dhcp_update_hostname}");
  34. #update dns block
  35. my $fqdn;
  36. if ($h_name) {
  37. $fqdn=lc($h_name);
  38. $fqdn=~s/_/-/g;
  39. if ($fqdn!~/$ad_zone$/i) {
  40. $fqdn=~s/\.$//;
  41. $fqdn=lc($fqdn.'.'.$ad_zone);
  42. }
  43. }
  44. db_log_info($dbh,"Manual create dns record $fqdn");
  45. update_ad_hostname($fqdn,$ip,$ad_zone,$ad_dns,$dbh);
  46. if ($reverse) {
  47. db_log_info($dbh,"Manual create dns ptr-record $fqdn => $ip");
  48. update_ad_ptr($fqdn,$ip,$ad_dns,$dbh);
  49. }
  50. exit;