freeside/FS/FS Daemon.pm,NONE,1.1 svc_acct.pm,1.176,1.177 Conf.pm,1.126,1.127
ivan
ivan at pouncequick.420.am
Mon Apr 25 02:33:40 PDT 2005
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv6040/FS/FS
Modified Files:
svc_acct.pm Conf.pm
Added Files:
Daemon.pm
Log Message:
pick up freeside-sqlradius-radacctd again after all these years, now it just needs to update the "seconds" field(s), finally closes: Bug#1125
--- NEW FILE: Daemon.pm ---
package FS::Daemon;
use vars qw( @ISA @EXPORT_OK );
use vars qw( $pid_dir $me $pid_file $sigint $sigterm $logfile );
use Exporter;
use Fcntl qw(:flock);
use POSIX qw(setsid);
use Date::Format;
#this is a simple refactoring of the stuff from freeside-queued, just to
#avoid duplicate code. eventually this should use something from CPAN.
@ISA = qw(Exporter);
@EXPORT_OK = qw( daemonize1 drop_root daemonize2 sigint sigterm logfile );
$pid_dir = '/var/run';
sub daemonize1 {
$me = shift;
$pid_file = "$pid_dir/$me";
$pid_file .= '.'.shift if scalar(@_);
$pid_file .= '.pid';
chdir "/" or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
if ( $pid ) {
print "$me started with pid $pid\n"; #logging to $log_file\n";
exit unless $pid_file;
my $pidfh = new IO::File ">$pid_file" or exit;
print $pidfh "$pid\n";
exit;
}
#sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; $kids--; }
#$SIG{CHLD} = \&REAPER;
$sigterm = 0;
$sigint = 0;
$SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; };
$SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; };
}
sub drop_root {
my $freeside_gid = scalar(getgrnam('freeside'))
or die "can't find freeside group\n";
$) = $freeside_gid;
$( = $freeside_gid;
#if freebsd can't setuid(), presumably it can't setgid() either. grr fleabsd
($(,$)) = ($),$();
$) = $freeside_gid;
$> = $FS::UID::freeside_uid;
$< = $FS::UID::freeside_uid;
#freebsd is sofa king broken, won't setuid()
($<,$>) = ($>,$<);
$> = $FS::UID::freeside_uid;
}
sub daemonize2 {
open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
setsid or die "Can't start a new session: $!";
open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
$SIG{__DIE__} = \&_die;
$SIG{__WARN__} = \&_logmsg;
warn "$me starting\n";
}
sub sigint { $sigint; }
sub sigterm { $sigterm; }
sub logfile { $logfile = shift; } #_logmsg('test'); }
sub _die {
my $msg = shift;
unlink $pid_file if -e $pid_file;
_logmsg($msg);
}
sub _logmsg {
chomp( my $msg = shift );
my $log = new IO::File ">>$logfile";
flock($log, LOCK_EX);
seek($log, 0, 2);
print $log "[". time2str("%a %b %e %T %Y",time). "] [$$] $msg\n";
flock($log, LOCK_UN);
close $log;
}
Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.176
retrieving revision 1.177
diff -u -d -r1.176 -r1.177
--- svc_acct.pm 20 Apr 2005 06:41:39 -0000 1.176
+++ svc_acct.pm 25 Apr 2005 09:33:34 -0000 1.177
@@ -1120,6 +1120,41 @@
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,
Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -d -r1.126 -r1.127
--- Conf.pm 19 Apr 2005 09:50:06 -0000 1.126
+++ Conf.pm 25 Apr 2005 09:33:34 -0000 1.127
@@ -1448,6 +1448,13 @@
'type' => [qw( checkbox textarea )],
},
+ {
+ 'key' => 'svc_acct-usage_suspend',
+ 'section' => 'billing',
+ 'description' => 'Suspends the package an account belongs to when svc_acct.seconds is decremented to 0 or below (accounts with an empty seconds value are ignored). Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.',
+ 'type' => 'checkbox',
+ },
+
);
1;
More information about the freeside-commits
mailing list