<%doc> -- Add Host form -- % <%attr> title => 'Add Host' % % %####################################################################### %# %# Args section %# %####################################################################### <%args> $add_host_block $user => $ui->get_current_user($r) $zone_id => undef $hostname => undef $aliases => undef $expiration => undef $cpu => undef $other_cpu => undef $os => undef $other_os => undef $site_id => undef $site_name => undef $room_id => undef $room_number => undef $ethernet => undef $submit => undef $contact_name => undef $contact_email => undef $contact_phone => undef % % % %####################################################################### %# %# INIT section %# %####################################################################### % <%init> my $DEBUG = 0; print '%ARGS is
', Dumper(%ARGS), '

' if $DEBUG; my $manager = $ui->get_permission_manager($r); my $block = Ipblock->retrieve($add_host_block); unless ( $block ){ $m->comp('/generic/error.mhtml', error=>"Could not retrieve Ipblock: $add_host_block"); } unless ( $manager && $manager->can($user, "edit", $block) ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to edit ".$block->get_label); } my $zone; if ( $zone_id ){ $zone = Zone->retrieve($zone_id); }else{ $zone = $block->forward_zone(); } if ( $submit ){ # Obtain next available address my $address; my $ip_strategy = Netdot->config->get("IP_ALLOCATION_STRATEGY"); eval { $address = $block->get_next_free(strategy=>$ip_strategy); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>"$e"); } unless ( $address ){ $m->comp('/generic/error.mhtml', error=>"Could not get an available address from ".$block->get_label); } unless ( $zone ){ $m->comp('/generic/error.mhtml', error=>"A DNS Domain (Zone) is required"); } unless ( $hostname ){ $m->comp('/generic/error.mhtml', error=>"A hostname is required"); } eval { RR->validate_name($hostname); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); } if ( my $h = RR->search(name=>$hostname, zone=>$zone)->first ){ $m->comp('/generic/error.mhtml', error=>$h->get_label." is already taken"); } # We do not want two host scopes with the same physical address in the same subnet if ( $ethernet ){ if ( my $physaddr = PhysAddr->search(address=>$ethernet)->first ){ if ( my @host_scopes = $physaddr->dhcp_hosts ){ foreach my $host ( @host_scopes ){ if ( $host->ipblock->parent && $host->ipblock->parent->id == $block->id ){ my $hname = $host->ipblock->address; my $ipid = $host->ipblock->id; $m->comp('/generic/error.mhtml', error=>"Host $hname is already registered with Ethernet: $ethernet in this subnet"); } } } } } my $person = $ui->get_user_person($user); my %args; if ( $aliases ){ my @aliases = split ',', $aliases; foreach my $alias ( @aliases ){ $alias =~ s/\s+//g; # In case they included the domain part in the alias my $domain = $zone->name; $alias =~ s/\.$domain$//; if ( my $h = RR->search(name=>$alias, zone=>$zone)->first ){ $m->comp('/generic/error.mhtml', error=>$h->get_label." from your aliases list is already taken"); } eval { RR->validate_name($alias); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>"Invalid Alias $alias: $e"); } push @{$args{aliases}}, $alias; } } foreach my $key qw(hostname expiration ethernet) { $args{$key} = $ARGS{$key}; } $args{zone} = $zone; $args{person} = $person; $args{block} = $block; $args{address} = $address; my @text_records; # Hardware Info $args{cpu} = $cpu || $other_cpu; $args{os} = $os || $other_os; # Location if ( $room_id || $site_id || $site_name ){ my $txtdata; if ( my $room = Room->retrieve($room_id) ){ $txtdata = "LOC: ".$room->get_label if $room; # the room label includes the site name }elsif ( $room_number ){ $txtdata = "LOC: ".$room_number; if ( my $site = Site->retrieve($site_id) ){ $txtdata .= " ".$site->get_label; }elsif ( $site_name ){ $txtdata .= " ".$site_name; } }else{ if ( my $site = Site->retrieve($site_id) ){ $txtdata = $site->get_label; }elsif ( $site_name ){ $txtdata = $site_name; } } push @text_records, $txtdata if ( $txtdata ); } # Contacts if ( $person ){ # Add the current user as a contact my $txtdata = "CON: ".$person->get_label; $txtdata .= " (".$person->email.")" if $person->email; $txtdata .= ", ".$person->office if $person->office; push @text_records, $txtdata if ( $txtdata ); } # Add additional contact info if ( $contact_name ){ my $txtdata = ""; $txtdata = "CON: ".$contact_name; $txtdata .= " (".$contact_email.")" if $contact_email; $txtdata .= ", ".$contact_phone if $contact_phone; push @text_records, $txtdata if ( $txtdata ); } $args{text_records} = \@text_records if @text_records; my $rr; eval { $rr = RR->add_host(%args); }; if ( my $e = $@ ){ $m->comp("/generic/error.mhtml", error=>$e); }else{ $m->comp("../management/host.html", rr=>$rr); } } % if ( !$submit ){ % my $subnet_description = $block->get_label; % $subnet_description .= " (".$block->description.")" if $block->description; % % my $cpu_defaults = $ui->config->get('DEFAULT_HINFO_CPU_VALUES'); % my $os_defaults = $ui->config->get('DEFAULT_HINFO_OS_VALUES');
Add New Host in <% $subnet_description %>

Required fields are marked with an asterisk (*).

Help is available for some fields by clicking on the field name.


Host Identification

% if ( $zone ){ <% $zone->get_label %> % }else{ % }

<% $ui->date_field(table=>"RR", column=>"expiration", edit=>1, shortFieldName=>1, returnAsVar=>1) %>

Hardware Information

(if not listed)

(if not listed)

Location

(if not listed)

(if not listed)

Contact (other than you)

% }