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

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

Preliminary Model for a Web base interface to mondoarchive

  • Property svn:executable set to *
File size: 7.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
31# Fake it for now
32my %media = (
33 "CD" => "CD-R",
34 "CDRW" => "CD-RW",
35 "DVD" => "DVD+/-R/RW",
36 "ISO" => "ISO Image",
37 "USB" => "USB disk/key",
38 "TAPE" => "Tape",
39 "NFS" => "NFS File System",
40 "STREAM" => "Streaming"
41);
42my @media = sort keys %media;
43my %options = (
44 'FLOPPY' => 'Boot floppy production',
45 'AUTO', => 'Auto Restore Mode',
46 'NFSEXCL' => 'Exclude Network File Systems',
47 'MANEJECT' => 'Manual media ejection',
48 'DIFF' => 'Differential Backup',
49 'VERIF' => 'Media verification (Slower)',
50 'XATTR' => 'Extended Attributes and ACL Management (Slower)'
51);
52my @options = sort keys %options;
53my %speed = (
54 2 => '2x',
55 4 => '4x',
56 8 => '8x',
57 16 => '16x',
58 24 => '24x',
59 48 => '48x',
60 52 => '52x',
61);
62my @speed = sort {$a <=> $b} keys %speed;
63my %comp = (
64 GZIP => 'gzip (average)',
65 BZIP2 => 'bzip2 (size)',
66 LZO => 'lzo (speed)',
67);
68my @comp = sort keys %comp;
69my %compsize = (
70 0 => '0',
71 1 => '1',
72 2 => '2',
73 3 => '3',
74 4 => '4',
75 5 => '5',
76 6 => '6',
77 7 => '7',
78 8 => '8',
79 9 => '9',
80);
81my @compsize = sort {$a <=> $b} keys %compsize;
82my %boot = (
83 'LILO' => "LILO (ELILO for ia64)",
84 'GRUB' => "GRUB",
85 'NATIVE' => "Autodetected",
86);
87my @boot = sort keys %boot;
88
89print $cgi->header;
90print $cgi->start_html('Web Based MondoArchive');
91print << 'EOF';
92<IMG SRC="mondo_logo.gif" HEIGHT=66 WIDTH=66 ALIGN=LEFT>
93EOF
94print $cgi->h1('MondoArchive Image Creation');
95
96if (not ($cgi->param())) {
97 print $cgi->start_form;
98 print $cgi->hr;
99 print $cgi->h2('Mandatory Info');
100 print "<TABLE><TR><TD WIDTH=230>\n";
101 print "Media type: ",$cgi->popup_menu(-name=>'media',
102 -values=>\@media,
103 -default=>$media[0],
104 -labels=>\%media);
105 print "</TD><TD WIDTH=300>\n";
106 print "Destination path or device:\n";
107 print $cgi->textfield(-name=>'dest',
108 -default=>'',
109 -size=>15,
110 -maxlenght=>150);
111 print "</TD><TD WIDTH=250>\n";
112 print "Size of media (MB):\n";
113 print $cgi->textfield(-name=>'size',
114 -default=>'4380',
115 -size=>6,
116 -maxlenght=>6);
117 print "</TD></TR></TABLE>\n";
118 print $cgi->hr;
119
120 print $cgi->h2('Compression Info');
121 print "<TABLE><TR><TD WIDTH=330>\n";
122 print "Compression tool: ",$cgi->popup_menu(-name=>'comp',
123 -values=>\@comp,
124 -default=>'GZIP',
125 -labels=>\%comp);
126 print "</TD><TD WIDTH=300>\n";
127 print "Compression ratio: ",$cgi->popup_menu(-name=>'compsize',
128 -values=>\@compsize,
129 -default=>6,
130 -labels=>\%compsize);
131 print "</TD></TR></TABLE>\n";
132 print $cgi->hr;
133
134 print $cgi->h2('Optional Info');
135 print "<TABLE><TR><TD WIDTH=360>\n";
136 print $cgi->checkbox_group(-name=>'options',
137 -values=>\@options,
138 -defaults=>['NFSEXCL'],
139 -linebreak=>'true',
140 -labels=>\%options);
141 print "</TD><TD WIDTH=350>\n";
142 print "Temporary Directory:\n";
143 print $cgi->textfield(-name=>'temp',
144 -default=>'/var/cache/mondo/tmp',
145 -size=>25,
146 -maxlenght=>150);
147 print "<BR>";
148 print "Scratch Directory:\n";
149 print $cgi->textfield(-name=>'scratch',
150 -default=>'/var/cache/mondo/scratch',
151 -size=>25,
152 -maxlenght=>150);
153 print "<BR>";
154 print "ISO Image Name Prefix:\n";
155 print $cgi->textfield(-name=>'prefix',
156 -default=>'mondorescue',
157 -size=>15,
158 -maxlenght=>150);
159 print "<BR>";
160 print "Tape block size:\n";
161 print $cgi->textfield(-name=>'block',
162 -default=>'32768',
163 -size=>10,
164 -maxlenght=>10);
165 print "<BR>";
166 print "Media Speed (if pertinent): ",$cgi->popup_menu(-name=>'speed',
167 -values=>\@speed,
168 -default=>$speed[-1],
169 -labels=>\%speed);
170 print "<BR>";
171 print "Kernel:\n";
172 print $cgi->textfield(-name=>'kernel',
173 -default=>'NATIVE',
174 -size=>30,
175 -maxlenght=>150);
176 print "<BR>";
177 print "Postnuke script:\n";
178 print $cgi->textfield(-name=>'postnuke',
179 -default=>'',
180 -size=>30,
181 -maxlenght=>150);
182 print "<BR>";
183 print "</TD></TR>\n";
184 print "<TR><TD>\n";
185 print "Bootloader:<BR>\n",$cgi->radio_group(-name=>'boot',
186 -values=>\@boot,
187 -default=>'NATIVE',
188 -linebreak=>'true',
189 -labels=>\%boot);
190 print "</TD><TD>\n";
191 print "Excluded directories:\n";
192 print $cgi->textfield(-name=>'exclude',
193 -default=>'',
194 -size=>30,
195 -maxlenght=>150);
196 print "<BR>";
197 print "Included directories:\n";
198 print $cgi->textfield(-name=>'include',
199 -default=>'',
200 -size=>30,
201 -maxlenght=>150);
202 print "<BR>";
203 print "Command to launch before burning:\n";
204 print $cgi->textfield(-name=>'before',
205 -default=>'',
206 -size=>50,
207 -maxlenght=>150);
208 print "<BR>";
209 print "Command to launch after burning:\n";
210 print $cgi->textfield(-name=>'after',
211 -default=>'',
212 -size=>50,
213 -maxlenght=>150);
214 print "<BR>";
215 print "</TD></TR></TABLE>\n";
216 print $cgi->hr;
217 print $cgi->submit;
218 print $cgi->end_form;
219} else {
220 print $cgi->h2('You made the following choices :');
221 print $cgi->hr;
222 print "<BOLD>Mandatory options </BOLD> - ";
223 print "Language : <em>",$cgi->param('language'),", </em>";
224 print "Keyboard : <em>",$cgi->param('keyboard'),", </em>";
225 print "Timezone : <em>",$cgi->param('timezone'),"</em>";
226 print $cgi->hr;
227 print "<BOLD>Network</BOLD> configuration mode ";
228 if ($cgi->param('mode') eq 'STATIC') {
229 print "<em>static</em><P>";
230 print "Name : <em>",$cgi->param('name'),"</em><P>";
231 print "IP address : <em>",$cgi->param('address'),", </em>";
232 print "Netmask : <em>",$cgi->param('netmask'),"</em><P>";
233 print "Gateway : <em>",$cgi->param('gateway'),", </em>";
234 print "DNS server : <em>",$cgi->param('dns'),", </em>";
235 }
236 else {
237 print "<em>dynamic (DHCP)</em>"
238 }
239 print $cgi->hr;
240 print "<BOLD>Services</BOLD> activated at boot time : ";
241 foreach my $s ($cgi->param('options')) {
242 print "- <em>FTP server</em> -" if ( $s =~ /FTP/);
243 print "- <em>Web server</em> -" if ($s =~ /WWW/);
244 print "- <em>DNS server</em> -" if ($s =~ /DNS/);
245 print "- <em>Proxy/Cache server</em> -" if ($s =~ /SQUID/);
246 }
247 print $cgi->hr;
248 print "Your customization parameters are now being commited to the server which will then reboot to ensure a proper environement.<P>";
249 print "Please wait till it's done ...";
250 print $cgi->end_form;
251
252 #
253 # Now doing the job ...
254 #
255
256 my $genbin = "/tmp";
257 open(T,"> $genbin/populate") || die "Unable to open $genbin/populate";
258 print T "#!/bin/sh\n";
259 print T "#\n";
260
261 foreach my $s ($cgi->param('services')) {
262 print T "/sbin/chkconfig --level 345 named on\n" if ($s =~ /DNS/);
263 print T "/sbin/chkconfig --level 345 httpd on\n" if ($s =~ /WWW/);
264 print T "/sbin/chkconfig --level 345 squid on\n" if ($s =~ /SQUID/);
265 }
266 close(T);
267 chmod 0755,"$genbin/populate";
268 system("sudo $genbin/populate");
269 }
Note: See TracBrowser for help on using the repository browser.