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