+sub icradius_rr_insert {
+ my( $username, $password, %radreply ) = @_;
+
+ foreach my $attribute ( keys %radreply ) {
+ my $sth = $icradius_dbh->prepare(
+ "INSERT INTO radreply ( id, UserName, Attribute, Value ) VALUES ( ".
+ join(", ", map { $icradius_dbh->quote($_) } (
+ '',
+ $username,
+ $attribute,
+ $radreply{$attribute},
+ ) ). " )"
+ );
+ $sth->execute or die "can't insert into radreply table: ". $sth->errstr;
+ }
+
+ 1;
+}
+
+
+sub vpopmail_insert {
+ my( $username, $password, $domain, $vpopdir ) = @_;
+
+ (open(VPASSWD, ">>$exportdir/domains/$domain/vpasswd")
+ and flock(VPASSWD,LOCK_EX)
+ ) or die "can't open vpasswd file for $username\@$domain: $exportdir/domains/$domain/vpasswd";
+ print VPASSWD join(":",
+ $username,
+ $password,
+ '1',
+ '0',
+ $username,
+ "$vpopdir/domains/$domain/$username",
+ 'NOQUOTA',
+ ), "\n";
+
+ flock(VPASSWD,LOCK_UN);
+ close(VPASSWD);
+
+ mkdir "$exportdir/domains/$domain/$username", 0700 or die "can't create Maildir";
+ mkdir "$exportdir/domains/$domain/$username/Maildir", 0700 or die "can't create Maildir";
+ mkdir "$exportdir/domains/$domain/$username/Maildir/cur", 0700 or die "can't create Maildir";
+ mkdir "$exportdir/domains/$domain/$username/Maildir/new", 0700 or die "can't create Maildir";
+ mkdir "$exportdir/domains/$domain/$username/Maildir/tmp", 0700 or die "can't create Maildir";
+
+ my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_sync' };
+ my $error = $queue->insert;
+ die $error if $error;
+
+ 1;
+}
+
+sub vpopmail_sync {
+
+ my (@vpopmailmachines) = $conf->config('vpopmailmachines');
+ my ($machine, $dir, $uid, $gid) = split (/\s+/, $vpopmailmachines[0]);
+
+ chdir $exportdir;
+ my @args = ("$rsync", "-rlpt", "-e", "$ssh", "domains/", "vpopmail\@$machine:$vpopdir/domains/");
+ system {$args[0]} @args;
+
+}
+