apache export!
authorivan <ivan>
Thu, 20 Mar 2003 03:41:03 +0000 (03:41 +0000)
committerivan <ivan>
Thu, 20 Mar 2003 03:41:03 +0000 (03:41 +0000)
FS/FS/domain_record.pm
FS/FS/part_export.pm
FS/FS/part_export/apache.pm [new file with mode: 0644]
FS/MANIFEST
FS/t/part_export-apache.t [new file with mode: 0644]
bin/apache.export [new file with mode: 0755]
bin/bind.export
bin/bsdshell.export
bin/sysvshell.export

index 37cc6c9..3297e6b 100644 (file)
@@ -261,7 +261,7 @@ sub check {
       or return "Illegal data for PTR record: ". $self->recdata;
     $self->recdata($1);
   } elsif ( $self->rectype eq 'CNAME' ) {
       or return "Illegal data for PTR record: ". $self->recdata;
     $self->recdata($1);
   } elsif ( $self->rectype eq 'CNAME' ) {
-    $self->recdata =~ /^([a-z0-9\.\-]+)$/i
+    $self->recdata =~ /^([a-z0-9\.\-]+|\@)$/i
       or return "Illegal data for CNAME record: ". $self->recdata;
     $self->recdata($1);
   } elsif ( $self->rectype eq '_mstr' ) {
       or return "Illegal data for CNAME record: ". $self->recdata;
     $self->recdata($1);
   } elsif ( $self->rectype eq '_mstr' ) {
@@ -313,7 +313,7 @@ sub svc_domain {
 
 =head1 VERSION
 
 
 =head1 VERSION
 
-$Id: domain_record.pm,v 1.11 2002-06-23 19:16:45 ivan Exp $
+$Id: domain_record.pm,v 1.12 2003-03-20 03:41:03 ivan Exp $
 
 =head1 BUGS
 
 
 =head1 BUGS
 
index d62bef5..b46d843 100644 (file)
@@ -604,7 +604,7 @@ tie my %shellcommands_withdomain_options, 'Tie::IxHash',
 ;
 
 tie my %www_shellcommands_options, 'Tie::IxHash',
 ;
 
 tie my %www_shellcommands_options, 'Tie::IxHash',
-  'user' => { lable=>'Remote username', default=>'root' },
+  'user' => { label=>'Remote username', default=>'root' },
   'useradd' => { label=>'Insert command',
                  default=>'mkdir /var/www/$zone; chown $username /var/www/$zone; ln -s /var/www/$zone $homedir/$zone',
                },
   'useradd' => { label=>'Insert command',
                  default=>'mkdir /var/www/$zone; chown $username /var/www/$zone; ln -s /var/www/$zone $homedir/$zone',
                },
@@ -616,6 +616,27 @@ tie my %www_shellcommands_options, 'Tie::IxHash',
                 },
 ;
 
                 },
 ;
 
+tie my %apache_options, 'Tie::IxHash',
+  'user'       => { label=>'Remote username', default=>'root' },
+  'httpd_conf' => { label=>'httpd.conf snippet location',
+                    default=>'/etc/apache/httpd-freeside.conf', },
+  'template'   => {
+    label   => 'Template',
+    type    => 'textarea',
+    default => <<'END',
+<VirtualHost $domain> #generic
+#<VirtualHost ip.addr> #preferred, http://httpd.apache.org/docs/dns-caveats.html
+DocumentRoot /var/www/$zone
+ServerName $zone
+ServerAlias *.$zone
+#BandWidthModule On
+#LargeFileLimit 4096 12288
+</VirtualHost>
+
+END
+  },
+;
+
 tie my %domain_shellcommands_options, 'Tie::IxHash',
   'user' => { lable=>'Remote username', default=>'root' },
   'useradd' => { label=>'Insert command',
 tie my %domain_shellcommands_options, 'Tie::IxHash',
   'user' => { lable=>'Remote username', default=>'root' },
   'useradd' => { label=>'Insert command',
@@ -894,6 +915,11 @@ tie my %ldap_options, 'Tie::IxHash',
       'notes'    => 'Run remote commands via SSH, for virtual web sites.  You will need to <a href="../docs/ssh.html">setup SSH for unattended operation</a>.',
     },
 
       'notes'    => 'Run remote commands via SSH, for virtual web sites.  You will need to <a href="../docs/ssh.html">setup SSH for unattended operation</a>.',
     },
 
+    'apache' => {
+      'desc' => 'Export an Apache httpd.conf file snippet.',
+      'options' => \%apache_options,
+      'notes' => 'Batch export of an httpd.conf snippet from a template.  Typically used with something like <code>Include /etc/apache/httpd-freeside.conf</code> in httpd.conf.  <a href="http://search.cpan.org/search?dist=File-Rsync">File::Rsync</a> must be installed.  Run bin/apache.export to export the files.',
+    },
   },
 
   'svc_broadband' => {
   },
 
   'svc_broadband' => {
diff --git a/FS/FS/part_export/apache.pm b/FS/FS/part_export/apache.pm
new file mode 100644 (file)
index 0000000..b72c9bd
--- /dev/null
@@ -0,0 +1,7 @@
+package FS::part_export::bind;
+
+use vars qw(@ISA);
+use FS::part_export::null;
+
+@ISA = qw(FS::part_export::null);
+
index 7822865..32a4e4f 100644 (file)
@@ -66,6 +66,7 @@ FS/part_bill_event.pm
 FS/export_svc.pm
 FS/part_export.pm
 FS/part_export_option.pm
 FS/export_svc.pm
 FS/part_export.pm
 FS/part_export_option.pm
+FS/part_export/apache.pm
 FS/part_export/bind.pm
 FS/part_export/bind_slave.pm
 FS/part_export/bsdshell.pm
 FS/part_export/bind.pm
 FS/part_export/bind_slave.pm
 FS/part_export/bsdshell.pm
diff --git a/FS/t/part_export-apache.t b/FS/t/part_export-apache.t
new file mode 100644 (file)
index 0000000..b999508
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::part_export::apache;
+$loaded=1;
+print "ok 1\n";
diff --git a/bin/apache.export b/bin/apache.export
new file mode 100755 (executable)
index 0000000..6142c92
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -w
+
+use strict;
+#use File::Path;
+use File::Rsync;
+use Net::SSH qw(ssh);
+use FS::UID qw(adminsuidsetup datasrc);
+use FS::Record qw(qsearch qsearchs);
+use FS::part_export;
+use FS::cust_svc;
+use FS::svc_www;
+
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+#needs the export number in there somewhere too...?
+my $spooldir = "/usr/local/etc/freeside/export.". datasrc. "/apache";
+mkdir $spooldir, 0700 unless -d $spooldir;
+
+my @exports = qsearch('part_export', { 'exporttype' => 'apache' } );
+
+my $rsync = File::Rsync->new({
+  rsh     => 'ssh',
+#  dry_run => 1,
+});
+
+foreach my $export ( @exports ) {
+
+  my $machine = $export->machine;
+  my $file = "$spooldir/$machine.conf";
+
+  open(HTTPD_CONF,">$file") or die "can't open $file: $!";
+
+  my $template = $export->option('template');
+
+  my @svc_www = $export->svc_x;
+
+  foreach my $svc_www ( @svc_www ) {
+    use vars qw($zone $username);
+    $zone = $svc_www->domain_record->zone;
+    $username = $svc_www->svc_acct->username;
+    print HTTPD_CONF eval(qq("$template"));
+  }
+
+  my $user = $export->option('user');
+  my $httpd_conf = $export->option('httpd_conf')
+
+  $rsync->exec( {
+    src       => $file,
+    dest      => "$user\@$machine:$httpd_conf",
+  } ) or die "rsync to $machine failed: ". join(" / ", $rsync->err);
+ # warn $rsync->out;
+
+  ssh("root\@$machine", 'ndc reload');
+
+}
+
+close NAMED_CONF;
+
+# -----
+
+sub usage {
+  die "Usage:\n  export.export user\n"; 
+}
+
index 943aefb..055782a 100755 (executable)
@@ -46,12 +46,7 @@ foreach my $export ( @exports ) {
   my $zonepath = $export->option('zonepath');
   $zonepath =~ s/\/$//;
 
   my $zonepath = $export->option('zonepath');
   $zonepath =~ s/\/$//;
 
-  #false laziness with  freeside-sqlradius-reset and shell.export
-  my @svc_domain =
-    map { qsearchs('svc_domain', { 'svcnum' => $_->svcnum } ) }
-      map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
-        grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
-          $export->export_svc;
+  my @svc_domain = $export->svc_x;
 
   foreach my $svc_domain ( @svc_domain ) {
     my $domain = $svc_domain->domain;
 
   foreach my $svc_domain ( @svc_domain ) {
     my $domain = $svc_domain->domain;
index 10c2767..6e0d103 100755 (executable)
@@ -43,12 +43,7 @@ foreach my $export ( @bsd_exports ) {
   chmod 0644, "$prefix/passwd";
   chmod 0600, "$prefix/master.passwd";
 
   chmod 0644, "$prefix/passwd";
   chmod 0600, "$prefix/master.passwd";
 
-  #false laziness with  freeside-sqlradius-reset and bind.export
-  my @svc_acct = 
-    map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) }
-      map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
-        grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
-          $export->export_svc;
+  my @svc_acct = $export->svc_x;
 
   next unless @svc_acct;
 
 
   next unless @svc_acct;
 
index 8597661..c13912c 100755 (executable)
@@ -43,12 +43,7 @@ foreach my $export ( @sysv_exports ) {
   chmod 0644, "$prefix/passwd";
   chmod 0600, "$prefix/shadow";
 
   chmod 0644, "$prefix/passwd";
   chmod 0600, "$prefix/shadow";
 
-  #false laziness with  freeside-sqlradius-reset and bind.export
-  my @svc_acct = 
-    map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) }
-      map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
-        grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) }
-          $export->export_svc;
+  my @svc_acct = $export->svc_x;
 
   next unless @svc_acct;
 
 
   next unless @svc_acct;