X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Fmpfire.cgi;h=6cec8ff338c06e8458e77796e3d24e08ff53e10c;hp=6b6b4acb5e6ea06aaced0eb393989ba56d0414fd;hb=3e1c7cfc7de8ec2245f63bfa5eb63c59c8081e6a;hpb=69addbb81059f6683900912bb59aac444648c6a7 diff --git a/html/cgi-bin/mpfire.cgi b/html/cgi-bin/mpfire.cgi index 6b6b4acb5e..6cec8ff338 100644 --- a/html/cgi-bin/mpfire.cgi +++ b/html/cgi-bin/mpfire.cgi @@ -1,15 +1,38 @@ #!/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 . # +# # +############################################################################### use strict; + # enable only the following on debugging purpose -use warnings; -use CGI::Carp 'fatalsToBrowser'; +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; + +# use the special mpd POD and the encode POD to handle the utf8 scalars +use Audio::MPD; +use Encode; + +# initiate the connector for the mpd POD, mpd must be running on locahost +# port 6600 without authentication +my $mpd = Audio::MPD->new('localhost',6600,'','$REUSE'); +my $work = $mpd->status()->updating_db(); require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; @@ -19,262 +42,546 @@ my %color = (); 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"; -my @songdb = ; -close(DATEI); -@songdb = sort(@songdb); +my @songs; &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); &Header::showhttpheaders(); -sub refreshpage{&Header::openbox( 'Waiting', 1, "" );print "

$Lang::tr{'pagerefresh'}
";&Header::closebox();} +if ( $ENV{'QUERY_STRING'} =~ /title/){ + +################################################################################ +# $ENV{'QUERY_STRING'} =~ /title/ is used to handle the inline iframe used to +# display the current song playing ( artist - title - album aso ) +# the cgi call´s itself with a parameter and the iframe refreshes itself without +# reloading the whole page +################################################################################ + + my $number = $mpd->status()->song()+1; + my $volume = $mpd->status()->volume(); + my $random = $mpd->status()->random(); + + if ($random eq "0" ){ + $random="off"; + }else{ + $random="on"; + } + + my $repeat = $mpd->status()->repeat(); + if ($repeat eq "0" ){ + $repeat="off"; + }else{ + $repeat="on"; + } + + my $song = ""; + if ( $mpd->current() ) + { + $song = substr("-= ".$mpd->current()->Artist()." | ".$mpd->current()->Title(),0,85)." =-
"; + if ( $song eq "-= | =-
" ){ + $song = "None
" + }; + $song .= $mpd->current()->Track()."# ".substr($mpd->current()->Album(),0,90)."
"; + }else{ + $song = "None

"; + } + + if ( $song eq "None
#
" ){ + $song = "None
".substr($mpd->current()->file(),0,90)."
" + }; + $song .= "Playlist: ".$number."-".$mpd->status()->playlistlength()." Time: ".$mpd->status()->time()->sofar."/"; + $song .= $mpd->status()->time()->total." (".$mpd->status()->time()->percent()."%) Status: "; + $song .= $mpd->status()->state()." Volume: ".$volume." % Repeat: ".$repeat." Random: ".$random; + + print < + + + + +END +; + print"

".encode('utf-8', $song)."

"; + exit; +}elsif ( $ENV{'QUERY_STRING'} =~ /control/){ + +################################################################################ +# $ENV{'QUERY_STRING'} =~ /control/ is used to handle the inline iframe used to +# display the control button ( prev play skip stop toggle aso ) +# the cgi call´s itself with a parameter and only the iframe is reloaded on click +################################################################################ + + &Header::getcgihash(\%mpfiresettings); + if ( $mpfiresettings{'ACTION'} eq "playall" ){ + $mpd->playlist->clear(); + foreach ($mpd->collection->all_pathes){ + $mpd->playlist->add($_); + } + $mpd->play(); + }elsif ($mpfiresettings{'ACTION'} eq "x" ){ + $mpd->stop(); + }elsif ( $mpfiresettings{'ACTION'} eq "|>" ){ + $mpd->pause(); + }elsif ( $mpfiresettings{'ACTION'} eq "<<" ){ + $mpd->prev(); + }elsif ( $mpfiresettings{'ACTION'} eq ">>" ){ + $mpd->next(); + }elsif ( $mpfiresettings{'ACTION'} eq "+" ){ + $mpd->volume('+5'); + }elsif ( $mpfiresettings{'ACTION'} eq "-" ){ + $mpd->volume('-5'); + }elsif ( $mpfiresettings{'ACTION'} eq "++" ){ + $mpd->volume('+10'); + }elsif ( $mpfiresettings{'ACTION'} eq "--" ){ + $mpd->volume('-10'); + }elsif ( $mpfiresettings{'ACTION'} eq ">" ){ + $mpd->play(); + }elsif ( $mpfiresettings{'ACTION'} eq "repeat" ){ + $mpd->repeat(); + }elsif ( $mpfiresettings{'ACTION'} eq "shuffle" ){ + $mpd->random(); + } + print < + + + + + + + + + + + +END +; + print < + + + + + + + +
+ +END +; + exit; +} + +# just a little subpage to handle automatic page refresh on demand ( 1 sec ) +sub refreshpage{ + &Header::openbox( 'Waiting', 1, "" ); + print "

$Lang::tr{'pagerefresh'}
"; + &Header::closebox(); +} + +# if the mpd is updating his database because of user interaction then the cgi +# should display that the mpd is unavailable, and refresh the status every 5 seconds +if ($work ne ""){ + &Header::openpage($Lang::tr{'mpfire'}, 1,); + &Header::openbigbox('100%', 'left', '', $errormessage); + &Header::openbox( 'Waiting', 5, "" ); + print "

Database is updating, please be patient.
"; + &Header::closebox(); + &Header::closebigbox(); + &Header::closepage(); + exit; +} + +if ( $mpfiresettings{'PAGE'} eq "" ){ $mpfiresettings{'PAGE'} = "1";}; +if ( $mpfiresettings{'FRAME'} eq "" ){$mpfiresettings{'FRAME'} = "webradio";}; &Header::getcgihash(\%mpfiresettings); -&Header::openpage($Lang::tr{'mpfire'}, 1, ""); +&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'}; -&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings); -system("/usr/local/bin/mpfirectrl scan $mpfiresettings{'SCANDIR'} $mpfiresettings{'SCANDIRDEPS'}"); -refreshpage(); +if ( $mpfiresettings{'ACTION'} eq "scan" ){ + +# on keypress scan the given directory and store the path to the mpd config + &General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings); + &Header::getcgihash(\%mpfiresettings); + delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'}; + delete $mpfiresettings{'PAGE'}; delete $mpfiresettings{'FRAME'}; + &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); + + $mpd->updatedb(); + refreshpage(); +}elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){ + $message=system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"","2>/dev/null"); +}elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){ + $mpd->play(); +}elsif ( $mpfiresettings{'ACTION'} eq "emptyplaylist" ){ +# on keypress clear the playlist + $mpd->playlist->clear(); +}elsif ( $mpfiresettings{'ACTION'} eq "addtoplaylist" ){ + $mpd->playlist->add($mpfiresettings{'FILE'}); +}elsif ( $mpfiresettings{'ACTION'} eq "playalbum" ){ +# on keypress play the selected albums + my @select = split(/\|/,$mpfiresettings{'album'}); + $mpd->playlist->clear(); + foreach (@select){ + foreach ($mpd->collection->filenames_by_album($_)){ + if ( $_ ne "" ){ + $mpd->playlist->add($_); + } + } + } + $mpd->play(); +}elsif ( $mpfiresettings{'ACTION'} eq "playartist" ){ +# on keypress play the selected artist + my @select = split(/\|/,$mpfiresettings{'artist'}); + $mpd->playlist->clear(); + foreach (@select){ + foreach ($mpd->collection->filenames_by_artist($_)){ + if ( $_ ne "" ){ + $mpd->playlist->add($_); + } + } + } + $mpd->play(); +}elsif ( $mpfiresettings{'ACTION'} eq "playyear" ){ +# on keypress play the selected year + my @select = split(/\|/,$mpfiresettings{'year'}); + $mpd->playlist->clear(); + foreach (@select){ + foreach ($mpd->collection->filenames_by_year($_)){ + if ( $_ ne "" ){ + $mpd->playlist->add($_); + } + } + } + $mpd->play(); +}elsif ( $mpfiresettings{'ACTION'} eq "playgenre" ){ +# on keypress play the selected genre + my @select = split(/\|/,$mpfiresettings{'genre'}); + $mpd->playlist->clear(); + foreach (@select){ + foreach ($mpd->collection->filenames_by_genre($_)){ + if ( $_ ne "" ){ + $mpd->playlist->add($_); + } + } + } + $mpd->play(); +}elsif ( $mpfiresettings{'ACTION'} eq ">" ){ + $mpd->playlist->clear(); + $mpd->playlist->add($mpfiresettings{'FILE'}); + $mpd->play(); } -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" ) -{ -my @temp = ""; -my @album = split(/\|/,$mpfiresettings{'album'}); -my %hash = map{ $_, 1 }@album; - -foreach (@songdb){ - my @song = split(/\|/,$_); - chomp($song[0]); - push(@temp,$song[0]."\n") if exists $hash{$song[4]}; - } -open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist"; -print DATEI @temp; -close(DATEI); -system("/usr/local/bin/mpfirectrl playall"); -} -if ( $mpfiresettings{'ACTION'} eq "playartist" ) -{ -my @temp = ""; -my @artist = split(/\|/,$mpfiresettings{'artist'}); -my %hash = map{ $_, 1 }@artist; - -foreach (@songdb){ - my @song = split(/\|/,$_); - chomp($song[0]); - push(@temp,$song[0]."\n") if exists $hash{$song[1]}; - } -open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist"; -print DATEI @temp; -close(DATEI); -system("/usr/local/bin/mpfirectrl playall"); -} -if ( $mpfiresettings{'ACTION'} eq "playall" ) -{ -my @temp = ""; -foreach (@songdb){ - my @song = split(/\|/,$_); - chomp($song[0]); - push(@temp,$song[0]."\n"); - } -open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist"; -print DATEI @temp; -close(DATEI); -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);} + if ( $mpfiresettings{'SEARCH'} eq "artist" && $mpfiresettings{'SEARCHITEM'} ne "" ){ + foreach ($mpd->collection->songs_with_artist_partial_filename($mpfiresettings{'SEARCHITEM'})){ + if ( $_ ne "" ){ + push(@songs,$_); + } + } + }elsif ( $mpfiresettings{'SEARCH'} eq "title" && $mpfiresettings{'SEARCHITEM'} ne "" ){ + foreach ($mpd->collection->songs_with_title_partial_filename($mpfiresettings{'SEARCHITEM'})){ + if ( $_ ne "" ){ + push(@songs,$_); + } + } + }elsif ( $mpfiresettings{'SEARCH'} eq "album" && $mpfiresettings{'SEARCHITEM'} ne "" ){ + foreach ($mpd->collection->songs_with_album_partial_filename($mpfiresettings{'SEARCHITEM'})){ + if ( $_ ne "" ){ + push(@songs,$_); + } + } + }else{ + @songs = $mpd->collection->all_items_simple(); + shift(@songs); + } ############################################################################################################################ ################################### Aufbau der HTML Seite fr globale Sambaeinstellungen #################################### -$mpfiresettings{'SCANDIR'} = "/"; -$mpfiresettings{'SHOWLIST'} = "off"; - +$mpfiresettings{'MUSICDIR'} = "/var/mp3"; &General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings); ############################################################################################################################ ########################################### rekursiv nach neuen Mp3s Scannen ##############################################ä -if ( $message ne "" ) { print "$message"; } +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'}); - +# box to enter the music directory and initiate the scan process print < - - - + +
$Lang::tr{'Scan for Files'}
$Lang::tr{'Scan from Directory'}
$Lang::tr{'deep scan directories'}on / - off
-
$Lang::tr{'Scan from Directory'}
END ; &Header::closebox(); -my $song = qx(/usr/local/bin/mpfirectrl song); -if ( $song eq "" ){$song = "None";} - &Header::openbox('100%', 'center', $Lang::tr{'mpfire controls'}); +# box for the two iframes showing the current playbar and the control buttons print < + +END +; +print "Songs:".$mpd->stats()->songs()."
"; - - - - - - - - - - +&Header::closebox(); + +&Header::openbox('100%', 'center', ''); +print <";} -else { print"";} -print <
-
- - - -
-= $song =-

total $#songdb songs

+
END ; -if ( $mpfiresettings{'SHOWLIST'} eq "on" ){print"
+my @buttons=("webradio", "quick playlist","songs"); +foreach (@buttons){ + if ( $mpfiresettings{'FRAME'} eq $_ ) { + print ""; + } else { + print ""; + } +} + +print < END ; &Header::closebox(); +if ( $mpfiresettings{'FRAME'} eq "quick playlist" ) +{ &Header::openbox('100%', 'center', $Lang::tr{'quick playlist'}); +# box to quickly select artist, album, year or genre and play the selection +print ""; +print ""; -my @artist; -my @album; -foreach (@songdb){ - my @song = split(/\|/,$_); - push(@artist,$song[1]);push(@album,$song[4]);} - my %hash = map{ $_, 1 }@artist; - @artist = sort keys %hash; - my %hash = map{ $_, 1 }@album; - @album = sort keys %hash; print < - - - + -
$Lang::tr{'artist'} - ".$mpd->stats()->artists()."$Lang::tr{'album'} - ".$mpd->stats()->albums()."
$Lang::tr{'artist'} - $#artist$Lang::tr{'album'} - $#album
-
-
+ + - - -
-
+ + + +
+
+ - -
+
+ + + + + +$Lang::tr{'year'}$Lang::tr{'genre'} + +
+
+ + + +
+ +
+
- $song[1]
$song[2] - $song[3] - $song[4] - $song[5] - $song[6] - $song[7]:$song[8]
$song[9] - $song[10] + +foreach (sort($mpd->collection->all_genre())){ + if ( $_ ne '' ){ + print "\n"; + } +} + +print <
+ + + + + END ; - if ( $song[11] eq "0\n" ) {print "Stereo"; } - elsif ( $song[11] eq "1\n" ) {print "Joint
Stereo"; } - elsif ( $song[11] eq "2\n" ) {print "Dual
Channel"; } - elsif ( $song[11] eq "3\n" ) {print "Single
Channel"; } - else {print ""; } - $lines++ - } -print ""; + &Header::closebox(); } -&Header::openbox('100%', 'center', $Lang::tr{'mpfire playlist'}); - -open(DATEI, "<${General::swroot}/mpfire/playlist") || die "Could not open playlist"; -my @playlist = ; -close(DATEI); - +if ( $mpfiresettings{'FRAME'} eq "songs" ) +{ +&Header::openbox('100%', 'center', $Lang::tr{'mpfire search'}); +# box to quickly search artist, album or title print < - - + + + + + + + + + + + + + + + +
$Lang::tr{'current playlist'}

-
- - -
$Lang::tr{'artist'}$Lang::tr{'title'}$Lang::tr{'album'}
+ + END ; &Header::closebox(); -&Header::openbox('100%', 'center', $Lang::tr{'mpfire webradio'}); +&Header::openbox('100%', 'center', $Lang::tr{'mpfire songs'}); +print < + + +END +; +if ( $#songs > 100 ){ + print ""; +} +print < + + + +END +; + +my $lines=0;my $i=0;my $begin;my $end; +if ( $mpfiresettings{'PAGE'} eq 'all' ){ + $begin=0; + $end=$#songs; +}else{ + $begin=(($mpfiresettings{'PAGE'}-1) * 100); + $end=(($mpfiresettings{'PAGE'} * 100)-1); +} + foreach (@songs){ + if (!($i >= $begin && $i <= $end)){ + #print $begin."->".$i."<-".$end."\n"; + $i++;next; + } + my @song = split(/\=/,$mpd->collection->song($_)); + @song = reverse @song; + + if ($lines % 2) { + print ""; + }else{ + print ""; + } + print < +
+ + + + + + + + +
+ + + + + + + + + +END +; + print "
"; + print ""; + print ""; + $lines++; + $i++; +} + +print "
$Lang::tr{'Existing Files'}

$Lang::tr{'Pages'}

"; + my $pages =(int($#songs/100)+1); + for(my $i = 1; $i <= $pages; $i++){ + print ""; + if (!($i % 205)){ + print"
"; + } + } + print ""; + print "
$Lang::tr{'artist'}
$Lang::tr{'title'}
$Lang::tr{'number'}$Lang::tr{'album'}
".encode('utf-8', $song[0])."
".encode('utf-8', $song[1])."
".encode('utf-8', $song[2])."".encode('utf-8', $song[3])."
"; +&Header::closebox(); +} +if ( $mpfiresettings{'FRAME'} eq "webradio" ) +{ +&Header::openbox('100%', 'center', $Lang::tr{'mpfire webradio'}); +# box to select some webradio´s to be played by one click open(DATEI, "<${General::swroot}/mpfire/webradio") || die "Could not open playlist"; my @webradio = ; close(DATEI); @@ -282,21 +589,85 @@ close(DATEI); print < $Lang::tr{'webradio playlist'} -Stream +Stream END ; + +my $lines=0; foreach (@webradio){ - my @stream = split(/\|/,$_); - print <$stream[1] -
-
+ my @stream = split(/\|/,$_); + $lines++; + chomp($stream[2]); + if ($lines % 2) { + print ""; + }else{ + print ""; + } + chomp $stream[1];chomp $stream[2]; + print <$stream[1] +
+ +
+ +END +; +} + +$lines++; +if ($lines % 2){ + print ""; +}else{ + print ""; +} + +print <

http:// + + +
END ; - } print ""; &Header::closebox(); +} + +&Header::openbox('100%', 'center', $Lang::tr{'mpfire playlist'}); +# box to show the current playlist given from mpc system command +my @playlist = `mpc playlist 2>/dev/null`; + +print < +$Lang::tr{'current playlist'} + + +
+ + + +
+ + +
+ + + +
+ + +END +; +&Header::closebox(); &Header::closebigbox(); &Header::closepage();