4 use Term::Query qw(query);
6 use FS::UID qw(adminsuidsetup datasrc);
7 use FS::Record qw(qsearch qsearchs);
10 #use FS::domain_record;
16 my $user = shift or die &usage;
19 #$FS::svc_Common::noexport_hack = 1;
20 #$FS::domain_record::noserial_hack = 1;
22 use vars qw($defaultdomain);
23 $defaultdomain = '295.ca';
25 use vars qw(@svcpart $forward_svcpart);
29 use vars qw($spooldir);
30 $spooldir = "/usr/local/etc/freeside/export.". datasrc. "/sendmail";
31 mkdir($spooldir, 0755) unless -d $spooldir;
34 Enter the location and name of your Sendmail aliases file, for example
35 "mail.isp.com:/etc/mail/aliases"
37 my($aliases)=&getvalue(":");
39 use vars qw($aliases_machine $aliases_prefix);
40 $aliases_machine = (split(/:/, $aliases))[0];
41 $aliases_prefix = "$spooldir/$aliases_machine";
42 mkdir($aliases_prefix, 0755) unless -d $aliases_prefix;
44 #iscp("root\@$aliases","$aliases_prefix/aliases.import");
45 iscp("ivan\@$aliases","$aliases_prefix/aliases.import");
48 Enter the location and name of your Sendmail virtusertable directory, for example
49 "mail.isp.com:/etc/mail/virtusertable"
51 my($virtusertable)=&getvalue(":");
53 use vars qw($virtusertable_machine $virtusertable_prefix);
54 $virtusertable_machine = (split(/:/, $virtusertable))[0];
55 $virtusertable_prefix = "$spooldir/$virtusertable_machine";
56 mkdir($virtusertable_prefix, 0755) unless -d $virtusertable_prefix;
57 mkdir("$virtusertable_prefix/virtusertable.import", 0755)
58 unless -d "$virtusertable_prefix/virtusertable.import";
60 #iscp("root\@$virtusertable/*","$aliases_prefix/virtusertable.import/");
61 iscp("ivan\@$virtusertable/*","$aliases_prefix/virtusertable.import/");
65 $^W=0; # Term::Query isn't -w-safe
66 my $return = query $prompt, '';
76 "$aliases_prefix/aliases.import",
77 glob("$aliases_prefix/virtusertable.import/*"),
80 warn "importing $file\n";
82 open(FILE,"<$file") or die $!;
84 next if /^\s*#/ || /^\s*$/; #skip comments & blank lines
86 unless ( /^([\w\@\.\-]+)[:\s]\s*(.*\S)\s*$/ ) {
87 warn "Unparsable line: $_";
90 my($rawusername, $rawdest) = ($1, $2);
92 my($username, $domain);
93 if ( $rawusername =~ /^([\w\-\.\&]*)\@([\w\.\-]+)$/ ) {
96 } elsif ( $rawusername =~ /\@/ ) {
97 die "Unparsable username: $rawusername\n";
99 $username = $rawusername;
100 $domain = $defaultdomain;
103 #find svc_acct record or set $src
104 my($srcsvc, $src) = &svcnum_or_literal($username, $domain);
106 foreach my $dest ( split(/,/, $rawdest) ) {
108 my($dusername, $ddomain);
109 if ( $dest =~ /^([\w\-\.\&]+)\@([\w\.\-]+)$/ ) {
112 } elsif ( $dest =~ /\@/ ) {
113 die "Unparsable username: $dest\n";
116 $ddomain = $defaultdomain;
118 my($dstsvc, $dst) = &svcnum_or_literal($dusername, $ddomain);
120 my $svc_forward = new FS::svc_forward ({
121 svcpart => $forward_svcpart,
127 my $error = $svc_forward->insert;
128 #my $error = $svc_forward->check;
130 die "$rawusername: $rawdest: $error\n";
141 sub svcnum_or_literal {
142 my($username, $domain) = @_;
144 my $svc_domain = qsearchs('svc_domain', { 'domain' => $domain } );
145 my $domsvc = $svc_domain ? $svc_domain->svcnum : '';
147 my @svc_acct = grep { my $svc_acct = $_;
148 grep { $svc_acct->cust_svc->svcpart == $_ } @svcpart
150 qsearch('svc_acct', {
151 'username' => $username,
155 if ( scalar(@svc_acct) > 1 ) {
156 die "multiple sources found for $username\@$domain !\n";
159 my( $svcnum, $literal ) = ('', '');
161 my $svc_acct = $svc_acct[0];
162 $svcnum = $svc_acct->svcnum;
164 $literal = "$username\@$domain";
167 return( $svcnum, $literal );
172 die "Usage:\n\n sendmail.import user\n";