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

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

Much more advanced version

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