Control Skripe korrigiert
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / mpfire.cgi
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
9 use strict;
10 # enable only the following on debugging purpose
11 use warnings;
12 use CGI::Carp 'fatalsToBrowser';
13
14 require '/var/ipfire/general-functions.pl';
15 require "${General::swroot}/lang.pl";
16 require "${General::swroot}/header.pl";
17
18 my %color = ();
19 my %mainsettings = ();
20 my %mpfiresettings = ();
21 my %checked = ();
22 my $message = "";
23 my $errormessage = "";
24
25 open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "No Database found";
26 my @songdb = <DATEI>;
27 close(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();
34
35 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();}
36
37 &Header::getcgihash(\%mpfiresettings);
38 &Header::openpage($Lang::tr{'mpfire'}, 1, "<meta http-equiv='refresh' content='120' />");
39 &Header::openbigbox('100%', 'left', '', $errormessage);
40
41 ############################################################################################################################
42 ######################################## Scanne Verzeichnisse nach Mp3 Dateien #############################################
43
44 if ( $mpfiresettings{'ACTION'} eq "scan" )
45 {
46 delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};
47 &General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);
48 system("/usr/local/bin/mpfirectrl scan $mpfiresettings{'SCANDIR'} $mpfiresettings{'SCANDIRDEPS'}");
49 refreshpage();
50 }
51 elsif ( $mpfiresettings{'ACTION'} eq ">" ){system("/usr/local/bin/mpfirectrl","play","\"$mpfiresettings{'FILE'}\"");}
52 elsif ( $mpfiresettings{'ACTION'} eq "x" ){system("/usr/local/bin/mpfirectrl stop");}
53 elsif ( $mpfiresettings{'ACTION'} eq "||" ){system("/usr/local/bin/mpfirectrl pause");}
54 elsif ( $mpfiresettings{'ACTION'} eq "|>" ){system("/usr/local/bin/mpfirectrl resume");}
55 elsif ( $mpfiresettings{'ACTION'} eq ">>" ){system("/usr/local/bin/mpfirectrl next");}
56 elsif ( $mpfiresettings{'ACTION'} eq "stopweb" ){system("/usr/local/bin/mpfirectrl stopweb");}
57 elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"");}
58 elsif ( $mpfiresettings{'ACTION'} eq "+" ){system("/usr/local/bin/mpfirectrl volup 5");}
59 elsif ( $mpfiresettings{'ACTION'} eq "-" ){system("/usr/local/bin/mpfirectrl voldown 5");}
60 elsif ( $mpfiresettings{'ACTION'} eq "++" ){system("/usr/local/bin/mpfirectrl volup 10");}
61 elsif ( $mpfiresettings{'ACTION'} eq "--" ){system("/usr/local/bin/mpfirectrl voldown 10");}
62 elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){system("/usr/local/bin/mpfirectrl playall");}
63 elsif ( $mpfiresettings{'ACTION'} eq "playalbum" )
64 {
65 my @temp = "";
66 my @album = split(/\|/,$mpfiresettings{'album'});
67 my %hash = map{ $_, 1 }@album;
68
69 foreach (@songdb){
70 my @song = split(/\|/,$_);
71 chomp($song[0]);
72 push(@temp,$song[0]."\n") if exists $hash{$song[4]};
73 }
74 open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
75 print DATEI @temp;
76 close(DATEI);
77 system("/usr/local/bin/mpfirectrl playall");
78 }
79 elsif ( $mpfiresettings{'ACTION'} eq "playartist" )
80 {
81 my @temp = "";
82 my @artist = split(/\|/,$mpfiresettings{'artist'});
83 my %hash = map{ $_, 1 }@artist;
84
85 foreach (@songdb){
86 my @song = split(/\|/,$_);
87 chomp($song[0]);
88 push(@temp,$song[0]."\n") if exists $hash{$song[1]};
89 }
90 open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
91 print DATEI @temp;
92 close(DATEI);
93 system("/usr/local/bin/mpfirectrl playall");
94 }
95 elsif ( $mpfiresettings{'ACTION'} eq "playall" )
96 {
97 my @temp = "";
98 foreach (@songdb){
99 my @song = split(/\|/,$_);
100 chomp($song[0]);
101 push(@temp,$song[0]."\n");
102 }
103 open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
104 print DATEI @temp;
105 close(DATEI);
106 system("/usr/local/bin/mpfirectrl playall");
107 }
108 elsif ( $mpfiresettings{'SHOWLIST'} ){delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);}
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
121 if ( $message ne "" ) { print "<font color='red'>$message</font>"; }
122
123 &Header::openbox('100%', 'center', $Lang::tr{'mpfire scanning'});
124
125 print <<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>
136 END
137 ;
138 &Header::closebox();
139
140 my $song = qx(/usr/local/bin/mpfirectrl song);
141 if ( $song eq "" ){$song = "None";}
142
143 &Header::openbox('100%', 'center', $Lang::tr{'mpfire controls'});
144 print <<END
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>
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>
156 END
157 ;
158 if ( $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>";}
159 else { 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>";}
160 print <<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>
167 END
168 ;
169 &Header::closebox();
170
171 &Header::openbox('100%', 'center', $Lang::tr{'quick playlist'});
172
173 my @artist;
174 my @album;
175 foreach (@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;
182 print <<END
183 <table width='95%' cellspacing='0'>
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>
185 <tr><td align='center'>
186 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
187 <select name='artist' size='8' multiple='multiple' style='width:300px;'>
188 END
189 ;
190 foreach (@artist){print "<option>$_</option>";}
191 print <<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'}'>
198 <select name='album' size='8' multiple='multiple' style='width:300px;'>
199 END
200 ;
201 foreach (@album){print "<option>$_</option>";}
202 print <<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>
208 END
209 ;
210 &Header::closebox();
211
212 if ( $mpfiresettings{'SHOWLIST'} eq "on" ){
213
214 &Header::openbox('100%', 'center', $Lang::tr{'mpfire songs'});
215 print <<END
216
217 <table width='95%' cellspacing='5'>
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>
227 END
228 ;
229 my $lines = 0;
230 foreach (@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
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>
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>
243 END
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 }
252 print "</table></form>";
253 &Header::closebox();
254 }
255
256 &Header::openbox('100%', 'center', $Lang::tr{'mpfire playlist'});
257
258 open(DATEI, "<${General::swroot}/mpfire/playlist") || die "Could not open playlist";
259 my @playlist = <DATEI>;
260 close(DATEI);
261
262 my %hash;
263 foreach (@songdb){
264 my @song = split(/\|/,$_);
265 chomp($song[0]);
266 $hash{$song[0]}=$song[1]." - ".$song[2]." - ".$song[7].":".$song[8];
267 }
268
269 print <<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>
272 <tr><td align='center'><textarea cols='120' rows='10' name='playlist' style='font-size:11px' readonly='readonly' >
273 END
274 ;
275 foreach (@playlist){chomp($_);print $hash{$_}."\n";}
276 print <<END
277 </textarea><br/>
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>
283 END
284 ;
285 &Header::closebox();
286
287 &Header::openbox('100%', 'center', $Lang::tr{'mpfire webradio'});
288
289 open(DATEI, "<${General::swroot}/mpfire/webradio") || die "Could not open playlist";
290 my @webradio = <DATEI>;
291 close(DATEI);
292
293 print <<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>
297 END
298 ;
299 foreach (@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>
306 END
307 ;
308 }
309 print "</table>";
310 &Header::closebox();
311
312 &Header::closebigbox();
313 &Header::closepage();