Control Skripe korrigiert
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / mpfire.cgi
CommitLineData
a28fdc01
CS
1#!/usr/bin/perl
2#
3# IPFire CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The IPFire Team
8
9use strict;
10# enable only the following on debugging purpose
11use warnings;
12use CGI::Carp 'fatalsToBrowser';
13
14require '/var/ipfire/general-functions.pl';
15require "${General::swroot}/lang.pl";
16require "${General::swroot}/header.pl";
17
18my %color = ();
19my %mainsettings = ();
20my %mpfiresettings = ();
21my %checked = ();
22my $message = "";
23my $errormessage = "";
24
25open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "No Database found";
26my @songdb = <DATEI>;
27close(DATEI);
28@songdb = sort(@songdb);
29
30&General::readhash("${General::swroot}/main/settings", \%mainsettings);
31&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
32
33&Header::showhttpheaders();
a28fdc01 34
bac7231b 35sub 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();}
69addbb8
CS
36
37&Header::getcgihash(\%mpfiresettings);
bac7231b 38&Header::openpage($Lang::tr{'mpfire'}, 1, "<meta http-equiv='refresh' content='120' />");
a28fdc01
CS
39&Header::openbigbox('100%', 'left', '', $errormessage);
40
a28fdc01
CS
41############################################################################################################################
42######################################## Scanne Verzeichnisse nach Mp3 Dateien #############################################
43
44if ( $mpfiresettings{'ACTION'} eq "scan" )
45{
46delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};
47&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);
48system("/usr/local/bin/mpfirectrl scan $mpfiresettings{'SCANDIR'} $mpfiresettings{'SCANDIRDEPS'}");
69addbb8 49refreshpage();
a28fdc01 50}
bac7231b
CS
51elsif ( $mpfiresettings{'ACTION'} eq ">" ){system("/usr/local/bin/mpfirectrl","play","\"$mpfiresettings{'FILE'}\"");}
52elsif ( $mpfiresettings{'ACTION'} eq "x" ){system("/usr/local/bin/mpfirectrl stop");}
53elsif ( $mpfiresettings{'ACTION'} eq "||" ){system("/usr/local/bin/mpfirectrl pause");}
54elsif ( $mpfiresettings{'ACTION'} eq "|>" ){system("/usr/local/bin/mpfirectrl resume");}
55elsif ( $mpfiresettings{'ACTION'} eq ">>" ){system("/usr/local/bin/mpfirectrl next");}
56elsif ( $mpfiresettings{'ACTION'} eq "stopweb" ){system("/usr/local/bin/mpfirectrl stopweb");}
57elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"");}
58elsif ( $mpfiresettings{'ACTION'} eq "+" ){system("/usr/local/bin/mpfirectrl volup 5");}
59elsif ( $mpfiresettings{'ACTION'} eq "-" ){system("/usr/local/bin/mpfirectrl voldown 5");}
60elsif ( $mpfiresettings{'ACTION'} eq "++" ){system("/usr/local/bin/mpfirectrl volup 10");}
61elsif ( $mpfiresettings{'ACTION'} eq "--" ){system("/usr/local/bin/mpfirectrl voldown 10");}
62elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){system("/usr/local/bin/mpfirectrl playall");}
63elsif ( $mpfiresettings{'ACTION'} eq "playalbum" )
32ab16de
CS
64{
65my @temp = "";
66my @album = split(/\|/,$mpfiresettings{'album'});
67my %hash = map{ $_, 1 }@album;
68
69foreach (@songdb){
70 my @song = split(/\|/,$_);
71 chomp($song[0]);
72 push(@temp,$song[0]."\n") if exists $hash{$song[4]};
73 }
74open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
75print DATEI @temp;
76close(DATEI);
77system("/usr/local/bin/mpfirectrl playall");
78}
bac7231b 79elsif ( $mpfiresettings{'ACTION'} eq "playartist" )
32ab16de
CS
80{
81my @temp = "";
82my @artist = split(/\|/,$mpfiresettings{'artist'});
83my %hash = map{ $_, 1 }@artist;
84
85foreach (@songdb){
86 my @song = split(/\|/,$_);
87 chomp($song[0]);
88 push(@temp,$song[0]."\n") if exists $hash{$song[1]};
89 }
90open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
91print DATEI @temp;
92close(DATEI);
93system("/usr/local/bin/mpfirectrl playall");
94}
bac7231b 95elsif ( $mpfiresettings{'ACTION'} eq "playall" )
a28fdc01
CS
96{
97my @temp = "";
98foreach (@songdb){
99 my @song = split(/\|/,$_);
100 chomp($song[0]);
101 push(@temp,$song[0]."\n");
102 }
103open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
104print DATEI @temp;
105close(DATEI);
106system("/usr/local/bin/mpfirectrl playall");
107}
bac7231b 108elsif ( $mpfiresettings{'SHOWLIST'} ){delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);}
a28fdc01
CS
109
110############################################################################################################################
111################################### Aufbau der HTML Seite fr globale Sambaeinstellungen ####################################
112
113$mpfiresettings{'SCANDIR'} = "/";
114$mpfiresettings{'SHOWLIST'} = "off";
115
116&General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings);
117
118############################################################################################################################
119########################################### rekursiv nach neuen Mp3s Scannen ##############################################รค
120
121if ( $message ne "" ) { print "<font color='red'>$message</font>"; }
122
123&Header::openbox('100%', 'center', $Lang::tr{'mpfire scanning'});
a2d5130f 124
a28fdc01
CS
125print <<END
126<form method='post' action='$ENV{'SCRIPT_NAME'}'>
127<table width='95%' cellspacing='0'>
128<tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'Scan for Files'}</b></td></tr>
129<tr><td align='left' width='40%'>$Lang::tr{'Scan from Directory'}</td><td align='left'><input type='text' name='SCANDIR' value='$mpfiresettings{'SCANDIR'}' size="30" /></td></tr>
130<tr><td align='left' width='40%'>$Lang::tr{'deep scan directories'}</td><td align='left'>on <input type='radio' name='SCANDIRDEPS' value='on' checked='checked'/>/
131 <input type='radio' name='SCANDIRDEPS' value='off'/> off</td></tr>
132<tr><td align='center' colspan='2'><input type='hidden' name='ACTION' value='scan' />
133 <input type='image' alt='$Lang::tr{'Scan for Files'}' title='$Lang::tr{'Scan for Files'}' src='/images/edit-find.png' /></td></tr>
134</table>
135</form>
136END
137;
138&Header::closebox();
139
a2d5130f
CS
140my $song = qx(/usr/local/bin/mpfirectrl song);
141if ( $song eq "" ){$song = "None";}
142
a28fdc01 143&Header::openbox('100%', 'center', $Lang::tr{'mpfire controls'});
a28fdc01 144print <<END
69addbb8
CS
145
146 <table width='95%' cellspacing='0'>
147 <tr bgcolor='$color{'color20'}'> <td colspan='5' align='center'><marquee behavior='alternate' scrollamount='1' scrolldelay='5'><font color=red>-= $song =-</font></marquee></td></tr>
148 <tr><td colspan='5' align='center'><br/><b>total $#songdb songs</b><br/><br/></td></tr>
149 <tr>
a28fdc01
CS
150 <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>
151 <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>
152 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='|>' /><input type='image' alt='$Lang::tr{'resume'}' title='$Lang::tr{'resume'}' src='/images/media-resume.png' /></form></td>
153 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='playall' /><input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' /></form></td>
154 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><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>
155 </tr>
156END
157;
158if ( $mpfiresettings{'SHOWLIST'} eq "on" ){print"<tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='SHOWLIST' value='off' /><input type='image' alt='$Lang::tr{'off'}' title='$Lang::tr{'off'}' src='/images/audio-x-generic.png' /></form></td>";}
159else { print"<tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='SHOWLIST' value='on' /><input type='image' alt='$Lang::tr{'on'}' title='$Lang::tr{'on'}' src='/images/audio-x-generic-red.png' /></form></td>";}
160print <<END
161 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><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>
162 <td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'><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>
163 <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>
164 <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>
165 </tr>
166</table>
167END
168;
169&Header::closebox();
170
32ab16de
CS
171&Header::openbox('100%', 'center', $Lang::tr{'quick playlist'});
172
173my @artist;
174my @album;
175foreach (@songdb){
176 my @song = split(/\|/,$_);
177 push(@artist,$song[1]);push(@album,$song[4]);}
178 my %hash = map{ $_, 1 }@artist;
179 @artist = sort keys %hash;
180 my %hash = map{ $_, 1 }@album;
181 @album = sort keys %hash;
182print <<END
183 <table width='95%' cellspacing='0'>
69addbb8 184 <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>
32ab16de
CS
185 <tr><td align='center'>
186 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
69addbb8 187 <select name='artist' size='8' multiple='multiple' style='width:300px;'>
32ab16de
CS
188END
189;
190 foreach (@artist){print "<option>$_</option>";}
191print <<END
192 </select><br/>
193 <input type='hidden' name='ACTION' value='playartist' />
194 <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
195 </form></td>
196 <td align='center'>
197 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
69addbb8 198 <select name='album' size='8' multiple='multiple' style='width:300px;'>
32ab16de
CS
199END
200;
201 foreach (@album){print "<option>$_</option>";}
202print <<END
203 </select><br/>
204 <input type='hidden' name='ACTION' value='playalbum' />
205 <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
206 </form></td>
207 </tr></table>
208END
209;
210&Header::closebox();
211
a28fdc01
CS
212if ( $mpfiresettings{'SHOWLIST'} eq "on" ){
213
214&Header::openbox('100%', 'center', $Lang::tr{'mpfire songs'});
215print <<END
216
32ab16de 217<table width='95%' cellspacing='5'>
a28fdc01
CS
218<tr bgcolor='$color{'color20'}'><td colspan='9' align='left'><b>$Lang::tr{'Existing Files'}</b></td></tr>
219<tr><td align='center'></td>
220 <td align='center'><b>$Lang::tr{'artist'}<br/>$Lang::tr{'title'}</b></td>
221 <td align='center'><b>$Lang::tr{'number'}</b></td>
222 <td align='center'><b>$Lang::tr{'album'}</b></td>
223 <td align='center'><b>$Lang::tr{'year'}</b></td>
224 <td align='center'><b>$Lang::tr{'genre'}</b></td>
225 <td align='center'><b>$Lang::tr{'length'}<br/>$Lang::tr{'bitrate'} - $Lang::tr{'frequency'}</b></td>
226 <td align='center'><b>$Lang::tr{'mode'}</b></td></tr>
227END
228;
229my $lines = 0;
230foreach (@songdb){
231 my @song = split(/\|/,$_);
232
233 if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>";} else {print "<tr bgcolor='$color{'color22'}'>";}
234 $song[0]=~s/\/\//\//g;
235 print <<END
32ab16de 236 <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>
a28fdc01
CS
237 <td align='center'>$song[1]<br/>$song[2]</td>
238 <td align='center'>$song[3]</td>
239 <td align='center'>$song[4]</td>
240 <td align='center'>$song[5]</td>
241 <td align='center'>$song[6]</td>
242 <td align='center'>$song[7]:$song[8]<br/>$song[9] - $song[10]</td>
243END
244;
245 if ( $song[11] eq "0\n" ) {print "<td align='center'>Stereo</td></tr>"; }
246 elsif ( $song[11] eq "1\n" ) {print "<td align='center'>Joint<br/>Stereo</td></tr>"; }
247 elsif ( $song[11] eq "2\n" ) {print "<td align='center'>Dual<br/>Channel</td></tr>"; }
248 elsif ( $song[11] eq "3\n" ) {print "<td align='center'>Single<br/>Channel</td></tr>"; }
249 else {print "<td align='center'></td></tr>"; }
250 $lines++
251 }
252print "</table></form>";
253&Header::closebox();
254}
255
32ab16de
CS
256&Header::openbox('100%', 'center', $Lang::tr{'mpfire playlist'});
257
32ab16de
CS
258open(DATEI, "<${General::swroot}/mpfire/playlist") || die "Could not open playlist";
259my @playlist = <DATEI>;
260close(DATEI);
261
bac7231b
CS
262my %hash;
263foreach (@songdb){
264 my @song = split(/\|/,$_);
265 chomp($song[0]);
266 $hash{$song[0]}=$song[1]." - ".$song[2]." - ".$song[7].":".$song[8];
267}
268
32ab16de
CS
269print <<END
270<table width='95%' cellspacing='0'>
271<tr bgcolor='$color{'color20'}'><td colspan='9' align='left'><b>$Lang::tr{'current playlist'}</b></td></tr>
bac7231b
CS
272<tr><td align='center'><textarea cols='120' rows='10' name='playlist' style='font-size:11px' readonly='readonly' >
273END
274;
275foreach (@playlist){chomp($_);print $hash{$_}."\n";}
276print <<END
277</textarea><br/>
32ab16de
CS
278 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
279 <input type='hidden' name='ACTION' value='playlist' />
280 <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
281 </form></td></tr>
282</table>
283END
284;
285&Header::closebox();
286
a2d5130f
CS
287&Header::openbox('100%', 'center', $Lang::tr{'mpfire webradio'});
288
289open(DATEI, "<${General::swroot}/mpfire/webradio") || die "Could not open playlist";
290my @webradio = <DATEI>;
291close(DATEI);
292
293print <<END
294<table width='95%' cellspacing='0'>
295<tr bgcolor='$color{'color20'}'><td colspan='9' align='left'><b>$Lang::tr{'webradio playlist'}</b></td></tr>
296<tr><td>Stream</td><td colspan='2'></td></tr>
297END
298;
299foreach (@webradio){
300 my @stream = split(/\|/,$_);
301 print <<END
302 <tr><td>$stream[1]</td>
303 <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>
304 <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>
305</tr>
306END
307;
308 }
309print "</table>";
310&Header::closebox();
311
a28fdc01
CS
312&Header::closebigbox();
313&Header::closepage();