1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
#!/usr/bin/perl -w
use strict;
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::domain_record;
use FS::svc_acct;
##use FS::part_svc;
use FS::svc_forward;
use FS::svc_domain;
my $user = shift or die &usage;
adminsuidsetup $user;
#$FS::svc_Common::noexport_hack = 1;
#$FS::domain_record::noserial_hack = 1;
use vars qw($defaultdomain);
$defaultdomain = '295.ca';
use vars qw(@svcpart $forward_svcpart);
@svcpart = qw( 2 4 );
$forward_svcpart = 7;
use vars qw($spooldir);
$spooldir = "/usr/local/etc/freeside/export.". datasrc. "/sendmail";
mkdir($spooldir, 0755) unless -d $spooldir;
print "\n\n", <<END;
Enter the location and name of your Sendmail aliases file, for example
"mail.isp.com:/etc/mail/aliases"
END
my($aliases)=&getvalue(":");
use vars qw($aliases_machine $aliases_prefix);
$aliases_machine = (split(/:/, $aliases))[0];
$aliases_prefix = "$spooldir/$aliases_machine";
mkdir($aliases_prefix, 0755) unless -d $aliases_prefix;
#iscp("root\@$aliases","$aliases_prefix/aliases.import");
iscp("ivan\@$aliases","$aliases_prefix/aliases.import");
print "\n\n", <<END;
Enter the location and name of your Sendmail virtusertable directory, for example
"mail.isp.com:/etc/mail/virtusertable"
END
my($virtusertable)=&getvalue(":");
use vars qw($virtusertable_machine $virtusertable_prefix);
$virtusertable_machine = (split(/:/, $virtusertable))[0];
$virtusertable_prefix = "$spooldir/$virtusertable_machine";
mkdir($virtusertable_prefix, 0755) unless -d $virtusertable_prefix;
mkdir("$virtusertable_prefix/virtusertable.import", 0755)
unless -d "$virtusertable_prefix/virtusertable.import";
#iscp("root\@$virtusertable/*","$aliases_prefix/virtusertable.import/");
iscp("ivan\@$virtusertable/*","$aliases_prefix/virtusertable.import/");
sub getvalue {
my $prompt = shift;
$^W=0; # Term::Query isn't -w-safe
my $return = query $prompt, '';
$^W=1;
$return;
}
print "\n\n";
##
foreach my $file (
"$aliases_prefix/aliases.import",
glob("$aliases_prefix/virtusertable.import/*"),
) {
warn "importing $file\n";
open(FILE,"<$file") or die $!;
while (<FILE>) {
next if /^\s*#/ || /^\s*$/; #skip comments & blank lines
unless ( /^([\w\@\.\-]+)[:\s]\s*(.*\S)\s*$/ ) {
warn "Unparsable line: $_";
next;
}
my($rawusername, $rawdest) = ($1, $2);
my($username, $domain);
if ( $rawusername =~ /^([\w\-\.\&]*)\@([\w\.\-]+)$/ ) {
$username = $1;
$domain = $2;
} elsif ( $rawusername =~ /\@/ ) {
die "Unparsable username: $rawusername\n";
} else {
$username = $rawusername;
$domain = $defaultdomain;
}
#find svc_acct record or set $src
my($srcsvc, $src) = &svcnum_or_literal($username, $domain);
foreach my $dest ( split(/,/, $rawdest) ) {
my($dusername, $ddomain);
if ( $dest =~ /^([\w\-\.\&]+)\@([\w\.\-]+)$/ ) {
$dusername = $1;
$ddomain = $2;
} elsif ( $dest =~ /\@/ ) {
die "Unparsable username: $dest\n";
} else {
$dusername = $dest;
$ddomain = $defaultdomain;
}
my($dstsvc, $dst) = &svcnum_or_literal($dusername, $ddomain);
my $svc_forward = new FS::svc_forward ({
svcpart => $forward_svcpart,
srcsvc => $srcsvc,
src => $src,
dstsvc => $dstsvc,
dst => $dst,
});
my $error = $svc_forward->insert;
#my $error = $svc_forward->check;
if ( $error ) {
die "$rawusername: $rawdest: $error\n";
}
}
} #next entry
} #next file
##
sub svcnum_or_literal {
my($username, $domain) = @_;
my $svc_domain = qsearchs('svc_domain', { 'domain' => $domain } );
my $domsvc = $svc_domain ? $svc_domain->svcnum : '';
my @svc_acct = grep { my $svc_acct = $_;
grep { $svc_acct->cust_svc->svcpart == $_ } @svcpart
}
qsearch('svc_acct', {
'username' => $username,
'domsvc' => $domsvc,
});
if ( scalar(@svc_acct) > 1 ) {
die "multiple sources found for $username\@$domain !\n";
}
my( $svcnum, $literal ) = ('', '');
if ( @svc_acct ) {
my $svc_acct = $svc_acct[0];
$svcnum = $svc_acct->svcnum;
} else {
$literal = "$username\@$domain";
}
return( $svcnum, $literal );
}
sub usage {
die "Usage:\n\n sendmail.import user\n";
}
|