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