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