5 use FS::Daemon ':all'; #daemonize1 drop_root daemonize2 myexit logfile sig*
6 use FS::UID qw( adminsuidsetup );
7 use FS::Record qw( qsearch ); #qsearchs);
12 my $user = shift or die &usage;
14 #daemonize1('freeside-sprepaidd', $user); #keep unique pid files w/multi installs
15 daemonize1('freeside-cdrrewrited');
19 adminsuidsetup($user);
21 logfile( "%%%FREESIDE_LOG%%%/cdrrewrited-log.". $FS::UID::datasrc );
27 die "not running; cdr-asterisk_forward_rewrite and cdr-charged_party_rewrite ".
28 " conf options are both off\n"
35 #hmm... don't want to do an expensive search with an ever-growing bunch
36 # of unprocessed CDRs during the month... better to mark them all as
37 # rewritten "skipped", i.e. why we're a daemon in the first place
38 # instead of just doing this search like normal CDRs
44 'extra_sql' => 'FOR UPDATE',
46 'extra_sql' => 'WHERE freesidestatus IS NULL'.
47 ' AND freesiderewritestatus IS NULL'.
48 ' LIMIT 1024', #arbitrary, but don't eat too much memory
55 if ( $conf->exists('cdr-asterisk_forward_rewrite')
56 && $cdr->dstchannel =~ /^Local\/(\d+)/i && $1 ne $cdr->dst
62 warn "dst ". $cdr->dst. " does not match dstchannel $dst ".
63 "(". $cdr->dstchannel. "); rewriting CDR as a forwarded call";
65 $cdr->charged_party($cdr->dst);
69 push @status, 'asterisk_forward';
73 if ( $conf->exists('cdr-charged_party_rewrite') && ! $cdr->charged_party ) {
75 $cdr->set_charged_party;
76 push @status, 'charged_party';
80 $cdr->freesiderewritestatus(
81 scalar(@status) ? join('/', @status) : 'skipped'
84 my $error = $cdr->replace;
87 warn "WARNING: error rewriting CDR (will retry in 30 seconds):".
89 sleep 30; #i dunno, wait and see if the database comes back?
94 myexit() if sigterm() || sigint();
95 #sleep 1 unless $found;
96 sleep 5 unless $found;
103 $conf->exists('cdr-asterisk_forward_rewrite')
104 || $conf->exists('cdr-charged_party_rewrite');
108 die "Usage:\n\n freeside-cdrrewrited user\n";
113 freeside-cdrrewrited - Real-time daemon for CDR rewriting
121 Runs continuously, searches for CDRs and does forwarded-call rewriting if the
122 "cdr-asterisk_forward_rewrite" or "cdr-charged_party_rewrite" config option is