set_dns_record.pl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. use lib "$Bin/";
  10. use strict;
  11. use DBI;
  12. use Time::Local;
  13. use Net::Patricia;
  14. use NetAddr::IP;
  15. use Data::Dumper;
  16. use eyelib::config;
  17. use eyelib::main;
  18. use eyelib::mysql;
  19. use eyelib::net_utils;
  20. use File::Basename;
  21. use File::Path;
  22. my $h_name = $ARGV[0];
  23. my $ip = $ARGV[1];
  24. my $reverse = $ARGV[2] || '0';
  25. exit if (!$h_name and !$ip);
  26. my $ad_zone = get_option($dbh,33);
  27. my $ad_dns = get_option($dbh,3);
  28. my $subnets_dhcp = get_subnets_ref($dbh);
  29. my $enable_ad_dns_update = ($ad_zone and $ad_dns);
  30. my $subnet = GetSubNet($ip);
  31. log_debug("Subnet: $subnet");
  32. log_debug("DNS update flags - zone: $ad_zone dns: $ad_dns config: $update_hostname_from_dhcp subnet: $subnets_dhcp->{$subnet}->{dhcp_update_hostname}");
  33. #update dns block
  34. my $fqdn;
  35. if ($h_name) {
  36. $fqdn=lc($h_name);
  37. $fqdn=~s/_/-/g;
  38. if ($fqdn!~/$ad_zone$/i) {
  39. $fqdn=~s/\.$//;
  40. $fqdn=lc($fqdn.'.'.$ad_zone);
  41. }
  42. }
  43. db_log_info($dbh,"Manual create dns record $fqdn");
  44. update_dns_hostname($fqdn,$ip,$ad_zone,$ad_dns,$dbh);
  45. if ($reverse) {
  46. db_log_info($dbh,"Manual create dns ptr-record $fqdn => $ip");
  47. update_dns_ptr($fqdn,$ip,$ad_dns,$dbh);
  48. }
  49. exit;