2 # Save, update or delete a burn profile, and maybe start the burn process
4 require './burner-lib.pl';
6 &error_setup($text{'save_err'});
9 $profile = &get_profile($in{'id'});
10 &can_use_profile($profile) || &error($text{'edit_ecannot'});
13 $profile = { 'type' => $in{'type'} };
14 $access{'create'} || &error($text{'edit_ecannot'});
17 if (!$access{'edit'}) {
18 # No need to save, because we cannot
20 elsif ($in{'delete'}) {
21 # Just delete a profile
22 &delete_profile($profile);
26 $in{'name'} || &error($text{'save_ename'});
27 $profile->{'name'} = $in{'name'};
28 if ($profile->{'type'} == 1) {
29 # Validate single ISO inputs
30 -r $in{'iso'} || &error($text{'save_eiso'});
31 &can_directory($in{'iso'}) || &error($text{'save_ecannot1'});
32 $profile->{'iso'} = $in{'iso'};
33 $profile->{'isosize'} = $in{'isosize'};
35 elsif ($profile->{'type'} == 2) {
36 # Validate multi-directory inputs
37 foreach $k (keys %$profile) {
38 delete($profile->{$k}) if ($k =~ /^(source_|dest_)/);
41 for($i=0; defined($s = $in{"source_$i"}); $i++) {
43 -d $s || -r $s || &error(&text('save_esource', $s));
45 &error(&text('save_ecannot2', $s));
46 $in{"dest_$i"} =~ /^\/\S*$/ ||
47 &error(&text('save_edest', $s));
48 $profile->{"source_$j"} = $s;
49 $profile->{"dest_$j"} = $in{"dest_$i"};
52 $j || &error($text{'save_edirs'});
53 $profile->{'rock'} = $in{'rock'};
54 $profile->{'joliet'} = $in{'joliet'};
55 $profile->{'netatalk'} = $in{'netatalk'};
56 $profile->{'cap'} = $in{'cap'};
57 $profile->{'long'} = $in{'long'};
58 $profile->{'trans'} = $in{'trans'};
59 $profile->{'volid'} = $in{'volid'};
61 elsif ($profile->{'type'} == 3) {
62 # Validate audio track inputs .. each must be either an
63 # mp3 file or a directory
64 foreach $k (keys %$profile) {
65 delete($profile->{$k}) if ($k =~ /^source_/);
68 for($i=0; defined($s = $in{"source_$i"}); $i++) {
70 -d $s || -r $s || &error(&text('save_emp3', $s));
72 &error(&text('save_ecannot3', $s));
73 $profile->{"source_$j"} = $s;
76 $j || &error($text{'save_emp3s'});
78 elsif ($profile->{'type'} == 4) {
79 # Validate device file inputs
80 if ($in{'sdev'} eq '') {
81 -r $in{'other'} || &error($text{'save_eother'});
82 $profile->{'sdev'} = $in{'other'};
83 $profile->{'sdesc'} = $in{'other'};
86 $profile->{'sdev'} = $in{'sdev'};
87 foreach $d (&list_cdrecord_devices()) {
88 $profile->{'sdesc'} = $d->{'name'}
89 if ($d->{'dev'} eq $profile->{'sdev'});
92 &can_directory($profile->{'sdev'}) ||
93 &error($text{'save_ecannot4'});
94 $profile->{'fly'} = $in{'fly'};
95 $profile->{'srcdrv'} = $in{'srcdrv'};
96 $profile->{'dstdrv'} = $in{'dstdrv'};
99 # Save or create the profile
100 &save_profile($profile);
101 if ($in{'new'} && !&can_use_profile($profile)) {
102 # Add to this user's ACL
103 $access{'profiles'} = join(" ", split(/\s+/,
104 $access{'profiles'}), $profile->{'id'});
105 &save_module_acl(\%access);
109 if ($in{'burn'} || $in{'test'}) {
110 &ui_print_unbuffered_header(undef, $text{'burn_title'}, "");
112 if (!$config{'dev'}) {
113 # Cannot burn until device is set
114 print "<p>",&text('burn_edev', "edit_dev.cgi"),"<p>\n";
115 &ui_print_footer("", $text{"index_return"});
119 local ($iso, $temp, $msg);
120 if ($profile->{'type'} == 1) {
121 # No preparation to do
122 $iso = $profile->{'iso'};
124 $msg = &text($in{'test'} ? 'burn_rutest1' : 'burn_rusure1',
127 elsif ($profile->{'type'} == 2) {
128 # Need to build the ISO image
130 $iso = $config{'temp'} ? "$config{'temp'}/burner.iso"
131 : &tempname("burner.iso");
132 local $cmd = "$config{'mkisofs'} -graft-points -o $iso";
133 $cmd .= " -J" if ($profile->{'joliet'});
134 $cmd .= " --netatalk" if ($profile->{'netatalk'});
135 $cmd .= " --cap" if ($profile->{'cap'});
136 $cmd .= " -l" if ($profile->{'long'});
137 $cmd .= " -T" if ($profile->{'trans'});
138 if ($profile->{'rock'} == 2) {
141 elsif ($profile->{'rock'} == 1) {
144 if ($profile->{'volid'}) {
145 $cmd .= " -V '$profile->{'volid'}'";
147 $cmd .= " -N" if ($config{'novers'});
148 $cmd .= " -U" if ($config{'notrans'});
149 $cmd .= " -f" if ($config{'fsyms'});
150 $cmd .= " -nobak" if ($config{'nobak'});
151 for($i=0; defined($profile->{"source_$i"}); $i++) {
152 local $d = quotemeta($profile->{"dest_$i"});
153 $d .= "/" if ($d !~ /\/$/);
154 $cmd .= " ".$d."=".quotemeta($profile->{"source_$i"});
157 print "<b>",&text('burn_mheader', "<tt>$cmd</tt>"),"</b><br>\n";
159 open(MAKE, "$cmd 2>&1 |");
161 print &html_escape($_);
166 # Failed! No point going on ..
168 print "<b>$text{'burn_mfailed'}</b><br>\n";
169 &ui_print_footer("", $text{'index_return'});
172 $msg = $in{'test'} ? $text{'burn_rutest2'}
173 : $text{'burn_rusure2'};
175 # Check the size of the resulting ISO
176 local @st = stat($iso);
177 local $mb = int($st[7]/(1024*1024));
179 print "<b>",&text('burn_700', $mb),"</b><br>\n";
182 print "<b>",&text('burn_650', $mb),"</b><br>\n";
185 print &text('burn_size', $mb, 650),"<br>\n";
188 elsif ($profile->{'type'} == 3) {
189 # To convert MP3s into data suitable for CDs, run
190 # mpg123 -s -r 44100 file.mp3 >file.raw
192 # To burn to a CD, run
193 # cdrecord dev=0,0,0 -v -audio -swab -pad speed=8 *.raw
195 $audio = $config{'temp'} ? "$config{'temp'}/burner.audio"
196 : &tempname("burner.audio");
197 system("rm -rf $audio >/dev/null 2>&1");
200 for($i=0; defined($src = $profile->{"source_$i"}); $i++) {
203 foreach $m (sort { $a cmp $b } readdir(DIR)) {
204 push(@srcs, "$src/$m")
205 if ($m !~ /^\./ && -r "$src/$m");
215 print "<b>$text{'burn_nomp3s'}</b><br>\n";
216 &ui_print_footer("", $text{'index_return'});
220 local $mp3_basecmd = "$config{'mpg123'} -s -r 44100";
221 local $wav_basecmd = "$config{'sox'} -V";
222 print "<b>",&text('burn_mp3header', "<tt>$basecmd</tt>"),
227 for($i=0; $i<@srcs; $i++) {
228 print "<b>$srcs[$i]</b><br>\n";
229 local $dst = sprintf "%s/track-%3.3d.raw", $audio, $i;
230 local $q = quotemeta($srcs[$i]);
231 if ($srcs[$i] =~ /\.(mp3|mp2|mpg|mpeg)$/i) {
233 open(MPG, "$mp3_basecmd $q 2>&1 >$dst |");
235 next if (/^High Performance/i ||
236 /^Version\s+(\S+)/i ||
237 /^Uses code from various people/i ||
238 /^THIS SOFTWARE COMES WITH/i ||
241 print &html_escape($_);
245 elsif ($srcs[$i] =~ /\.(wav|ogg)$/i) {
246 # Convert from WAV or OGG
247 open(SOX, "$wav_basecmd $q -r 44100 $dst 2>&1 |");
249 print &html_escape($_);
257 local @st = stat($dst);
264 # Totally failed! No point going on ..
265 system("rm -rf ".quotemeta($audio)." >/dev/null 2>&1");
266 print "<b>$text{'burn_mp3failed'}</b><br>\n";
267 &ui_print_footer("", $text{'index_return'});
271 # Some errors occurred
272 print "<b>$text{'burn_mp3failed2'}</b><p>\n";
274 $msg = $in{'test'} ? $text{'burn_rutest3'}
275 : $text{'burn_rusure3'};
277 # Check the total size
278 local $mb = int($size/(1024*1024));
280 print "<b>",&text('burn_746', $mb),"</b><br>\n";
283 print "<b>",&text('burn_807', $mb),"</b><br>\n";
286 print &text('burn_mp3size', $mb, 746),"<br>\n";
289 elsif ($profile->{'type'} == 4) {
290 # No preparation to do for a copy
291 $iso = $profile->{'sdev'};
293 $msg = &text('burn_rusure4', $profile->{'sdesc'});
298 print "<center><form action=burn.cgi>\n";
299 print "<input type=hidden name=iso value='$iso'>\n";
300 print "<input type=hidden name=audio value='$audio'>\n";
301 print "<input type=hidden name=temp value='$temp'>\n";
302 print "<input type=hidden name=id value='$profile->{'id'}'>\n";
303 printf "<input type=hidden name=test value='%d'>\n",
305 print "<b>$msg</b><p>\n";
306 print "<input type=submit name=ok value='$text{'burn_ok'}'>\n";
308 print "<input type=submit name=cancel value='$text{'burn_cancel'}'>\n";
311 print "<br>$text{'burn_eject'}\n";
312 print "<input type=radio name=eject value=1> $text{'yes'}\n";
313 print "<input type=radio name=eject value=0 checked> $text{'no'}\n";
315 if ($profile->{'type'} != 4 ||
316 $profile->{'sdev'} ne $config{'dev'}) {
317 printf "<br>$text{'burn_bg'}\n";
318 print "<input type=radio name=bg value=1> $text{'yes'}\n";
319 print "<input type=radio name=bg value=0 checked> $text{'no'}\n";
322 if ($profile->{'type'} != 4) {
323 print "<br>$text{'burn_blank'} <select name=blank>\n";
324 print "<option value='' selected> $text{'no'}\n";
325 print "<option value=fast> $text{'burn_bfast'}\n";
326 print "<option value=all> $text{'burn_ball'}\n";
329 print "</form></center>\n";
332 # Redirect to the burn page
333 print "<script>document.location = \"burn.cgi?iso=$iso&audio=$audio&temp=$temp&id=$profile->{'id'}&test=",$in{'test'} ? 1 : 0,"\";</script>\n";
336 &ui_print_footer("", $text{'index_return'});