2 use base qw(FS::svc_Common);
5 use vars qw($conf $apacheip);
6 #use FS::Record qw( qsearch qsearchs );
7 use FS::Record qw( qsearchs dbh );
10 use FS::domain_record;
14 #ask FS::UID to run this stuff for us later
15 $FS::UID::callback{'FS::svc_www'} = sub {
17 $apacheip = $conf->config('apacheip');
22 FS::svc_www - Object methods for svc_www records
28 $record = new FS::svc_www \%hash;
29 $record = new FS::svc_www { 'column' => 'value' };
31 $error = $record->insert;
33 $error = $new_record->replace($old_record);
35 $error = $record->delete;
37 $error = $record->check;
39 $error = $record->suspend;
41 $error = $record->unsuspend;
43 $error = $record->cancel;
47 An FS::svc_www object represents an web virtual host. FS::svc_www inherits
48 from FS::svc_Common. The following fields are currently supported:
52 =item svcnum - primary key
54 =item recnum - DNS `A' record corresponding to this web virtual host. (see L<FS::domain_record>)
56 =item usersvc - account (see L<FS::svc_acct>) corresponding to this web virtual host.
66 Creates a new web virtual host. To add the record to the database, see
69 Note that this stores the hash reference, not a distinct copy of the hash it
70 points to. You can ask the object for a copy with the I<hash> method.
77 'name_plural' => 'Virtual hosting services',
78 'display_weight' => 40,
79 'cancel_weight' => 20,
85 sub table { 'svc_www'; }
87 =item label [ END_TIMESTAMP [ START_TIMESTAMP ] ]
89 Returns the zone name for this virtual host.
91 END_TIMESTAMP and START_TIMESTAMP can optionally be passed when dealing with
98 $self->domain_record(@_)->zone;
101 =item insert [ , OPTION => VALUE ... ]
103 Adds this record to the database. If there is an error, returns the error,
104 otherwise returns false.
106 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
107 defined. An FS::cust_svc record will be created and inserted.
109 Currently available options are: I<depend_jobnum>
111 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
112 jobnums), all provisioning jobs will have a dependancy on the supplied
113 jobnum(s) (they will not run until the specific job(s) complete(s)).
120 #return '' unless $self->recnum =~ /^([\w\-]+|\@)\.(([\w\.\-]+\.)+\w+)$/;
121 return '' unless $self->recnum =~ /^([\w\-]+|\@)\.(\d+)$/;
123 my( $reczone, $domain_svcnum ) = ( $1, $2 );
124 unless ( $apacheip ) {
125 return "Configuration option apacheip not set; can't autocreate A record";
126 #"for $reczone". $svc_domain->domain;
128 my $domain_record = new FS::domain_record {
129 'svcnum' => $domain_svcnum,
130 'reczone' => $reczone,
133 'recdata' => $apacheip,
135 my $error = $domain_record->insert;
136 return $error if $error;
138 $self->recnum($domain_record->recnum);
144 Delete this record from the database.
152 $error = $self->SUPER::delete(@_);
153 return $error if $error;
158 =item replace OLD_RECORD
160 Replaces the OLD_RECORD with this one in the database. If there is an error,
161 returns the error, otherwise returns false.
166 # my ( $new, $old ) = ( shift, shift );
169 # $error = $new->SUPER::replace($old, @_);
170 # return $error if $error;
177 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
181 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
185 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
189 Checks all fields to make sure this is a valid web virtual host. If there is
190 an error, returns the error, otherwise returns false. Called by the insert
198 my $x = $self->setfixed;
199 return $x unless ref($x);
203 $self->ut_numbern('svcnum')
204 # || $self->ut_number('recnum')
205 || $self->ut_numbern('usersvc')
206 || $self->ut_anything('config')
208 return $error if $error;
210 if ( $self->recnum =~ /^(\d+)$/ ) {
213 return "Unknown recnum: ". $self->recnum
214 unless qsearchs('domain_record', { 'recnum' => $self->recnum } );
216 } elsif ( $self->recnum =~ /^([\w\-]+|\@)\.(([\w\.\-]+\.)+\w+)$/ ) {
218 my( $reczone, $domain ) = ( $1, $2 );
220 my $svc_domain = qsearchs( 'svc_domain', { 'domain' => $domain } )
221 or return "unknown domain $domain (recnum $1.$2)";
223 my $domain_record = qsearchs( 'domain_record', {
224 'reczone' => $reczone,
225 'svcnum' => $svc_domain->svcnum,
228 if ( $domain_record ) {
229 $self->recnum($domain_record->recnum);
231 #insert will create it
232 #$self->recnum("$reczone.$domain");
233 $self->recnum("$reczone.". $svc_domain->svcnum);
237 return "Illegal recnum: ". $self->recnum;
240 if ( $self->usersvc ) {
241 return "Unknown usersvc0 (svc_acct.svcnum): ". $self->usersvc
242 unless qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
251 Returns the FS::domain_record record for this web virtual host's zone (see
252 L<FS::domain_record>).
256 Returns the FS::svc_acct record for this web virtual host's owner (see
263 qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
272 L<FS::svc_Common>, L<FS::Record>, L<FS::domain_record>, L<FS::cust_svc>,
273 L<FS::part_svc>, L<FS::cust_pkg>, schema.html from the base documentation.