4 use vars qw(@ISA $conf $apacheroot $apachemachine $nossh_hack );
5 #use FS::Record qw( qsearch qsearchs );
6 use FS::Record qw( qsearchs );
13 @ISA = qw( FS::svc_Common );
15 #ask FS::UID to run this stuff for us later
16 $FS::UID::callback{'FS::svc_www'} = sub {
18 $apacheroot = $conf->config('apacheroot');
19 $apachemachine = $conf->config('apachemachine');
24 FS::svc_www - Object methods for svc_www records
30 $record = new FS::svc_www \%hash;
31 $record = new FS::svc_www { 'column' => 'value' };
33 $error = $record->insert;
35 $error = $new_record->replace($old_record);
37 $error = $record->delete;
39 $error = $record->check;
41 $error = $record->suspend;
43 $error = $record->unsuspend;
45 $error = $record->cancel;
49 An FS::svc_www object represents an web virtual host. FS::svc_www inherits
50 from FS::svc_Common. The following fields are currently supported:
54 =item svcnum - primary key
56 =item recnum - DNS `A' record corresponding to this web virtual host. (see L<FS::domain_record))
58 =item usersvc - account (see L<FS::svc_acct>) corresponding to this web virtual host.
68 Creates a new web virtual host. To add the record to the database, see
71 Note that this stores the hash reference, not a distinct copy of the hash it
72 points to. You can ask the object for a copy with the I<hash> method.
76 sub table { 'svc_www'; }
80 Adds this record to the database. If there is an error, returns the error,
81 otherwise returns false.
83 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
84 defined. An FS::cust_svc record will be created and inserted.
86 If the configuration values (see L<FS::Conf>) I<apachemachine>, and
87 I<apacheroot> exist, the command:
89 mkdir $apacheroot/$zone;
90 chown $username $apacheroot/$zone;
91 ln -s $apacheroot/$zone $homedir/$zone
93 I<$zone> is the DNS A record pointed to by I<recnum>
94 I<$username> is the username pointed to by I<usersvc>
95 I<$homedir> is that user's home directory
97 is executed on I<apachemachine> via ssh. This behaviour can be surpressed by
98 setting $FS::svc_www::nossh_hack true.
106 $error = $self->SUPER::insert;
107 return $error if $error;
109 my $domain_record = qsearchs('domain_record', { 'recnum' => $self->recnum } ); # or die ?
110 my $zone = $domain_record->reczone;
112 unless ( $zone =~ /\.$/ ) {
113 my $dom_svcnum = $domain_record->svcnum;
114 my $svc_domain = qsearchs('svc_domain', { 'svcnum' => $dom_svcnum } );
116 $zone .= $svc_domain->domain;
119 my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
121 my $username = $svc_acct->username;
123 my $homedir = $svc_acct->dir;
133 ssh("root\@$apachemachine",
134 "mkdir $apacheroot/$zone; ".
135 "chown $username $apacheroot/$zone; ".
136 "ln -s $apacheroot/$zone $homedir/$zone"
145 Delete this record from the database.
153 $error = $self->SUPER::delete;
154 return $error if $error;
159 =item replace OLD_RECORD
161 Replaces the OLD_RECORD with this one in the database. If there is an error,
162 returns the error, otherwise returns false.
167 my ( $new, $old ) = ( shift, shift );
170 $error = $new->SUPER::replace($old);
171 return $error if $error;
178 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
182 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
186 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
190 Checks all fields to make sure this is a valid example. If there is
191 an error, returns the error, otherwise returns false. Called by the insert
199 my $x = $self->setfixed;
200 return $x unless ref($x);
204 $self->ut_numbern('svcnum')
205 || $self->ut_number('recnum')
206 || $self->ut_number('usersvc')
208 return $error if $error;
210 return "Unknown recnum: ". $self->recnum
211 unless qsearchs('domain_record', { 'recnum' => $self->recnum } );
213 return "Unknown usersvc (svc_acct.svcnum): ". $self->usersvc
214 unless qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
223 $Id: svc_www.pm,v 1.2 2000-03-01 08:13:59 ivan Exp $
229 L<FS::svc_Common>, L<FS::Record>, L<FS::domain_record>, L<FS::cust_svc>,
230 L<FS::part_svc>, L<FS::cust_pkg>, schema.html from the base documentation.
235 Revision 1.2 2000-03-01 08:13:59 ivan
238 Revision 1.1 2000/02/03 05:16:52 ivan
239 beginning of DNS and Apache support