]> git.ipfire.org Git - people/trikolon/ipfire-2.x.git/blame - html/cgi-bin/mpfire.cgi
core59: start/stop ipsec and ssh at update.
[people/trikolon/ipfire-2.x.git] / html / cgi-bin / mpfire.cgi
CommitLineData
a28fdc01 1#!/usr/bin/perl
19f5a6cc
CS
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
a28fdc01
CS
21
22use strict;
e5a63a6f 23
a28fdc01 24# enable only the following on debugging purpose
19f5a6cc
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
a28fdc01 27
e5a63a6f
CS
28# use the special mpd POD and the encode POD to handle the utf8 scalars
29use Audio::MPD;
30use Encode;
31
32# initiate the connector for the mpd POD, mpd must be running on locahost
33# port 6600 without authentication
34my $mpd = Audio::MPD->new('localhost',6600,'','$REUSE');
35my $work = $mpd->status()->updating_db();
36
a28fdc01
CS
37require '/var/ipfire/general-functions.pl';
38require "${General::swroot}/lang.pl";
39require "${General::swroot}/header.pl";
40
41my %color = ();
42my %mainsettings = ();
43my %mpfiresettings = ();
44my %checked = ();
8871b9f2 45my $message = '0';
a28fdc01 46my $errormessage = "";
e5a63a6f 47my @songs;
a28fdc01 48
a28fdc01
CS
49&General::readhash("${General::swroot}/main/settings", \%mainsettings);
50&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
51
8a5898e7 52&Header::showhttpheaders();
e5a63a6f
CS
53
54if ( $ENV{'QUERY_STRING'} =~ /title/){
55
56################################################################################
57# $ENV{'QUERY_STRING'} =~ /title/ is used to handle the inline iframe used to
58# display the current song playing ( artist - title - album aso )
59# the cgi call´s itself with a parameter and the iframe refreshes itself without
60# reloading the whole page
61################################################################################
62
63 my $number = $mpd->status()->song()+1;
64 my $volume = $mpd->status()->volume();
65 my $random = $mpd->status()->random();
66
67 if ($random eq "0" ){
68 $random="off";
69 }else{
70 $random="on";
71 }
72
73 my $repeat = $mpd->status()->repeat();
74 if ($repeat eq "0" ){
75 $repeat="off";
76 }else{
77 $repeat="on";
78 }
79
80 my $song = "";
81 if ( $mpd->current() )
82 {
3fcb086e 83 $song = substr("-= ".$mpd->current()->Artist()." | ".$mpd->current()->Title(),0,85)." =-<br /> ";
e5a63a6f
CS
84 if ( $song eq "-= | =-<br /> " ){
85 $song = "None<br />"
86 };
87 $song .= $mpd->current()->Track()."# ".substr($mpd->current()->Album(),0,90)."<br />";
88 }else{
89 $song = "None<br /><br />";
90 }
91
92 if ( $song eq "None<br /># <br />" ){
93 $song = "None<br />".substr($mpd->current()->file(),0,90)."<br />"
94 };
95 $song .= "Playlist: ".$number."-".$mpd->status()->playlistlength()." Time: ".$mpd->status()->time()->sofar."/";
96 $song .= $mpd->status()->time()->total." (".$mpd->status()->time()->percent()."%) Status: ";
97 $song .= $mpd->status()->state()." Volume: ".$volume." % Repeat: ".$repeat." Random: ".$random;
98
99 print <<END
a609bfb0 100<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
901a50cf 101<meta http-equiv='refresh' content='5'>
e5a63a6f 102<title></title>
901a50cf 103<body>
6cd3f682 104<table width='100%' cellspacing='0' align='center' style="background-image:url(/images/mpfire/box.png);background-repeat:no-repeat">
8a5898e7
CS
105END
106;
e5a63a6f
CS
107 print"<tr ><td align='center'><font color='red' face='Verdana' size='2'><br />".encode('utf-8', $song)."<br /><br /></font></td></tr></table></body>";
108 exit;
109}elsif ( $ENV{'QUERY_STRING'} =~ /control/){
a28fdc01 110
e5a63a6f
CS
111################################################################################
112# $ENV{'QUERY_STRING'} =~ /control/ is used to handle the inline iframe used to
113# display the control button ( prev play skip stop toggle aso )
114# the cgi call´s itself with a parameter and only the iframe is reloaded on click
115################################################################################
69addbb8 116
e5a63a6f
CS
117 &Header::getcgihash(\%mpfiresettings);
118 if ( $mpfiresettings{'ACTION'} eq "playall" ){
119 $mpd->playlist->clear();
120 foreach ($mpd->collection->all_pathes){
121 $mpd->playlist->add($_);
a609bfb0 122 }
e5a63a6f
CS
123 $mpd->play();
124 }elsif ($mpfiresettings{'ACTION'} eq "x" ){
125 $mpd->stop();
126 }elsif ( $mpfiresettings{'ACTION'} eq "|>" ){
127 $mpd->pause();
128 }elsif ( $mpfiresettings{'ACTION'} eq "<<" ){
129 $mpd->prev();
130 }elsif ( $mpfiresettings{'ACTION'} eq ">>" ){
131 $mpd->next();
132 }elsif ( $mpfiresettings{'ACTION'} eq "+" ){
133 $mpd->volume('+5');
134 }elsif ( $mpfiresettings{'ACTION'} eq "-" ){
135 $mpd->volume('-5');
136 }elsif ( $mpfiresettings{'ACTION'} eq "++" ){
137 $mpd->volume('+10');
138 }elsif ( $mpfiresettings{'ACTION'} eq "--" ){
139 $mpd->volume('-10');
140 }elsif ( $mpfiresettings{'ACTION'} eq ">" ){
141 $mpd->play();
142 }elsif ( $mpfiresettings{'ACTION'} eq "repeat" ){
143 $mpd->repeat();
144 }elsif ( $mpfiresettings{'ACTION'} eq "shuffle" ){
145 $mpd->random();
a609bfb0 146 }
e5a63a6f
CS
147 print <<END
148<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
149<title></title>
150<body>
151<table width='95%' cellspacing='0'>
152<tr>
153<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><input type='hidden' name='ACTION' value='<<' /><input type='image' alt='$Lang::tr{'prev'}' title='$Lang::tr{'prev'}' src='/images/media-skip-backward.png' /></form></td>
154<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><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>
155<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><input type='hidden' name='ACTION' value='|>' /><input type='image' alt='$Lang::tr{'toggle'}' title='$Lang::tr{'toggle'}' src='/images/media-resume.png' /></form></td>
156<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><input type='hidden' name='ACTION' value='>' /><input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' /></form></td>
157<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><input type='hidden' name='ACTION' value='playall' /><input type='image' alt='$Lang::tr{'play'} all' title='$Lang::tr{'play'} all' src='/images/media-playback-start-all.png' /></form></td>
158<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><input type='hidden' name='ACTION' value='>>' /><input type='image' alt='$Lang::tr{'next'}' title='$Lang::tr{'next'}' src='/images/media-skip-forward.png' /></form></td>
159</tr>
160END
161;
162 print <<END
163<tr>
164<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><input type='hidden' name='ACTION' value='repeat' /><input type='image' alt='$Lang::tr{'repeat'}' title='$Lang::tr{'repeat'}' src='/images/media-repeat.png' /></form></td>
165<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><input type='hidden' name='ACTION' value='--' /><input type='image' alt='$Lang::tr{'voldown10'}' title='$Lang::tr{'voldown10'}' src='/images/audio-volume-low-red.png' /></form></td>
166<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><input type='hidden' name='ACTION' value='-' /><input type='image' alt='$Lang::tr{'voldown5'}' title='$Lang::tr{'voldown5'}' src='/images/audio-volume-low.png' /></form></td>
167<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><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>
168<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><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>
169<td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}?control'><input type='hidden' name='ACTION' value='shuffle' /><input type='image' alt='$Lang::tr{'shuffle'}' title='$Lang::tr{'shuffle'}' src='/images/media-shuffle.png' /></form></td>
170</tr>
171</table>
172</body>
173END
174;
175 exit;
176}
a609bfb0 177
e5a63a6f
CS
178# just a little subpage to handle automatic page refresh on demand ( 1 sec )
179sub refreshpage{
180 &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='1;' />" );
181 print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>$Lang::tr{'pagerefresh'}</font></center>";
182 &Header::closebox();
183}
184
185# if the mpd is updating his database because of user interaction then the cgi
186# should display that the mpd is unavailable, and refresh the status every 5 seconds
187if ($work ne ""){
188 &Header::openpage($Lang::tr{'mpfire'}, 1,);
189 &Header::openbigbox('100%', 'left', '', $errormessage);
190 &Header::openbox( 'Waiting', 5, "<meta http-equiv='refresh' content='5;' />" );
191 print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>Database is updating, please be patient.</font></center>";
192 &Header::closebox();
193 &Header::closebigbox();
194 &Header::closepage();
195 exit;
196}
a609bfb0 197
3e1c7cfc
AF
198if ( $mpfiresettings{'PAGE'} eq "" ){ $mpfiresettings{'PAGE'} = "1";};
199if ( $mpfiresettings{'FRAME'} eq "" ){$mpfiresettings{'FRAME'} = "webradio";};
70ccd4a7 200
69addbb8 201&Header::getcgihash(\%mpfiresettings);
8a5898e7 202&Header::openpage($Lang::tr{'mpfire'}, 1,);
a28fdc01
CS
203&Header::openbigbox('100%', 'left', '', $errormessage);
204
a28fdc01
CS
205############################################################################################################################
206######################################## Scanne Verzeichnisse nach Mp3 Dateien #############################################
207
e5a63a6f 208if ( $mpfiresettings{'ACTION'} eq "scan" ){
70ccd4a7 209
e5a63a6f
CS
210# on keypress scan the given directory and store the path to the mpd config
211 &General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings);
212 &Header::getcgihash(\%mpfiresettings);
213 delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};
3e1c7cfc 214 delete $mpfiresettings{'PAGE'}; delete $mpfiresettings{'FRAME'};
e5a63a6f
CS
215 &General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);
216
217 open(DATEI, "<${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden";
218 my @Zeilen = <DATEI>;
219 close(DATEI);
220
221 open(DATEI, ">${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden";
222 foreach (@Zeilen){
223 if ( $_ =~ /music_directory/){
224 print DATEI "music_directory \"".$mpfiresettings{'MUSICDIR'}."\"\n";
225 }else {
226 print DATEI $_;
227 }
a609bfb0 228 }
e5a63a6f
CS
229 close(DATEI);
230
231 $mpd->updatedb();
232 refreshpage();
233}elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){
234 $message=system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"","2>/dev/null");
235}elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){
96481f95 236 $mpd->play();
e5a63a6f
CS
237}elsif ( $mpfiresettings{'ACTION'} eq "emptyplaylist" ){
238# on keypress clear the playlist
239 $mpd->playlist->clear();
240}elsif ( $mpfiresettings{'ACTION'} eq "addtoplaylist" ){
241 $mpd->playlist->add($mpfiresettings{'FILE'});
242}elsif ( $mpfiresettings{'ACTION'} eq "playalbum" ){
243# on keypress play the selected albums
244 my @select = split(/\|/,$mpfiresettings{'album'});
245 $mpd->playlist->clear();
a609bfb0 246 foreach (@select){
e5a63a6f
CS
247 foreach ($mpd->collection->filenames_by_album($_)){
248 if ( $_ ne "" ){
249 $mpd->playlist->add($_);
250 }
251 }
a609bfb0 252 }
e5a63a6f
CS
253 $mpd->play();
254}elsif ( $mpfiresettings{'ACTION'} eq "playartist" ){
255# on keypress play the selected artist
256 my @select = split(/\|/,$mpfiresettings{'artist'});
257 $mpd->playlist->clear();
a609bfb0 258 foreach (@select){
e5a63a6f
CS
259 foreach ($mpd->collection->filenames_by_artist($_)){
260 if ( $_ ne "" ){
261 $mpd->playlist->add($_);
262 }
263 }
a609bfb0 264 }
e5a63a6f
CS
265 $mpd->play();
266}elsif ( $mpfiresettings{'ACTION'} eq "playyear" ){
267# on keypress play the selected year
268 my @select = split(/\|/,$mpfiresettings{'year'});
269 $mpd->playlist->clear();
a609bfb0 270 foreach (@select){
e5a63a6f
CS
271 foreach ($mpd->collection->filenames_by_year($_)){
272 if ( $_ ne "" ){
273 $mpd->playlist->add($_);
274 }
275 }
a609bfb0 276 }
e5a63a6f
CS
277 $mpd->play();
278}elsif ( $mpfiresettings{'ACTION'} eq "playgenre" ){
279# on keypress play the selected genre
280 my @select = split(/\|/,$mpfiresettings{'genre'});
281 $mpd->playlist->clear();
282 foreach (@select){
283 foreach ($mpd->collection->filenames_by_genre($_)){
284 if ( $_ ne "" ){
285 $mpd->playlist->add($_);
286 }
287 }
288 }
289 $mpd->play();
290}elsif ( $mpfiresettings{'ACTION'} eq ">" ){
291 $mpd->playlist->clear();
292 $mpd->playlist->add($mpfiresettings{'FILE'});
293 $mpd->play();
8050f37b 294}
8050f37b 295
e5a63a6f
CS
296 if ( $mpfiresettings{'SEARCH'} eq "artist" && $mpfiresettings{'SEARCHITEM'} ne "" ){
297 foreach ($mpd->collection->songs_with_artist_partial_filename($mpfiresettings{'SEARCHITEM'})){
298 if ( $_ ne "" ){
299 push(@songs,$_);
300 }
301 }
302 }elsif ( $mpfiresettings{'SEARCH'} eq "title" && $mpfiresettings{'SEARCHITEM'} ne "" ){
303 foreach ($mpd->collection->songs_with_title_partial_filename($mpfiresettings{'SEARCHITEM'})){
304 if ( $_ ne "" ){
305 push(@songs,$_);
306 }
307 }
308 }elsif ( $mpfiresettings{'SEARCH'} eq "album" && $mpfiresettings{'SEARCHITEM'} ne "" ){
309 foreach ($mpd->collection->songs_with_album_partial_filename($mpfiresettings{'SEARCHITEM'})){
310 if ( $_ ne "" ){
311 push(@songs,$_);
312 }
313 }
314 }else{
315 @songs = $mpd->collection->all_items_simple();
316 shift(@songs);
317 }
a28fdc01
CS
318
319############################################################################################################################
320################################### Aufbau der HTML Seite fr globale Sambaeinstellungen ####################################
321
e98aa5c2 322$mpfiresettings{'MUSICDIR'} = "/var/mp3";
a28fdc01
CS
323&General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings);
324
325############################################################################################################################
326########################################### rekursiv nach neuen Mp3s Scannen ##############################################ä
327
e5a63a6f
CS
328if ( $message ne '0' ){
329 print "<font color='red'>An Error occured while launching the command</font>";
330}elsif ( $message ne "" && $message ne '0' ){
331 print "<font color='red'>$message</font>";
332}
a28fdc01
CS
333
334&Header::openbox('100%', 'center', $Lang::tr{'mpfire scanning'});
e5a63a6f 335# box to enter the music directory and initiate the scan process
a28fdc01
CS
336print <<END
337<form method='post' action='$ENV{'SCRIPT_NAME'}'>
338<table width='95%' cellspacing='0'>
339<tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'Scan for Files'}</b></td></tr>
19f5a6cc 340<tr><td align='left' width='40%'>$Lang::tr{'Scan from Directory'}</td><td align='left'><input type='text' name='MUSICDIR' value='$mpfiresettings{'MUSICDIR'}' size="50" /></td></tr>
e5a63a6f 341<tr><td align='center' colspan='2'><input type='hidden' name='ACTION' value='scan' /><input type='image' alt='$Lang::tr{'Scan for Files'}' title='$Lang::tr{'Scan for Files'}' src='/images/edit-find.png' /></td></tr>
a28fdc01
CS
342</table>
343</form>
344END
345;
346&Header::closebox();
347
348&Header::openbox('100%', 'center', $Lang::tr{'mpfire controls'});
e5a63a6f 349# box for the two iframes showing the current playbar and the control buttons
a28fdc01 350print <<END
e5a63a6f
CS
351<iframe height='85' width='685' src='/cgi-bin/mpfire.cgi?title' scrolling='no' frameborder='no' marginheight='0'></iframe>
352<iframe height='50' width='685' src='/cgi-bin/mpfire.cgi?control' scrolling='no' frameborder='no' marginheight='0'></iframe>
a28fdc01
CS
353END
354;
e5a63a6f
CS
355print "<b>Songs:".$mpd->stats()->songs()."</b><br />";
356
a28fdc01
CS
357&Header::closebox();
358
3e1c7cfc
AF
359&Header::openbox('100%', 'center', '');
360print <<END
361<tr><td align='center' colspan='4'>
362<form method='post' action='$ENV{'SCRIPT_NAME'}'>
363END
364;
365my @buttons=("webradio", "quick playlist","songs");
366foreach (@buttons){
367 if ( $mpfiresettings{'FRAME'} eq $_ ) {
368 print "<input type='submit' name='FRAME' value='$_' disabled />";
369 } else {
370 print "<input type='submit' name='FRAME' value='$_' />";
371 }
372}
373
374print <<END
375</form></td></tr>
376END
377;
378&Header::closebox();
379
380if ( $mpfiresettings{'FRAME'} eq "quick playlist" )
381{
32ab16de 382&Header::openbox('100%', 'center', $Lang::tr{'quick playlist'});
e5a63a6f 383# box to quickly select artist, album, year or genre and play the selection
cb5e9c6c 384print "<table width='95%' cellspacing='0'>";
e5a63a6f
CS
385print "<tr><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'artist'} - ".$mpd->stats()->artists()."</b></td><td align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'album'} - ".$mpd->stats()->albums()."</b></td></tr>";
386
05882fff 387print <<END
e5a63a6f
CS
388<tr><td align='center'>
389<form method='post' action='$ENV{'SCRIPT_NAME'}'>
390<select name='artist' size='8' multiple='multiple' style='width:300px;'>
32ab16de
CS
391END
392;
e5a63a6f 393
f7d54895 394foreach (sort($mpd->collection->all_artists())){
e5a63a6f
CS
395 if ( $_ ne '' ){
396 print "<option>".encode('utf-8', $_)."</option>\n";
397 }
398}
399
32ab16de 400print <<END
e5a63a6f
CS
401</select><br/>
402<input type='hidden' name='ACTION' value='playartist' />
403<input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
3e1c7cfc 404<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
e5a63a6f
CS
405</form></td>
406<td align='center'>
407<form method='post' action='$ENV{'SCRIPT_NAME'}'>
408<select name='album' size='8' multiple='multiple' style='width:300px;'>
32ab16de
CS
409END
410;
e5a63a6f 411
f7d54895 412foreach (sort($mpd->collection->all_albums())){
e5a63a6f
CS
413 if ( $_ ne '' ){
414 print "<option>".encode('utf-8', $_)."</option>\n";
415 }
416}
417
32ab16de 418print <<END
e5a63a6f
CS
419</select><br/>
420<input type='hidden' name='ACTION' value='playalbum' />
421<input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
3e1c7cfc 422<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
e5a63a6f
CS
423</form></td>
424</tr>
425<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>
426<tr><td align='center'>
427<form method='post' action='$ENV{'SCRIPT_NAME'}'>
428<select name='year' size='8' multiple='multiple' style='width:300px;'>
05882fff
CS
429END
430;
e5a63a6f 431
f7d54895 432foreach (sort($mpd->collection->all_years())){
e5a63a6f
CS
433 if ( $_ ne '' ){
434 print "<option>$_</option>\n";
435 }
436}
437
05882fff 438print <<END
e5a63a6f
CS
439</select><br/>
440<input type='hidden' name='ACTION' value='playyear' />
441<input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
3e1c7cfc 442<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
e5a63a6f
CS
443</form></td>
444<td align='center'>
445<form method='post' action='$ENV{'SCRIPT_NAME'}'>
446<select name='genre' size='8' multiple='multiple' style='width:300px;'>
8050f37b
CS
447END
448;
e5a63a6f 449
f7d54895 450foreach (sort($mpd->collection->all_genre())){
e5a63a6f
CS
451 if ( $_ ne '' ){
452 print "<option>$_</option>\n";
453 }
454}
455
8050f37b 456print <<END
e5a63a6f
CS
457</select><br/>
458<input type='hidden' name='ACTION' value='playgenre' />
459<input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
3e1c7cfc 460<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
e5a63a6f
CS
461</form></td>
462</tr></table>
8050f37b
CS
463END
464;
e5a63a6f
CS
465
466&Header::closebox();
3e1c7cfc 467}
e5a63a6f 468
3e1c7cfc
AF
469if ( $mpfiresettings{'FRAME'} eq "songs" )
470{
e5a63a6f
CS
471&Header::openbox('100%', 'center', $Lang::tr{'mpfire search'});
472# box to quickly search artist, album or title
8050f37b 473print <<END
6cd3f682 474<form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'mpfire songs'}'>
e5a63a6f
CS
475<table width='95%' cellspacing='0'>
476<tr>
477<td align='right' width='33%'>$Lang::tr{'artist'}</td>
478<td align='center' width='33%'>$Lang::tr{'title'}</td>
479<td align='left' width='33%'>$Lang::tr{'album'}</td>
480</tr>
481<tr>
482<td align='right' width='33%'><input type='radio' name='SEARCH' value='artist' /></td>
483<td align='center' width='33%'><input type='radio' name='SEARCH' value='title' checked='checked' /></td>
484<td align='left' width='33%'><input type='radio' name='SEARCH' value='album' /></td>
485</tr>
486<tr>
487<td align='center' colspan='3'><input type='text' name='SEARCHITEM' value='$mpfiresettings{'SEARCHITEM'}' size="50" /></td>
488</tr>
489<tr>
490<td align='center' colspan='3'><input type='hidden' name='ACTION' value='search' /><input type='image' alt='$Lang::tr{'Scan for Songs'}' title='$Lang::tr{'Scan for Songs'}' src='/images/edit-find.png' /></td>
491</tr>
492</table>
3e1c7cfc 493<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
e5a63a6f 494</form>
32ab16de
CS
495END
496;
497&Header::closebox();
498
a28fdc01
CS
499&Header::openbox('100%', 'center', $Lang::tr{'mpfire songs'});
500print <<END
e5a63a6f
CS
501<a id='$Lang::tr{'mpfire songs'}' name='$Lang::tr{'mpfire songs'}'></a>
502<table width='95%' cellspacing='3'>
503<tr bgcolor='$color{'color20'}'><td colspan='4' align='left'><b>$Lang::tr{'Existing Files'}</b></td></tr>
8871b9f2
CS
504END
505;
e5a63a6f
CS
506if ( $#songs > 100 ){
507 print "<tr><td align='center' colspan='4'><br/>$Lang::tr{'Pages'}<br/><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='submit' name='PAGE' value='all' /><br/>";
508 my $pages =(int($#songs/100)+1);
509 for(my $i = 1; $i <= $pages; $i++){
510 print "<input type='submit' name='PAGE' value='$i' />";
511 if (!($i % 205)){
512 print"<br/>";
513 }
514 }
3e1c7cfc 515 print "<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />";
e5a63a6f 516 print "</form></td></tr>";
8871b9f2
CS
517}
518print <<END
a28fdc01 519<tr><td align='center'></td>
e5a63a6f
CS
520<td align='center'><b>$Lang::tr{'artist'}<br/>$Lang::tr{'title'}</b></td>
521<td align='center'><b>$Lang::tr{'number'}</b></td>
522<td align='center'><b>$Lang::tr{'album'}</b></td>
a28fdc01
CS
523END
524;
e5a63a6f 525
8871b9f2
CS
526my $lines=0;my $i=0;my $begin;my $end;
527if ( $mpfiresettings{'PAGE'} eq 'all' ){
a609bfb0 528 $begin=0;
e5a63a6f
CS
529 $end=$#songs;
530}else{
a609bfb0
CS
531 $begin=(($mpfiresettings{'PAGE'}-1) * 100);
532 $end=(($mpfiresettings{'PAGE'} * 100)-1);
8871b9f2 533}
e5a63a6f 534 foreach (@songs){
a609bfb0 535 if (!($i >= $begin && $i <= $end)){
e5a63a6f
CS
536 #print $begin."->".$i."<-".$end."\n";
537 $i++;next;
538 }
539 my @song = split(/\=/,$mpd->collection->song($_));
540 @song = reverse @song;
a609bfb0 541
e5a63a6f
CS
542 if ($lines % 2) {
543 print "<tr bgcolor='$color{'color20'}'>";
544 }else{
545 print "<tr bgcolor='$color{'color22'}'>";
546 }
a609bfb0 547 print <<END
e5a63a6f
CS
548<td align='center' style="white-space:nowrap;">
549<form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'mpfire songs'}'>
550<input type='hidden' name='ACTION' value='addtoplaylist' />
551<input type='hidden' name='FILE' value="$_" />
552<input type='hidden' name='PAGE' value='$mpfiresettings{'PAGE'}' />
3e1c7cfc 553<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
e5a63a6f
CS
554<input type='hidden' name='SEARCH' value='$mpfiresettings{'SEARCH'}' />
555<input type='hidden' name='SEARCHITEM' value='$mpfiresettings{'SEARCHITEM'}' />
556<input type='image' alt='$Lang::tr{'add'}' title='$Lang::tr{'add'}' src='/images/list-add.png' />
557</form>
558<form method='post' action='$ENV{'SCRIPT_NAME'}#$Lang::tr{'mpfire songs'}'>
559<input type='hidden' name='ACTION' value='>' />
560<input type='hidden' name='FILE' value="$_" />
561<input type='hidden' name='PAGE' value='$mpfiresettings{'PAGE'}' />
3e1c7cfc 562<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
e5a63a6f
CS
563<input type='hidden' name='SEARCH' value='$mpfiresettings{'SEARCH'}' />
564<input type='hidden' name='SEARCHITEM' value='$mpfiresettings{'SEARCHITEM'}' />
565<input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
566</form>
567</td>
a28fdc01
CS
568END
569;
e5a63a6f
CS
570 print "<td align='center'>".encode('utf-8', $song[0])."<br/>".encode('utf-8', $song[1])."</td>";
571 print "<td align='center'>".encode('utf-8', $song[2])."</td>";
572 print "<td align='center'>".encode('utf-8', $song[3])."</td>";
a609bfb0
CS
573 $lines++;
574 $i++;
e5a63a6f
CS
575}
576
8871b9f2 577print "</table>";
a28fdc01 578&Header::closebox();
e5a63a6f
CS
579}
580
3e1c7cfc
AF
581if ( $mpfiresettings{'FRAME'} eq "webradio" )
582{
a2d5130f 583&Header::openbox('100%', 'center', $Lang::tr{'mpfire webradio'});
e5a63a6f 584# box to select some webradio´s to be played by one click
a2d5130f
CS
585open(DATEI, "<${General::swroot}/mpfire/webradio") || die "Could not open playlist";
586my @webradio = <DATEI>;
587close(DATEI);
588
589print <<END
590<table width='95%' cellspacing='0'>
591<tr bgcolor='$color{'color20'}'><td colspan='9' align='left'><b>$Lang::tr{'webradio playlist'}</b></td></tr>
efb2af14 592<tr><td align='left'>Stream</td><td colspan='2'></td></tr>
a2d5130f
CS
593END
594;
e5a63a6f 595
d089ce65 596my $lines=0;
a2d5130f 597foreach (@webradio){
a609bfb0
CS
598 my @stream = split(/\|/,$_);
599 $lines++;
600 chomp($stream[2]);
e5a63a6f
CS
601 if ($lines % 2) {
602 print "<tr bgcolor='$color{'color22'}'>";
603 }else{
604 print "<tr>";
605 }
3fcb086e 606 chomp $stream[1];chomp $stream[2];
e5a63a6f
CS
607 print <<END
608<td align='left'><a href='$stream[2]' target='_blank'>$stream[1]</a></td>
3e1c7cfc
AF
609<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' align='middle' />
610<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
611</form></td>
a2d5130f
CS
612</tr>
613END
614;
e5a63a6f
CS
615}
616
617$lines++;
618if ($lines % 2){
619 print "<tr bgcolor='$color{'color22'}'>";
620}else{
621 print "<tr>";
622}
623
d089ce65 624print <<END
e5a63a6f 625<td align='center' colspan='2'><form method='post' action='$ENV{'SCRIPT_NAME'}'><br />http://<input type=text name='FILE' value='www.meineradiourl:1234' size='75' />
3e1c7cfc
AF
626<input type='hidden' name='ACTION' value='playweb' /><input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' align='top' />
627<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
628</form></td>
d089ce65
CS
629</tr>
630END
631;
a2d5130f 632print "</table>";
3e1c7cfc
AF
633&Header::closebox();
634}
635
636&Header::openbox('100%', 'center', $Lang::tr{'mpfire playlist'});
637# box to show the current playlist given from mpc system command
638my @playlist = `mpc playlist 2>/dev/null`;
639
640print <<END
641<table width='95%' cellspacing='0'>
642<tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'current playlist'}</b></td></tr>
643<tr><td align='center' colspan='2' ><textarea cols='100' rows='10' name='playlist' style='font-size:11px;width:650px;' readonly='readonly'>
644END
645;
646
647foreach (@playlist){
648 $_=~s/&/&amp\;/g;;print $_;
649}
650
651print <<END
652</textarea></td></tr><tr>
653<td align='right'>
654<form method='post' action='$ENV{'SCRIPT_NAME'}'>
655<input type='hidden' name='ACTION' value='emptyplaylist' />
656<input type='image' alt='$Lang::tr{'clear playlist'}' title='$Lang::tr{'clear playlist'}' src='/images/user-trash.png' />
657<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
658</form>
659</td>
660<td align='left'>
661<form method='post' action='$ENV{'SCRIPT_NAME'}'>
662<input type='hidden' name='ACTION' value='playlist' />
663<input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
664<input type='hidden' name='FRAME' value='$mpfiresettings{'FRAME'}' />
665</form>
666</td></tr>
667</table>
668END
669;
670
a2d5130f 671&Header::closebox();
a28fdc01
CS
672&Header::closebigbox();
673&Header::closepage();