#!/usr/bin/perl ##################################################### # config my %reporter_numbers = ( '030123456' => 'Louis Lane', '0123456879' => 'Clark Kent', '555123456789' => 'Peter Parker', ); my $basedir = '/var/www/Live'; my $rssfile = 'rss.xml'; my $csvfile = 'rss.csv'; my $htmlfile = 'rss.html'; my $itemfile = 'rss.items'; my $urlbase = 'http://radio.example.com/Live'; my $castitel = 'Radio ReporTel LIVE'; my $kuerzel = 'RRTL'; # mailfrom empty = do not send mail my $mailfrom = ''; my $mailto = 'test@example.com'; ##################################################### # no config below ##################################################### use MIME::Base64; use DateTime; while () { s/\r//g; # Remove Windooze's \r, it is safe to do this $message .= $_; } # open (FH, ">/tmp/reportel.eml") or # print FH $message; # close(FH); ($mailheader, $body, $audio64mime, $muell) = split(/--==AVM_Fritz_Box==multipart\/mixed==0==/, $message, 4); # ($mailheader, $muell) = split(/\n\n/, $body, 2); $mailheader .= "\n"; $audio64mime .= "\n"; # Clear+free memory undef $message; undef $muell; undef $body; ($audioheader, $audiobody) = split(/\n\n/, $audio64mime, 2); $audioheader .= "\n"; # Clear+free memory undef $audio64mime; #### Match gegen Mail-Header if ( $audioheader =~ /Content-Disposition: attachment; filename="(\d{2})\.(\d{2})\.(\d{2})_(\d{2})\.(\d{2})_Anruf\.(\d*).wav"/ ){ $day = $1; $mon = $2; $yr = 2000 + $3; $hr = $4; $min = $5; $tel = $6; my $dt = DateTime->new( year => $yr, month => $mon, day => $day, hour => $hr, minute => $min, time_zone => 'Europe/Berlin', ); $stddate = $dt->strftime("%a, %e %b %Y %T %Z"); if ( exists $reporter_numbers{$tel} ) { $name = $reporter_numbers{$tel}; $filename = $kuerzel . "_" . $yr . "-" . $mon . "-" . $day . "_" . $hr . ":" . $min . ":00" . "_" . $name; open (FH, ">$basedir/$filename.wav") or die "reportel: problem writing wav file"; binmode FH; print FH decode_base64($audiobody); close(FH); chmod 0644, "$basedir/$filename.wav"; $filesize = -s "$basedir/$filename.wav"; #### konvertieren in OGG # @args = ("oggenc", "--quiet", "--artist", "$name", "--genre", "Podcast", "--album", "$castitel", "--track", "$filename", "--output=$baseurl/$filename.ogg", "$baseurl/$filename.wav"); @args = ("sox", "--norm", "-q", "$basedir/$filename.wav", "-C", "4", "$basedir/$filename.ogg"); system(@args) == 0 or die "reportel: system @args failed: $?"; $filesize = -s "$basedir/$filename.ogg"; chmod 0644, "$basedir/$filename.ogg"; #### publish CSV open (FH, ">>$basedir/$csvfile") or die "reportel: problem writing csv file"; print FH $kuerzel . "\t"; print FH $yr . "-" . $mon . "-" . $day . "\t"; print FH $hr . ":" . $min . ":00\t"; print FH $name . "\t"; print FH $filesize . "\t"; print FH "$urlbase/$filename.ogg?src=page\n"; close(FH); chmod 0644, "$basedir/$csvfile"; #### publish HTML snippet open (FH, ">>$basedir/$htmlfile") or die "reportel: problem writing html file"; print FH "$kuerzel "; print FH $yr . "-" . $mon . "-" . $day . " " . $hr . ":" . $min . " "; print FH $name . "
\n"; close(FH); chmod 0644, "$basedir/$htmlfile"; #### publish RSS open (FH, ">>$basedir/$itemfile") or die "reportel: problem writing item file"; print FH " \n"; print FH " <![CDATA[ $kuerzel $yr" . "-" . $mon . "-" . $day . " um " . $hr . ":" . $min . " von " . $name . " ]]>\n"; print FH " $urlbase/#$filename\n"; print FH " $urlbase/#$filename\n"; print FH " $stddate\n"; print FH " \n"; print FH " \n"; # print FH " \n"; # print FH " \n"; print FH " \n\n"; close(FH); chmod 0644, "$basedir/$itemfile"; open (FS, ">$basedir/$rssfile") or die "reportel: problem writing rss file"; print FS "\n"; print FS "\n\n"; print FS " $castitel\n"; print FS " $castitel\n"; print FS " $urlbase/$rssfile\n"; print FS " $stddate\n"; print FS " de\n\n"; open (FI, "$basedir/$itemfile") or die "reportel: problem reading item file"; while ($line = ) { print FS $line; } close(FI); print FS "\n\n"; close(FS); chmod 0644, "$basedir/$rssfile"; #### publish mail if ( length($mailfrom) > 8 ) { open (SENDMAIL,"|/usr/sbin/sendmail -t -f " . $mailfrom) or die "reportel: cannot open sendmail"; print SENDMAIL "To: " . $mailto . "\n"; print SENDMAIL "Subject: New ReporTel cast $filename\n"; print SENDMAIL "From: " . $mailfrom . "\n"; print SENDMAIL "Content-Type: text/plain; charset=\"utf8\"\n"; print SENDMAIL "Content-Transfer-Encoding: 8bit\n\n"; print SENDMAIL "$castitel ($kuerzel)\n"; print SENDMAIL "Report by $name on $day.$mon.$yr at $hr:$min\n\n"; print SENDMAIL "Download at\n"; print SENDMAIL "$urlbase/$filename.ogg?src=mail\n"; close SENDMAIL; } } else { die "reportel: problem - not a valid phone sender $tel"; } } else { die "reportel: problem - not an AB file"; } exit 0; # ----------------------------------------------------------------------- # Shortcut: Distributable under GPL # ----------------------------------------------------------------------- # Copyright (C) 2011- Volker Tanger # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. or on their website http://www.gnu.org/copyleft/gpl.html # # -----------------------------------------------------------------------