4 use vars qw(%part_svc %domain_part_svc);
7 use Term::Query qw(query);
8 use FS::UID qw(adminsuidsetup); #datasrc
9 use FS::Record qw(qsearch qsearchs);
14 my $user = shift or die &usage;
17 #push @FS::svc_acct::shells, qw(/bin/sync /sbin/shutdown /bin/halt /sbin/halt); #others?
19 $FS::svc_Common::noexport_hack = 1;
20 $FS::svc_domain::whois_hack = 1;
24 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
26 die "No services with svcdb svc_acct!\n" unless %part_svc;
28 print "\n\n", &menu_svc, "\n", <<END;
29 Enter part number to import.
31 my $mailbox_svcpart = &getpart;
33 %domain_part_svc = map { $_->svcpart, $_ }
34 qsearch('part_svc', { 'svcdb' => 'svc_domain'} );
36 die "No services with svcdb svc_domain!\n" unless %domain_part_svc;
38 print "\n\n", &menu_domain_svc, "\n", <<END;
39 Enter part number for domains.
41 my $domain_svcpart = &getdomainpart;
43 my $datasrc = &getvalue("\n\nEnter the DBI datasource:");
44 my $db_user = &getvalue("\n\nEnter the database user:");
45 my $db_pass = &getvalue("\n\nEnter the database password:");
48 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
51 ( join "\n", map "$_: ".$domain_part_svc{$_}->svc, sort keys %domain_part_svc ). "\n";
54 $^W=0; # Term::Query isn't -w-safe
55 my $return = query "Enter part number:", 'irk', [ keys %part_svc ];
60 $^W=0; # Term::Query isn't -w-safe
61 my $return = query "Enter part number:", 'irk', [ keys %domain_part_svc ];
67 $^W=0; # Term::Query isn't -w-safe
68 my $return = query $prompt, '';
77 my $dbh = DBI->connect( $datasrc, $db_user, $db_pass )
80 my $sth = $dbh->prepare('SELECT username, password, crypt, name, domain FROM mailbox')
82 $sth->execute or die $sth->errstr;
85 while ( defined ( $row = $sth->fetchrow_arrayref ) ) {
86 my( $r_username, $password, $crypt, $finger, $r_domain ) = @$row;
88 my( $username, $domain );
89 if ( $r_username =~ /^([^@]+)\@([^@]+)$/ ) {
93 $username = $r_username;
96 my $svc_domain = qsearchs('svc_domain', { 'domain' => $domain } )
97 || new FS::svc_domain {
99 'svcpart' => $domain_svcpart,
102 unless ( $svc_domain->svcnum ) {
103 my $error = $svc_domain->insert;
105 die "can't insert domain $domain: $error\n";
109 $password = $crypt if $password eq '*CRYPTED*';
111 $finger =~ s/Outdoor Power.*$/Outdoor Power/;
113 my $svc_acct = new FS::svc_acct {
114 'svcpart' => $mailbox_svcpart,
115 'username' => $username,
116 'domsvc' => $svc_domain->svcnum,
117 '_password' => $password,
121 my $error = $svc_acct->insert;
122 #my $error = $svc_acct->check;
124 if ( $error =~ /duplicate/i ) {
125 warn "$r_username / $r_domain: $error";
127 die "$r_username / $r_domain: $error";
134 die "Usage:\n\n postfix_courierimap.import user\n";