[1222] | 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 |
|
---|
| 15 | use strict;
|
---|
| 16 | use CGI;
|
---|
| 17 | use CGI::Carp qw(fatalsToBrowser);
|
---|
| 18 | use Data::Dumper;
|
---|
| 19 | use AppConfig;
|
---|
| 20 | use AppConfig::File;
|
---|
| 21 |
|
---|
| 22 | my $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 |
|
---|
[1223] | 31 | my $command="";
|
---|
| 32 |
|
---|
[1222] | 33 | # Fake it for now
|
---|
| 34 | my %media = (
|
---|
[1223] | 35 | "CDR" => "CD-R",
|
---|
[1222] | 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 | );
|
---|
| 44 | my @media = sort keys %media;
|
---|
| 45 | my %options = (
|
---|
[1223] | 46 | 'NOFLOPPY' => 'No Boot floppy production',
|
---|
| 47 | 'NOBOOTABLE' => 'Create Non-Bootable media',
|
---|
[1222] | 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 | );
|
---|
| 55 | my @options = sort keys %options;
|
---|
| 56 | my %speed = (
|
---|
| 57 | 2 => '2x',
|
---|
| 58 | 4 => '4x',
|
---|
| 59 | 8 => '8x',
|
---|
| 60 | 16 => '16x',
|
---|
| 61 | 24 => '24x',
|
---|
| 62 | 48 => '48x',
|
---|
| 63 | 52 => '52x',
|
---|
| 64 | );
|
---|
| 65 | my @speed = sort {$a <=> $b} keys %speed;
|
---|
| 66 | my %comp = (
|
---|
| 67 | GZIP => 'gzip (average)',
|
---|
| 68 | BZIP2 => 'bzip2 (size)',
|
---|
| 69 | LZO => 'lzo (speed)',
|
---|
| 70 | );
|
---|
| 71 | my @comp = sort keys %comp;
|
---|
[1223] | 72 | my %ratio = (
|
---|
[1222] | 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 | );
|
---|
[1223] | 84 | my @ratio = sort {$a <=> $b} keys %ratio;
|
---|
[1222] | 85 | my %boot = (
|
---|
[1223] | 86 | 'LILO' => "LILO",
|
---|
[1222] | 87 | 'GRUB' => "GRUB",
|
---|
[1223] | 88 | 'ELILO' => "ELILO (ia64)",
|
---|
| 89 | 'RAW' => "RAW",
|
---|
[1222] | 90 | 'NATIVE' => "Autodetected",
|
---|
| 91 | );
|
---|
| 92 | my @boot = sort keys %boot;
|
---|
| 93 |
|
---|
| 94 | print $cgi->header;
|
---|
| 95 | print $cgi->start_html('Web Based MondoArchive');
|
---|
| 96 | print << 'EOF';
|
---|
| 97 | <IMG SRC="mondo_logo.gif" HEIGHT=66 WIDTH=66 ALIGN=LEFT>
|
---|
| 98 | EOF
|
---|
| 99 | print $cgi->h1('MondoArchive Image Creation');
|
---|
| 100 |
|
---|
| 101 | if (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";
|
---|
[1223] | 132 | print "Compression ratio: ",$cgi->popup_menu(-name=>'compratio',
|
---|
| 133 | -values=>\@ratio,
|
---|
[1222] | 134 | -default=>6,
|
---|
[1223] | 135 | -labels=>\%ratio);
|
---|
[1222] | 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,
|
---|
[1223] | 143 | -defaults=>['NFSEXCL', 'NOFLOPPY'],
|
---|
[1222] | 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>";
|
---|
[1223] | 188 | print "NFS (server:export):\n";
|
---|
| 189 | print $cgi->textfield(-name=>'nfs',
|
---|
| 190 | -default=>'',
|
---|
| 191 | -size=>30,
|
---|
| 192 | -maxlenght=>150);
|
---|
| 193 | print "<BR>";
|
---|
[1222] | 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);
|
---|
[1223] | 201 | print "<BR>";
|
---|
| 202 | print "Debug:\n";
|
---|
| 203 | print $cgi->popup_menu(-name=>'debug',
|
---|
| 204 | -values=>\@ratio,
|
---|
| 205 | -default=>2,
|
---|
| 206 | -labels=>\%ratio);
|
---|
[1222] | 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 {
|
---|
[1223] | 237 | $command="mondoarchive -O -K ".$cgi->param('debug')." ";
|
---|
| 238 | if ($cgi->param('debug') eq 'STATIC') {
|
---|
| 239 | } else {
|
---|
[1222] | 240 | }
|
---|
| 241 | foreach my $s ($cgi->param('options')) {
|
---|
[1223] | 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/);
|
---|
[1222] | 250 | }
|
---|
[1223] | 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:');
|
---|
[1222] | 276 | print $cgi->hr;
|
---|
[1223] | 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>";
|
---|
[1222] | 281 | print "Please wait till it's done ...";
|
---|
| 282 | print $cgi->end_form;
|
---|
| 283 |
|
---|
| 284 | #
|
---|
| 285 | # Now doing the job ...
|
---|
| 286 | #
|
---|
[1223] | 287 | #system("sudo $command");
|
---|
[1222] | 288 | }
|
---|