forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
burn.cgi
executable file
·144 lines (137 loc) · 3.97 KB
/
burn.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/local/bin/perl
# burn.cgi
# Do a real or test burn of a CD
require './burner-lib.pl';
&ReadParse();
$profile = &get_profile($in{'id'});
&can_use_profile($profile) || &error($text{'edit_ecannot'});
if ($in{'cancel'}) {
if ($in{'iso'}) {
unlink($in{'iso'});
}
elsif ($in{'audio'}) {
system("rm -rf $in{'audio'} >/dev/null 2>&1");
}
&redirect("");
exit;
}
if ($profile->{'type'} != 4) {
if ($in{'iso'} && !-r $in{'iso'}) {
&error(&text('burn_egone', "edit_profile.cgi?id=$profile->{'id'}"));
}
elsif ($in{'audio'} && !-d $in{'audio'}) {
&error(&text('burn_egone2', "edit_profile.cgi?id=$profile->{'id'}"));
}
}
if ($in{'bg'}) {
&ui_print_unbuffered_header(undef, $text{'burn_title'}, "");
}
else {
&ui_print_header(undef, $text{'burn_title'}, "");
}
if ($profile->{'type'} == 4) {
# Copying a CD
$cdrtemp = $config{'temp'} ? "$config{'temp'}/burner.bin"
: &tempname("burner.bin");
if ($in{'second_step'}) {
# Writing out a copied CD
$cmd = "$config{'cdrdao'} write --device $config{'dev'}";
$cmd .= " --speed $config{'speed'}";
$cmd .= " --eject" if ($in{'eject'});
$cmd .= " --driver $profile->{'dstdrv'}"
if ($profile->{'dstdrv'});
$cmd .= " $cdrtemp.toc";
$cmd .= " ; rm -f $cdrtemp $cdrtemp.toc";
}
elsif ($profile->{'sdev'} eq $config{'dev'}) {
# Using same drive .. need to create .toc and .bin files first
$cmd = "$config{'cdrdao'} read-cd --device $config{'dev'} --datafile $cdrtemp --eject";
$cmd .= " --driver $profile->{'srcdrv'}"
if ($profile->{'srcdrv'});
$cmd .= " $cdrtemp.toc";
$second_step++;
}
else {
# Copying from one drive to another
$cmd = "$config{'cdrdao'} copy --device $config{'dev'} --source-device $profile->{'sdev'}";
if ($profile->{'fly'}) {
$cmd .= " --on-the-fly";
}
else {
$cmd .= " --datafile $cdrtemp";
}
$cmd .= " --speed $config{'speed'}";
$cmd .= " --eject" if ($in{'eject'});
$cmd .= " --driver $profile->{'dstdrv'}"
if ($profile->{'dstdrv'});
$cmd .= " --source-driver $profile->{'srcdrv'}"
if ($profile->{'srcdrv'});
}
}
elsif ($in{'iso'}) {
# Burning data CD
$cmd = "$config{'cdrecord'} -v dev=$config{'dev'} speed=$config{'speed'}";
$cmd .= " $config{'extra'}" if ($config{'extra'});
$cmd .= " -dummy" if ($in{'test'});
$cmd .= " -eject" if ($in{'eject'} && !$in{'test'});
$cmd .= " -isosize" if ($profile->{'isosize'});
$cmd .= " blank=$in{'blank'}" if ($in{'blank'});
$cmd .= " '$in{'iso'}'";
}
else {
# Burning audio CD
$cmd = "$config{'cdrecord'} -v dev=$config{'dev'} speed=$config{'speed'}";
$cmd .= " -dummy" if ($in{'test'});
$cmd .= " -eject" if ($in{'eject'} && !$in{'test'});
$cmd .= " -audio -swab -pad $in{'audio'}/*.raw";
}
if ($in{'bg'} && !$second_step) {
# Start in background
if (!fork()) {
close(STDIN); close(STDOUT); close(STDERR);
system("$cmd >/dev/null 2>&1 </dev/null");
if ($in{'temp'}) {
if ($in{'iso'}) {
unlink($in{'iso'});
}
else {
system("rm -rf $in{'audio'} >/dev/null 2>&1");
}
}
exit;
}
print "<b>",&text($in{'test'} ? 'burn_theader2' : 'burn_header2',
"<tt>$cmd</tt>"),"</b><p>\n";
}
else {
# Run command and show output
print "<b>",&text($in{'test'} ? 'burn_theader' : 'burn_header',
"<tt>$cmd</tt>"),"</b><br>\n";
print "<pre>";
&foreign_require("proc", "proc-lib.pl");
&foreign_call("proc", "safe_process_exec", $cmd, 0, 0, STDOUT,
undef, 1, 0);
print "</pre>\n";
$rv = $?;
if ($in{'temp'}) {
if ($in{'iso'}) {
unlink($in{'iso'});
}
else {
system("rm -rf $in{'audio'} >/dev/null 2>&1");
}
}
if ($second_step && !$rv) {
# Show button to write out data
print "<center><form action=burn.cgi>\n";
print "$text{'burn_seconddesc'}<p>\n";
print "<input type=submit name=second_step ",
"value='$text{'burn_second'}'>\n";
foreach $k (keys %in) {
print "<input type=hidden name=$k value='$in{$k}'>\n";
}
print "</form></center>\n";
}
}
&ui_print_footer("edit_profile.cgi?id=$profile->{'id'}", $text{'edit_return'},
"", $text{'index_return'});