source: ProjectBuilder/projects/hyperlinux/cgi-bin/hyperlinux.pl@ 1778

Last change on this file since 1778 was 1778, checked in by Bruno Cornec, 11 years ago
  • New hyperlinux project for pre-installing servers
  • Property svn:executable set to *
File size: 7.0 KB
Line 
1#!/usr/bin/perl -w
2
3#
4# HyPer-Linux perl script
5# ======================
6# The script is a cgi-bin script allowing the automatic configuration
7# of HP ProLiant through a Web Browser, for preloaded Linux distribution
8# customization.
9#
10# This program is free software and is made available under the GPLv2.
11# (c) 2013 B. Cornec - Hewlett-Packard
12#
13
14use strict;
15use CGI;
16use CGI::Carp qw(fatalsToBrowser);
17
18my $distrib = "RH64";
19my $infofile = "/usr/share/lib/locale";
20
21my $cgi = new CGI;
22
23my $name;
24my $s;
25my $ftp;
26my $shortname;
27my $sysfont;
28my $unused;
29my %lang;
30my %keyboard;
31my %timezone;
32my @lang;
33my @keyboard;
34my @timezone;
35my $lang;
36my $keyboard;
37my $timezone;
38
39open(INFO,$infofile) || die "Unable to open $infofile";
40while (<INFO>) {
41 s/ / /g;
42 ($name, $shortname, $sysfont, $unused, $lang, $keyboard, $timezone) = split(/ /);
43 chomp($timezone);
44 $name =~ s/ //g;
45 $timezone =~ s/ //g;
46 $keyboard =~ s/ //g;
47 $lang =~ s/ //g;
48 $lang{$lang} = "$name"." ($lang)";
49 push(@lang, ($lang));
50 $keyboard{$keyboard} = "$name"." ($keyboard)";
51 push(@keyboard, ($keyboard));
52 $timezone{$timezone} = "$name"." ($timezone)";
53 push(@timezone, ($timezone));
54 }
55
56print $cgi->header;
57print $cgi->start_html('HyPer-Linux Configuration');
58print $cgi->h1('HyPer-Linux Configuration');
59print $cgi->hr;
60print << EOF;
61<TABLE WIDTH="100%" >
62<TR>
63 <TD rowspan=2><IMG SRC="hp.gif" HEIGHT=66 WIDTH=66 ALIGN=LEFT> </TD>
64 <TD> <FONT SIZE=+3> RedHat Enterprise Linux Installation Server </FONT> </TD>
65</TR>
66<TR>
67 <TD align=right></TD>
68</TR>
69</TABLE>
70
71
72if (not ($cgi->param())) {
73print $cgi->start_form;
74print $cgi->h2('Configuration of the localization');
75print "Language : ",$cgi->popup_menu(-name=>'language',
76 -values=>\@lang,
77 -default=>'fr_FR',
78 -labels=>\%lang);
79print "<P>\n";
80print "Keyboard : ",$cgi->popup_menu(-name=>'keyboard',
81 -values=>\@keyboard,
82 -default=>'fr',
83 -labels=>\%keyboard);
84print "<P>\n";
85print "Timezone : ",$cgi->popup_menu(-name=>'timezone',
86 -values=>\@timezone,
87 -default=>'Europe/Paris',
88 -labels=>\%timezone);
89print "<P>\n";
90print $cgi->hr;
91
92my %labels = ('MySQL' => 'MySQL Server',
93 'PGSQL' => 'PostgreSQL Server',
94 'EDB' => 'EnterpriseDB Server');
95print $cgi->h2('Configuration of the services');
96print "Which services do you want to activate by default at boot time : <P>\n",$cgi->popup_menu(-name=>'services',
97 -values=>['MySQL','PGSQL','EDB'],
98 -defaults=>['PGSQL'],
99 -labels=>\%labels);
100print $cgi->hr;
101print $cgi->h2('Configuration of the network parameters');
102%labels = ('DHCP' => 'Configuration through a DHCP server',
103 'STATIC' => 'Static IP configuration');
104print "Mode : ",$cgi->popup_menu(-name=>'mode',
105 -values=>['DHCP','STATIC'],
106 -default=>'DHCP',
107 -labels=>\%labels);
108print "<P>\n";
109print "If you choose just above the Static IP configuration mode, please fill the following fields :<P>\n";
110print "Full Qualified Domain Name of the system : ",$cgi->textfield(-name=>'name',
111 -default=>'netserver',
112 -size=>15,
113 -maxlenght=>15);
114print "<P>IP address : ",$cgi->textfield(-name=>'address',
115 -default=>'192.168.1.1',
116 -size=>15,
117 -maxlenght=>15);
118print " Netmask : ",$cgi->textfield(-name=>'netmask',
119 -default=>'255.255.255.0',
120 -size=>15,
121 -maxlenght=>15);
122print "<P>Gateway : ",$cgi->textfield(-name=>'gateway',
123 -default=>'192.168.1.254',
124 -size=>15,
125 -maxlenght=>15);
126print " Primary DNS : ",$cgi->textfield(-name=>'dns',
127 -default=>'192.168.1.100',
128 -size=>15,
129 -maxlenght=>15);
130print "<P>\n";
131print $cgi->submit;
132print $cgi->end_form;
133}
134
135else {
136 print $cgi->h2('You made the following choices :');
137 print $cgi->hr;
138 print "<BOLD>Localisation </BOLD> - ";
139 print "Language : <em>",$cgi->param('language'),", </em>";
140 print "Keyboard : <em>",$cgi->param('keyboard'),", </em>";
141 print "Timezone : <em>",$cgi->param('timezone'),"</em>";
142 print $cgi->hr;
143 print "<BOLD>Network</BOLD> configuration mode ";
144 if ($cgi->param('mode') eq 'STATIC') {
145 print "<em>static</em><P>";
146 print "Name : <em>",$cgi->param('name'),"</em><P>";
147 print "IP address : <em>",$cgi->param('address'),", </em>";
148 print "Netmask : <em>",$cgi->param('netmask'),"</em><P>";
149 print "Gateway : <em>",$cgi->param('gateway'),", </em>";
150 print "DNS server : <em>",$cgi->param('dns'),", </em>";
151 }
152 else {
153 print "<em>dynamic (DHCP)</em>"
154 }
155 print $cgi->hr;
156 print "<BOLD>Services</BOLD> activated at boot time : ";
157 foreach $s ($cgi->param('services')) {
158 print "- <em>MySQL server</em> -" if ( $s =~ /MySQL/);
159 print "- <em>PostgreSQL server</em> -" if ($s =~ /PGSQL/);
160 print "- <em>EnterpriseDB server</em> -" if ($s =~ /EDB/);
161 }
162 print $cgi->hr;
163 print "Your customization parameters are now being commited to the server which will then reboot to ensure a proper environement.<P>";
164 print "Please wait till it's done ...";
165 print $cgi->end_form;
166
167 #
168 # Now doing the job ...
169 #
170 my $gendir = "/var/hyperlinux";
171 my $gensys = "$gendir/sysconfig";
172 my $gennet = "$gendir/network";
173 my $genbin = "$gendir/bin";
174 mkdir $gendir,0700;
175 mkdir $gensys,0700;
176 mkdir $gennet,0700;
177 mkdir $genbin,0700;
178
179 if ($distrib eq "RH70") {
180 #
181 # Localisation
182 #
183 open(T,"> $gensys/clock") || die "Unable to open $gensys/clock";
184 print T 'ZONE="',$cgi->param('timezone'),'"',"\n";
185 #print T "UTC=false\n";
186 #print T "ARC=false\n";
187 close(T);
188 open(T,"> $gensys/keyboard") || die "Unable to open $gensys/keyboard";
189 print T 'KEYBOARDTYPE="pc"',"\n";
190 print T 'KEYTABLE="',$cgi->param('keyboard'),'"',"\n";
191 close(T);
192 open(T,"> $gensys/i18n") || die "Unable to open $gensys/i18n";
193 print T 'LANG="',$cgi->param('language'),'"',"\n";
194 close(T);
195 #
196 # Network
197 #
198 open(T,"> $gensys/network") || die "Unable to open $gensys/network";
199 print T 'NETWORKING="yes"',"\n";
200 print T 'GATEWAYDEV="eth0"',"\n";
201 print T 'GATEWAY="',$cgi->param('gateway'),'"',"\n";
202 print T 'HOSTNAME="',$cgi->param('name'),'"',"\n";
203 close(T);
204 open(T,"> $gennet/ifcfg-eth0") || die "Unable to open $gennet/ifcfg-eth0";
205 print T "DEVICE=eth0\n";
206 print T "USERCTL=no\n";
207 print T "ONBOOT=yes\n";
208 if ($cgi->param('mode') eq 'DHCP') {
209 print T "BOOTPROTO=dhcp\n";
210 print T "IPADDR=\n";
211 print T "NETMASK=\n";
212 print T "NETWORK=\n";
213 print T "BROADCAST=\n";
214 }
215 else {
216 print T "BOOTPROTO=none\n";
217 print T 'IPADDR="',$cgi->param('address'),'"',"\n";
218 print T 'NETMASK="',$cgi->param('netmask'),'"',"\n";
219 print T "NETWORK=\n";
220 print T "BROADCAST=\n";
221 }
222 close(T);
223 #
224 # Services
225 #
226 open(T,"> $genbin/populate") || die "Unable to open $genbin/populate";
227 print T "#!/bin/sh\n";
228 print T "#\n";
229
230 $ftp = 0;
231 foreach $s ($cgi->param('services')) {
232 print T "/sbin/chkconfig --level 345 mysqld on\n" if ($s =~ /MySQL/);
233 print T "/sbin/chkconfig --level 345 postgresql on\n" if ($s =~ /PGSQL/);
234 print T "/sbin/chkconfig --level 345 EDB on\n" if ($s =~ /EDB/);
235 }
236 print T "/bin/mv $gensys/* /etc/sysconfig\n";
237 print T "/bin/mv $gennet/* /etc/sysconfig/network-scripts\n";
238 print T "/sbin/shutdown -r +1 'Reboot for HyPer-Linux Configuration...'\n";
239 close(T);
240 chmod 0755,"$genbin/populate";
241 system("sudo $genbin/populate");
242 }
243}
Note: See TracBrowser for help on using the repository browser.