#!/usr/bin/perl -w
#
# $Id$
#
# mondo-web perl script
# ======================
# The script is a cgi-bin script serving as a Web interface for mondoarchive
# It generates the right mondoarchive command depending on answers to questions
# it asks to the user.
#
# This program is free software and is made available under the GPLv2.
# (c) B. Cornec 2007
#
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Data::Dumper;
use AppConfig;
my $cgi = new CGI;
my $default = "";
my @default;
# Handling Configuration files
my $file1 = "/etc/mondo/mondo.conf.dist";
my $file2 = "/etc/mondo/mondo.conf";
my $config = AppConfig->new({
# Auto Create variables mentioned in Conf file
CREATE => 1,
DEBUG => 0,
GLOBAL => {
# Each conf item has one single parameter
ARGCOUNT => AppConfig::ARGCOUNT_ONE
}
});
$config->file($file1, $file2);
my $command="";
# Fake it for now
my %media = (
"CDR" => "CD-R",
"CDRW" => "CD-RW",
"DVD" => "DVD+/-R/RW",
"ISO" => "ISO Image",
"USB" => "USB disk/key",
"TAPE" => "Tape",
"NFS" => "NFS File System",
"STREAM" => "Streaming"
);
my @media = sort keys %media;
my %options = (
'NOBOOTABLE' => 'Create Non-Bootable media',
'AUTO', => 'Auto Restore Mode',
'NFSEXCL' => 'Exclude Network File Systems',
'MANEJECT' => 'Manual media ejection',
'DIFF' => 'Differential Backup',
'VERIF' => 'Media verification (Slower)',
'XATTR' => 'Extended Attributes and ACL Management (Slower)'
);
my @options = sort keys %options;
my %speed = (
1 => '1x',
2 => '2x',
4 => '4x',
8 => '8x',
16 => '16x',
24 => '24x',
48 => '48x',
52 => '52x',
);
my @speed = sort {$a <=> $b} keys %speed;
my %comp = (
GZIP => 'gzip (average)',
BZIP2 => 'bzip2 (size)',
LZO => 'lzo (speed)',
);
my @comp = sort keys %comp;
my %ratio = (
0 => '0',
1 => '1',
2 => '2',
3 => '3',
4 => '4',
5 => '5',
6 => '6',
7 => '7',
8 => '8',
9 => '9',
);
my @ratio = sort {$a <=> $b} keys %ratio;
my %boot = (
'LILO' => "LILO",
'GRUB' => "GRUB",
'ELILO' => "ELILO (ia64)",
'RAW' => "RAW",
'NATIVE' => "Autodetected",
);
my @boot = sort keys %boot;
print $cgi->header;
print $cgi->start_html('Web Based MondoArchive');
print << 'EOF';
EOF
print $cgi->h1('MondoArchive Image Creation');
if (not ($cgi->param())) {
print $cgi->start_form;
print $cgi->hr;
print $cgi->h2('Mandatory Info');
print "
\n"; print "Media type: ",$cgi->popup_menu(-name=>'media', -values=>\@media, -default=>$media[0], -labels=>\%media); print " | \n"; print "Destination path or device:\n"; print $cgi->textfield(-name=>'dest', -default=>$config->get("mondo_images_dir"), -size=>15, -maxlenght=>150); print " | \n"; print "Size of media (MB):\n"; print $cgi->textfield(-name=>'size', -default=>$config->get("mondo_media_size"), -size=>6, -maxlenght=>6); print " |
\n"; $default = 'GZIP' if ($config->get("mondo_compression_tool") =~ /gzip/); $default = 'BZIP2' if ($config->get("mondo_compression_tool") =~ /bzip2/); $default = 'LZO' if ($config->get("mondo_compression_tool") =~ /lzo/); print "Compression tool: ",$cgi->popup_menu(-name=>'comp', -values=>\@comp, -default=>$default, -labels=>\%comp); print " | \n"; print "Compression ratio: ",$cgi->popup_menu(-name=>'compratio', -values=>\@ratio, -default=>$config->get("mondo_compression_level"), -labels=>\%ratio); print " |
\n"; @default = (@default,'AUTO') if ($config->get("mondo_automatic_restore") =~ /yes/); @default = (@default,'DIFF') if ($config->get("mondo_differential") =~ /yes/); #'NFSEXCL' => 'Exclude Network File Systems', @default = (@default, 'NFSEXCL'); #'NOBOOTABLE' => 'Create Non-Bootable media', #'MANEJECT' => 'Manual media ejection', #'VERIF' => 'Media verification (Slower)', #'XATTR' => 'Extended Attributes and ACL Management (Slower)' print $cgi->checkbox_group(-name=>'options', -values=>\@options, -defaults=>\@default, -linebreak=>'true', -labels=>\%options); print " | \n";
print "Temporary Directory:\n";
print $cgi->textfield(-name=>'temp',
-default=>$config->get("mondo_tmp_dir"),
-size=>25,
-maxlenght=>150);
print " "; print "Scratch Directory:\n"; print $cgi->textfield(-name=>'scratch', -default=>$config->get("mondo_scratch_dir"), -size=>25, -maxlenght=>150); print " "; print "ISO Image Name Prefix:\n"; print $cgi->textfield(-name=>'prefix', -default=>$config->get("mondo_prefix"), -size=>15, -maxlenght=>150); print " "; print "Tape block size:\n"; print $cgi->textfield(-name=>'block', -default=>$config->get("mondo_external_tape_blocksize"), -size=>10, -maxlenght=>10); print " "; print "Media Speed (if pertinent): ",$cgi->popup_menu(-name=>'speed', -values=>\@speed, -default=>$config->get("mondo_iso_burning_speed"), -labels=>\%speed); print " "; print "Kernel:\n"; print $cgi->textfield(-name=>'kernel', -default=>$config->get("mondo_kernel"), -size=>30, -maxlenght=>150); print " "; print "Postnuke script:\n"; print $cgi->textfield(-name=>'postnuke', -default=>'', -size=>30, -maxlenght=>150); print " "; print "NFS (server:export):\n"; print $cgi->textfield(-name=>'nfs', -default=>'', -size=>30, -maxlenght=>150); print " "; print " |
\n";
print "Bootloader: \n",$cgi->radio_group(-name=>'boot', -values=>\@boot, -default=>$config->get("mondo_boot_loader"), -linebreak=>'true', -labels=>\%boot); print " "; print "Debug:\n"; print $cgi->popup_menu(-name=>'debug', -values=>\@ratio, -default=>$config->get("mondo_log_level"), -labels=>\%ratio); print " | \n";
print "Excluded directories:\n";
print $cgi->textfield(-name=>'exclude',
-default=>$config->get("mondo_exclude_files"),
-size=>30,
-maxlenght=>150);
print " "; print "Included directories:\n"; print $cgi->textfield(-name=>'include', -default=>$config->get("mondo_include_files"), -size=>30, -maxlenght=>150); print " "; print "Command to launch before burning:\n"; print $cgi->textfield(-name=>'before', -default=>'', -size=>50, -maxlenght=>150); print " "; print "Command to launch after burning:\n"; print $cgi->textfield(-name=>'after', -default=>'', -size=>50, -maxlenght=>150); print " "; print " |
"; print "Please wait till it's done ..."; print $cgi->end_form; # # Now doing the job ... # #system("sudo $command"); }