Apache-DnsZone

 view release on metacpan or  search on metacpan

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

    }; 
    if ($@) {
	$self->{'dbh'}->rollback();
	return 0;
    }
    return 1;
}

sub get_domain_count {
    my $self = shift;
    my $uid = shift;
    return $self->{'dbh'}->selectrow_array("select count(id) from domains where owner = ?", undef, $uid);
}

sub get_one_domain_id {
    my $self = shift;
    my $uid = shift;
    return $self->{'dbh'}->selectrow_array("select id from domains where owner = ?", undef, $uid);
}

sub is_valid_lang {
    my $self = shift;
    my $lang_id = shift;
    return $self->{'dbh'}->selectrow_array("select 1 from languages where id = ?", undef, $lang_id);
}

sub is_valid_abbrev {
    my $self = shift;
    my $lang_abbrev = shift;
    return $self->{'dbh'}->selectrow_array("select 1 from languages where abbrev = ?", undef, $lang_abbrev);
}

sub get_lang_from_abbrev {
    my $self = shift;
    my $lang_abbrev = shift;
    return $self->{'dbh'}->selectrow_array("select lang from languages where abbrev = ?", undef, $lang_abbrev);
}

sub lang_select_box {
    my $self = shift;
    my $uid = shift;
    my $lang_id = shift || 0;
    if ($lang_id == 0) {
	$lang_id = $self->get_user_lang_id($uid);
    }
    my $lang_select = qq{<select name="lang">\n};
    my $sth_lang = $self->{'dbh'}->prepare("select id,lang,language from languages order by language asc");
    $sth_lang->execute();
    while (my ($l_id, $l_lang, $l_language) = $sth_lang->fetchrow_array()) {
	$lang_select .= qq{<option value="$l_id"};
	if ($lang_id == $l_id) {
	    $lang_select .= qq{ selected};
	}
	$lang_select .= qq{>$l_language ($l_lang)</option>\n};
    }
    $sth_lang->finish();
    $lang_select .= qq{</select>\n};
    return $lang_select;
}

sub update_password {
    my $self = shift;
    my $uid = shift;
    my $password = shift;
    eval {
	my $sth_password_update = $self->{'dbh'}->prepare("update users set password = ? where id = ?");
	$sth_password_update->execute($password, $uid);
	$sth_password_update->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
	$self->{'dbh'}->rollback();
	return 0;
    }

    return 1;
}

sub domain_stat {
    my $self = shift;
    my $dom_id = shift;
    return $self->{'dbh'}->selectrow_array("select domain,owner from domains where id = ?", undef, $dom_id);
}

sub get_max_record_count {
    my $self = shift;
    my $dom_id = shift;
    return $self->{'dbh'}->selectrow_array("select A_count, AAAA_count, CNAME_count, MX_count, NS_count, PTR_count, TXT_count from rec_count where domain = ?", undef, $dom_id);
}

sub get_a_count {
    my $self = shift;
    my $dom_id = shift;
    return $self->{'dbh'}->selectrow_array("select count(id) from records_A where domain = ?", undef, $dom_id);
}

sub does_A_exist {
    my $self = shift;
    my $dom_id = shift;
    my $host = shift;
    return $self->{'dbh'}->selectrow_array("select count(id) from records_A where domain = ? and name = ?", undef, $dom_id, $host)
}

sub is_duplicate_A {
    my $self = shift;
    my $dom_id = shift;
    my $host = shift;
    my $address = shift;
    return $self->{'dbh'}->selectrow_array("select count(id) from records_A where domain = ? and name = ? and address = ?", undef, $dom_id, $host, $address)
}

sub get_aaaa_count {
    my $self = shift;
    my $dom_id = shift;
    return $self->{'dbh'}->selectrow_array("select count(id) from records_AAAA where domain = ?", undef, $dom_id);
}

sub does_AAAA_exist {
    my $self = shift;
    my $dom_id = shift;
    my $host = shift;

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

    $sth->execute($owner_id);
    return $sth;
}

sub view_domain_A_prepare {
    my $self = shift;
    my $dom_id = shift;
    my $sth = $self->{'dbh'}->prepare("select id, name, address, ttl, rec_lock from records_A where domain = ?");
    $sth->execute($dom_id);
    return $sth;
}

sub view_domain_AAAA_prepare {
    my $self = shift;
    my $dom_id = shift;
    my $sth = $self->{'dbh'}->prepare("select id, name, address, ttl, rec_lock from records_AAAA where domain = ?");
    $sth->execute($dom_id);
    return $sth;
}

sub view_domain_CNAME_prepare {
    my $self = shift;
    my $dom_id = shift;
    my $sth = $self->{'dbh'}->prepare("select id, name, cname, ttl, rec_lock from records_CNAME where domain = ?");
    $sth->execute($dom_id);
    return $sth;
}

sub view_domain_MX_prepare {
    my $self = shift;
    my $dom_id = shift;
    my $sth = $self->{'dbh'}->prepare("select id, name, exchanger, preference, ttl, rec_lock from records_MX where domain = ?");
    $sth->execute($dom_id);
    return $sth;
}

sub view_domain_NS_prepare {
    my $self = shift;
    my $dom_id = shift;
    my $sth = $self->{'dbh'}->prepare("select id, name, nsdname, ttl, rec_lock from records_NS where domain = ?");
    $sth->execute($dom_id);
    return $sth;
}

sub view_domain_PTR_prepare {
    my $self = shift;
    my $dom_id = shift;
    my $sth = $self->{'dbh'}->prepare("select id, name, ptrdname, ttl, rec_lock from records_PTR where domain = ?");
    $sth->execute($dom_id);
    return $sth;
}

sub view_domain_TXT_prepare {
    my $self = shift;
    my $dom_id = shift;
    my $sth = $self->{'dbh'}->prepare("select id, name, txtdata, ttl, rec_lock from records_TXT where domain = ?");
    $sth->execute($dom_id);
    return $sth;
}

sub update_serial_soa {
    my $self = shift;
    my $domain_id = shift;
    my $serial = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::update_serial_soa called});
    eval {
	my $sth = $self->{'dbh'}->prepare("update soa set serial = ? where domain = ?");
	$sth->execute($serial, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::update_SOA failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    return 1;
}

sub update_SOA {
    my $self = shift;
    my $domain_id = shift;
    my $serial = shift;
    my $soa_email = shift;
    my $refresh = shift;
    my $retry = shift;
    my $expire = shift;
    my $default_ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::update_SOA called});
    eval {
	my $sth = $self->{'dbh'}->prepare("update soa set email = ?, serial = ?, refresh = ?, retry = ?, expire = ?, default_ttl = ? where domain = ?");
	$sth->execute($soa_email, $serial, $refresh, $retry, $expire, $default_ttl, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::update_SOA failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    return 1;
}

sub set_A {
    my $self = shift;
    my $domain_id = shift;
    my $name = shift;
    my $ip = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::set_A called});
    eval {
	my $sth = $self->{'dbh'}->prepare("insert into records_A (id, domain, name, address, ttl) values (records_A_id.nextval, ?, ?, ?, ?)");
	$sth->execute($domain_id, $name, $ip, $ttl);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::set_A failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    return 1;
}

sub update_A {
    my $self = shift;
    my $domain_id = shift;
    my $a_id = shift;
    my $name = shift;
    my $ip = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::update_A called});
    eval {
	my $sth = $self->{'dbh'}->prepare("update records_A set name = ?, address = ?, ttl = ? where id = ? and domain = ?");
	$sth->execute($name, $ip, $ttl, $a_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::update_A failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub delete_A {
    my $self = shift;
    my $domain_id = shift;
    my $a_id = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::delete_A called});
    eval {
	my $sth = $self->{'dbh'}->prepare("delete from records_A where id = ? and domain = ?");
	$sth->execute($a_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::delete_A failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub set_AAAA {
    my $self = shift;
    my $domain_id = shift;
    my $name = shift;
    my $address = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::set_AAAA called});
    eval {
	my $sth = $self->{'dbh'}->prepare("insert into records_AAAA (id, domain, name, address, ttl) values (records_AAAA_id.nextval, ?, ?, ?, ?)");
	$sth->execute($domain_id, $name, $address, $ttl);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::set_AAAA failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    return 1;
}

sub update_AAAA {
    my $self = shift;
    my $domain_id = shift;
    my $aaaa_id = shift;
    my $name = shift;
    my $address = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::update_AAAA called});
    eval {
	my $sth = $self->{'dbh'}->prepare("update records_AAAA set name = ?, address = ?, ttl = ? where id = ? and domain = ?");
	$sth->execute($name, $address, $ttl, $aaaa_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::update_AAAA failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub delete_AAAA {
    my $self = shift;
    my $domain_id = shift;
    my $aaaa_id = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::delete_AAAA called});
    eval {
	my $sth = $self->{'dbh'}->prepare("delete from records_AAAA where id = ? and domain = ?");
	$sth->execute($aaaa_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::delete_AAAA failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub set_CNAME {
    my $self = shift;
    my $domain_id = shift;
    my $name = shift;
    my $cname = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::set_CNAME called});
    eval {
	my $sth = $self->{'dbh'}->prepare("insert into records_CNAME (id, domain, name, cname, ttl) values (records_CNAME_id.nextval, ?, ?, ?, ?)");
	$sth->execute($domain_id, $name, $cname, $ttl);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::set_CNAME failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub update_CNAME {
    my $self = shift;
    my $domain_id = shift;
    my $cname_id = shift;
    my $name = shift;
    my $cname = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::update_CNAME called});
    eval {
	my $sth = $self->{'dbh'}->prepare("update records_CNAME set name = ?, cname = ?, ttl = ? where id = ? and domain = ?");
	$sth->execute($name, $cname, $ttl, $cname_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::update_CNAME failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub delete_CNAME {
    my $self = shift;
    my $domain_id = shift;
    my $cname_id = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::delete_CNAME called});
    eval {
	my $sth = $self->{'dbh'}->prepare("delete from records_CNAME where id = ? and domain = ?");
	$sth->execute($cname_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::delete_CNAME failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub set_MX {
    my $self = shift;
    my $domain_id = shift;
    my $name = shift;
    my $exchanger = shift;
    my $preferece = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::set_MX called});
    eval {
	my $sth = $self->{'dbh'}->prepare("insert into records_MX (id, domain, name, exchanger, preference, ttl) values (records_MX_id.nextval, ?, ?, ?, ?, ?)");
	$sth->execute($domain_id, $name, $exchanger, $preferece, $ttl);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::set_MX failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub update_MX {
    my $self = shift;
    my $domain_id = shift;
    my $mx_id = shift;
    my $name = shift;
    my $exchanger = shift;
    my $preference = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::update_MX called});
    eval {
	my $sth = $self->{'dbh'}->prepare("update records_MX set name = ?, exchanger = ?, preference = ?, ttl = ? where id = ? and domain = ?");
	$sth->execute($name, $exchanger, $preference, $ttl, $mx_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::update_MX failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub delete_MX {
    my $self = shift;
    my $domain_id = shift;
    my $mx_id = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::delete_MX called});
    eval {
	my $sth = $self->{'dbh'}->prepare("delete from records_MX where id = ? and domain = ?");
	$sth->execute($mx_id, $domain_id);
	$sth->prepare();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::delete_MX failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub set_NS {
    my $self = shift;
    my $domain_id = shift;
    my $name = shift;
    my $ns = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::set_NS called});
    eval {
	my $sth = $self->{'dbh'}->prepare("insert into records_NS (id, domain, name, nsdname, ttl) values (records_NS_id.nextval, ?, ?, ?, ?)");
	$sth->execute($domain_id, $name, $ns, $ttl);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::set_NS failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub update_NS {
    my $self = shift;
    my $domain_id = shift;
    my $ns_id = shift;
    my $name = shift;
    my $ns = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::update_NS called});
    eval {
	my $sth = $self->{'dbh'}->prepare("update records_NS set name = ?, nsdname = ?, ttl = ? where id = ? and domain = ?");
	$sth->execute($name, $ns, $ttl, $ns_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::update_NS failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub delete_NS {
    my $self = shift;
    my $domain_id = shift;
    my $ns_id = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::delete_NS called});
    eval {
	my $sth = $self->{'dbh'}->prepare("delete from records_NS where id = ? and domain = ?");
	$sth->execute($ns_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::delete_NS failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub set_PTR {
    my $self = shift;
    my $domain_id = shift;
    my $name = shift;
    my $ptrdname = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::set_PTR called});
    eval {
	my $sth = $self->{'dbh'}->prepare("insert into records_PTR (domain, name, ptrdname, ttl) values (?, ?, ?, ?)");
	$sth->execute($domain_id, $name, $ptrdname, $ttl);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::set_PTR failed: $@});
        $self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub update_PTR {
    my $self = shift;
    my $domain_id = shift;
    my $ptr_id = shift;
    my $name = shift;
    my $ptrdname = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::update_PTR called});
    eval {
	my $sth = $self->{'dbh'}->prepare("update records_PTR set name = ?, ptrdname = ?, ttl = ? where id = ? and domain = ?");
	$sth->execute($name, $ptrdname, $ttl, $ptr_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::update_PTR failed: $@});
        $self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub delete_PTR {
    my $self = shift;
    my $domain_id = shift;
    my $ptr_id = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::delete_PTR called});
    eval {
	my $sth = $self->{'dbh'}->prepare("delete from records_PTR where id = ? and domain = ?");
	$sth->execute($ptr_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::delete_PTR failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub set_TXT {
    my $self = shift;
    my $domain_id = shift;
    my $name = shift;
    my $txt = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::set_TXT called});
    eval {
	my $sth = $self->{'dbh'}->prepare("insert into records_TXT (id, domain, name, txtdata, ttl) values (records_TXT_id.nextval, ?, ?, ?, ?)");
	$sth->execute($domain_id, $name, $txt, $ttl);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::set_TXT failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub update_TXT {
    my $self = shift;
    my $domain_id = shift;
    my $txt_id = shift;
    my $name = shift;
    my $txt = shift;
    my $ttl = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::update_TXT called});
    eval {
	my $sth = $self->{'dbh'}->prepare("update records_TXT set name = ?, txtdata = ?, ttl = ? where id = ? and domain = ?");
	$sth->execute($name, $txt, $ttl, $txt_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::update_TXT failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

sub delete_TXT {
    my $self = shift;
    my $domain_id = shift;
    my $txt_id = shift;
    Apache::DnsZone::Debug(5, qq{Apache::DnsZone::DB::delete_TXT called});
    eval {
	my $sth = $self->{'dbh'}->prepare("delete from records_TXT where id = ? and domain = ?");
	$sth->execute($txt_id, $domain_id);
	$sth->finish();
	$self->{'dbh'}->commit();
    };
    if ($@) {
        Apache::DnsZone::Debug(1, qq{Apache::DnsZone::DB::delete_TXT failed: $@});
	$self->{'dbh'}->rollback();
	return 0;
    }
    Apache::DnsZone::update_serial($domain_id);
    return 1;
}

1;



( run in 0.946 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )