#!/usr/bin/perl ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2007 Michael Tremer & Christian Schmidt # # # # 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 3 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, see . # # # ############################################################################### use strict; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; my %color = (); my %mainsettings = (); my %mpfiresettings = (); my %checked = (); my $message = '0'; my $errormessage = ""; &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); if ( $ENV{'QUERY_STRING'} =~ /title/){ my $song = `/usr/local/bin/mpfirectrl song 2>/dev/null`; if ( $song eq "" ){$song = "None";} &Header::showhttpheaders(); print < Song
-= $song =-
END ; } else{ &Header::showhttpheaders(); sub refreshpage{&Header::openbox( 'Waiting', 1, "" );print "

$Lang::tr{'pagerefresh'}
";&Header::closebox();} $mpfiresettings{'PAGE'} = "1"; open(DATEI, "<${General::swroot}/mpfire/db/mpd.db") || die "No Database found"; my @songdb = ; close(DATEI); my @artist; my @album; my @genre; my @year; my $linecount = 0; my %songs; my $key;my $file;my $Time;my $Artist;my $Title;my $Album;my $Track;my $Date;my $Genre; foreach (@songdb){ if ( $_ =~ /mtime: / ){ $songs{$key}="$file|$Time|$Artist|$Title|$Album|$Track|$Date|$Genre"; push(@artist,$Artist);push(@album,$Album);push(@year,$Date);push(@genre,$Genre); $key="";$file="";$Time="";$Artist="";$Title="";$Album="";$Track="";$Date="";$Genre=""; } elsif ( $_ =~ /key: / ){my @temp = split(/: /,$_);$key=$temp[1];} elsif ( $_ =~ /file: / ){my @temp = split(/: /,$_);$file=$temp[1];} elsif ( $_ =~ /Time: / ){my @temp = split(/: /,$_);$Time=$temp[1];} elsif ( $_ =~ /Artist: / ){my @temp = split(/: /,$_);$Artist=$temp[1];} elsif ( $_ =~ /Title: / ){my @temp = split(/: /,$_);$Title=$temp[1];} elsif ( $_ =~ /Album: / ){my @temp = split(/: /,$_);$Album=$temp[1];} elsif ( $_ =~ /Track: / ){my @temp = split(/: /,$_);$Track=$temp[1];} elsif ( $_ =~ /Date: / ){my @temp = split(/: /,$_);$Date=$temp[1];} elsif ( $_ =~ /Genre: / ){my @temp = split(/: /,$_);$Genre=$temp[1];} else {next;} } my %hash = map{ $_, 1 }@artist; @artist = sort keys %hash; my %hash = map{ $_, 1 }@album; @album = sort keys %hash; my %hash = map{ $_, 1 }@year; @year = sort keys %hash; my %hash = map{ $_, 1 }@genre; @genre = sort keys %hash; my $artistcount = $#artist+1; my $albumcount = $#album+1; my $yearcount = $#year+1; my $genrecount = $#genre+1; &Header::getcgihash(\%mpfiresettings); &Header::openpage($Lang::tr{'mpfire'}, 1,); &Header::openbigbox('100%', 'left', '', $errormessage); ############################################################################################################################ ######################################## Scanne Verzeichnisse nach Mp3 Dateien ############################################# if ( $mpfiresettings{'ACTION'} eq "scan" ) { delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};delete $mpfiresettings{'PAGE'}; &General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings); open(DATEI, "<${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden"; my @Zeilen = ; close(DATEI); open(DATEI, ">${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden"; foreach (@Zeilen){ if ( $_ =~ /music_directory/){print DATEI "music_directory \"".$mpfiresettings{'MUSICDIR'}."\"\n";} else {print DATEI $_;} } close(DATEI); $message=system("/usr/local/bin/mpfirectrl scan 2>/dev/null"); refreshpage(); } elsif ( $mpfiresettings{'ACTION'} eq ">" ){$message=system("/usr/local/bin/mpfirectrl","play","\"$mpfiresettings{'FILE'}\"","2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "x" ){$message=system("/usr/local/bin/mpfirectrl stop 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "|>" ){$message=system("/usr/local/bin/mpfirectrl toggle 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "<<" ){$message=system("/usr/local/bin/mpfirectrl prev 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq ">>" ){$message=system("/usr/local/bin/mpfirectrl next 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "+" ){$message=system("/usr/local/bin/mpfirectrl volup 5 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "-" ){$message=system("/usr/local/bin/mpfirectrl voldown 5 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "++" ){$message=system("/usr/local/bin/mpfirectrl volup 10 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "--" ){$message=system("/usr/local/bin/mpfirectrl voldown 10 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){$message=system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"","2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){$message=system("/usr/local/bin/mpfirectrl playlist 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "emptyplaylist" ){$message=system("/usr/local/bin/mpfirectrl clearplaylist 2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "addtoplaylist" ){$message=system("/usr/local/bin/mpfirectrl","playadd","\"$mpfiresettings{'FILE'}\"","2>/dev/null");} elsif ( $mpfiresettings{'ACTION'} eq "playall" ){ my @temp = ""; my @song = ""; foreach (keys(%songs)){ @song = split(/\|/,$songs{$_});push(@temp,$song[0]) } open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist"; print DATEI @temp; close(DATEI); $message=system("/usr/local/bin/mpfirectrl playlist 2>/dev/null"); } elsif ( $mpfiresettings{'ACTION'} eq "playalbum" ) { my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'album'}); foreach (keys(%songs)){ @song = split(/\|/,$songs{$_});$song[4] =~ s/\W/ /g; foreach (@select){ $_ =~ s/\W/ /g; if ( $song[4] =~ /$_/ ){push(@temp,$song[0]);} } } open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist"; print DATEI @temp; close(DATEI); $message=system("/usr/local/bin/mpfirectrl playlist 2>/dev/null"); } elsif ( $mpfiresettings{'ACTION'} eq "playartist" ) { my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'artist'}); foreach (keys(%songs)){ @song = split(/\|/,$songs{$_});$song[2] =~ s/\W/ /g; foreach (@select){ $_ =~ s/\W/ /g; if ( $song[2] =~ /$_/ ){push(@temp,$song[0]);} } } open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist"; print DATEI @temp; close(DATEI); $message=system("/usr/local/bin/mpfirectrl playlist 2>/dev/null"); } elsif ( $mpfiresettings{'ACTION'} eq "playyear" ) { my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'year'}); foreach (keys(%songs)){ @song = split(/\|/,$songs{$_});$song[6] =~ s/\W/ /g; foreach (@select){ $_ =~ s/\W/ /g; if ( $song[6] =~ /$_/ ){push(@temp,$song[0]);} } } open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist"; print DATEI @temp; close(DATEI); $message=system("/usr/local/bin/mpfirectrl playlist 2>/dev/null"); } elsif ( $mpfiresettings{'ACTION'} eq "playgenre" ) { my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'genre'}); foreach (keys(%songs)){ @song = split(/\|/,$songs{$_});$song[7] =~ s/\W/ /g; foreach (@select){ $_ =~ s/\W/ /g; if ( $song[7] =~ /$_/ ){push(@temp,$song[0]);} } } open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist"; print DATEI @temp; close(DATEI); $message=system("/usr/local/bin/mpfirectrl playlist 2>/dev/null"); } elsif ( $mpfiresettings{'SHOWLIST'} ){delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};delete $mpfiresettings{'PAGE'};&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);refreshpage();} ############################################################################################################################ ################################### Aufbau der HTML Seite fr globale Sambaeinstellungen #################################### $mpfiresettings{'MUSICDIR'} = "/"; &General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings); ############################################################################################################################ ########################################### rekursiv nach neuen Mp3s Scannen ##############################################รค if ( $message ne '0' ) { print "An Error occured while launching the command"; } elsif ( $message ne "" && $message ne '0' ) { print "$message"; } &Header::openbox('100%', 'center', $Lang::tr{'mpfire scanning'}); print <
$Lang::tr{'Scan for Files'}
$Lang::tr{'Scan from Directory'}
END ; &Header::closebox(); my $Volume = `/usr/local/bin/mpfirectrl volume 2>/dev/null`; $Volume=~s//
/g; my $stats = `mpc stats | tail -4 2>/dev/null`; $stats=~s/\\/
/g &Header::openbox('100%', 'center', $Lang::tr{'mpfire controls'}); print < END ; my $countsongs=`/usr/local/bin/mpfirectrl stats 2>/dev/null`; print ""; print < END ; if ( $mpfiresettings{'SHOWLIST'} eq "on" ){print"";} else { print"";} print <
".$countsongs."
$Volume

$stats
END ; &Header::closebox(); &Header::openbox('100%', 'center', $Lang::tr{'quick playlist'}); print ""; if ( $#songdb eq '-1' ) {print "";} else {print "";} print < END ; if ( $#songdb eq '-1' ) {print "";} else {print "";} print <
$Lang::tr{'artist'}$Lang::tr{'album'}
$Lang::tr{'artist'} - ".$artistcount."$Lang::tr{'album'} - ".$albumcount."
$Lang::tr{'year'}$Lang::tr{'genre'}
$Lang::tr{'year'} - ".$yearcount."$Lang::tr{'genre'} - ".$genrecount."
END ; &Header::closebox(); if ( $mpfiresettings{'SHOWLIST'} eq "on" ){ &Header::openbox('100%', 'center', $Lang::tr{'mpfire songs'}); print < END ; my $lines=0;my $i=0;my $begin;my $end; if ( $mpfiresettings{'PAGE'} eq 'all' ){ $begin=0; $end=keys(%songs); } else{ $begin=(($mpfiresettings{'PAGE'}-1) * 100); $end=(($mpfiresettings{'PAGE'} * 100)-1); } foreach (keys(%songs)){ if (!($i >= $begin && $i <= $end)){ # print $begin."->".$i."<-".$end."\n"; $i++;next;} my @song = split(/\|/,$songs{$_}); my $minutes = sprintf ("%.0f", $song[1] / 60 ); my $seconds = $song[1] % 60; if ($lines % 2) {print "";} else {print "";} print <
END ; $lines++; $i++; } print "
$Lang::tr{'Existing Files'}

$Lang::tr{'Pages'}

END ; my $pages =(int(keys(%songs)/100)+1); for(my $i = 1; $i <= $pages; $i++) { print ""; if (!($i % 205)){print"
";} } print <
$Lang::tr{'artist'}
$Lang::tr{'title'}
$Lang::tr{'number'} $Lang::tr{'album'} $Lang::tr{'year'} $Lang::tr{'genre'} $Lang::tr{'length'}
$song[2]
$song[3]
$song[5] $song[4] $song[6] $song[7] $minutes:$seconds
"; &Header::closebox(); } &Header::openbox('100%', 'center', $Lang::tr{'mpfire playlist'}); my @playlist = `mpc playlist 2>/dev/null`; print < $Lang::tr{'current playlist'}
END ; &Header::closebox(); &Header::openbox('100%', 'center', $Lang::tr{'mpfire webradio'}); open(DATEI, "<${General::swroot}/mpfire/webradio") || die "Could not open playlist"; my @webradio = ; close(DATEI); print < $Lang::tr{'webradio playlist'} Stream END ; my $lines=0; foreach (@webradio){ my @stream = split(/\|/,$_); $lines++; chomp($stream[2]); if ($lines % 2) {print "";} else {print "";} print <$stream[1]
END ; } $lines++; if ($lines % 2) {print "";} else {print "";} print <
http://
END ; print ""; &Header::closebox(); &Header::closebigbox(); &Header::closepage(); }