source: MondoRescue/branches/stable/mondo-web/mondo-web.pl@ 1553

Last change on this file since 1553 was 1225, checked in by Bruno Cornec, 17 years ago

mondo-web now uses the mondo configuration file for its initial setup

  • Property svn:executable set to *
File size: 9.3 KB
Line 
1#!/usr/bin/perl -w
2#
3# $Id$
4#
5# mondo-web perl script
6# ======================
7# The script is a cgi-bin script serving as a Web interface for mondoarchive
8# It generates the right mondoarchive command depending on answers to questions
9# it asks to the user.
10#
11# This program is free software and is made available under the GPLv2.
12# (c) B. Cornec 2007
13#
14
15use strict;
16use CGI;
17use CGI::Carp qw(fatalsToBrowser);
18use Data::Dumper;
19use AppConfig;
20
21my $cgi = new CGI;
22my $default = "";
23my @default;
24
25# Handling Configuration files
26my $file1 = "/etc/mondo/mondo.conf.dist";
27my $file2 = "/etc/mondo/mondo.conf";
28
29my $config = AppConfig->new({
30 # Auto Create variables mentioned in Conf file
31 CREATE => 1,
32 DEBUG => 0,
33 GLOBAL => {
34 # Each conf item has one single parameter
35 ARGCOUNT => AppConfig::ARGCOUNT_ONE
36 }
37 });
38$config->file($file1, $file2);
39
40my $command="";
41
42# Fake it for now
43my %media = (
44 "CDR" => "CD-R",
45 "CDRW" => "CD-RW",
46 "DVD" => "DVD+/-R/RW",
47 "ISO" => "ISO Image",
48 "USB" => "USB disk/key",
49 "TAPE" => "Tape",
50 "NFS" => "NFS File System",
51 "STREAM" => "Streaming"
52);
53my @media = sort keys %media;
54my %options = (
55 'NOFLOPPY' => 'No Boot floppy production',
56 'NOBOOTABLE' => 'Create Non-Bootable media',
57 'AUTO', => 'Auto Restore Mode',
58 'NFSEXCL' => 'Exclude Network File Systems',
59 'MANEJECT' => 'Manual media ejection',
60 'DIFF' => 'Differential Backup',
61 'VERIF' => 'Media verification (Slower)',
62 'XATTR' => 'Extended Attributes and ACL Management (Slower)'
63);
64my @options = sort keys %options;
65my %speed = (
66 1 => '1x',
67 2 => '2x',
68 4 => '4x',
69 8 => '8x',
70 16 => '16x',
71 24 => '24x',
72 48 => '48x',
73 52 => '52x',
74);
75my @speed = sort {$a <=> $b} keys %speed;
76my %comp = (
77 GZIP => 'gzip (average)',
78 BZIP2 => 'bzip2 (size)',
79 LZO => 'lzo (speed)',
80);
81my @comp = sort keys %comp;
82my %ratio = (
83 0 => '0',
84 1 => '1',
85 2 => '2',
86 3 => '3',
87 4 => '4',
88 5 => '5',
89 6 => '6',
90 7 => '7',
91 8 => '8',
92 9 => '9',
93);
94my @ratio = sort {$a <=> $b} keys %ratio;
95my %boot = (
96 'LILO' => "LILO",
97 'GRUB' => "GRUB",
98 'ELILO' => "ELILO (ia64)",
99 'RAW' => "RAW",
100 'NATIVE' => "Autodetected",
101);
102my @boot = sort keys %boot;
103
104print $cgi->header;
105print $cgi->start_html('Web Based MondoArchive');
106print << 'EOF';
107<IMG SRC="mondo_logo.gif" HEIGHT=66 WIDTH=66 ALIGN=LEFT>
108EOF
109print $cgi->h1('MondoArchive Image Creation');
110
111if (not ($cgi->param())) {
112 print $cgi->start_form;
113 print $cgi->hr;
114 print $cgi->h2('Mandatory Info');
115 print "<TABLE><TR><TD WIDTH=230>\n";
116 print "Media type: ",$cgi->popup_menu(-name=>'media',
117 -values=>\@media,
118 -default=>$media[0],
119 -labels=>\%media);
120 print "</TD><TD WIDTH=300>\n";
121 print "Destination path or device:\n";
122 print $cgi->textfield(-name=>'dest',
123 -default=>$config->get("mondo_images_dir"),
124 -size=>15,
125 -maxlenght=>150);
126 print "</TD><TD WIDTH=250>\n";
127 print "Size of media (MB):\n";
128 print $cgi->textfield(-name=>'size',
129 -default=>$config->get("mondo_media_size"),
130 -size=>6,
131 -maxlenght=>6);
132 print "</TD></TR></TABLE>\n";
133 print $cgi->hr;
134
135 print $cgi->h2('Compression Info');
136 print "<TABLE><TR><TD WIDTH=330>\n";
137 $default = 'GZIP' if ($config->get("mondo_compression_tool") =~ /gzip/);
138 $default = 'BZIP2' if ($config->get("mondo_compression_tool") =~ /bzip2/);
139 $default = 'LZO' if ($config->get("mondo_compression_tool") =~ /lzo/);
140 print "Compression tool: ",$cgi->popup_menu(-name=>'comp',
141 -values=>\@comp,
142 -default=>$default,
143 -labels=>\%comp);
144 print "</TD><TD WIDTH=300>\n";
145 print "Compression ratio: ",$cgi->popup_menu(-name=>'compratio',
146 -values=>\@ratio,
147 -default=>$config->get("mondo_compression_level"),
148 -labels=>\%ratio);
149 print "</TD></TR></TABLE>\n";
150 print $cgi->hr;
151
152 print $cgi->h2('Optional Info');
153 print "<TABLE><TR><TD WIDTH=360>\n";
154
155 @default = (@default,'AUTO') if ($config->get("mondo_automatic_restore") =~ /yes/);
156 @default = (@default,'NOFLOPPY') if ($config->get("mondo_write_boot_floppy") =~ /no/);
157 @default = (@default,'DIFF') if ($config->get("mondo_differential") =~ /yes/);
158 #'NFSEXCL' => 'Exclude Network File Systems',
159 @default = (@default, 'NFSEXCL');
160 #'NOBOOTABLE' => 'Create Non-Bootable media',
161 #'MANEJECT' => 'Manual media ejection',
162 #'VERIF' => 'Media verification (Slower)',
163 #'XATTR' => 'Extended Attributes and ACL Management (Slower)'
164 print $cgi->checkbox_group(-name=>'options',
165 -values=>\@options,
166 -defaults=>\@default,
167 -linebreak=>'true',
168 -labels=>\%options);
169 print "</TD><TD WIDTH=350>\n";
170 print "Temporary Directory:\n";
171 print $cgi->textfield(-name=>'temp',
172 -default=>$config->get("mondo_tmp_dir"),
173 -size=>25,
174 -maxlenght=>150);
175 print "<BR>";
176 print "Scratch Directory:\n";
177 print $cgi->textfield(-name=>'scratch',
178 -default=>$config->get("mondo_scratch_dir"),
179 -size=>25,
180 -maxlenght=>150);
181 print "<BR>";
182 print "ISO Image Name Prefix:\n";
183 print $cgi->textfield(-name=>'prefix',
184 -default=>$config->get("mondo_prefix"),
185 -size=>15,
186 -maxlenght=>150);
187 print "<BR>";
188 print "Tape block size:\n";
189 print $cgi->textfield(-name=>'block',
190 -default=>$config->get("mondo_external_tape_blocksize"),
191 -size=>10,
192 -maxlenght=>10);
193 print "<BR>";
194 print "Media Speed (if pertinent): ",$cgi->popup_menu(-name=>'speed',
195 -values=>\@speed,
196 -default=>$config->get("mondo_iso_burning_speed"),
197 -labels=>\%speed);
198 print "<BR>";
199 print "Kernel:\n";
200 print $cgi->textfield(-name=>'kernel',
201 -default=>$config->get("mondo_kernel"),
202 -size=>30,
203 -maxlenght=>150);
204 print "<BR>";
205 print "Postnuke script:\n";
206 print $cgi->textfield(-name=>'postnuke',
207 -default=>'',
208 -size=>30,
209 -maxlenght=>150);
210 print "<BR>";
211 print "NFS (server:export):\n";
212 print $cgi->textfield(-name=>'nfs',
213 -default=>'',
214 -size=>30,
215 -maxlenght=>150);
216 print "<BR>";
217 print "</TD></TR>\n";
218 print "<TR><TD>\n";
219 print "Bootloader:<BR>\n",$cgi->radio_group(-name=>'boot',
220 -values=>\@boot,
221 -default=>$config->get("mondo_boot_loader"),
222 -linebreak=>'true',
223 -labels=>\%boot);
224 print "<BR>";
225 print "Debug:\n";
226 print $cgi->popup_menu(-name=>'debug',
227 -values=>\@ratio,
228 -default=>$config->get("mondo_log_level"),
229 -labels=>\%ratio);
230 print "</TD><TD>\n";
231 print "Excluded directories:\n";
232 print $cgi->textfield(-name=>'exclude',
233 -default=>$config->get("mondo_exclude_files"),
234 -size=>30,
235 -maxlenght=>150);
236 print "<BR>";
237 print "Included directories:\n";
238 print $cgi->textfield(-name=>'include',
239 -default=>$config->get("mondo_include_files"),
240 -size=>30,
241 -maxlenght=>150);
242 print "<BR>";
243 print "Command to launch before burning:\n";
244 print $cgi->textfield(-name=>'before',
245 -default=>'',
246 -size=>50,
247 -maxlenght=>150);
248 print "<BR>";
249 print "Command to launch after burning:\n";
250 print $cgi->textfield(-name=>'after',
251 -default=>'',
252 -size=>50,
253 -maxlenght=>150);
254 print "<BR>";
255 print "</TD></TR></TABLE>\n";
256 print $cgi->hr;
257 print $cgi->submit;
258 print $cgi->end_form;
259} else {
260 $command="mondoarchive -O -K ".$cgi->param('debug')." ";
261 if ($cgi->param('debug') eq 'STATIC') {
262 } else {
263 }
264 foreach my $s ($cgi->param('options')) {
265 $command .= "-F " if ($s =~ /NOFLOPPY/);
266 $command .= "-W " if ($s =~ /NOBOOTABLE/);
267 $command .= "-H " if ($s =~ /AUTO/);
268 $command .= "-N " if ($s =~ /NFSEXCL/);
269 $command .= "-m " if ($s =~ /MANEJECT/);
270 $command .= "-D " if ($s =~ /DIFF/);
271 $command .= "-V " if ($s =~ /VERIF/);
272 $command .= "-z " if ($s =~ /XATTR/);
273 }
274 my $speed = $cgi->param('speed');
275 $command .= "-c $speed " if ($cgi->param('media') =~ /^CDR$/);
276 $command .= "-w $speed " if ($cgi->param('media') =~ /^CDRW$/);
277 $command .= "-n ".$cgi->param('nfs')." " if (($cgi->param('media') =~ /NFS/) && ($cgi->param('nfs') ne ""));
278 $command .= "-r " if ($cgi->param('media') =~ /DVD/);
279 $command .= "-i " if ($cgi->param('media') =~ /ISO/);
280 $command .= "-U " if ($cgi->param('media') =~ /USB/);
281 $command .= "-t " if ($cgi->param('media') =~ /TAPE/);
282 $command .= "-b ".$cgi->param('block')." " if (($cgi->param('media') =~ /TAPE/) && ($cgi->param('block') ne ""));
283 $command .= "-u " if ($cgi->param('media') =~ /STREAM/);
284 $command .= "-L " if ($cgi->param('comp') =~ /LZO/);
285 $command .= "-G " if ($cgi->param('comp') =~ /GZIP/);
286 $command .= "-E \"".$cgi->param('exclude')."\" " if ($cgi->param('exclude') ne "");
287 $command .= "-I \"".$cgi->param('include')."\" " if ($cgi->param('include') ne "");
288 $command .= "-T ".$cgi->param('temp')." " if ($cgi->param('temp') ne "");
289 $command .= "-S ".$cgi->param('scratch')." " if ($cgi->param('scratch') ne "");
290 $command .= "-B ".$cgi->param('before')." " if ($cgi->param('before') ne "");
291 $command .= "-A ".$cgi->param('after')." " if ($cgi->param('after') ne "");
292 $command .= "-p ".$cgi->param('prefix')." " if ($cgi->param('prefix') ne "");
293 $command .= "-P ".$cgi->param('postnuke')." " if ($cgi->param('postnuke') ne "");
294 $command .= "-l ".$cgi->param('boot')." " if ($cgi->param('boot') ne 'NATIVE');
295 $command .= "-k ".$cgi->param('kernel')." " if (($cgi->param('kernel') ne "") && ($cgi->param('kernel') ne 'NATIVE'));
296 $command .= "-d ".$cgi->param('dest')." -s ".$cgi->param('size')." -".$cgi->param('compratio')." ";
297
298 print $cgi->h2('Here is the mondoarchive command generated:');
299 print $cgi->hr;
300 print $command;
301
302 print $cgi->hr;
303 print "That mondoarchive is now being commited to the server which launch the disaster recovery procedure.<P>";
304 print "Please wait till it's done ...";
305 print $cgi->end_form;
306
307 #
308 # Now doing the job ...
309 #
310 #system("sudo $command");
311 }
Note: See TracBrowser for help on using the repository browser.