@saltset @pw_set );
use Carp;
use Fcntl qw(:flock);
-use Crypt::PasswdMD5;
+use Crypt::PasswdMD5 1.2;
use FS::UID qw( datasrc );
use FS::Conf;
use FS::Record qw( qsearch qsearchs fields dbh dbdef );
qsearch('acct_snarf', { 'svcnum' => $self->svcnum } );
}
+=item decrement_seconds SECONDS
+
+Decrements the I<seconds> field of this record by the given amount.
+
+=cut
+
+sub decrement_seconds {
+ my( $self, $seconds ) = @_;
+
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my $sth = dbh->prepare(
+ 'UPDATE svc_acct SET seconds = seconds - ? WHERE svcnum = ?'
+ ) or die dbh->errstr;;
+ $sth->execute($seconds, $self->svcnum) or die $sth->errstr;
+ if ( $conf->exists('svc_acct-usage_suspend')
+ && $self->seconds - $seconds <= 0 ) {
+ #my $error = $self->suspend;
+ my $error = $self->cust_svc->cust_pkg->suspend;
+ die $error if $error;
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+}
+
=item seconds_since TIMESTAMP
Returns the number of seconds this account has been online since TIMESTAMP,
}
-=item crypt_password
+=item crypt_password [ DEFAULT_ENCRYPTION_TYPE ]
Returns an encrypted password, either by passing through an encrypted password
in the database or by encrypting a plaintext password from the database.
+The optional DEFAULT_ENCRYPTION_TYPE parameter can be set to I<crypt> (classic
+UNIX DES crypt), I<md5> (md5 crypt supported by most modern Linux and BSD
+distrubtions), or (eventually) I<blowfish> (blowfish hashing supported by
+OpenBSD, SuSE, other Linux distibutions with pam_unix2, etc.). The default
+encryption type is only used if the password is not already encrypted in the
+database.
+
=cut
sub crypt_password {
|| $self->_password =~ /^\$(1|2a?)\$/ ) {
$self->_password;
} else {
- crypt(
- $self->_password,
- $saltset[int(rand(64))].$saltset[int(rand(64))]
- );
+ my $encryption = scalar(@_) ? shift : 'crypt';
+ if ( $encryption eq 'crypt' ) {
+ crypt(
+ $self->_password,
+ $saltset[int(rand(64))].$saltset[int(rand(64))]
+ );
+ } elsif ( $encryption eq 'md5' ) {
+ unix_md5_crypt( $self->_password );
+ } elsif ( $encryption eq 'blowfish' ) {
+ die "unknown encryption method $encryption";
+ } else {
+ die "unknown encryption method $encryption";
+ }
}
}