Changeset 357
- Timestamp:
- Sep 14, 2018, 11:58:01 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ddt/ddt
r356 r357 305 305 my $ip = shift; 306 306 307 if ($ip ne 'pool') { 308 my @ip_split = split /\./, $ip; 309 310 if ( scalar(@ip_split) != 4 ) { 311 print {*STDERR} "Error: bad IP syntax: $ip\n"; 312 return 0; 313 } 314 } 307 return 1 if $ip ne 'pool'; 308 309 return 0 if $ip !~ m{^(\d+\.){3}\d+$}; 310 return 0 if not NetAddr::IP->new("$ip/32"); 315 311 return 1; 316 312 } … … 480 476 control_syntax_mac_address($mac) or exit; 481 477 control_exist_mac($computer_db, $mac) or die "Error: physical MAC address already exists: $mac\n"; 482 control_syntax_ip($ip) or exit;478 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n"; 483 479 control_exist_ip($computer_db, $ip) or die "Error: IP $ip address already exist in sector $sector\n"; 484 480 control_ip_in_range($computer_db, $sector, $ip) or die "Error: IP $ip is not in sector $sector IP range.\n"; … … 516 512 control_syntax_mac_address($mac) or exit; 517 513 control_exist_mac($computer_db, $mac) or die "Error: physical MAC address already exists: $mac\n"; 518 control_syntax_ip($ip) or exit;514 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n"; 519 515 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in sector $sector: $ip.\n"; 520 516 control_ip_in_range($computer_db, $sector, $ip) or die "Error: IP $ip is not in sector $sector IP range.\n"; … … 702 698 control_exist_sector($computer_db, $sector) or exit; 703 699 control_exist_hostname($computer_db, $sector, $hostname) or die "Error: host already exist in sector $sector: $hostname\n"; 704 control_syntax_ip($ip) or exit;700 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n"; 705 701 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in sector $sector: $ip.\n"; 706 702 control_ip_in_range($computer_db, $sector, $ip) or die "Error: IP $ip is not in sector $sector IP range.\n"; … … 746 742 control_exist_mac($computer_db, $mac) or die "Error: physical MAC address already exists: $mac\n"; 747 743 if ($ip ne '') { 748 control_syntax_ip($ip) or exit;744 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n"; 749 745 if ( control_exist_ip($computer_db, $ip) == 1 ) { 750 746 print "Error: unkown IP address: $ip\n"; … … 805 801 die "Error: unkown host: $hostname, in sector: $sector\n"; 806 802 } 807 control_syntax_ip($ip) or exit;803 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n"; 808 804 control_exist_ip($computer_db, $ip) or die "Error: IP $ip address already exist in sector $sector\n"; 809 805 control_ip_in_range($computer_db, $sector, $ip) or die "Error: IP $ip is not in sector $sector IP range.\n"; … … 840 836 841 837 control_exist_sector($computer_db, $sector) or exit; 842 control_syntax_ip($ip) or exit;838 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n"; 843 839 if ( control_exist_ip($computer_db, $ip) == 1 ) { 844 840 die "Error: unkown IP address: $ip\n"; … … 1005 1001 my $computer_db = ipamdb_load($COMPUTER_YAML); 1006 1002 1007 control_exist_sector($computer_db, $sector) 1008 control_syntax_ip($ip) or exit;1009 control_syntax_mac_address($mac) 1003 control_exist_sector($computer_db, $sector) or exit; 1004 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n"; 1005 control_syntax_mac_address($mac) or exit; 1010 1006 1011 1007 LOOP_ON_SECTOR: … … 1114 1110 1115 1111 if ($ip ne '') { # disable by IP 1116 control_syntax_ip($ip) ;1112 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n";; 1117 1113 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1118 1114 die "Error: unkown IP address: $ip [FAILED]\n"; … … 1242 1238 1243 1239 if ($ip ne '') { # enable by IP 1244 control_syntax_ip($ip) ;1240 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n";; 1245 1241 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1246 1242 print "Error: unkown IP address: $ip\n"; … … 1725 1721 #---control if address exist ---# 1726 1722 if ($ipaddress_pool =~ /,/) { 1723 LOOP_ON_IP: 1727 1724 for my $ip (split /,/, $ipaddress_pool) { 1728 1725 if ($ip =~ /-/) { … … 1737 1734 } 1738 1735 else { 1739 control_syntax_ip($ip) or next ;1736 control_syntax_ip($ip) or next LOOP_ON_IP; 1740 1737 if ( control_exist_ip($computer_db, $ip) == 0 ) { 1741 1738 print "L'adresse IP $ip existe déjà\n"; … … 1927 1924 control_exist_sector($computer_db, $sector) or exit; 1928 1925 if ($ip ne '') { 1929 control_syntax_ip($ip) ;1926 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n";; 1930 1927 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1931 1928 die "Error: unkown IP address: $ip\n"; … … 2003 2000 control_exist_sector($computer_db, $sector) or exit; 2004 2001 if ($ip ne '') { 2005 control_syntax_ip($ip) ;2002 control_syntax_ip($ip) or die "Error: bad IP syntax $ip\n";; 2006 2003 if ( control_exist_ip($computer_db, $ip) == 1 ) { 2007 2004 die "Error: unkown IP address: $ip\n"; … … 2777 2774 close(FILE); 2778 2775 2776 LINE: 2779 2777 for my $ligne (@buffer) { 2780 2778 #-- … … 2817 2815 if ( control_exist_hostname($computer_db, $sector, $hostname) == 0 ) { 2818 2816 print "Error: host already exist in sector $sector: $hostname\n"; 2819 next ;2820 } 2821 control_syntax_mac_address($mac) or next ;2817 next LINE; 2818 } 2819 control_syntax_mac_address($mac) or next LINE; 2822 2820 if ( control_exist_mac($computer_db, $mac) == 0) { 2823 2821 print "Error: physical MAC address already exists: $mac\n"; 2824 next ;2825 } 2826 2827 control_syntax_ip($ip) or next ;2822 next LINE; 2823 } 2824 2825 control_syntax_ip($ip) or next LINE; 2828 2826 if ( control_exist_ip($computer_db, $ip) == 0 ) { 2829 2827 print "Error: IP address already exists: $ip\n"; 2830 next ;2828 next LINE; 2831 2829 } 2832 2830 my $timestamp = time;
Note: See TracChangeset
for help on using the changeset viewer.