6b6b4acb5e6ea06aaced0eb393989ba56d0414fd
[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
52 if ( $mpfiresettings{'ACTION'} eq ">" ){system("/usr/local/bin/mpfirectrl","play","\"$mpfiresettings{'FILE'}\"");}
53 if ( $mpfiresettings{'ACTION'} eq "x" ){system("/usr/local/bin/mpfirectrl stop");}
54 if ( $mpfiresettings{'ACTION'} eq "||" ){system("/usr/local/bin/mpfirectrl pause");}
55 if ( $mpfiresettings{'ACTION'} eq "|>" ){system("/usr/local/bin/mpfirectrl resume");}
56 if ( $mpfiresettings{'ACTION'} eq ">>" ){system("/usr/local/bin/mpfirectrl next");}
57 if ( $mpfiresettings{'ACTION'} eq "stopweb" ){system("/usr/local/bin/mpfirectrl stopweb");}
58 if ( $mpfiresettings{'ACTION'} eq "playweb" ){system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"");}
59 if ( $mpfiresettings{'ACTION'} eq "+" ){system("/usr/local/bin/mpfirectrl volup 5");}
60 if ( $mpfiresettings{'ACTION'} eq "-" ){system("/usr/local/bin/mpfirectrl voldown 5");}
61 if ( $mpfiresettings{'ACTION'} eq "++" ){system("/usr/local/bin/mpfirectrl volup 10");}
62 if ( $mpfiresettings{'ACTION'} eq "--" ){system("/usr/local/bin/mpfirectrl voldown 10");}
63 if ( $mpfiresettings{'ACTION'} eq "playlist" ){system("/usr/local/bin/mpfirectrl playall");}
64 if ( $mpfiresettings{'ACTION'} eq "playalbum" )
65 {
66 my @temp = "";
67 my @album = split(/\|/,$mpfiresettings{'album'});
68 my %hash = map{ $_, 1 }@album;
69
70 foreach (@songdb){
71 my @song = split(/\|/,$_);
72 chomp($song[0]);
73 push(@temp,$song[0]."\n") if exists $hash{$song[4]};
74 }
75 open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
76 print DATEI @temp;
77 close(DATEI);
78 system("/usr/local/bin/mpfirectrl playall");
79 }
80 if ( $mpfiresettings{'ACTION'} eq "playartist" )
81 {
82 my @temp = "";
83 my @artist = split(/\|/,$mpfiresettings{'artist'});
84 my %hash = map{ $_, 1 }@artist;
85
86 foreach (@songdb){
87 my @song = split(/\|/,$_);
88 chomp($song[0]);
89 push(@temp,$song[0]."\n") if exists $hash{$song[1]};
90 }
91 open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
92 print DATEI @temp;
93 close(DATEI);
94 system("/usr/local/bin/mpfirectrl playall");
95 }
96 if ( $mpfiresettings{'ACTION'} eq "playall" )
97 {
98 my @temp = "";
99 foreach (@songdb){
100 my @song = split(/\|/,$_);
101 chomp($song[0]);
102 push(@temp,$song[0]."\n");
103 }
104 open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist";
105 print DATEI @temp;
106 close(DATEI);
107 system("/usr/local/bin/mpfirectrl playall");
108 }
109 if ( $mpfiresettings{'SHOWLIST'} ){delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);}
110
111 ############################################################################################################################
112 ################################### Aufbau der HTML Seite fr globale Sambaeinstellungen ####################################
113
114 $mpfiresettings{'SCANDIR'} = "/";
115 $mpfiresettings{'SHOWLIST'} = "off";
116
117 &General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings);
118
119 ############################################################################################################################
120 ########################################### rekursiv nach neuen Mp3s Scannen ##############################################รค
121
122 if ( $message ne "" ) { print "<font color='red'>$message</font>"; }
123
124 &Header::openbox('100%', 'center', $Lang::tr{'mpfire scanning'});
125
126 print <<END
127 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
128 <table width='95%' cellspacing='0'>
129 <tr bgcolor='$color{'color20'}'><td colspan='2' align='left'><b>$Lang::tr{'Scan for Files'}</b></td></tr>
130 <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>
131 <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'/>/
132 <input type='radio' name='SCANDIRDEPS' value='off'/> off</td></tr>
133 <tr><td align='center' colspan='2'><input type='hidden' name='ACTION' value='scan' />
134 <input type='image' alt='$Lang::tr{'Scan for Files'}' title='$Lang::tr{'Scan for Files'}' src='/images/edit-find.png' /></td></tr>
135 </table>
136 </form>
137 END
138 ;
139 &Header::closebox();
140
141 my $song = qx(/usr/local/bin/mpfirectrl song);
142 if ( $song eq "" ){$song = "None";}
143
144 &Header::openbox('100%', 'center', $Lang::tr{'mpfire controls'});
145 print <<END
146
147 <table width='95%' cellspacing='0'>
148 <tr bgcolor='$color{'color20'}'> <td colspan='5' align='center'><marquee behavior='alternate' scrollamount='1' scrolldelay='5'><font color=red>-= $song =-</font></marquee></td></tr>
149 <tr><td colspan='5' align='center'><br/><b>total $#songdb songs</b><br/><br/></td></tr>
150 <tr>
151 <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>
152 <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>
153 <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>
154 <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>
155 <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>
156 </tr>
157 END
158 ;
159 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>";}
160 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>";}
161 print <<END
162 <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>
163 <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>
164 <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>
165 <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>
166 </tr>
167 </table>
168 END
169 ;
170 &Header::closebox();
171
172 &Header::openbox('100%', 'center', $Lang::tr{'quick playlist'});
173
174 my @artist;
175 my @album;
176 foreach (@songdb){
177 my @song = split(/\|/,$_);
178 push(@artist,$song[1]);push(@album,$song[4]);}
179 my %hash = map{ $_, 1 }@artist;
180 @artist = sort keys %hash;
181 my %hash = map{ $_, 1 }@album;
182 @album = sort keys %hash;
183 print <<END
184 <table width='95%' cellspacing='0'>
185 <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>
186 <tr><td align='center'>
187 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
188 <select name='artist' size='8' multiple='multiple' style='width:300px;'>
189 END
190 ;
191 foreach (@artist){print "<option>$_</option>";}
192 print <<END
193 </select><br/>
194 <input type='hidden' name='ACTION' value='playartist' />
195 <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
196 </form></td>
197 <td align='center'>
198 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
199 <select name='album' size='8' multiple='multiple' style='width:300px;'>
200 END
201 ;
202 foreach (@album){print "<option>$_</option>";}
203 print <<END
204 </select><br/>
205 <input type='hidden' name='ACTION' value='playalbum' />
206 <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
207 </form></td>
208 </tr></table>
209 END
210 ;
211 &Header::closebox();
212
213 if ( $mpfiresettings{'SHOWLIST'} eq "on" ){
214
215 &Header::openbox('100%', 'center', $Lang::tr{'mpfire songs'});
216 print <<END
217
218 <table width='95%' cellspacing='5'>
219 <tr bgcolor='$color{'color20'}'><td colspan='9' align='left'><b>$Lang::tr{'Existing Files'}</b></td></tr>
220 <tr><td align='center'></td>
221 <td align='center'><b>$Lang::tr{'artist'}<br/>$Lang::tr{'title'}</b></td>
222 <td align='center'><b>$Lang::tr{'number'}</b></td>
223 <td align='center'><b>$Lang::tr{'album'}</b></td>
224 <td align='center'><b>$Lang::tr{'year'}</b></td>
225 <td align='center'><b>$Lang::tr{'genre'}</b></td>
226 <td align='center'><b>$Lang::tr{'length'}<br/>$Lang::tr{'bitrate'} - $Lang::tr{'frequency'}</b></td>
227 <td align='center'><b>$Lang::tr{'mode'}</b></td></tr>
228 END
229 ;
230 my $lines = 0;
231 foreach (@songdb){
232 my @song = split(/\|/,$_);
233
234 if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>";} else {print "<tr bgcolor='$color{'color22'}'>";}
235 $song[0]=~s/\/\//\//g;
236 print <<END
237 <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>
238 <td align='center'>$song[1]<br/>$song[2]</td>
239 <td align='center'>$song[3]</td>
240 <td align='center'>$song[4]</td>
241 <td align='center'>$song[5]</td>
242 <td align='center'>$song[6]</td>
243 <td align='center'>$song[7]:$song[8]<br/>$song[9] - $song[10]</td>
244 END
245 ;
246 if ( $song[11] eq "0\n" ) {print "<td align='center'>Stereo</td></tr>"; }
247 elsif ( $song[11] eq "1\n" ) {print "<td align='center'>Joint<br/>Stereo</td></tr>"; }
248 elsif ( $song[11] eq "2\n" ) {print "<td align='center'>Dual<br/>Channel</td></tr>"; }
249 elsif ( $song[11] eq "3\n" ) {print "<td align='center'>Single<br/>Channel</td></tr>"; }
250 else {print "<td align='center'></td></tr>"; }
251 $lines++
252 }
253 print "</table></form>";
254 &Header::closebox();
255 }
256
257 &Header::openbox('100%', 'center', $Lang::tr{'mpfire playlist'});
258
259 open(DATEI, "<${General::swroot}/mpfire/playlist") || die "Could not open playlist";
260 my @playlist = <DATEI>;
261 close(DATEI);
262
263 print <<END
264 <table width='95%' cellspacing='0'>
265 <tr bgcolor='$color{'color20'}'><td colspan='9' align='left'><b>$Lang::tr{'current playlist'}</b></td></tr>
266 <tr><td align='center'><textarea cols='120' rows='10' name='playlist' style='font-size:10px' readonly='readonly' >@playlist</textarea><br/>
267 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
268 <input type='hidden' name='ACTION' value='playlist' />
269 <input type='image' alt='$Lang::tr{'play'}' title='$Lang::tr{'play'}' src='/images/media-playback-start.png' />
270 </form></td></tr>
271 </table>
272 END
273 ;
274 &Header::closebox();
275
276 &Header::openbox('100%', 'center', $Lang::tr{'mpfire webradio'});
277
278 open(DATEI, "<${General::swroot}/mpfire/webradio") || die "Could not open playlist";
279 my @webradio = <DATEI>;
280 close(DATEI);
281
282 print <<END
283 <table width='95%' cellspacing='0'>
284 <tr bgcolor='$color{'color20'}'><td colspan='9' align='left'><b>$Lang::tr{'webradio playlist'}</b></td></tr>
285 <tr><td>Stream</td><td colspan='2'></td></tr>
286 END
287 ;
288 foreach (@webradio){
289 my @stream = split(/\|/,$_);
290 print <<END
291 <tr><td>$stream[1]</td>
292 <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>
293 <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>
294 </tr>
295 END
296 ;
297 }
298 print "</table>";
299 &Header::closebox();
300
301 &Header::closebigbox();
302 &Header::closepage();