1 package FS::domain_record;
5 #use FS::Record qw( qsearch qsearchs );
6 use FS::Record qw( qsearchs );
13 FS::domain_record - Object methods for domain_record records
17 use FS::domain_record;
19 $record = new FS::domain_record \%hash;
20 $record = new FS::domain_record { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::domain_record object represents an entry in a DNS zone.
33 FS::domain_record inherits from FS::Record. The following fields are currently
38 =item recnum - primary key
40 =item svcnum - Domain (see L<FS::svc_domain>) of this entry
42 =item reczone - partial (or full) zone for this entry
44 =item recaf - address family for this entry, currently only `IN' is recognized.
46 =item rectype - record type for this entry (A, MX, etc.)
48 =item recdata - data for this entry
58 Creates a new entry. To add the example to the database, see L<"insert">.
60 Note that this stores the hash reference, not a distinct copy of the hash it
61 points to. You can ask the object for a copy with the I<hash> method.
65 sub table { 'domain_record'; }
69 Adds this record to the database. If there is an error, returns the error,
70 otherwise returns false.
76 Delete this record from the database.
80 =item replace OLD_RECORD
82 Replaces the OLD_RECORD with this one in the database. If there is an error,
83 returns the error, otherwise returns false.
89 Checks all fields to make sure this is a valid example. If there is
90 an error, returns the error, otherwise returns false. Called by the insert
95 # the check method should currently be supplied - FS::Record contains some
96 # data checking routines
102 $self->ut_numbern('recnum')
103 || $self->ut_number('svcnum')
105 return $error if $error;
107 return "Unknown svcnum (in svc_domain)"
108 unless qsearchs('svc_domain', { 'svcnum' => $self->svcnum } );
110 $self->reczone =~ /^(@|[a-z0-9\.\-]+)$/
111 or return "Illegal reczone: ". $self->reczone;
114 $self->recaf =~ /^(IN)$/ or return "Illegal recaf: ". $self->recaf;
117 $self->rectype =~ /^(SOA|NS|MX|A|PTR|CNAME)$/
118 or return "Illegal rectype (only SOA NS MX A PTR CNAME recognized): ".
122 if ( $self->rectype eq 'SOA' ) {
123 my $recdata = $self->recdata;
124 $recdata =~ s/\s+/ /g;
125 $recdata =~ /^([a-z0-9\.\-]+ [\w\-\+]+\.[a-z0-9\.\-]+ \( (\d+ ){5}\))$/
126 or return "Illegal data for SOA record: $recdata";
128 } elsif ( $self->rectype eq 'NS' ) {
129 $self->recdata =~ /^([a-z0-9\.\-]+)$/
130 or return "Illegal data for NS record: ". $self->recdata;
132 } elsif ( $self->rectype eq 'MX' ) {
133 $self->recdata =~ /^(\d+)\s+([a-z0-9\.\-]+)$/
134 or return "Illegal data for MX record: ". $self->recdata;
135 $self->recdata("$1 $2");
136 } elsif ( $self->rectype eq 'A' ) {
137 $self->recdata =~ /^((\d{1,3}\.){3}\d{1,3})$/
138 or return "Illegal data for A record: ". $self->recdata;
140 } elsif ( $self->rectype eq 'PTR' ) {
141 $self->recdata =~ /^([a-z0-9\.\-]+)$/
142 or return "Illegal data for PTR record: ". $self->recdata;
144 } elsif ( $self->rectype eq 'CNAME' ) {
145 $self->recdata =~ /^([a-z0-9\.\-]+)$/
146 or return "Illegal data for CNAME record: ". $self->recdata;
159 $Id: domain_record.pm,v 1.3 2001-08-21 02:44:47 ivan Exp $
163 The data validation doesn't check everything it could. In particular,
164 there is no protection against bad data that passes the regex, duplicate
165 SOA records, forgetting the trailing `.', impossible IP addersses, etc. Of
166 course, it's still better than editing the zone files directly. :)
170 L<FS::Record>, schema.html from the base documentation.