#!/usr/bin/perl
-#
-# IPFire CGIs
-#
-# This code is distributed under the terms of the GPL
-#
-# (c) The IPFire Team
+###############################################################################
+# #
+# 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 <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
use strict;
# enable only the following on debugging purpose
-use warnings;
-use CGI::Carp 'fatalsToBrowser';
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
require '/var/ipfire/general-functions.pl';
require "${General::swroot}/lang.pl";
my %mainsettings = ();
my %mpfiresettings = ();
my %checked = ();
-my $message = "";
+my $message = '0';
my $errormessage = "";
open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "No Database found";
&Header::showhttpheaders();
-sub refreshpage{&Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='1;'>" );print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>$Lang::tr{'pagerefresh'}</font></center>";&Header::closebox();}
+sub refreshpage{&Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='1;' />" );print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>$Lang::tr{'pagerefresh'}</font></center>";&Header::closebox();}
+
+$mpfiresettings{'PAGE'} = "1";
&Header::getcgihash(\%mpfiresettings);
-&Header::openpage($Lang::tr{'mpfire'}, 1, "<meta http-equiv='refresh' content='120'>");
+&Header::openpage($Lang::tr{'mpfire'}, 1, "<meta http-equiv='refresh' content='120' />");
&Header::openbigbox('100%', 'left', '', $errormessage);
############################################################################################################################
if ( $mpfiresettings{'ACTION'} eq "scan" )
{
-delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};
+delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};delete $mpfiresettings{'PAGE'};
&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);
-system("/usr/local/bin/mpfirectrl scan $mpfiresettings{'SCANDIR'} $mpfiresettings{'SCANDIRDEPS'}");
+$message=system("/usr/local/bin/mpfirectrl scan $mpfiresettings{'SCANDIR'} $mpfiresettings{'SCANDIRDEPS'}");
refreshpage();
}
-
-if ( $mpfiresettings{'ACTION'} eq ">" ){system("/usr/local/bin/mpfirectrl","play","\"$mpfiresettings{'FILE'}\"");}
-if ( $mpfiresettings{'ACTION'} eq "x" ){system("/usr/local/bin/mpfirectrl stop");}
-if ( $mpfiresettings{'ACTION'} eq "||" ){system("/usr/local/bin/mpfirectrl pause");}
-if ( $mpfiresettings{'ACTION'} eq "|>" ){system("/usr/local/bin/mpfirectrl resume");}
-if ( $mpfiresettings{'ACTION'} eq ">>" ){system("/usr/local/bin/mpfirectrl next");}
-if ( $mpfiresettings{'ACTION'} eq "stopweb" ){system("/usr/local/bin/mpfirectrl stopweb");}
-if ( $mpfiresettings{'ACTION'} eq "playweb" ){system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"");}
-if ( $mpfiresettings{'ACTION'} eq "+" ){system("/usr/local/bin/mpfirectrl volup 5");}
-if ( $mpfiresettings{'ACTION'} eq "-" ){system("/usr/local/bin/mpfirectrl voldown 5");}
-if ( $mpfiresettings{'ACTION'} eq "++" ){system("/usr/local/bin/mpfirectrl volup 10");}
-if ( $mpfiresettings{'ACTION'} eq "--" ){system("/usr/local/bin/mpfirectrl voldown 10");}
-if ( $mpfiresettings{'ACTION'} eq "playlist" ){system("/usr/local/bin/mpfirectrl playall");}
-if ( $mpfiresettings{'ACTION'} eq "playalbum" )
+elsif ( $mpfiresettings{'ACTION'} eq ">" ){$message=system("/usr/local/bin/mpfirectrl","play","\"$mpfiresettings{'FILE'}\"");}
+elsif ( $mpfiresettings{'ACTION'} eq "x" ){$message=system("/usr/local/bin/mpfirectrl stop");}
+elsif ( $mpfiresettings{'ACTION'} eq "||" ){$message=system("/usr/local/bin/mpfirectrl pause");}
+elsif ( $mpfiresettings{'ACTION'} eq "|>" ){$message=system("/usr/local/bin/mpfirectrl resume");}
+elsif ( $mpfiresettings{'ACTION'} eq ">>" ){$message=system("/usr/local/bin/mpfirectrl next");}
+elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){$message=system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"");}
+elsif ( $mpfiresettings{'ACTION'} eq "+" ){$message=system("/usr/local/bin/mpfirectrl volup 5");}
+elsif ( $mpfiresettings{'ACTION'} eq "-" ){$message=system("/usr/local/bin/mpfirectrl voldown 5");}
+elsif ( $mpfiresettings{'ACTION'} eq "++" ){$message=system("/usr/local/bin/mpfirectrl volup 10");}
+elsif ( $mpfiresettings{'ACTION'} eq "--" ){$message=system("/usr/local/bin/mpfirectrl voldown 10");}
+elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){$message=system("/usr/local/bin/mpfirectrl playall");}
+elsif ( $mpfiresettings{'ACTION'} eq "emptyplaylist" ){$message=system("unlink ${General::swroot}/mpfire/playlist && touch ${General::swroot}/mpfire/playlist");}
+elsif ( $mpfiresettings{'ACTION'} eq "addtoplaylist" ){
+open(DATEI, ">>${General::swroot}/mpfire/playlist") || die "Could not add playlist";
+print DATEI $mpfiresettings{'FILE'}."\n";
+close(DATEI);
+}
+elsif ( $mpfiresettings{'ACTION'} eq "playalbum" )
{
my @temp = "";
my @album = split(/\|/,$mpfiresettings{'album'});
open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
print DATEI @temp;
close(DATEI);
-system("/usr/local/bin/mpfirectrl playall");
+$message=system("/usr/local/bin/mpfirectrl playall");
}
-if ( $mpfiresettings{'ACTION'} eq "playartist" )
+elsif ( $mpfiresettings{'ACTION'} eq "playartist" )
{
my @temp = "";
my @artist = split(/\|/,$mpfiresettings{'artist'});
open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
print DATEI @temp;
close(DATEI);
-system("/usr/local/bin/mpfirectrl playall");
+$message=system("/usr/local/bin/mpfirectrl playall");
+}
+elsif ( $mpfiresettings{'ACTION'} eq "playyear" )
+{
+my @temp = "";
+my @year = split(/\|/,$mpfiresettings{'year'});
+my %hash = map{ $_, 1 }@year;
+
+foreach (@songdb){
+ my @song = split(/\|/,$_);
+ chomp($song[0]);
+ push(@temp,$song[0]."\n") if exists $hash{$song[5]};
+ }
+open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
+print DATEI @temp;
+close(DATEI);
+$message=system("/usr/local/bin/mpfirectrl playall");
}
-if ( $mpfiresettings{'ACTION'} eq "playall" )
+elsif ( $mpfiresettings{'ACTION'} eq "playgenre" )
+{
+my @temp = "";
+my @genre = split(/\|/,$mpfiresettings{'genre'});
+my %hash = map{ $_, 1 }@genre;
+
+foreach (@songdb){
+ my @song = split(/\|/,$_);
+ chomp($song[0]);
+ push(@temp,$song[0]."\n") if exists $hash{$song[6]};
+ }
+open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
+print DATEI @temp;
+close(DATEI);
+$message=system("/usr/local/bin/mpfirectrl playall");
+}
+elsif ( $mpfiresettings{'ACTION'} eq "playall" )
{
my @temp = "";
foreach (@songdb){
open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
print DATEI @temp;
close(DATEI);
-system("/usr/local/bin/mpfirectrl playall");
+$message=system("/usr/local/bin/mpfirectrl playall");
}
-if ( $mpfiresettings{'SHOWLIST'} ){delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);}
+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 ####################################
############################################################################################################################
########################################### rekursiv nach neuen Mp3s Scannen ##############################################รค
-if ( $message ne "" ) { print "<font color='red'>$message</font>"; }
+if ( $message ne '0' ) { print "<font color='red'>An Error occured while launching the command</font>"; }
+elsif ( $message ne "" && $message ne '0' ) { print "<font color='red'>$message</font>"; }
&Header::openbox('100%', 'center', $Lang::tr{'mpfire scanning'});
my $song = qx(/usr/local/bin/mpfirectrl song);
if ( $song eq "" ){$song = "None";}
+my $Volume = `/usr/local/bin/mpfirectrl volume`;
+$Volume=~s/<break>/<br \/>/g;
+
&Header::openbox('100%', 'center', $Lang::tr{'mpfire controls'});
print <<END
<table width='95%' cellspacing='0'>
<tr bgcolor='$color{'color20'}'> <td colspan='5' align='center'><marquee behavior='alternate' scrollamount='1' scrolldelay='5'><font color=red>-= $song =-</font></marquee></td></tr>
- <tr><td colspan='5' align='center'><br/><b>total $#songdb songs</b><br/><br/></td></tr>
+END
+;
+if ( $#songdb eq '-1' ) {print "<tr><td colspan='5' align='center'><br/><b>total 0 songs</b><br/><br/></td></tr>";}
+else {print "<tr><td colspan='5' align='center'><br/><b>total $#songdb songs</b><br/><br/></td></tr>";}
+print <<END
<tr>
<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='x' /><input type='image' alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/media-playback-stop.png' /></form></td>
<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='||' /><input type='image' alt='$Lang::tr{'pause'}' title='$Lang::tr{'pause'}' src='/images/media-playback-pause.png' /></form></td>
<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='+' /><input type='image' alt='$Lang::tr{'volup5'}' title='$Lang::tr{'volup5'}' src='/images/audio-volume-high.png' /></form></td>
<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='++' /><input type='image' alt='$Lang::tr{'volup10'}' title='$Lang::tr{'volup10'}' src='/images/audio-volume-high-red.png' /></form></td>
</tr>
+<tr><td colspan='5' align='center'>$Volume</td></tr>
</table>
END
;
&Header::closebox();
+if ( $#songdb ne '0' ){
&Header::openbox('100%', 'center', $Lang::tr{'quick playlist'});
-my @artist;
-my @album;
+my @artist; my @album; my @genre; my @year;
foreach (@songdb){
my @song = split(/\|/,$_);
- push(@artist,$song[1]);push(@album,$song[4]);}
+ push(@artist,$song[1]); push(@album,$song[4]); push(@year,$song[5]); push(@genre,$song[6]);}
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;
+print "<table width='95%' cellspacing='0'>";
+if ( $#songdb eq '-1' ) {print "<tr><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'artist'}</b></td><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'album'}</b></td></tr>";}
+else {print "<tr><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'artist'} - ".$artistcount."</b></td><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'album'} - ".$albumcount."</b></td></tr>";}
print <<END
- <table width='95%' cellspacing='0'>
- <tr><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'artist'} - $#artist</b></td><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'album'} - $#album</b></td></tr>
<tr><td align='center'>
<form method='post' action='$ENV{'SCRIPT_NAME'}'>
<select name='artist' size='8' multiple='multiple' style='width:300px;'>
END
;
- foreach (@artist){print "<option>$_</option>";}
+foreach (@artist){if ( $_ ne '' ){print "<option>$_</option>";}}
print <<END
</select><br/>
<input type='hidden' name='ACTION' value='playartist' />
<select name='album' size='8' multiple='multiple' style='width:300px;'>
END
;
- foreach (@album){print "<option>$_</option>";}
+ foreach (@album){if ( $_ ne '' ){print "<option>$_</option>";}}
print <<END
</select><br/>
<input type='hidden' name='ACTION' value='playalbum' />
<input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
</form></td>
+ </tr>
+END
+;
+if ( $#songdb eq '-1' ) {print "<tr><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'year'}</b></td><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'genre'}</b></td></tr>";}
+else {print "<tr><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'year'} - ".$yearcount."</b></td><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'genre'} - ".$genrecount."</b></td></tr>";}
+print <<END
+ <tr><td align='center'>
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <select name='year' size='8' multiple='multiple' style='width:300px;'>
+END
+;
+ foreach (@year){if ( $_ ne '' ){print "<option>$_</option>";}}
+print <<END
+ </select><br/>
+ <input type='hidden' name='ACTION' value='playyear' />
+ <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
+ </form></td>
+ <td align='center'>
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <select name='genre' size='8' multiple='multiple' style='width:300px;'>
+END
+;
+ foreach (@genre){if ( $_ ne '' ){print "<option>$_</option>";}}
+print <<END
+ </select><br/>
+ <input type='hidden' name='ACTION' value='playgenre' />
+ <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
+ </form></td>
</tr></table>
END
;
&Header::closebox();
+}
+
if ( $mpfiresettings{'SHOWLIST'} eq "on" ){
<table width='95%' cellspacing='5'>
<tr bgcolor='$color{'color20'}'><td colspan='9' align='left'><b>$Lang::tr{'Existing Files'}</b></td></tr>
+<tr><td align='center' colspan='9'><br/>$Lang::tr{'Pages'}<br/><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='submit' name='PAGE' value='all' /><br/>
+END
+;
+my $pages =(int($#songdb/100)+1);
+for(my $i = 1; $i <= $pages; $i++) {
+print "<input type='submit' name='PAGE' value='$i' />";
+if (!($i % 205)){print"<br/>";}
+}
+print <<END
+</form></td></tr>
<tr><td align='center'></td>
<td align='center'><b>$Lang::tr{'artist'}<br/>$Lang::tr{'title'}</b></td>
<td align='center'><b>$Lang::tr{'number'}</b></td>
<td align='center'><b>$Lang::tr{'mode'}</b></td></tr>
END
;
-my $lines = 0;
+my $lines=0;my $i=0;my $begin;my $end;
+if ( $mpfiresettings{'PAGE'} eq 'all' ){
+ $begin=0;
+ $end=$#songdb;
+}
+else{
+ $begin=(($mpfiresettings{'PAGE'}-1) * 100);
+ $end=(($mpfiresettings{'PAGE'} * 100)-1);
+}
foreach (@songdb){
+ if (!($i >= $begin && $i <= $end)){
+ #print $begin."->".$i."<-".$end."\n";
+ $i++;next;}
my @song = split(/\|/,$_);
if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>";} else {print "<tr bgcolor='$color{'color22'}'>";}
$song[0]=~s/\/\//\//g;
print <<END
- <td align='center' style="white-space:nowrap;"><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='>' /><input type='hidden' name='FILE' value="$song[0]" /><input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' /></form></td>
+ <td align='center' style="white-space:nowrap;"><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='addtoplaylist' /><input type='hidden' name='FILE' value="$song[0]" /><input type='image' alt='$Lang::tr{'add'}' title='$Lang::tr{'add'}' src='/images/list-add.png' /></form><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='>' /><input type='hidden' name='FILE' value="$song[0]" /><input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' /></form></td>
<td align='center'>$song[1]<br/>$song[2]</td>
<td align='center'>$song[3]</td>
<td align='center'>$song[4]</td>
elsif ( $song[11] eq "2\n" ) {print "<td align='center'>Dual<br/>Channel</td></tr>"; }
elsif ( $song[11] eq "3\n" ) {print "<td align='center'>Single<br/>Channel</td></tr>"; }
else {print "<td align='center'></td></tr>"; }
- $lines++
+ $lines++;
+ $i++;
}
-print "</table></form>";
+print "</table>";
&Header::closebox();
}
my @playlist = <DATEI>;
close(DATEI);
+my %hash;
+foreach (@songdb){
+ my @song = split(/\|/,$_);
+ chomp($song[0]);
+ $hash{$song[0]}=$song[1]." - ".$song[2]." - ".$song[7].":".$song[8];
+}
+
print <<END
<table width='95%' cellspacing='0'>
-<tr bgcolor='$color{'color20'}'><td colspan='9' align='left'><b>$Lang::tr{'current playlist'}</b></td></tr>
-<tr><td align='center'><textarea cols='120' rows='10' name='playlist' style='font-size:10px' readonly='readonly' >@playlist</textarea><br/>
- <form method='post' action='$ENV{'SCRIPT_NAME'}'>
- <input type='hidden' name='ACTION' value='playlist' />
- <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
- </form></td></tr>
+<tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'current playlist'}</b></td></tr>
+<tr><td align='center' colspan='2' ><textarea cols='100' rows='10' name='playlist' style='font-size:11px;width:650px;' readonly='readonly'>
+END
+;
+foreach (@playlist){chomp($_);print $hash{$_}."\n";}
+print <<END
+</textarea></td></tr><tr>
+<td align='right'>
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='emptyplaylist' />
+ <input type='image' alt='$Lang::tr{'clear playlist'}' title='$Lang::tr{'clear playlist'}' src='/images/user-trash.png' />
+ </form>
+</td>
+<td align='left'>
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='playlist' />
+ <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
+ </form>
+ </td></tr>
</table>
END
;
my @stream = split(/\|/,$_);
print <<END
<tr><td>$stream[1]</td>
- <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='stopweb' /><input type='image' alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/media-playback-stop.png' /></form></td>
<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='FILE' value='$stream[0]' /><input type='hidden' name='ACTION' value='playweb' /><input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' /></form></td>
</tr>
END