Changeset 236
- Timestamp:
- Jun 22, 2018, 7:19:17 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ddt/ddt
r235 r236 79 79 80 80 my $xdg_config_home = $ENV{'XDG_CONFIG_HOME'} || "$ENV{'HOME'}/.config"; 81 $CONFIG = YAML::Syck::LoadFile("$xdg_config_home/ddt/config.yml") if -e "$xdg_config_home/ddt/config.yml";81 $CONFIG = config_load("$xdg_config_home/ddt/config.yml") if -e "$xdg_config_home/ddt/config.yml"; 82 82 83 83 my $COMPUTER_BASENAME = $CONFIG->{'database'}{'basename'} || 'ddt'; … … 101 101 touch $COMPUTER_YAML if not -e $COMPUTER_YAML; 102 102 103 my $COMPUTER_DB = YAML::Syck::LoadFile($COMPUTER_YAML);103 my $COMPUTER_DB = ipamdb_load($COMPUTER_YAML); 104 104 105 105 if (defined $cmd_db{$command}) { … … 115 115 116 116 #-------------------------------------------------------------------------------- 117 # LOAD SAVE section 118 #-------------------------------------------------------------------------------- 119 120 sub config_load { 121 my $config_file = shift; 122 123 my $configdb = YAML::Syck::LoadFile($config_file); 124 125 return $configdb; 126 } 127 128 #--------------------------------------------------------------- 129 # Load computer database 130 131 sub ipamdb_load { 132 my $database_file = shift; 133 134 my $computerdb = YAML::Syck::LoadFile($database_file); 135 136 return $computerdb; 137 } 138 139 #--------------------------------------------------------------- 140 # Save computer database 141 142 sub ipamdb_save { 143 my ($database_file, $computerdb) = @_; 144 145 my $dirdb = $database_file; 146 $dirdb =~ s{ / [^/]* $}{}xms; 147 mkdir "$dirdb", 0755 unless -d "$dirdb"; 148 YAML::Syck::DumpFile($database_file, $computerdb); 149 150 return $computerdb; 151 } 152 153 #-------------------------------------------------------------------------------- 117 154 # CONTROL section 118 155 #-------------------------------------------------------------------------------- … … 144 181 145 182 sub control_exist_hostname { 146 my ($COMPUTER_DB, $domain , $hostname) = @_;147 148 if ($COMPUTER_DB->{$domain } eq '') {183 my ($COMPUTER_DB, $domainset, $hostname) = @_; 184 185 if ($COMPUTER_DB->{$domainset} eq '') { 149 186 return 1; 150 187 } 151 188 152 my @domain db = @{$COMPUTER_DB->{$domain}};153 154 for my $value (@domain db) {189 my @domainsetdb = @{$COMPUTER_DB->{$domainset}}; 190 191 for my $value (@domainsetdb) { 155 192 for my $id (keys %{$value}) { 156 193 if ($value->{$id}->{'hostname'} eq $hostname) { … … 171 208 my ($COMPUTER_DB, $mac) = @_; 172 209 173 for my $domain _name(keys %{$COMPUTER_DB}) {174 next if $domain _nameeq 'dset';175 next if $domain _nameeq 'pool';176 next if $domain _nameeq 'pxe';177 next if $domain _nameeq 'tag';178 179 my @domain db = @{$COMPUTER_DB->{$domain_name}};180 for my $value (@domain db) {210 for my $domainset_current (keys %{$COMPUTER_DB}) { 211 next if $domainset_current eq 'dset'; 212 next if $domainset_current eq 'pool'; 213 next if $domainset_current eq 'pxe'; 214 next if $domainset_current eq 'tag'; 215 216 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 217 for my $value (@domainsetdb) { 181 218 for my $id (keys %{$value}) { 182 219 if ($id eq $mac) { … … 198 235 my ($COMPUTER_DB, $ip) = @_; 199 236 200 for my $domain _name(keys %{$COMPUTER_DB}) {201 next if $domain _nameeq 'dset';202 next if $domain _nameeq 'pool';203 next if $domain _nameeq 'pxe';204 next if $domain _nameeq 'tag';205 206 for my $value (@{$COMPUTER_DB->{$domain _name}}) {237 for my $domainset_current (keys %{$COMPUTER_DB}) { 238 next if $domainset_current eq 'dset'; 239 next if $domainset_current eq 'pool'; 240 next if $domainset_current eq 'pxe'; 241 next if $domainset_current eq 'tag'; 242 243 for my $value (@{$COMPUTER_DB->{$domainset_current}}) { 207 244 for my $id (keys %{$value}) { 208 245 #print "Erreur: cette adresse IP $ip existe déjà\n"; … … 321 358 322 359 sub get_mac_from_hostname { 323 my ($domain , $hostname, $mac) = @_;360 my ($domainset, $hostname, $mac) = @_; 324 361 325 362 return $mac if $mac ne ''; … … 327 364 328 365 LOOP_ON_COMPUTER: 329 for my $computer (@{$COMPUTER_DB->{$domain }}) {366 for my $computer (@{$COMPUTER_DB->{$domainset}}) { 330 367 my ($mac_address, $attribute) = %{$computer}; 331 368 … … 339 376 340 377 sub get_mac_from_ip { 341 my ($domain , $ip, $mac) = @_;378 my ($domainset, $ip, $mac) = @_; 342 379 343 380 return $mac if $mac ne ''; … … 345 382 346 383 LOOP_ON_COMPUTER: 347 for my $computer (@{$COMPUTER_DB->{$domain }}) {384 for my $computer (@{$COMPUTER_DB->{$domainset}}) { 348 385 my ($mac_address, $attribute) = %{$computer}; 349 386 … … 358 395 359 396 sub get_computer_from_mac { 360 my ($domain , $mac) = @_;397 my ($domainset, $mac) = @_; 361 398 362 399 LOOP_ON_COMPUTER: 363 for my $computer (@{$COMPUTER_DB->{$domain }}) {400 for my $computer (@{$COMPUTER_DB->{$domainset}}) { 364 401 my ($mac_address, $attribute) = %{$computer}; 365 402 … … 385 422 control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 386 423 387 my @domain db = @{$COMPUTER_DB->{$domainset}};424 my @domainsetdb = @{$COMPUTER_DB->{$domainset}}; 388 425 my $cpt=0; 389 for my $value (@domain db) {426 for my $value (@domainsetdb) { 390 427 for my $id (keys %{$value}) { 391 428 … … 395 432 $COMPUTER_DB->{$domainset}[$cpt]{$id}{'alias'} = $alias; 396 433 $COMPUTER_DB->{$domainset}[$cpt]{$id}{'modify_time'} = time; 397 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);434 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 398 435 print "Update attribute alias [OK]\n"; 399 436 exit; … … 414 451 $comment = normalize_comment($comment); 415 452 control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 416 control_syntax_mac_address($mac) or exit;417 control_exist_mac($COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n";418 control_syntax_ip($ip) or exit;419 control_exist_ip($COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n";420 control_syntax_comment($comment) or exit;453 control_syntax_mac_address($mac) or exit; 454 control_exist_mac($COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n"; 455 control_syntax_ip($ip) or exit; 456 control_exist_ip($COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n"; 457 control_syntax_comment($comment) or exit; 421 458 my $timestamp = time; 422 459 push @{$COMPUTER_DB->{$domainset}}, { $mac => { … … 432 469 print "Add the computer: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset\n"; 433 470 434 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);471 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 435 472 } 436 473 … … 447 484 $mac = normalize_mac_address($mac); 448 485 $comment = normalize_comment($comment); 449 control_exist_domainset($COMPUTER_DB, $domainset) or exit;486 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 450 487 control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 451 control_syntax_mac_address($mac) or exit;452 control_exist_mac($COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n";453 control_syntax_ip($ip) or exit;454 control_exist_ip($COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n";455 control_syntax_comment($comment) or exit;488 control_syntax_mac_address($mac) or exit; 489 control_exist_mac($COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n"; 490 control_syntax_ip($ip) or exit; 491 control_exist_ip($COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n"; 492 control_syntax_comment($comment) or exit; 456 493 457 494 push @{$COMPUTER_DB->{$domainset}}, { $mac => { … … 467 504 print "Add the computer: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset\n"; 468 505 469 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);506 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 470 507 } 471 508 … … 479 516 $mac = normalize_mac_address($mac); 480 517 $comment = normalize_comment($comment); 481 control_exist_domainset($COMPUTER_DB, $domainset) 518 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 482 519 control_syntax_mac_address($mac) or exit; 483 control_exist_mac($COMPUTER_DB, $mac) 484 control_exist_pool($COMPUTER_DB, $pool) 520 control_exist_mac($COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n"; 521 control_exist_pool($COMPUTER_DB, $pool) or die "Error: The pool doesn't exists: $pool\n"; 485 522 control_syntax_comment($comment) or exit; 486 523 push @{$COMPUTER_DB->{$domainset}}, { $mac => { … … 495 532 print "Add the computer in pool MAC: $mac, Domain Set: $domainset, Pool: $pool\n"; 496 533 497 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);534 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 498 535 } 499 536 … … 628 665 my $timestamp = time; 629 666 630 control_exist_domainset($COMPUTER_DB, $domainset) 631 control_exist_hostname($COMPUTER_DB, $domainset, $hostname) 667 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 668 control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 632 669 control_syntax_ip($ip) or exit; 633 control_exist_ip($COMPUTER_DB, $ip) 670 control_exist_ip($COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n"; 634 671 control_syntax_comment($comment) or exit; 635 672 … … 649 686 print "Add the virtual computer: $hostname, IP: $ip, Domain Set: $domainset\n"; 650 687 651 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);688 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 652 689 } 653 690 … … 667 704 668 705 $mac = normalize_mac_address($mac); 669 control_exist_domainset($COMPUTER_DB, $domainset) 706 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 670 707 control_syntax_mac_address($mac) or exit; 671 control_exist_mac($COMPUTER_DB, $mac) 708 control_exist_mac($COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n"; 672 709 if ($ip ne '') { 673 710 control_syntax_ip($ip) or exit; … … 676 713 exit; 677 714 } 678 my @domain db = @{$COMPUTER_DB->{$domainset}};715 my @domainsetdb = @{$COMPUTER_DB->{$domainset}}; 679 716 my $cpt = 0; 680 for my $value (@domain db) {717 for my $value (@domainsetdb) { 681 718 for my $id (keys %{$value}) { 682 719 if ($value->{$id}->{'ip'} eq $ip) { … … 684 721 $host->{'modify_time'} = time; 685 722 $COMPUTER_DB->{$domainset}->[$cpt] = { $mac => $host }; 686 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);723 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 687 724 print "Update [OK]\n"; 688 725 print "Hostname: $host->{'hostname'}\n"; … … 701 738 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 702 739 } 703 my @domain db = @{$COMPUTER_DB->{$domainset}};740 my @domainsetdb = @{$COMPUTER_DB->{$domainset}}; 704 741 my $cpt = 0; 705 for my $value (@domain db) {742 for my $value (@domainsetdb) { 706 743 for my $id (keys %{$value}) { 707 744 if ($value->{$id}->{'hostname'} eq $hostname) { … … 709 746 $host->{'modify_time'} = time; 710 747 $COMPUTER_DB->{$domainset}->[$cpt] = { $mac => $host }; 711 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);748 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 712 749 print "Update [OK]\n"; 713 750 print "Hostname: $host->{'hostname'}\n"; … … 736 773 control_syntax_ip($ip) or exit; 737 774 control_exist_ip($COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n"; 738 my @domain db = @{$COMPUTER_DB->{$domainset}};775 my @domainsetdb = @{$COMPUTER_DB->{$domainset}}; 739 776 my $cpt = 0; 740 for my $value (@domain db) {777 for my $value (@domainsetdb) { 741 778 for my $id (keys %{$value}) { 742 779 if (($value->{$id}->{'hostname'} eq $hostname) … … 748 785 $COMPUTER_DB->{$domainset}[$cpt]{$id}{'ip'} = $ip; 749 786 $COMPUTER_DB->{$domainset}[$cpt]{$id}{'modify_time'} = time; 750 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);787 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 751 788 print "Update [OK]\n"; 752 789 print "Hostname: $hostname\n"; … … 783 820 control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 784 821 785 my @domain db = @{$COMPUTER_DB->{$domainset}};822 my @domainsetdb = @{$COMPUTER_DB->{$domainset}}; 786 823 my $cpt = 0; 787 for my $value (@domain db) {824 for my $value (@domainsetdb) { 788 825 for my $id (keys %{$value}) { 789 826 if ($value->{$id}->{'ip'} eq $ip) { 790 827 $COMPUTER_DB->{$domainset}[$cpt]{$id}{'hostname'} = $hostname; 791 828 $COMPUTER_DB->{$domainset}[$cpt]{$id}{'modify_time'} = time; 792 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);829 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 793 830 print "Update [OK]\n"; 794 831 print "Hostname: $hostname\n"; … … 902 939 control_syntax_comment($comment) or exit; 903 940 904 my @domain db = @{$COMPUTER_DB->{$domainset}};941 my @domainsetdb = @{$COMPUTER_DB->{$domainset}}; 905 942 my $cpt = 0; 906 for my $value (@domain db) {943 for my $value (@domainsetdb) { 907 944 for my $id (keys %{$value}) { 908 945 if ($id eq $mac) { … … 911 948 $host->{'modify_time'} = time; 912 949 913 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);950 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 914 951 exit; 915 952 } … … 947 984 948 985 LOOP_ON_DOMAINSET: 949 for my $domain _name(keys %{$COMPUTER_DB}) {950 next if $domain _nameeq 'dset';951 next if $domain _nameeq 'pool';952 next if $domain _nameeq 'pxe';953 next if $domain _nameeq 'tag';954 955 my @domain db = @{$COMPUTER_DB->{$domain_name}};986 for my $domainset_current (keys %{$COMPUTER_DB}) { 987 next if $domainset_current eq 'dset'; 988 next if $domainset_current eq 'pool'; 989 next if $domainset_current eq 'pxe'; 990 next if $domainset_current eq 'tag'; 991 992 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 956 993 my $cpt_mac = 0; 957 for my $value (@domain db) {994 for my $value (@domainsetdb) { 958 995 for my $id (keys %{$value}) { 959 996 if ($id eq $mac) { 960 my $host = $COMPUTER_DB->{$domain _name}[$cpt_mac]{$mac};997 my $host = $COMPUTER_DB->{$domainset_current}[$cpt_mac]{$mac}; 961 998 next LOOP_ON_DOMAINSET if $host->{'ip'} ne $ip; 962 999 963 1000 $host->{'modify_time'} = time; 964 splice(@{$COMPUTER_DB->{$domain _name}}, $cpt_mac => 1);1001 splice(@{$COMPUTER_DB->{$domainset_current}}, $cpt_mac => 1); 965 1002 push @{$COMPUTER_DB->{$domainset}}, { $mac => $host }; 966 1003 967 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1004 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 968 1005 exit; 969 1006 } … … 1029 1066 1030 1067 delete $attribute->{'tag'} if $tags eq 'universal'; 1031 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1068 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1032 1069 exit; 1033 1070 } … … 1054 1091 } 1055 1092 1056 for my $domain _name(keys %{$COMPUTER_DB}) {1057 next if $domain _nameeq 'dset';1058 next if $domain _nameeq 'pool';1059 next if $domain _nameeq 'pxe';1060 next if $domain _nameeq 'tag';1061 1062 my @domain db = @{$COMPUTER_DB->{$domain_name}};1093 for my $domainset_current (keys %{$COMPUTER_DB}) { 1094 next if $domainset_current eq 'dset'; 1095 next if $domainset_current eq 'pool'; 1096 next if $domainset_current eq 'pxe'; 1097 next if $domainset_current eq 'tag'; 1098 1099 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 1063 1100 my $cpt_mac = 0; 1064 for my $value (@domain db) {1101 for my $value (@domainsetdb) { 1065 1102 for my $id (keys %{$value}) { 1066 1103 1067 1104 if ($value->{$id}->{'ip'} eq $ip) { 1068 1105 my $timestamp = time; 1069 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1070 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'enabled'} = 'no';1071 print "L'adresse IP: $ip a été désactivée. Valeur du champs enabled: [".$COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'enabled'}."]\n";1072 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1106 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1107 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no'; 1108 print "L'adresse IP: $ip a été désactivée. Valeur du champs enabled: [".$COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1109 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1073 1110 exit; 1074 1111 } … … 1092 1129 $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'no'; 1093 1130 print "La machine $hostname (domaine: $domainset) a été désactivé du DHCP. Valeur du champs enabled: [".$COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1094 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1131 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1095 1132 exit; 1096 1133 } … … 1119 1156 } 1120 1157 1121 for my $domain _name(keys %{$COMPUTER_DB}) {1122 next if $domain _nameeq 'dset';1123 next if $domain _nameeq 'pool';1124 next if $domain _nameeq 'pxe';1125 next if $domain _nameeq 'tag';1126 1127 my @domain db = @{$COMPUTER_DB->{$domain_name}};1158 for my $domainset_current (keys %{$COMPUTER_DB}) { 1159 next if $domainset_current eq 'dset'; 1160 next if $domainset_current eq 'pool'; 1161 next if $domainset_current eq 'pxe'; 1162 next if $domainset_current eq 'tag'; 1163 1164 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 1128 1165 1129 1166 $cpt_mac=0; 1130 for my $value (@domain db) {1167 for my $value (@domainsetdb) { 1131 1168 for my $id (keys %{$value}) { 1132 1169 if ($id eq $mac) { 1133 1170 if ($value->{$id}->{'ip'} eq $pool) { 1134 #splice(@{$COMPUTER_DB->($domain _name)} , $cpt_mac => 1);1171 #splice(@{$COMPUTER_DB->($domainset_current)} , $cpt_mac => 1); 1135 1172 my $timestamp = time; 1136 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1137 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'enabled'} = 'no';1138 print $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'enabled'}."\n";1139 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1173 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1174 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no'; 1175 print $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."\n"; 1176 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1140 1177 print "Désactivation de la machine $mac du pool $pool [OK]\n"; 1141 1178 exit; … … 1168 1205 } 1169 1206 1170 for my $domain _name(keys %{$COMPUTER_DB}) {1171 next if $domain _nameeq 'dset';1172 next if $domain _nameeq 'pool';1173 next if $domain _nameeq 'pxe';1174 next if $domain _nameeq 'tag';1175 1176 my @domain db = @{$COMPUTER_DB->{$domain_name}};1207 for my $domainset_current (keys %{$COMPUTER_DB}) { 1208 next if $domainset_current eq 'dset'; 1209 next if $domainset_current eq 'pool'; 1210 next if $domainset_current eq 'pxe'; 1211 next if $domainset_current eq 'tag'; 1212 1213 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 1177 1214 my $cpt_mac=0; 1178 for my $value (@domain db) {1215 for my $value (@domainsetdb) { 1179 1216 for my $id (keys %{$value}) { 1180 1217 if ($value->{$id}->{'ip'} eq $ip) { 1181 1218 my $timestamp = time; 1182 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1183 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'enabled'} = 'yes';1184 print "L'adresse IP: $ip a été réactivée. Valeur du champs enabled: [".$COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'enabled'}."]\n";1185 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1219 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1220 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes'; 1221 print "L'adresse IP: $ip a été réactivée. Valeur du champs enabled: [".$COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1222 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1186 1223 exit; 1187 1224 } … … 1204 1241 $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'yes'; 1205 1242 print "La machine $hostname (domaine: $domainset) a été réactivée du DHCP. Valeur du champs enabled: [".$COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1206 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1243 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1207 1244 exit; 1208 1245 } … … 1231 1268 } 1232 1269 1233 for my $domain _name(keys %{$COMPUTER_DB}) {1234 next if $domain _nameeq 'dset';1235 next if $domain _nameeq 'pool';1236 next if $domain _nameeq 'pxe';1237 next if $domain _nameeq 'tag';1238 1239 my @domain db = @{$COMPUTER_DB->{$domain_name}};1270 for my $domainset_current (keys %{$COMPUTER_DB}) { 1271 next if $domainset_current eq 'dset'; 1272 next if $domainset_current eq 'pool'; 1273 next if $domainset_current eq 'pxe'; 1274 next if $domainset_current eq 'tag'; 1275 1276 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 1240 1277 1241 1278 $cpt_mac=0; 1242 for my $value (@domain db) {1279 for my $value (@domainsetdb) { 1243 1280 for my $id (keys %{$value}) { 1244 1281 if ($id eq $mac) { 1245 1282 if ($value->{$id}->{'ip'} eq $pool) { 1246 #splice(@{$COMPUTER_DB->($domain _name)} , $cpt_mac => 1);1283 #splice(@{$COMPUTER_DB->($domainset_current)} , $cpt_mac => 1); 1247 1284 my $timestamp = time; 1248 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1249 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'enabled'} = 'yes';1250 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1285 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1286 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes'; 1287 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1251 1288 print "Réactivation de la machine $mac du pool $pool [OK]\n"; 1252 1289 exit; … … 1381 1418 splice(@{$COMPUTER_DB->{$domainset}}, $cpt_mac => 1); 1382 1419 print "La machine $ip a été supprimer du domaine $domainset\n"; 1383 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1420 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1384 1421 exit; 1385 1422 } … … 1400 1437 splice(@{$COMPUTER_DB->{$domainset}}, $cpt_mac => 1); 1401 1438 print "La machine $hostname a été supprimer du domaine $domainset\n"; 1402 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1439 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1403 1440 exit; 1404 1441 } … … 1429 1466 } 1430 1467 1431 for my $domain _name(keys %{$COMPUTER_DB}) {1432 next if $domain _nameeq 'dset';1433 next if $domain _nameeq 'pool';1434 next if $domain _nameeq 'pxe';1435 next if $domain _nameeq 'tag';1436 1437 my @domain db = @{$COMPUTER_DB->{$domain_name}};1468 for my $domainset_current (keys %{$COMPUTER_DB}) { 1469 next if $domainset_current eq 'dset'; 1470 next if $domainset_current eq 'pool'; 1471 next if $domainset_current eq 'pxe'; 1472 next if $domainset_current eq 'tag'; 1473 1474 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 1438 1475 1439 1476 $cpt_mac=0; 1440 for my $value (@domain db) {1477 for my $value (@domainsetdb) { 1441 1478 for my $id (keys %{$value}) { 1442 1479 1443 1480 if ($id eq $mac) { 1444 1481 if ($value->{$id}->{'ip'} eq $pool) { 1445 #splice(@{$COMPUTER_DB->($domain _name)} , $cpt_mac => 1);1446 splice(@{$COMPUTER_DB->{$domain _name}}, $cpt_mac => 1);1447 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1482 #splice(@{$COMPUTER_DB->($domainset_current)} , $cpt_mac => 1); 1483 splice(@{$COMPUTER_DB->{$domainset_current}}, $cpt_mac => 1); 1484 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1448 1485 print "Suppression de la machine $mac du pool $pool [OK]\n"; 1449 1486 exit; … … 1544 1581 }; 1545 1582 $COMPUTER_DB->{$domainset} ||= []; # Create empty Domain Set computer list by default 1546 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1583 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1547 1584 } 1548 1585 … … 1618 1655 'domain' => $domainset, 1619 1656 }; 1620 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1657 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1621 1658 } 1622 1659 … … 1682 1719 'modify_time' => $timestamp, 1683 1720 }; 1684 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1721 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1685 1722 } 1686 1723 … … 1705 1742 # Test if some computer use this config 1706 1743 LOOP_ON_DOMAIN: 1707 for my $domain _name(keys %{$COMPUTER_DB}) {1708 next if $domain _nameeq 'dset';1709 next if $domain _nameeq 'pool';1710 next if $domain _nameeq 'pxe';1711 next if $domain _nameeq 'tag';1744 for my $domainset_current (keys %{$COMPUTER_DB}) { 1745 next if $domainset_current eq 'dset'; 1746 next if $domainset_current eq 'pool'; 1747 next if $domainset_current eq 'pxe'; 1748 next if $domainset_current eq 'tag'; 1712 1749 1713 1750 LOOP_ON_COMPUTER: 1714 for my $computer (@{$COMPUTER_DB->{$domain _name}}) {1751 for my $computer (@{$COMPUTER_DB->{$domainset_current}}) { 1715 1752 my ($mac_address, $attribute) = %{$computer}; 1716 1753 1717 1754 if (exists $attribute->{'pxe_config'}) { 1718 1755 my $hostname = $attribute->{'hostname'}; 1719 die "Error: computer still use this PXE config: $hostname.$domain _name$mac_address\n" if $pxe_config eq $attribute->{'pxe_config'};1756 die "Error: computer still use this PXE config: $hostname.$domainset_current $mac_address\n" if $pxe_config eq $attribute->{'pxe_config'}; 1720 1757 } 1721 1758 } … … 1723 1760 1724 1761 delete $COMPUTER_DB->{'pxe'}{$pxe_config}; 1725 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1762 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1726 1763 } 1727 1764 … … 1783 1820 } 1784 1821 1785 for my $domain _name(keys %{$COMPUTER_DB}) {1786 next if $domain _nameeq 'dset';1787 next if $domain _nameeq 'pool';1788 next if $domain _nameeq 'pxe';1789 next if $domain _nameeq 'tag';1822 for my $domainset_current (keys %{$COMPUTER_DB}) { 1823 next if $domainset_current eq 'dset'; 1824 next if $domainset_current eq 'pool'; 1825 next if $domainset_current eq 'pxe'; 1826 next if $domainset_current eq 'tag'; 1790 1827 1791 1828 my $cpt_mac = 0; 1792 for my $computer (@{$COMPUTER_DB->{$domain _name}}) {1829 for my $computer (@{$COMPUTER_DB->{$domainset_current}}) { 1793 1830 for my $id (keys %{$computer}) { 1794 1831 if ($computer->{$id}->{'ip'} eq $ip) { 1795 1832 my $timestamp = time; 1796 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1797 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'pxe_config'} = $pxe_config;1833 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1834 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'} = $pxe_config; 1798 1835 print "IP Address: $ip, PXE enabled in config: $pxe_config\n"; 1799 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1836 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1800 1837 exit; 1801 1838 } … … 1818 1855 $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'} = $pxe_config; 1819 1856 print "Host $hostname ($domainset), PXE enabled in config: $pxe_config\n"; 1820 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1857 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1821 1858 exit; 1822 1859 } … … 1862 1899 } 1863 1900 1864 for my $domain _name(keys %{$COMPUTER_DB}) {1865 next if $domain _nameeq 'dset';1866 next if $domain _nameeq 'pool';1867 next if $domain _nameeq 'pxe';1868 next if $domain _nameeq 'tag';1901 for my $domainset_current (keys %{$COMPUTER_DB}) { 1902 next if $domainset_current eq 'dset'; 1903 next if $domainset_current eq 'pool'; 1904 next if $domainset_current eq 'pxe'; 1905 next if $domainset_current eq 'tag'; 1869 1906 1870 1907 my $cpt_mac = 0; 1871 for my $computer (@{$COMPUTER_DB->{$domain _name}}) {1908 for my $computer (@{$COMPUTER_DB->{$domainset_current}}) { 1872 1909 for my $id (keys %{$computer}) { 1873 1910 if ($computer->{$id}->{'ip'} eq $ip) { 1874 next if not exists $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'pxe_config'};1875 1876 my $pxe_config = $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'pxe_config'};1911 next if not exists $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'}; 1912 1913 my $pxe_config = $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'}; 1877 1914 my $timestamp = time; 1878 $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1879 delete $COMPUTER_DB->{$domain _name}[$cpt_mac]->{$id}->{'pxe_config'};1915 $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1916 delete $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'}; 1880 1917 print "IP Address: $ip, PXE disable from config: $pxe_config\n"; 1881 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1918 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1882 1919 exit; 1883 1920 } … … 1903 1940 delete $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'}; 1904 1941 print "Host $hostname ($domainset), PXE disable from config: $pxe_config\n"; 1905 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1942 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1906 1943 exit; 1907 1944 } … … 1954 1991 'modify_time' => $timestamp, 1955 1992 }; 1956 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);1993 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1957 1994 } 1958 1995 … … 1977 2014 # Test if some computer use this config 1978 2015 LOOP_ON_DOMAIN: 1979 for my $domain _name(keys %{$COMPUTER_DB}) {1980 next if $domain _nameeq 'dset';1981 next if $domain _nameeq 'pool';1982 next if $domain _nameeq 'pxe';1983 next if $domain _nameeq 'tag';2016 for my $domainset_current (keys %{$COMPUTER_DB}) { 2017 next if $domainset_current eq 'dset'; 2018 next if $domainset_current eq 'pool'; 2019 next if $domainset_current eq 'pxe'; 2020 next if $domainset_current eq 'tag'; 1984 2021 1985 2022 LOOP_ON_COMPUTER: 1986 for my $computer (@{$COMPUTER_DB->{$domain _name}}) {2023 for my $computer (@{$COMPUTER_DB->{$domainset_current}}) { 1987 2024 my ($mac_address, $attribute) = %{$computer}; 1988 2025 1989 2026 if (exists $attribute->{'tag'}) { 1990 2027 my $hostname = $attribute->{'hostname'}; 1991 die "Error: Computer still use this TAG: $hostname.$domain _name$mac_address\n" if $tag eq $attribute->{'tag'};2028 die "Error: Computer still use this TAG: $hostname.$domainset_current $mac_address\n" if $tag eq $attribute->{'tag'}; 1992 2029 } 1993 2030 } … … 1995 2032 1996 2033 delete $COMPUTER_DB->{'tag'}{$tag}; 1997 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);2034 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 1998 2035 } 1999 2036 … … 2026 2063 2027 2064 LOOP_ON_DOMAIN: 2028 for my $domain _name(keys %{$COMPUTER_DB}) {2029 next if $domain _nameeq 'dset';2030 next if $domain _nameeq 'pool';2031 next if $domain _nameeq 'pxe';2032 next if $domain _nameeq 'tag';2033 2034 my @domain db = @{$COMPUTER_DB->{$domain_name}};2065 for my $domainset_current (keys %{$COMPUTER_DB}) { 2066 next if $domainset_current eq 'dset'; 2067 next if $domainset_current eq 'pool'; 2068 next if $domainset_current eq 'pxe'; 2069 next if $domainset_current eq 'tag'; 2070 2071 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 2035 2072 2036 2073 LOOP_ON_COMPUTER: 2037 for my $computer (@domain db) {2074 for my $computer (@domainsetdb) { 2038 2075 my ($mac_address, $attribute) = %{$computer}; 2039 2076 my $new_mac = normalize_mac_address($mac_address); … … 2056 2093 print "# FLAG :$flag_change\n"; 2057 2094 2058 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB) if $flag_change;2095 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB) if $flag_change; 2059 2096 } 2060 2097 … … 2064 2101 2065 2102 LOOP_ON_DOMAIN: 2066 for my $domain _name(keys %{$COMPUTER_DB}) {2067 next if $domain _nameeq 'dset';2068 next if $domain _nameeq 'pool';2069 next if $domain _nameeq 'pxe';2070 next if $domain _nameeq 'tag';2071 2072 print "$domain _name\n";2103 for my $domainset_current (keys %{$COMPUTER_DB}) { 2104 next if $domainset_current eq 'dset'; 2105 next if $domainset_current eq 'pool'; 2106 next if $domainset_current eq 'pxe'; 2107 next if $domainset_current eq 'tag'; 2108 2109 print "$domainset_current\n"; 2073 2110 } 2074 2111 } … … 2094 2131 2095 2132 LOOP_ON_DOMAIN: 2096 for my $domain _name(keys %{$COMPUTER_DB}) {2097 next if $domain _nameeq 'dset';2098 next if $domain _nameeq 'pool';2099 next if $domain _nameeq 'pxe';2100 next if $domain _nameeq 'tag';2101 2102 my @domain db = @{$COMPUTER_DB->{$domain_name}};2133 for my $domainset_current (keys %{$COMPUTER_DB}) { 2134 next if $domainset_current eq 'dset'; 2135 next if $domainset_current eq 'pool'; 2136 next if $domainset_current eq 'pxe'; 2137 next if $domainset_current eq 'tag'; 2138 2139 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 2103 2140 2104 2141 LOOP_ON_COMPUTER: 2105 for my $computer (@domain db) {2142 for my $computer (@domainsetdb) { 2106 2143 my ($mac_address, $attribute) = %{$computer}; 2107 2144 … … 2125 2162 2126 2163 printf "%-30s %-20s %17s %9s %3s %10s %s\n", 2127 $attribute->{'hostname'} . '.' . $domain _name,2164 $attribute->{'hostname'} . '.' . $domainset_current, 2128 2165 $attribute->{'ip'}, 2129 2166 $mac_address, … … 2144 2181 2145 2182 LOOP_ON_DOMAIN: 2146 for my $domain _name(keys %{$COMPUTER_DB}) {2147 next if $domain _nameeq 'dset';2148 next if $domain _nameeq 'pool';2149 next if $domain _nameeq 'pxe';2150 next if $domain _nameeq 'tag';2151 2152 print "\n# *** List of computers in the domain set: $domain _name***\n";2183 for my $domainset_current (keys %{$COMPUTER_DB}) { 2184 next if $domainset_current eq 'dset'; 2185 next if $domainset_current eq 'pool'; 2186 next if $domainset_current eq 'pxe'; 2187 next if $domainset_current eq 'tag'; 2188 2189 print "\n# *** List of computers in the domain set: $domainset_current ***\n"; 2153 2190 printf "%-30s %-20s %17s %5s %7s %-10s %s\n", 2154 2191 'Hostname', … … 2159 2196 'Date', 2160 2197 'Comment'; 2161 my @domain db = @{$COMPUTER_DB->{$domain_name}};2198 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 2162 2199 2163 2200 LOOP_ON_COMPUTER: 2164 for my $computer (@domain db) {2201 for my $computer (@domainsetdb) { 2165 2202 my ($mac_address, $attribute) = %{$computer}; 2166 2203 … … 2170 2207 'mac_address' => $mac_address, 2171 2208 %{$attribute}, 2172 'domain' => $domain _name,2209 'domain' => $domainset_current, 2173 2210 }; 2174 2211 next LOOP_ON_COMPUTER; … … 2198 2235 2199 2236 printf "%-30s %-20s %17s %9s %3s %10s %s\n", 2200 $attribute->{'hostname'} . '.' . $domain _name,2237 $attribute->{'hostname'} . '.' . $domainset_current, 2201 2238 $ip, 2202 2239 $mac_address, … … 2247 2284 my %file_pool; 2248 2285 2249 for my $domain _name(keys %{$COMPUTER_DB}) {2250 next if $domain _nameeq 'dset';2251 next if $domain _nameeq 'pool';2252 next if $domain _nameeq 'pxe';2253 next if $domain _nameeq 'tag';2254 2255 open FILE_VLAN, '>', "$FOLDER_GEN_DHCP/$domain _name";2256 my @domain db = @{$COMPUTER_DB->{$domain_name}};2257 for my $value (@domain db) {2286 for my $domainset_current (keys %{$COMPUTER_DB}) { 2287 next if $domainset_current eq 'dset'; 2288 next if $domainset_current eq 'pool'; 2289 next if $domainset_current eq 'pxe'; 2290 next if $domainset_current eq 'tag'; 2291 2292 open FILE_VLAN, '>', "$FOLDER_GEN_DHCP/$domainset_current"; 2293 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 2294 for my $value (@domainsetdb) { 2258 2295 ALL_MAC_ADDRESS: 2259 2296 for my $mac_addres (keys %{$value}) { … … 2350 2387 my $pool_domain; 2351 2388 2352 for my $domain _name(keys %{$COMPUTER_DB}) {2353 next if $domain _nameeq 'dset';2354 next if $domain _nameeq 'pool';2355 next if $domain _nameeq 'pxe';2356 next if $domain _nameeq 'tag';2357 2358 if ($domain _nameeq 'pool') {2389 for my $domainset_current (keys %{$COMPUTER_DB}) { 2390 next if $domainset_current eq 'dset'; 2391 next if $domainset_current eq 'pool'; 2392 next if $domainset_current eq 'pxe'; 2393 next if $domainset_current eq 'tag'; 2394 2395 if ($domainset_current eq 'pool') { 2359 2396 #next; 2360 for my $value (@{$COMPUTER_DB->{$domain _name}}) {2397 for my $value (@{$COMPUTER_DB->{$domainset_current}}) { 2361 2398 for my $pool_name (keys %{$value}) { 2362 2399 $pool_domain = $value->{$pool_name}->{'domain'}."\n"; … … 2381 2418 else { 2382 2419 #--- Création du fichier non-reverse ---# 2383 open ( FILE_FORWARD_DNS, ">> $FOLDER_GEN_DNS/db.$domain _name.fwd");2384 open ( FILE_REVERSE_DNS, ">> $FOLDER_GEN_DNS/db.$domain _name.rev");2385 my @domain db = @{$COMPUTER_DB->{$domain_name}};2386 for my $value (@domain db) {2420 open ( FILE_FORWARD_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.fwd"); 2421 open ( FILE_REVERSE_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.rev"); 2422 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 2423 for my $value (@domainsetdb) { 2387 2424 for my $id (keys %{$value}) { 2388 2425 #host pcdavoust { deny-unknown-clients; … … 2396 2433 my $enabled = $value->{$id}->{'enabled'}; 2397 2434 2398 my $dns_domain = $domain _name;2399 if (exists $COMPUTER_DB->{'dset'}{$domain _name}) {2400 $dns_domain = $COMPUTER_DB->{'dset'}{$domain _name}{'dns_extension'};2435 my $dns_domain = $domainset_current; 2436 if (exists $COMPUTER_DB->{'dset'}{$domainset_current}) { 2437 $dns_domain = $COMPUTER_DB->{'dset'}{$domainset_current}{'dns_extension'}; 2401 2438 } 2402 2439 my @T_split = split(/\./ , $ip); … … 2421 2458 #$cpt=$cpt+1; 2422 2459 } 2423 print "- DNS: db.$domain _name.fwd db.$domain_name.rev [CREATE].\n";2460 print "- DNS: db.$domainset_current.fwd db.$domainset_current.rev [CREATE].\n"; 2424 2461 print "Ex : sort -k 4n -t . /usr/local/dhcp-dns-tools/dns/dns.hmg.priv\n"; 2425 2462 close FILE_REVERSE_DNS; … … 2447 2484 2448 2485 LOOP_ON_DOMAIN: 2449 for my $domain _name(keys %{$COMPUTER_DB}) {2450 next if $domain _nameeq 'dset';2451 next if $domain _nameeq 'pool';2452 next if $domain _nameeq 'pxe';2453 next if $domain _nameeq 'tag';2454 2455 my @domain db = @{$COMPUTER_DB->{$domain_name}};2486 for my $domainset_current (keys %{$COMPUTER_DB}) { 2487 next if $domainset_current eq 'dset'; 2488 next if $domainset_current eq 'pool'; 2489 next if $domainset_current eq 'pxe'; 2490 next if $domainset_current eq 'tag'; 2491 2492 my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}}; 2456 2493 2457 2494 LOOP_ON_COMPUTER: 2458 for my $computer (@domain db) {2495 for my $computer (@domainsetdb) { 2459 2496 my ($mac_address, $attribute) = %{$computer}; 2460 2497 #my $new_mac = normalize_mac_address($mac_address); … … 2467 2504 2468 2505 if ($attribute->{'hostname'} ne $dns_hostname) { 2469 print "$mac_address ($domain _name) $ip - $dns_hostname / $attribute->{'hostname'} # $attribute->{'comment'}\n";2506 print "$mac_address ($domainset_current) $ip - $dns_hostname / $attribute->{'hostname'} # $attribute->{'comment'}\n"; 2470 2507 next LOOP_ON_COMPUTER; 2471 2508 } … … 2656 2693 } 2657 2694 2658 YAML::Syck::DumpFile("$COMPUTER_YAML", $COMPUTER_DB);2695 ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB); 2659 2696 } 2660 2697
Note: See TracChangeset
for help on using the changeset viewer.