diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/bind.export | 15 | ||||
-rwxr-xr-x | bin/bind.import | 2 | ||||
-rw-r--r-- | bin/create-fetchmailrc | 47 | ||||
-rwxr-xr-x | bin/create-history-tables | 13 | ||||
-rwxr-xr-x | bin/dbdef-create | 4 | ||||
-rwxr-xr-x | bin/fix-sequences | 69 | ||||
-rwxr-xr-x | bin/masonize | 6 | ||||
-rwxr-xr-x | bin/passwd.import | 2 | ||||
-rwxr-xr-x | bin/svc_acct_sm.import | 262 |
9 files changed, 273 insertions, 147 deletions
diff --git a/bin/bind.export b/bin/bind.export index 64d44065d..055782a20 100755 --- a/bin/bind.export +++ b/bin/bind.export @@ -30,10 +30,6 @@ foreach my $export ( @exports ) { my $machine = $export->machine; my $prefix = "$spooldir/$machine"; - my $bind_rel = $export->option('bind_release'); - my $ndc_cmd = ($bind_rel eq 'BIND9') ? 'rndc' : 'ndc'; - my $minttl = $export->option('bind9_minttl'); - #prevent old domain files from piling up #rmtree "$prefix" or die "can't rmtree $prefix.db: $!"; @@ -83,10 +79,6 @@ END open (DB_MASTER,">$prefix/db.$domain") or die "can't open $prefix/db.$domain: $!"; - if ($bind_rel eq 'BIND9') { - print DB_MASTER "\$TTL $minttl\n\$ORIGIN $domain.\n"; - } - my @domain_records = qsearch('domain_record', { 'svcnum' => $svc_domain->svcnum } ); foreach my $domain_record ( @@ -122,7 +114,7 @@ END } ) or die "rsync to $machine failed: ". join(" / ", $rsync->err); # warn $rsync->out; - ssh("root\@$machine", "$ndc_cmd reload"); + ssh("root\@$machine", 'ndc reload'); } @@ -133,9 +125,6 @@ foreach my $sexport ( @sexports ) { #false laziness with above my $machine = $sexport->machine; my $prefix = "$spooldir/$machine"; - my $bind_rel = $sexport->option('bind_release'); - my $ndc_cmd = ($bind_rel eq 'BIND9') ? 'rndc' : 'ndc'; - #prevent old domain files from piling up #rmtree "$prefix" or die "can't rmtree $prefix.db: $!"; @@ -177,7 +166,7 @@ END } ) or die "rsync to $machine failed: ". join(" / ", $rsync->err); # warn $rsync->out; - ssh("root\@$machine", "$ndc_cmd reload"); + ssh("root\@$machine", 'ndc reload'); } close NAMED_CONF; diff --git a/bin/bind.import b/bin/bind.import index 3287b0183..8f6ca3011 100755 --- a/bin/bind.import +++ b/bin/bind.import @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: bind.import,v 1.4 2004-02-12 10:44:11 ivan Exp $ +# $Id: bind.import,v 1.3.4.1 2004-02-12 10:44:13 ivan Exp $ #need to manually put header in /usr/local/etc/freeside/export.<datasrc./bind/<machine>/named.conf.HEADER diff --git a/bin/create-fetchmailrc b/bin/create-fetchmailrc deleted file mode 100644 index 11bde0ce3..000000000 --- a/bin/create-fetchmailrc +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/perl -w -# this quick hack helps you generate/maintain .fetchmailrc files from -# FS::acct_snarf data. it is run from a shellcommands export as: -# create-fetchmailrc $username $dir $snarf_machine1 $snarf_username1 $snarf__password1 $snarf_machine2 $snarf_username2 $snarf__password2 ... - -use strict; -use POSIX qw( setuid setgid ); - -my $header = <<END; -# Configuration created by create-fetchmailrc -set postmaster "postmaster" -set bouncemail -set no spambounce -set properties "" -set daemon 240 -END - -my $username = shift @ARGV or die "no username specified\n"; -my $homedir = shift @ARGV or die "no homedir specified\n"; -my $filename = "$homedir/.fetchmailrc"; - -my $gid = scalar(getgrnam($username)) or die "can't find $username's gid\n"; -my $uid = scalar(getpwnam($username)) or die "can't find $username's uid\n"; - -exit unless $ARGV[0]; - -open(FETCHMAILRC, ">$filename") or die "can't open $filename: $!\n"; -chown $uid, $gid, $filename or die "can't chown $uid.$gid $filename: $!\n"; -chmod 0600, $filename or die "can't chmod 600 $filename: $!\n"; -print FETCHMAILRC $header; - -while ($ARGV[0]) { - my( $s_machine, $s_username, $s_password ) = splice( @ARGV, 0, 3 ); - print FETCHMAILRC <<END; -poll $s_machine - user '$s_username' there with password '$s_password' is '$username' here -END -} - -close FETCHMAILRC; - -setgid($gid) or die "can't setgid $gid\n"; -setuid($uid) or die "can't setuid $uid\n"; -$ENV{HOME} = $homedir; - -system(qq(fetchmail -a -K --antispam "550,451" -d 180 -f $filename)); - diff --git a/bin/create-history-tables b/bin/create-history-tables index 39248bf3f..c610e70cf 100755 --- a/bin/create-history-tables +++ b/bin/create-history-tables @@ -2,7 +2,7 @@ use strict; use DBI; -use DBIx::DBSchema 0.21; +use DBIx::DBSchema 0.20; use DBIx::DBSchema::Table; use DBIx::DBSchema::Column; use DBIx::DBSchema::ColGroup::Unique; @@ -65,16 +65,7 @@ foreach my $table ( @tables ) { 'default' => '', 'local' => '', } ), - map { - my $column = $tableobj->column($_); - $column->type('int') - if $column->type eq 'serial'; - $column->default('') - if $column->default =~ /^nextval\(/i; - ( my $local = $column->local ) =~ s/AUTO_INCREMENT//i; - $column->local($local); - $column; - } $tableobj->columns + map { $tableobj->column($_) } $tableobj->columns ], } ); foreach my $statement ( $h_tableobj->sql_create_table($dbh) ) { diff --git a/bin/dbdef-create b/bin/dbdef-create index a449d67cc..0b297b9e6 100755 --- a/bin/dbdef-create +++ b/bin/dbdef-create @@ -1,8 +1,10 @@ #!/usr/bin/perl -Tw +# +# $Id: dbdef-create,v 1.5 2001-08-21 02:43:18 ivan Exp $ use strict; use DBI; -use DBIx::DBSchema 0.22; +use DBIx::DBSchema; use FS::UID qw(adminsuidsetup datasrc driver_name); my $user = shift or die &usage; diff --git a/bin/fix-sequences b/bin/fix-sequences deleted file mode 100755 index 2ff89d3e5..000000000 --- a/bin/fix-sequences +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/perl -Tw - -# run dbdef-create first! - -use strict; -use DBI; -use DBIx::DBSchema 0.21; -use DBIx::DBSchema::Table; -use DBIx::DBSchema::Column; -use DBIx::DBSchema::ColGroup::Unique; -use DBIx::DBSchema::ColGroup::Index; -use FS::UID qw(adminsuidsetup driver_name); -use FS::Record qw(dbdef); - -my $user = shift or die &usage; -my $dbh = adminsuidsetup $user; - -my $schema = dbdef(); - -#false laziness w/fs-setup -my @tables = scalar(@ARGV) - ? @ARGV - : grep { ! /^h_/ } $schema->tables; -foreach my $table ( @tables ) { - my $tableobj = $schema->table($table) - or die "unknown table $table (did you run dbdef-create?)\n"; - - my $primary_key = $tableobj->primary_key; - next unless $primary_key; - - my $col = $tableobj->column($primary_key); - - - next unless uc($col->type) eq 'SERIAL' - || ( driver_name eq 'Pg' - && defined($col->default) - && $col->default =~ /^nextval\(/i - ) - || ( driver_name eq 'mysql' - && defined($col->local) - && $col->local =~ /AUTO_INCREMENT/i - ); - - my $seq = "${table}_${primary_key}_seq"; - if ( driver_name eq 'Pg' - && defined($col->default) - && $col->default =~ /^nextval\('"(public\.)?(\w+_seq)"'::text\)$/ - ) { - $seq = $2; - } - - warn "fixing sequence for $table\n"; - - - my $sql = "SELECT setval( '$seq', - ( SELECT max($primary_key) FROM $table ) );"; - - #warn $col->default. " $seq\n$sql\n"; - $dbh->do( $sql ) or die $dbh->errstr; - -} - -$dbh->commit or die $dbh->errstr; -$dbh->disconnect or die $dbh->errstr; - -sub usage { - die "Usage:\n fix-sequences user [ table table ... ] \n"; -} - diff --git a/bin/masonize b/bin/masonize index 3139e0af5..475c9a6bf 100755 --- a/bin/masonize +++ b/bin/masonize @@ -1,7 +1,6 @@ #!/usr/bin/perl -foreach $file ( split(/\n/, `find . -depth -print`) ) { - next unless $file =~ /(cgi|html)$/; +foreach $file ( split(/\n/, `find . -depth -print | grep cgi\$`) ) { open(F,$file) or die "can't open $file for reading: $!"; @file = <F>; #print "$file ". scalar(@file). "\n"; @@ -9,7 +8,6 @@ foreach $file ( split(/\n/, `find . -depth -print`) ) { system("chmod u+w $file"); open(W,">$file") or die "can't open $file for writing: $!"; select W; $| = 1; select STDOUT; - $newline = ''; #avoid prepending extraneous newlines $all = join('',@file); $mode = 'html'; @@ -28,7 +26,7 @@ foreach $file ( split(/\n/, `find . -depth -print`) ) { #die; next; } elsif ( $all =~ /^<%(.*)$/s ) { - print W $newline; $newline = "\n"; + print W "\n"; $all = $1; $mode = 'perlc'; next; diff --git a/bin/passwd.import b/bin/passwd.import index 093f8bafd..df53b50ad 100755 --- a/bin/passwd.import +++ b/bin/passwd.import @@ -1,5 +1,5 @@ #!/usr/bin/perl -Tw -# $Id: passwd.import,v 1.8 2003-06-12 14:08:00 ivan Exp $ +# $Id: passwd.import,v 1.5.4.3 2003-06-12 14:08:02 ivan Exp $ use strict; use vars qw(%part_svc); diff --git a/bin/svc_acct_sm.import b/bin/svc_acct_sm.import new file mode 100755 index 000000000..b668405f5 --- /dev/null +++ b/bin/svc_acct_sm.import @@ -0,0 +1,262 @@ +#!/usr/bin/perl -Tw +# +# $Id: svc_acct_sm.import,v 1.10 2001-08-21 02:43:18 ivan Exp $ + +use strict; +use vars qw(%d_part_svc %m_part_svc); +use Term::Query qw(query); +use Net::SCP qw(iscp); +use FS::UID qw(adminsuidsetup datasrc); +use FS::Record qw(qsearch qsearchs); +use FS::svc_acct_sm; +use FS::svc_domain; +use FS::svc_acct; +use FS::part_svc; + +my $user = shift or die &usage; +adminsuidsetup $user; + +my($spooldir)="/usr/local/etc/freeside/export.". datasrc; + +my(%mta) = ( + 1 => "qmail", + 2 => "sendmail", +); + +### + +%d_part_svc = + map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_domain'}); +%m_part_svc = + map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct_sm'}); + +die "No services with svcdb svc_domain!\n" unless %d_part_svc; +die "No services with svcdb svc_svc_acct_sm!\n" unless %m_part_svc; + +print "\n\n", + ( join "\n", map "$_: ".$d_part_svc{$_}->svc, sort keys %d_part_svc ), + "\n\n"; +$^W=0; #Term::Query isn't -w-safe +my $domain_svcpart = + query "Enter part number for domains: ", 'irk', [ keys %d_part_svc ]; +$^W=1; + +print "\n\n", + ( join "\n", map "$_: ".$m_part_svc{$_}->svc, sort keys %m_part_svc ), + "\n\n"; +$^W=0; #Term::Query isn't -w-safe +my $mailalias_svcpart = + query "Enter part number for mail aliases: ", 'irk', [ keys %m_part_svc ]; +$^W=1; + +print "\n\n", <<END; +Select your MTA from the following list. +END +print join "\n", map "$_: $mta{$_}", sort keys %mta; +print "\n\n"; +$^W=0; #Term::Query isn't -w-safe +my $mta = query ":", 'irk', [ keys %mta ]; +$^W=1; + +if ( $mta{$mta} eq "qmail" ) { + + print "\n\n", <<END; +Enter the location and name of your qmail control directory, for example +"mail.isp.com:/var/qmail/control" +END + my($control)=&getvalue(":"); + iscp("root\@$control/rcpthosts","$spooldir/rcpthosts.import"); +# iscp("root\@$control/recipientmap","$spooldir/recipientmap.import"); + iscp("root\@$control/virtualdomains","$spooldir/virtualdomains.import"); + +# print "\n\n", <<END; +#Enter the name of the machine with your user .qmail files, for example +#"mail.isp.com" +#END +# print ":"; +# my($shellmachine)=&getvalue; + +} elsif ( $mta{$mta} eq "sendmail" ) { + + print "\n\n", <<END; +Enter the location and name of your sendmail virtual user table, for example +"mail.isp.com:/etc/virtusertable" +END + my($virtusertable)=&getvalue(":"); + iscp("root\@$virtusertable","$spooldir/virtusertable.import"); + + print "\n\n", <<END; +Enter the location and name of your sendmail.cw file, for example +"mail.isp.com:/etc/sendmail.cw" +END + my($sendmail_cw)=&getvalue(":"); + iscp("root\@$sendmail_cw","$spooldir/sendmail.cw.import"); + +} else { + die "Unknown MTA!\n"; +} + +sub getvalue { + my $prompt = shift; + $^W=0; #Term::Query isn't -w-safe + my $data = query $prompt, ''; + $^W=1; + $data; +} + +print "\n\n"; + +### + +$FS::svc_domain::whois_hack=1; +$FS::svc_acct_sm::nossh_hack=1; + +if ( $mta{$mta} eq "qmail" ) { + open(RCPTHOSTS,"<$spooldir/rcpthosts.import") + or die "Can't open $spooldir/rcpthosts.import: $!"; +} elsif ( $mta{$mta} eq "sendmail" ) { + open(RCPTHOSTS,"<$spooldir/sendmail.cw.import") + or die "Can't open $spooldir/sendmail.cw.import: $!"; +} else { + die "Unknown MTA!\n"; +} + +my(%svcnum); + +while (<RCPTHOSTS>) { + next if /^(#|$)/; + next if $mta{$mta} eq 'sendmail' && /^\s*$/; #blank lines + /^\.?([\w\-\.]+)$/ + #or do { warn "Strange rcpthosts/sendmail.cw line: $_"; next; }; + or die "Strange rcpthosts/sendmail.cw line: $_"; + my $domain = $1; + my($svc_domain); + unless ( $svc_domain = qsearchs('svc_domain', {'domain'=>$domain} ) ) { + $svc_domain = new FS::svc_domain ({ + 'domain' => $domain, + 'svcpart' => $domain_svcpart, + 'action' => 'N', + }); + my $error = $svc_domain->insert; + #warn $error if $error; + die $error if $error; + } + $svcnum{$domain}=$svc_domain->svcnum; +} +close RCPTHOSTS; + +#these two loops have enough similar parts they should probably be merged +if ( $mta{$mta} eq "qmail" ) { + + open(VD_FIX,">$spooldir/virtualdomains.FIX"); + print VD_FIX "#!/usr/bin/perl\n"; + + open(VIRTUALDOMAINS,"<$spooldir/virtualdomains.import") + or die "Can't open $spooldir/virtualdomains.import: $!"; + while (<VIRTUALDOMAINS>) { + next if /^#/; + /^\.?([\w\-\.]+):(\w+)(\-([\w\-\.]+))?$/ + #or do { warn "Strange virtualdomains line: $_"; next; }; + or die "Strange virtualdomains line: $_"; + my($domain,$username,$dash_ext,$extension)=($1,$2,$3,$4); + $dash_ext ||= ''; + $extension ||= ''; + my($svc_acct)=qsearchs('svc_acct',{'username'=>$username}); + unless ( $svc_acct ) { + #warn "Unknown user $username in virtualdomains; skipping\n"; + #die "Unknown user $username in virtualdomains; skipping\n"; + next; + } + if ( $domain ne $extension ) { + #warn "virtualdomains line $domain:$username$dash_ext changed to $domain:$username-$domain\n"; + my($dir)=$svc_acct->dir; + my($qdomain)=$domain; + $qdomain =~ s/\./:/g; #see manpage for 'dot-qmail': EXTENSION ADDRESSES + #example to move .qmail files for virtual domains to their new location + #dry run + #issh("root\@$shellmachine",'perl -e \'foreach $a (<'. $dir. '/.qmail'. $dash_ext. '-*>) { $old=$a; $a =~ s/\\.qmail'. $dash_ext. '\\-/\\.qmail\\-'. $qdomain. '\\-/; print " $old -> $a\n"; }\''); + #the real thing + #issh("root\@$shellmachine",'perl -e \'foreach $a (<'. $dir. '/.qmail'. $dash_ext. '-*>) { $old=$a; $a =~ s/\\.qmail'. $dash_ext. '\\-/\\.qmail\\-'. $qdomain. '\\-/; rename $old, $a; }\''); + print VD_FIX <<END; +foreach \$file (<$dir/.qmail$dash_ext-*>) { + \$old = \$file; + \$file =~ s/\.qmail$dash_ext\-/\.qmail\-$qdomain\-/; + rename \$old, \$file; +} +END + } + + unless ( exists $svcnum{$domain} ) { + my($svc_domain) = new FS::svc_domain ({ + 'domain' => $domain, + 'svcpart' => $domain_svcpart, + 'action' => 'N', + }); + my $error = $svc_domain->insert; + #warn $error if $error; + die $error if $error; + $svcnum{$domain}=$svc_domain->svcnum; + } + + my($svc_acct_sm)=new FS::svc_acct_sm ({ + 'domsvc' => $svcnum{$domain}, + 'domuid' => $svc_acct->uid, + 'domuser' => '*', + 'svcpart' => $mailalias_svcpart, + }); + my($error)=''; + $error=$svc_acct_sm->insert; + #warn $error if $error; + die $error, ", domain $domain" if $error; + } + close VIRTUALDOMAINS; + close VD_FIX; + +} elsif ( $mta{$mta} eq "sendmail" ) { + + open(VIRTUSERTABLE,"<$spooldir/virtusertable.import") + or die "Can't open $spooldir/virtusertable.import: $!"; + while (<VIRTUSERTABLE>) { + next if /^#/; #comments? + next if /^\s*$/; #blank lines + /^([\w\-\.]+)?\@([\w\-\.]+)\t+([\w\-\.]+)$/ + #or do { warn "Strange virtusertable line: $_"; next; }; + or die "Strange virtusertable line: $_"; + my($domuser,$domain,$username)=($1,$2,$3); + my($svc_acct)=qsearchs('svc_acct',{'username'=>$username}); + unless ( $svc_acct ) { + #warn "Unknown user $username in virtusertable"; + die "Unknown user $username in virtusertable"; + next; + } + my($svc_acct_sm)=new FS::svc_acct_sm ({ + 'domsvc' => $svcnum{$domain}, + 'domuid' => $svc_acct->uid, + 'domuser' => $domuser || '*', + 'svcpart' => $mailalias_svcpart, + }); + my($error)=''; + $error=$svc_acct_sm->insert; + #warn $error if $error; + die $error if $error; + } + close VIRTUSERTABLE; + +} else { + die "Unknown MTA!\n"; +} + +#open(RECIPIENTMAP,"<$spooldir/recipientmap.import"); +#close RECIPIENTMAP; + +print "\n\n", <<END if $mta{$mta} eq "qmail"; +Don\'t forget to run $spooldir/virtualdomains.FIX before using +$spooldir/virtualdomains ! +END + +# + +sub usage { + die "Usage:\n\n svc_acct_sm.import user\n"; +} + |