#!/usr/local/bin/perl # Save, update or delete a burn profile, and maybe start the burn process require './burner-lib.pl'; &ReadParse(); &error_setup($text{'save_err'}); if ($in{'id'}) { $profile = &get_profile($in{'id'}); &can_use_profile($profile) || &error($text{'edit_ecannot'}); } else { $profile = { 'type' => $in{'type'} }; $access{'create'} || &error($text{'edit_ecannot'}); } if (!$access{'edit'}) { # No need to save, because we cannot } elsif ($in{'delete'}) { # Just delete a profile &delete_profile($profile); } else { # Validate inputs $in{'name'} || &error($text{'save_ename'}); $profile->{'name'} = $in{'name'}; if ($profile->{'type'} == 1) { # Validate single ISO inputs -r $in{'iso'} || &error($text{'save_eiso'}); &can_directory($in{'iso'}) || &error($text{'save_ecannot1'}); $profile->{'iso'} = $in{'iso'}; $profile->{'isosize'} = $in{'isosize'}; } elsif ($profile->{'type'} == 2) { # Validate multi-directory inputs foreach $k (keys %$profile) { delete($profile->{$k}) if ($k =~ /^(source_|dest_)/); } local $j = 0; for($i=0; defined($s = $in{"source_$i"}); $i++) { next if (!$s); -d $s || -r $s || &error(&text('save_esource', $s)); &can_directory($s) || &error(&text('save_ecannot2', $s)); $in{"dest_$i"} =~ /^\/\S*$/ || &error(&text('save_edest', $s)); $profile->{"source_$j"} = $s; $profile->{"dest_$j"} = $in{"dest_$i"}; $j++; } $j || &error($text{'save_edirs'}); $profile->{'rock'} = $in{'rock'}; $profile->{'joliet'} = $in{'joliet'}; $profile->{'netatalk'} = $in{'netatalk'}; $profile->{'cap'} = $in{'cap'}; $profile->{'long'} = $in{'long'}; $profile->{'trans'} = $in{'trans'}; $profile->{'volid'} = $in{'volid'}; } elsif ($profile->{'type'} == 3) { # Validate audio track inputs .. each must be either an # mp3 file or a directory foreach $k (keys %$profile) { delete($profile->{$k}) if ($k =~ /^source_/); } local $j = 0; for($i=0; defined($s = $in{"source_$i"}); $i++) { next if (!$s); -d $s || -r $s || &error(&text('save_emp3', $s)); &can_directory($s) || &error(&text('save_ecannot3', $s)); $profile->{"source_$j"} = $s; $j++; } $j || &error($text{'save_emp3s'}); } elsif ($profile->{'type'} == 4) { # Validate device file inputs if ($in{'sdev'} eq '') { -r $in{'other'} || &error($text{'save_eother'}); $profile->{'sdev'} = $in{'other'}; $profile->{'sdesc'} = $in{'other'}; } else { $profile->{'sdev'} = $in{'sdev'}; foreach $d (&list_cdrecord_devices()) { $profile->{'sdesc'} = $d->{'name'} if ($d->{'dev'} eq $profile->{'sdev'}); } } &can_directory($profile->{'sdev'}) || &error($text{'save_ecannot4'}); $profile->{'fly'} = $in{'fly'}; $profile->{'srcdrv'} = $in{'srcdrv'}; $profile->{'dstdrv'} = $in{'dstdrv'}; } # Save or create the profile &save_profile($profile); if ($in{'new'} && !&can_use_profile($profile)) { # Add to this user's ACL $access{'profiles'} = join(" ", split(/\s+/, $access{'profiles'}), $profile->{'id'}); &save_module_acl(\%access); } } if ($in{'burn'} || $in{'test'}) { &ui_print_unbuffered_header(undef, $text{'burn_title'}, ""); if (!$config{'dev'}) { # Cannot burn until device is set print "
",&text('burn_edev', "edit_dev.cgi"),"
\n";
&ui_print_footer("", $text{"index_return"});
exit;
}
local ($iso, $temp, $msg);
if ($profile->{'type'} == 1) {
# No preparation to do
$iso = $profile->{'iso'};
$temp = 0;
$msg = &text($in{'test'} ? 'burn_rutest1' : 'burn_rusure1',
"$iso");
}
elsif ($profile->{'type'} == 2) {
# Need to build the ISO image
$temp = 1;
$iso = $config{'temp'} ? "$config{'temp'}/burner.iso"
: &tempname("burner.iso");
local $cmd = "$config{'mkisofs'} -graft-points -o $iso";
$cmd .= " -J" if ($profile->{'joliet'});
$cmd .= " --netatalk" if ($profile->{'netatalk'});
$cmd .= " --cap" if ($profile->{'cap'});
$cmd .= " -l" if ($profile->{'long'});
$cmd .= " -T" if ($profile->{'trans'});
if ($profile->{'rock'} == 2) {
$cmd .= " -r";
}
elsif ($profile->{'rock'} == 1) {
$cmd .= " -R";
}
if ($profile->{'volid'}) {
$cmd .= " -V '$profile->{'volid'}'";
}
$cmd .= " -N" if ($config{'novers'});
$cmd .= " -U" if ($config{'notrans'});
$cmd .= " -f" if ($config{'fsyms'});
$cmd .= " -nobak" if ($config{'nobak'});
for($i=0; defined($profile->{"source_$i"}); $i++) {
local $d = quotemeta($profile->{"dest_$i"});
$d .= "/" if ($d !~ /\/$/);
$cmd .= " ".$d."=".quotemeta($profile->{"source_$i"});
}
print "",&text('burn_mheader', "$cmd"),"
\n";
print "
"; open(MAKE, "$cmd 2>&1 |"); while(\n"; if ($?) { # Failed! No point going on .. unlink($iso); print "$text{'burn_mfailed'}) { print &html_escape($_); } close(MAKE); print "
"; local $size; local $errors; for($i=0; $i<@srcs; $i++) { print "$srcs[$i]"; if (!$size) { # Totally failed! No point going on .. system("rm -rf ".quotemeta($audio)." >/dev/null 2>&1"); print "$text{'burn_mp3failed'}
\n"; local $dst = sprintf "%s/track-%3.3d.raw", $audio, $i; local $q = quotemeta($srcs[$i]); if ($srcs[$i] =~ /\.(mp3|mp2|mpg|mpeg)$/i) { # Convert from MP3 open(MPG, "$mp3_basecmd $q 2>&1 >$dst |"); while() { next if (/^High Performance/i || /^Version\s+(\S+)/i || /^Uses code from various people/i || /^THIS SOFTWARE COMES WITH/i || /^Directory: /i || !/\S/); print &html_escape($_); } close(MPG); } elsif ($srcs[$i] =~ /\.(wav|ogg)$/i) { # Convert from WAV or OGG open(SOX, "$wav_basecmd $q -r 44100 $dst 2>&1 |"); while( ) { print &html_escape($_); } close(SOX); } if ($?) { $errors++; } else { local @st = stat($dst); $size += $st[7]; } print " \n"; } print "
\n";
}
$msg = $in{'test'} ? $text{'burn_rutest3'}
: $text{'burn_rusure3'};
# Check the total size
local $mb = int($size/(1024*1024));
if ($mb > 746) {
print "",&text('burn_746', $mb),"
\n";
}
elsif ($mb > 807) {
print "",&text('burn_807', $mb),"
\n";
}
else {
print &text('burn_mp3size', $mb, 746),"
\n";
}
}
elsif ($profile->{'type'} == 4) {
# No preparation to do for a copy
$iso = $profile->{'sdev'};
$temp = 0;
$msg = &text('burn_rusure4', $profile->{'sdesc'});
}
if ($in{'ask'}) {
# Show confirm page
print "