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

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

handle 2 new conf file parameters

  • Property svn:executable set to *
File size: 9.2 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 'NOBOOTABLE' => 'Create Non-Bootable media',
56 'AUTO', => 'Auto Restore Mode',
57 'NFSEXCL' => 'Exclude Network File Systems',
58 'MANEJECT' => 'Manual media ejection',
59 'DIFF' => 'Differential Backup',
60 'VERIF' => 'Media verification (Slower)',
61 'XATTR' => 'Extended Attributes and ACL Management (Slower)'
62);
63my @options = sort keys %options;
64my %speed = (
65 1 => '1x',
66 2 => '2x',
67 4 => '4x',
68 8 => '8x',
69 16 => '16x',
70 24 => '24x',
71 48 => '48x',
72 52 => '52x',
73);
74my @speed = sort {$a <=> $b} keys %speed;
75my %comp = (
76 GZIP => 'gzip (average)',
77 BZIP2 => 'bzip2 (size)',
78 LZO => 'lzo (speed)',
79);
80my @comp = sort keys %comp;
81my %ratio = (
82 0 => '0',
83 1 => '1',
84 2 => '2',
85 3 => '3',
86 4 => '4',
87 5 => '5',
88 6 => '6',
89 7 => '7',
90 8 => '8',
91 9 => '9',
92);
93my @ratio = sort {$a <=> $b} keys %ratio;
94my %boot = (
95 'LILO' => "LILO",
96 'GRUB' => "GRUB",
97 'ELILO' => "ELILO (ia64)",
98 'RAW' => "RAW",
99 'BOOT0' => "BOOT0 (FreeBSD)",
100 'DD' => "DD (FreeBSD)",
101 'NATIVE' => "Autodetected",
102);
103my @boot = sort keys %boot;
104
105print $cgi->header;
106print $cgi->start_html('Web Based MondoArchive');
107print << 'EOF';
108<IMG SRC="mondo_logo.gif" HEIGHT=66 WIDTH=66 ALIGN=LEFT>
109EOF
110print $cgi->h1('MondoArchive Image Creation');
111
112if (not ($cgi->param())) {
113 print $cgi->start_form;
114 print $cgi->hr;
115 print $cgi->h2('Mandatory Info');
116 print "<TABLE><TR><TD WIDTH=230>\n";
117 print "Media type: ",$cgi->popup_menu(-name=>'media',
118 -values=>\@media,
119 -default=>$media[0],
120 -labels=>\%media);
121 print "</TD><TD WIDTH=300>\n";
122 print "Destination path or device:\n";
123 print $cgi->textfield(-name=>'dest',
124 -default=>$config->get("mondo_images_dir"),
125 -size=>15,
126 -maxlenght=>150);
127 print "</TD><TD WIDTH=250>\n";
128 print "Size of media (MB):\n";
129 print $cgi->textfield(-name=>'size',
130 -default=>$config->get("mondo_media_size"),
131 -size=>6,
132 -maxlenght=>6);
133 print "</TD></TR></TABLE>\n";
134 print $cgi->hr;
135
136 print $cgi->h2('Compression Info');
137 print "<TABLE><TR><TD WIDTH=330>\n";
138 $default = 'GZIP' if ($config->get("mondo_compression_tool") =~ /gzip/);
139 $default = 'BZIP2' if ($config->get("mondo_compression_tool") =~ /bzip2/);
140 $default = 'LZO' if ($config->get("mondo_compression_tool") =~ /lzo/);
141 print "Compression tool: ",$cgi->popup_menu(-name=>'comp',
142 -values=>\@comp,
143 -default=>$default,
144 -labels=>\%comp);
145 print "</TD><TD WIDTH=300>\n";
146 print "Compression ratio: ",$cgi->popup_menu(-name=>'compratio',
147 -values=>\@ratio,
148 -default=>$config->get("mondo_compression_level"),
149 -labels=>\%ratio);
150 print "</TD></TR></TABLE>\n";
151 print $cgi->hr;
152
153 print $cgi->h2('Optional Info');
154 print "<TABLE><TR><TD WIDTH=360>\n";
155
156 @default = (@default,'AUTO') if ($config->get("mondo_automatic_restore") =~ /yes/);
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 .= "-W " if ($s =~ /NOBOOTABLE/);
266 $command .= "-H " if ($s =~ /AUTO/);
267 $command .= "-N " if ($s =~ /NFSEXCL/);
268 $command .= "-m " if ($s =~ /MANEJECT/);
269 $command .= "-D " if ($s =~ /DIFF/);
270 $command .= "-V " if ($s =~ /VERIF/);
271 $command .= "-z " if ($s =~ /XATTR/);
272 }
273 my $speed = $cgi->param('speed');
274 $command .= "-c $speed " if ($cgi->param('media') =~ /^CDR$/);
275 $command .= "-w $speed " if ($cgi->param('media') =~ /^CDRW$/);
276 $command .= "-n ".$cgi->param('nfs')." " if (($cgi->param('media') =~ /NFS/) && ($cgi->param('nfs') ne ""));
277 $command .= "-r " if ($cgi->param('media') =~ /DVD/);
278 $command .= "-i " if ($cgi->param('media') =~ /ISO/);
279 $command .= "-U " if ($cgi->param('media') =~ /USB/);
280 $command .= "-t " if ($cgi->param('media') =~ /TAPE/);
281 $command .= "-b ".$cgi->param('block')." " if (($cgi->param('media') =~ /TAPE/) && ($cgi->param('block') ne ""));
282 $command .= "-u " if ($cgi->param('media') =~ /STREAM/);
283 $command .= "-L " if ($cgi->param('comp') =~ /LZO/);
284 $command .= "-G " if ($cgi->param('comp') =~ /GZIP/);
285 $command .= "-E \"".$cgi->param('exclude')."\" " if ($cgi->param('exclude') ne "");
286 $command .= "-I \"".$cgi->param('include')."\" " if ($cgi->param('include') ne "");
287 $command .= "-T ".$cgi->param('temp')." " if ($cgi->param('temp') ne "");
288 $command .= "-S ".$cgi->param('scratch')." " if ($cgi->param('scratch') ne "");
289 $command .= "-B ".$cgi->param('before')." " if ($cgi->param('before') ne "");
290 $command .= "-A ".$cgi->param('after')." " if ($cgi->param('after') ne "");
291 $command .= "-p ".$cgi->param('prefix')." " if ($cgi->param('prefix') ne "");
292 $command .= "-P ".$cgi->param('postnuke')." " if ($cgi->param('postnuke') ne "");
293 $command .= "-l ".$cgi->param('boot')." " if ($cgi->param('boot') ne 'NATIVE');
294 $command .= "-k ".$cgi->param('kernel')." " if (($cgi->param('kernel') ne "") && ($cgi->param('kernel') ne 'NATIVE'));
295 $command .= "-d ".$cgi->param('dest')." -s ".$cgi->param('size')." -".$cgi->param('compratio')." ";
296
297 print $cgi->h2('Here is the mondoarchive command generated:');
298 print $cgi->hr;
299 print $command;
300
301 print $cgi->hr;
302 print "That mondoarchive is now being commited to the server which launch the disaster recovery procedure.<P>";
303 print "Please wait till it's done ...";
304 print $cgi->end_form;
305
306 #
307 # Now doing the job ...
308 #
309 #system("sudo $command");
310 }
Note: See TracBrowser for help on using the repository browser.