Apache-DnsZone

 view release on metacpan or  search on metacpan

lib/Apache/DnsZone.pm  view on Meta::CPAN

    output_redirect($r, 1, '/admin?action=default');
    $dbh->close();
    return REDIRECT;
}

sub settings {
    my $r = shift || Apache->request();
    Debug(3, qq{calling settings()});
    init($r); 
    my $user = $r->connection->user;

    if (apr()->param('button') && lc(apr()->param('button')) eq lc($lang{'SUBMIT'})) {
        Debug(5, qq{This is an update of settings request});
	my ($uid) = $dbh->get_user_id($user);

	my $all_set = 1;
	my $user_email = apr()->param('user_email');
	if (!($user_email = check_email($user_email))) {
	    $all_set = 0;
	}
	my $lang_id = apr()->param('lang');
	if (!check_lang($lang_id)) {
	    $all_set = 0;
	}
        if (apr()->param('password') && apr()->param('password_confirm')) {
	    if (apr()->param('password') ne apr()->param('password_confirm')) {
		$all_set = 0;
	    } 
	}
	if ((apr()->param('password') && !apr()->param('password_confirm')) || (!apr()->param('password') && apr()->param('password_confirm'))) {
	    $all_set = 0;
	}
	if ($all_set) {
	    # update email and language
	    Debug(5, qq{Updating email and language settings});
	    $dbh->set_user_lang_email($uid, $lang_id, $user_email);
	    if (apr()->param('password') && apr()->param('password') ne '' && apr()->param('password_confirm') && apr()->param('password_confirm') ne '' && apr()->param('password') eq apr()->param('password_confirm')) {
	        Debug(5, qq{Updating password});
		$dbh->set_user_password($uid, apr()->param('password'));
	    }
	} else {
	    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
	    $tpl->define(layout => 'layout.tpl', settings => 'settings.tpl', menu => 'menu.tpl');
	    $tpl->assign(%lang);
	    $tpl->assign(TITLE => $lang{'PAGE_SETTINGS'});
	    $tpl->assign(DEBUG => '');
	    
	    if ($dbh->get_domain_count($uid) == 1) {
		$tpl->assign(ADDITIONAL_MENU => '');
	    } else {
		$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
	    }

	    $tpl->assign(LANG_VALUE => $dbh->lang_select_box($uid, $lang_id));
	    $tpl->assign(EMAIL_VALUE => encode_entities(apr()->param('user_email')));
	    
	    $tpl->assign(NEW_PASSWORD_VALUE => encode_entities(apr()->param('password')));
	    $tpl->assign(CONFIRM_PASSWORD_VALUE => encode_entities(apr()->param('password_confirm')));
	    
	    if (!($user_email = check_email($user_email))) {
		$tpl->assign(EMAIL => qq{<font color="red">} . $lang{EMAIL} . qq{</font>});
	    }
	    if (!check_lang($lang_id)) {
		$tpl->assign(LANGUAGE => qq{<font color="red">} . $lang{LANGUAGE} . qq{</font>});
	    }
	    if (apr()->param('password') && apr()->param('password') ne '' && apr()->param('password_confirm') && apr()->param('password_confirm') ne '') {
		if (!(apr()->param('password') eq apr()->param('confirm_password'))) {
		    $tpl->assign(NEW_PASSWORD => qq{<font color="red">} . $lang{NEW_PASSWORD} . qq{</font>});
		    $tpl->assign(CONFIRM_PASSWORD => qq{<font color="red">} . $lang{CONFIRM_PASSWORD} . qq{</font>});
		}
	    }
	    if ((apr()->param('password') && !apr()->param('password_confirm')) || (!apr()->param('password') && apr()->param('password_confirm'))) {
		    $tpl->assign(NEW_PASSWORD => qq{<font color="red">} . $lang{NEW_PASSWORD} . qq{</font>});
		    $tpl->assign(CONFIRM_PASSWORD => qq{<font color="red">} . $lang{CONFIRM_PASSWORD} . qq{</font>});
	    }

	    $tpl->parse(MENU => "menu");
	    $tpl->parse(MAIN => ["settings", "layout"]);
	    
	    my $content_ref = $tpl->fetch("MAIN");  
	    
	    output_headers($r, 1, length(${$content_ref}));
	  
	    $r->print(${$content_ref});
    
            $dbh->close();
	    return OK;
	}

        output_redirect($r, 1, '/admin?action=default');

	$dbh->close();
	return REDIRECT;
    } else {
        Debug(5, qq{This is a view of settings request});
	my ($uid, $user_email, $lang_id, $lang) = $dbh->get_user_info($user);

        my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
        $tpl->define(layout => 'layout.tpl', settings => 'settings.tpl', menu => 'menu.tpl');
        $tpl->assign(%lang);
        $tpl->assign(TITLE => $lang{'PAGE_SETTINGS'});
        $tpl->assign(DEBUG => '');
        $tpl->assign(LANG_VALUE => $dbh->lang_select_box($uid, $lang_id));
        $tpl->assign(EMAIL_VALUE => $user_email);

        if ($dbh->get_domain_count($uid) == 1) {
	    $tpl->assign(ADDITIONAL_MENU => '');
	} else {
	    $tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
	}
	  
        $tpl->assign(NEW_PASSWORD_VALUE => '');
	$tpl->assign(CONFIRM_PASSWORD_VALUE => '');

        $tpl->parse(MENU => "menu");
	$tpl->parse(MAIN => ["settings", "layout"]);

	my $content_ref = $tpl->fetch("MAIN");  

        output_headers($r, 1, length(${$content_ref}));

        $r->print(${$content_ref});

	$dbh->close();
	return OK;
    }
}

sub delete_record {
    my $r = shift || Apache->request();
    Debug(3, qq{calling delete_record()});
    init($r);
    my $user = $r->connection->user;
    my ($uid, $email, $lang_id, $lang) = $dbh->get_user_info($user);

lib/Apache/DnsZone.pm  view on Meta::CPAN

    
    if (apr()->param('button') && lc(apr()->param('button')) eq lc($lang{'SUBMIT'})) {
	# this the update
        Debug(5, qq{This is a submit of add_record request});

	for ($type) {
	    if (/^A$/) { 
		# actually there needs to be another check to see if they really exists the parameters maybe up in the checking of the rec_lock
		my $all_set = 1;
		my $ip = apr()->param('ip');
		if (!($ip = check_ip($ip))) {
		    $all_set = 0;
		}
		my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_add_A($dom_id, $host, $ip)) {
		    # update dns! and sql
		    # check wheter name is the same? so no need for update?
		    # rule checking like not the same a and cname record
		    # check wheter an excact copy exists in dns to avoid errors
		    
		    if (dns_set_A($dom_id, $host, $ip, $ttl)) {
		      Debug(5, qq{dns_set_A succeded\n});
		    } else {
		      Debug(5, qq{dns_set_A failed\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');
		    
		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_ADD};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'a/add.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host'))); # maybe it needs to fully qualify it if it was okay?
		    $tpl->assign(IP_ADDRESS_VALUE => encode_entities(apr()->param('ip')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    # do the red-marker assignment
		    # and the error text getting
		    my $error_text = $lang{ERROR_CORRECT};

		    if (!($ip = check_ip($ip))) {
			$tpl->assign(IP_ADDRESS => qq{<font color="red">} . $lang{IP_ADDRESS} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_IP}};
		    }
		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    # check_before_add_A
		    if ($all_set) {
			# this means check_before_add_A failed!
			# text for error?
			$tpl->assign(IP_ADDRESS => qq{<font color="red">} . $lang{IP_ADDRESS} . qq{</font>});
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }
		    $tpl->assign(EXPLANATION => $error_text);
		    
		    $tpl->assign(DOM_ID => $dom_id);

		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
	        }
	    }
	    elsif (/^AAAA$/) { 
		# actually there needs to be another check to see if they really exists the parameters maybe up in the checking of the rec_lock
		my $all_set = 1;
		my $ipv6 = apr()->param('ipv6');

		if (ip_is_ipv6($ipv6)) {
		    $ipv6 = ip_expand_address($ipv6, 6); # to always have the correct full address to match against
		} else {
		    $all_set = 0;
		}
		my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_add_AAAA($dom_id, $host, $ipv6)) {
		    # update dns! and sql
		    # check wheter name is the same? so no need for update?
		    # rule checking like not the same a and cname record
		    # check wheter an excact copy exists in dns to avoid errors
		    
		    if (dns_set_AAAA($dom_id, $host, $ipv6, $ttl)) {
		      Debug(5, qq{dns_set_AAAA succeded\n});
		    } else {
		      Debug(5, qq{dns_set_AAAA failed\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');
		    
		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_ADD};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'aaaa/add.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host'))); # maybe it needs to fully qualify it if it was okay?
		    $tpl->assign(IPV6_ADDRESS_VALUE => encode_entities(apr()->param('ipv6')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    # do the red-marker assignment
		    # and the error text getting
		    my $error_text = $lang{ERROR_CORRECT};

		    if (!ip_is_ipv6($ipv6)) {
			$tpl->assign(IPV6_ADDRESS => qq{<font color="red">} . $lang{IPV6_ADDRESS} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_IPV6}};
		    }
		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    # check_before_add_AAAA
		    if ($all_set) {
			# this means check_before_add_AAAA failed!
			# text for error?
			$tpl->assign(IPV6_ADDRESS => qq{<font color="red">} . $lang{IPV6_ADDRESS} . qq{</font>});
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }
		    $tpl->assign(EXPLANATION => $error_text);
		    
		    $tpl->assign(DOM_ID => $dom_id);

		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
	        }
	    }
	    elsif (/^CNAME$/) { 
		my $all_set = 1;
		my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $cname = apr()->param('cname');
		if (!check_cname_host($cname)) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		# do the update dance!
		if ($all_set && check_before_add_CNAME($dom_id, $host)) {
		    # update dns! and sql
		    # check wheter name is the same? so no need for update?
		    # rule checking
		    # check wheter an excact copy exists in dns to avoid errors
		    
		    if (dns_set_CNAME($dom_id, $host, $cname, $ttl)) {
		        Debug(5, qq{dns_set_CNAME succeded\n});
		    } else {
		        Debug(5, qq{dns_set_CNAME failed\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');

		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_ADD};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'cname/add.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host')));
		    $tpl->assign(CNAME_VALUE => encode_entities(apr()->param('cname')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!check_cname_host($cname)) {
			$tpl->assign(CNAME => qq{<font color="red">} . $lang{CNAME} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_CNAME}};
		    }
		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    if ($all_set) {
			# means check_before_add_CNAME failed
			$tpl->assign(CNAME => qq{<font color="red">} . $lang{CNAME} . qq{</font>});
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});			
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }
		    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    
		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);
		    
		    my $content_ref = $tpl->fetch("MAIN");
		    
		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
		}
	    }
	    elsif (/^MX$/) { 
		my $all_set = 1;
		my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $exchanger = apr()->param('exchanger');
		if (!check_exchanger($exchanger)) {
		    $all_set = 0;
		}
		my $preference = apr()->param('preference');
		if (!check_preference($preference)) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_add_MX($dom_id, $host, $exchanger, $preference)) {
		    if (dns_set_MX($dom_id, $host, $exchanger, $preference, $ttl)) {
		        Debug(5, qq{dns_set_MX succeded\n});
		    } else {
		        Debug(5, qq{dns_set_MX failed\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');
		    
		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_ADD};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'mx/add.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host')));
		    $tpl->assign(MX_VALUE => encode_entities(apr()->param('exchanger')));
		    $tpl->assign(PREFERENCE_VALUE => encode_entities(apr()->param('preference')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_exchanger($exchanger)) {
			$tpl->assign(MX => qq{<font color="red">} . $lang{MX} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_MX}};
		    }
		    if (!check_preference($preference)) {
			$tpl->assign(PREFERENCE => qq{<font color="red">} . $lang{PREFERENCE} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_PREFERENCE}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    if ($all_set) {
			# means check_before_add_MX failed
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$tpl->assign(PREFERENCE => qq{<font color="red">} . $lang{PREFERENCE} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }
		    $tpl->assign(EXPLANATION => $error_text);
		    
		    $tpl->assign(DOM_ID => $dom_id);
		    
		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));

		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
		}
	    }
	    elsif (/^NS$/) { 
		my $all_set = 1;
		my $zone = "";
		if (!($zone = check_fqdn_ns(apr()->param('zone'), $domain))) {
		    $all_set = 0;
		}
		my $nameserver = apr()->param('nsdname');
		if (!check_nameserver($nameserver)) {
		    $all_set = 0;
		}
		
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_add_NS($dom_id, $zone, $nameserver)) {
		    if (dns_set_NS($dom_id, $zone, $nameserver, $ttl)) {
		        Debug(5, qq{dns_set_NS succeded\n});
		    } else {
		        Debug(5, qq{dns_set_NS failed\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');

                    if ($dbh->get_domain_count($uid) == 1) {
                        $tpl->assign(ADDITIONAL_MENU => '');
                    } else {
	                $tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
                    }

		    my $page_title = $lang{PAGE_ADD};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'ns/add.tpl');
		    $tpl->assign(ZONE_VALUE => encode_entities(apr()->param('zone')));
		    $tpl->assign(NS_VALUE => encode_entities(apr()->param('nsdname')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!($zone = check_fqdn_ns(apr()->param('zone'), $domain))) {
			$tpl->assign(ZONE => qq{<font color="red">} . $lang{ZONE} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_ZONE}};
		    }
		    if (!check_nameserver($nameserver)) {
			$tpl->assign(NS => qq{<font color="red">} . $lang{NS} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_NS}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
                    if ($all_set) {
			$tpl->assign(ZONE => qq{<font color="red">} . $lang{ZONE} . qq{</font>});
			$tpl->assign(NS => qq{<font color="red">} . $lang{NS} . qq{</font>});    
                        $error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
                    }

                    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);

                    $tpl->parse(MENU => "menu");
                    $tpl->parse(MAIN => ["record", "layout"]);

                    my $content_ref = $tpl->fetch("MAIN");

                    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
		}
	    }
	    if (/^PTR$/) { 
		# actually there needs to be another check to see if they really exists the parameters maybe up in the checking of the rec_lock
		my $all_set = 1;
		my $reverse = apr()->param('host');
		if (!(check_host($reverse))) {
		    $all_set = 0;
		}
		my $host = "";
		if (!($host = check_reverse(apr()->param('reverse'), $domain))) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_add_PTR($dom_id, $host, $reverse)) {
		    # update dns! and sql
		    # check wheter name is the same? so no need for update?
		    # rule checking like not the same a and cname record
		    # check wheter an excact copy exists in dns to avoid errors
		    
		    if (dns_set_PTR($dom_id, $host, $reverse, $ttl)) {
		      Debug(5, qq{dns_set_PTR succeded\n});
		    } else {
		      Debug(5, qq{dns_set_PTR failed\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');
		    
		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_ADD};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'ptr/add.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host'))); # maybe it needs to fully qualify it if it was okay?
		    $tpl->assign(REVERSE_HOST_VALUE => encode_entities(apr()->param('reverse')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    # do the red-marker assignment
		    # and the error text getting
		    my $error_text = $lang{ERROR_CORRECT};

		    if (!(check_host(apr()->param('host')))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!($host = check_reverse(apr()->param('reverse'), $domain))) {
			$tpl->assign(REVERSE => qq{<font color="red">} . $lang{REVERSE} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_REVERSE}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    # check_before_add_PTR
		    if ($all_set) {
			# this means check_before_add_PTR failed!
			# text for error?
			$tpl->assign(REVERSE => qq{<font color="red">} . $lang{REVERSE} . qq{</font>});
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }
		    $tpl->assign(EXPLANATION => $error_text);
		    
		    $tpl->assign(DOM_ID => $dom_id);

		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
	        }
	    }
	    elsif (/^TXT$/) { 
		my $all_set = 1;
		my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $txtdata = apr()->param('txtdata');
		if (!check_txt($txtdata)) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_add_TXT($dom_id, $host, $txtdata)) {
		    if (dns_set_TXT($dom_id, $host, $txtdata, $ttl)) {
		        Debug(5, qq{dns_set_TXT succeded\n});
		    } else {
		        Debug(5, qq{dns_set_TXT failed\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');

		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
                    }

		    my $page_title = $lang{PAGE_ADD};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);
		    $tpl->define(record => 'txt/add.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host')));
		    $tpl->assign(TXT_VALUE => encode_entities(apr()->param('txtdata')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_txt($txtdata)) {
			$tpl->assign(TXT => qq{<font color="red">} . $lang{TXT} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_TXT}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
                    if ($all_set) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$tpl->assign(TXT => qq{<font color="red">} . $lang{TXT} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
                    }

                    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    
                    $tpl->parse(MENU => "menu");
                    $tpl->parse(MAIN => ["record", "layout"]);

                    my $content_ref = $tpl->fetch("MAIN");

                    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
		}
	    }
	    else { 
	        Debug(1, qq{User trying to update an unexsisting type: $type\n});
	    }
	}
	
        output_redirect($r, 1, qq{/admin?action=view&dom_id=$dom_id});
	$dbh->close();
	return REDIRECT;
    } else {
	# this is the view
        Debug(5, qq{This is an view of add_record request});

        my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
        $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
        $tpl->assign(%lang);
        $tpl->assign(DEBUG => '');
	
	if ($dbh->get_domain_count($uid) == 1) {
	    $tpl->assign(ADDITIONAL_MENU => '');
	} else {
	    $tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
	}

        my $page_title = $lang{PAGE_ADD};
        $page_title =~ s/\$record/$type/;
        $page_title =~ s/\$domain/$domain/;

        $tpl->assign(TITLE => $page_title);
	$tpl->assign(EXPLANATION => $lang{FILLOUT_FIELDS});
	for ($type) {
	    if (/^A$/) {
		$tpl->define(record => 'a/add.tpl');
		$tpl->assign(HOST_VALUE => '');
		$tpl->assign(IP_ADDRESS_VALUE => '');
		$tpl->assign(TTL_VALUE => '');
	    }
	    elsif (/^AAAA$/) {
		$tpl->define(record => 'aaaa/add.tpl');
		$tpl->assign(HOST_VALUE => '');
		$tpl->assign(IPV6_ADDRESS_VALUE => '');

lib/Apache/DnsZone.pm  view on Meta::CPAN

		my $retry = apr()->param('retry');
		my $expire = apr()->param('expire');
		my $default_ttl = apr()->param('default_ttl');
		my $all_set = 1;
		if (!(check_ttl($refresh) && check_ttl($retry) && check_ttl($expire) && check_ttl($default_ttl))) {
		    $all_set = 0;
		}
		if (!($soa_email = check_email($soa_email))) {
		    $all_set = 0;
		}
		if ($soa_email =~ /\..*?\@/) { 
		    # is there a dot before the @ => invalid for a soa email
		    $all_set = 0;
                } 
		if ($all_set) {
		    my $serial = get_serial_from_zone($dom_id);
		    $serial++;
		    $soa_email =~ s/\@/\./;
		    if (is_updated_SOA($dom_id, $soa_email, $refresh, $retry, $expire, $default_ttl)) {
			if (dns_update_SOA($dom_id, $serial, $soa_email, $refresh, $retry, $expire, $default_ttl)) {
			    Debug(2, qq{dns_update_SOA succeded\n});
			} else {
			    Debug(2, qq{dns_update_SOA failed\n});
			}
		    } else {
		        Debug(2, qq{Dns record not changed so not updated\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');
		    
		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_EDIT};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'soa/edit.tpl');
		    $tpl->assign(ADMIN_EMAIL_VALUE => encode_entities(apr()->param('soa_email')));
		    $tpl->assign(REFRESH_VALUE => encode_entities(apr()->param('refresh')));
		    $tpl->assign(RETRY_VALUE => encode_entities(apr()->param('retry')));
		    $tpl->assign(EXPIRE_VALUE => encode_entities(apr()->param('expire')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('default_ttl')));
		    
		    my ($auth_ns, $serial) = $dbh->get_authns_serial($dom_id);

		    $tpl->assign(AUTH_NS_VALUE => $auth_ns);
		    $tpl->assign(SERIAL_VALUE => $serial);

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!check_ttl($refresh)) {
			$tpl->assign(REFRESH => qq{<font color="red">} . $lang{REFRESH} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_REFRESH}};
		    }
		    if (!check_ttl($retry)) {
			$tpl->assign(RETRY => qq{<font color="red">} . $lang{RETRY} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_RETRY}};
		    }
		    if (!check_ttl($expire)) {
			$tpl->assign(EXPIRE => qq{<font color="red">} . $lang{EXPIRE} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_EXPIRE}};
		    }
		    if (!check_ttl($default_ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    
		    if (!($soa_email = check_email($soa_email))) {
			$tpl->assign(ADMIN_EMAIL => qq{<font color="red">} . $lang{ADMIN_EMAIL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_ADMIN_EMAIL}};
		    }
		    if ($soa_email =~ /\..*?\@/) { 
			# is there a dot before the @ => invalid for a soa email
			$tpl->assign(ADMIN_EMAIL => qq{<font color="red">} . $lang{ADMIN_EMAIL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_ADMIN_EMAIL}};
		    } 
		    
		    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    $tpl->assign(RECORD_ID => $record_id);

		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));

		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
		}
	    } 
	    elsif (/^A$/) { 
		# actually there needs to be another check to see if they really exists the parameters maybe up in the checking of the rec_lock
		my $all_set = 1;
		my $ip = apr()->param('ip');
		if (!($ip = check_ip($ip))) {
		    $all_set = 0;
		}
		my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_edit_A($dom_id, $record_id, $host, $ip)) {
		    # update dns! and sql
		    # check wheter name is the same? so no need for update?
		    
		    # check wheter an excact copy exists in dns to avoid errors
		    if (is_updated_A($dom_id, $record_id, $host, $ip, $ttl)) {
			if (dns_update_A($dom_id, $record_id, $host, $ip, $ttl)) {
			    Debug(2, qq{dns_update_A succeded\n});
			} else {
			    Debug(2, qq{dns_update_A failed\n});
			}
		    } else {
		        Debug(2, qq{Dns record not changed so not updated\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');
		    
		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_EDIT};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'a/edit.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host'))); # maybe it needs to fully qualify it if it was okay?
		    $tpl->assign(IP_ADDRESS_VALUE => encode_entities(apr()->param('ip')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    # do the red-marker assignment

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!($ip = check_ip(apr()->param('ip')))) {
			$tpl->assign(IP_ADDRESS => qq{<font color="red">} . $lang{IP_ADDRESS} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_IP}};
		    }
		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    if ($all_set) {
			$tpl->assign(IP_ADDRESS => qq{<font color="red">} . $lang{IP_ADDRESS} . qq{</font>});
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }

		    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    $tpl->assign(RECORD_ID => $record_id);

		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
	        }
	    }
	    elsif (/^AAAA$/) { 
		# actually there needs to be another check to see if they really exists the parameters maybe up in the checking of the rec_lock
		my $all_set = 1;
		my $ipv6 = apr()->param('ipv6');
                if (ip_is_ipv6($ipv6)) {
		    $ipv6 = ip_expand_address($ipv6, 6); # to always have the correct full address to match against
		} else {
		    $all_set = 0;
		}
		my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_edit_AAAA($dom_id, $record_id, $host, $ipv6)) {
		    # update dns! and sql
		    # check wheter name is the same? so no need for update?
		    
		    # check wheter an excact copy exists in dns to avoid errors
		    if (is_updated_AAAA($dom_id, $record_id, $host, $ipv6, $ttl)) {
			if (dns_update_AAAA($dom_id, $record_id, $host, $ipv6, $ttl)) {
			    Debug(2, qq{dns_update_AAAA succeded\n});
			} else {
			    Debug(2, qq{dns_update_AAAA failed\n});
			}
		    } else {
		        Debug(2, qq{Dns record not changed so not updated\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');
		    
		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_EDIT};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'aaaa/edit.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host'))); # maybe it needs to fully qualify it if it was okay?
		    $tpl->assign(IPV6_ADDRESS_VALUE => encode_entities(apr()->param('ipv6')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    # do the red-marker assignment

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!ip_is_ipv6($ipv6)) {
			$tpl->assign(IPV6_ADDRESS => qq{<font color="red">} . $lang{IPV6_ADDRESS} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_IPV6}};
		    }
		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    if ($all_set) {
			$tpl->assign(IPV6_ADDRESS => qq{<font color="red">} . $lang{IPV6_ADDRESS} . qq{</font>});
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }

		    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    $tpl->assign(RECORD_ID => $record_id);

		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
	        }
	    }
	    elsif (/^CNAME$/) { 
		my $all_set = 1;
                my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $cname = apr()->param('cname');
		if (!check_cname_host($cname)) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		# do the update dance!
		if ($all_set && check_before_edit_CNAME($dom_id, $record_id, $host, $cname)) {
		    # update dns! and sql
		    # check wheter name is the same? so no need for update?
		    
		    # check wheter an excact copy exists in dns to avoid errors
		    if (is_updated_CNAME($dom_id, $record_id, $host, $cname, $ttl)) {
			if (dns_update_CNAME($dom_id, $record_id, $host, $cname, $ttl)) {
			    Debug(2, qq{dns_update_CNAME succeded\n});
			} else {
			    Debug(2, qq{dns_update_CNAME failed\n});
			}
		    } else {
		        Debug(2, qq{Dns record not changed so not updated\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');

		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_EDIT};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'cname/edit.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host')));
		    $tpl->assign(CNAME_VALUE => encode_entities(apr()->param('cname')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!check_cname_host($cname)) {
			$tpl->assign(CNAME => qq{<font color="red">} . $lang{CNAME} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_CNAME}};
		    }
		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    if ($all_set) {
			$tpl->assign(CNAME => qq{<font color="red">} . $lang{CNAME} . qq{</font>});
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }

		    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    $tpl->assign(RECORD_ID => $record_id);
		    
		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
		}
	    }
	    elsif (/^MX$/) { 
		my $all_set = 1;
		my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $exchanger = apr()->param('exchanger');
		if (!check_exchanger($exchanger)) {
		    $all_set = 0;
		}
		my $preference = apr()->param('preference');
		if (!check_preference($preference)) { 
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_edit_MX($dom_id, $record_id, $host, $exchanger, $preference)) {
		    if (is_updated_MX($dom_id, $record_id, $host, $exchanger, $preference, $ttl)) {
                        if (dns_update_MX($dom_id, $record_id, $host, $exchanger, $preference, $ttl)) {
			    Debug(2, qq{dns_update_MX succeded\n});
			} else {
			    Debug(2, qq{dns_update_MX failed\n});
		        }
                    } else {
    		        Debug(2, qq{Dns record not changed so not updated\n});
                    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');

                    if ($dbh->get_domain_count($uid) == 1) {
                        $tpl->assign(ADDITIONAL_MENU => '');
                    } else {
	                $tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
                    }

		    my $page_title = $lang{PAGE_EDIT};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'mx/edit.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host')));
		    $tpl->assign(MX_VALUE => encode_entities(apr()->param('exchanger')));
		    $tpl->assign(PREFERENCE_VALUE => encode_entities(apr()->param('preference')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

                    my $error_text = $lang{ERROR_CORRECT};

		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_exchanger($exchanger)) {
			$tpl->assign(MX => qq{<font color="red">} . $lang{MX} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_MX}};
		    }
		    if (!check_preference($preference)) {
			$tpl->assign(PREFERENCE => qq{<font color="red">} . $lang{PREFERENCE} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_PREFERENCE}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
                    if ($all_set) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$tpl->assign(PREFERENCE => qq{<font color="red">} . $lang{PREFERENCE} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
                    }

                    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    $tpl->assign(RECORD_ID => $record_id);
		    
                    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

                    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$tpl->fetch("MAIN")});	

                    $dbh->close();
		    return OK;
		}
	    }
	    elsif (/^NS$/) { 
		my $all_set = 1;
		my $zone = "";
		if (!($zone = check_fqdn_ns(apr()->param('zone'), $domain))) {
		    $all_set = 0;
		}
		my $nameserver = apr()->param('nsdname');
		if (!check_nameserver($nameserver)) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_edit_NS($dom_id, $record_id, $zone, $nameserver)) {
		    if (is_updated_NS($dom_id, $record_id, $zone, $nameserver, $ttl)) {
			if (dns_update_NS($dom_id, $record_id, $zone, $nameserver, $ttl)) {
			    Debug(2, qq{dns_update_NS succeded\n});
                        } else {
			    Debug(2, qq{dns_update_NS failed\n});
                        }
                    } else {
			Debug(2, qq{Dns record not changed so not updating\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');

		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
                    }

		    my $page_title = $lang{PAGE_EDIT};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'ns/edit.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('zone')));
		    $tpl->assign(NS_VALUE => encode_entities(apr()->param('nsdname')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!($zone = check_fqdn_ns(apr()->param('zone'), $domain))) {
			$tpl->assign(ZONE => qq{<font color="red">} . $lang{ZONE} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_ZONE}};
		    }
		    if (!check_nameserver($nameserver)) {
			$tpl->assign(NS => qq{<font color="red">} . $lang{NS} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_NS}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
                    if ($all_set) {
			$tpl->assign(ZONE => qq{<font color="red">} . $lang{ZONE} . qq{</font>});
			$tpl->assign(NS => qq{<font color="red">} . $lang{NS} . qq{</font>});
                        $error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }

                    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    $tpl->assign(RECORD_ID => $record_id);

                    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

                    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

		    $dbh->close();
                    return OK;
		}
	    }
	    elsif (/^PTR$/) { 
		# actually there needs to be another check to see if they really exists the parameters maybe up in the checking of the rec_lock
		my $all_set = 1;
		my $reverse = apr()->param('host');
		if (!(check_host($reverse))) {
		    $all_set = 0;
		}
		my $host = "";
		if (!($host = check_reverse(apr()->param('reverse'), $domain))) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_edit_PTR($dom_id, $record_id, $host, $reverse)) {
		    # update dns! and sql
		    # check wheter name is the same? so no need for update?
		    
		    # check wheter an excact copy exists in dns to avoid errors
		    if (is_updated_PTR($dom_id, $record_id, $host, $reverse, $ttl)) {
			if (dns_update_PTR($dom_id, $record_id, $host, $reverse, $ttl)) {
			    Debug(2, qq{dns_update_PTR succeded\n});
			} else {
			    Debug(2, qq{dns_update_PTR failed\n});
			}
		    } else {
		        Debug(2, qq{Dns record not changed so not updated\n});
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');
		    
		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_EDIT};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);

		    $tpl->define(record => 'ptr/edit.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host'))); # maybe it needs to fully qualify it if it was okay?
		    $tpl->assign(REVERSE_HOST_VALUE => encode_entities(apr()->param('reverse')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    # do the red-marker assignment

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!(check_host(apr()->param('host')))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_IP}};
		    }
		    if (!($host = check_reverse(apr()->param('reverse'), $domain))) {
			$tpl->assign(REVERSE_HOST => qq{<font color="red">} . $lang{REVERSE_HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_REVERSE}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    if ($all_set) {
			$tpl->assign(REVERSE_HOST => qq{<font color="red">} . $lang{REVERSE_HOST} . qq{</font>});
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }

		    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    $tpl->assign(RECORD_ID => $record_id);

		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

 	            $dbh->close();
		    return OK;
	        }
	    }
	    elsif (/^TXT$/) { 
		my $all_set = 1;
		my $host = "";
		if (!($host = check_fqdn(apr()->param('host'), $domain))) {
		    $all_set = 0;
		}
		my $txtdata = apr()->param('txtdata');
		if (!check_txt($txtdata)) {
		    $all_set = 0;
		}
		my $ttl = apr()->param('ttl');
		if (!check_ttl($ttl)) {
		    $all_set = 0;
		}
		if ($all_set && check_before_edit_TXT($dom_id, $record_id, $host, $txtdata)) {
		    if (is_updated_TXT($dom_id, $record_id, $host, $txtdata, $ttl)) {
			if (dns_update_TXT($dom_id, $record_id, $host, $txtdata, $ttl)) {
			    Debug(2, qq{dns_update_TXT succeded\n});
			} else {
			    Debug(2, qq{dns_update_TXT failed\n});
			}
		    } else {
			Debug(2, qq{Dns record not changed so not updating\n});			
		    }
		} else {
		    my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
		    $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
		    $tpl->assign(%lang);
		    $tpl->assign(DEBUG => '');

		    if ($dbh->get_domain_count($uid) == 1) {
			$tpl->assign(ADDITIONAL_MENU => '');
		    } else {
			$tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
		    }

		    my $page_title = $lang{PAGE_EDIT};
		    $page_title =~ s/\$record/$type/;
		    $page_title =~ s/\$domain/$domain/;
		    
		    $tpl->assign(TITLE => $page_title);
		    $tpl->define(record => 'txt/edit.tpl');
		    $tpl->assign(HOST_VALUE => encode_entities(apr()->param('host')));
		    $tpl->assign(TXT_VALUE => encode_entities(apr()->param('txtdata')));
		    $tpl->assign(TTL_VALUE => encode_entities(apr()->param('ttl')));

		    my $error_text = $lang{ERROR_CORRECT};

		    if (!($host = check_fqdn(apr()->param('host'), $domain))) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_HOST}};
		    }
		    if (!check_txt($txtdata)) {
			$tpl->assign(TXT => qq{<font color="red">} . $lang{TXT} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TXT}};
		    }
		    if (!check_ttl($ttl)) {
			$tpl->assign(TTL => qq{<font color="red">} . $lang{TTL} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_TTL}};
		    }
		    if ($all_set) {
			$tpl->assign(HOST => qq{<font color="red">} . $lang{HOST} . qq{</font>});
			$tpl->assign(TXT => qq{<font color="red">} . $lang{TXT} . qq{</font>});
			$error_text .= qq{<br>$lang{ERROR_DUPLICATE}};
		    }

		    $tpl->assign(EXPLANATION => $error_text);

		    $tpl->assign(DOM_ID => $dom_id);
		    $tpl->assign(RECORD_ID => $record_id);
		    
		    $tpl->parse(MENU => "menu");
		    $tpl->parse(MAIN => ["record", "layout"]);

		    my $content_ref = $tpl->fetch("MAIN");

		    output_headers($r, 1, length(${$content_ref}));
		    
		    $r->print(${$content_ref});	

                    $dbh->close();
		    return OK;
		}
	    }
	    else { 
	        Debug(1, qq{User trying to update an unexsisting type: $type\n});
	    }
	}
        output_redirect($r, 1, qq{/admin?action=view&dom_id=$dom_id});
	$dbh->close();
	return REDIRECT;
    } else {
	# is view
        Debug(5, qq{This is a view of edit_record request});    

        my $tpl = new CGI::FastTemplate($cfg->{'cfg'}->{DnsZoneTemplateDir});
        $tpl->define(layout => 'layout.tpl', menu => 'menu.tpl');
        $tpl->assign(%lang);
        $tpl->assign(DEBUG => '');
	
	if ($dbh->get_domain_count($uid) == 1) {
	    $tpl->assign(ADDITIONAL_MENU => '');
	} else {
	    $tpl->assign(ADDITIONAL_MENU => qq{<a href="/admin?action=default">$lang{LIST_DOMAIN}</a> | });
	}

        my $page_title = $lang{PAGE_EDIT};
        $page_title =~ s/\$record/$type/;
        $page_title =~ s/\$domain/$domain/;

        $tpl->assign(TITLE => $page_title);
	$tpl->assign(EXPLANATION => $lang{EDIT_FIELDS});
	for ($type) {
	    if (/^SOA$/) {
		my ($auth_ns, $soa_email, $serial, $refresh, $retry, $expire, $default_ttl) = $dbh->soa_lookup($dom_id);
		$soa_email =~ s/\./\@/;	    
		$tpl->define(record => 'soa/edit.tpl');
		$tpl->assign(AUTH_NS_VALUE => $auth_ns);
		$tpl->assign(SERIAL_VALUE => $serial);
		$tpl->assign(ADMIN_EMAIL_VALUE => $soa_email);
		$tpl->assign(REFRESH_VALUE => $refresh);
		$tpl->assign(RETRY_VALUE => $retry);
		$tpl->assign(EXPIRE_VALUE => $expire);



( run in 0.676 second using v1.01-cache-2.11-cpan-5735350b133 )