2 # Actually creates a new zone
4 require './zones-lib.pl';
7 &error_setup($text{'create_err'});
8 &foreign_require("time", "time-lib.pl");
9 &foreign_require("useradmin", "user-lib.pl");
12 $form = &get_create_form(\%in);
13 $form->validate_redirect("create_form.cgi");
14 $path = $form->get_value("path") || "$config{'base_dir'}/$in{'name'}";
15 mkdir($config{'base_dir'}, 0700);
16 -d $path && $form->validate_redirect("create_form.cgi",
17 [ [ "path", &text('create_epath2', $path) ] ]);
18 @pkgs = split(/[\r\n]+/, $form->get_value("pkgs"));
20 push(@pkgs, $root_directory);
23 # Validate initial configuration fields, and create sysidcfg
25 if ($in{'root_def'}) {
26 ($root) = grep { $_->{'user'} eq 'root' }
27 &useradmin::list_users();
28 $root || &error($text{'create_eroot'});
29 push(@sysidcfg, [ 'root_password' => $root->{'pass'} ]);
32 push(@sysidcfg, [ 'root_password' =>
33 &useradmin::encrypt_password(
34 $form->get_value("root")) ]);
36 if ($in{'timezone_def'}) {
37 push(@sysidcfg, [ 'timezone' =>
38 &time::get_current_timezone() ]);
41 push(@sysidcfg, [ 'timezone' => $form->get_value('timezone') ]);
43 if ($in{'locale_def'}) {
44 push(@sysidcfg, [ 'system_locale' => &get_global_locale() ]);
47 push(@sysidcfg, [ 'system_locale' => $form->get_value('locale') ]);
49 if ($in{'terminal_def'}) {
50 push(@sysidcfg, [ 'terminal' => 'vt100' ]);
53 push(@sysidcfg, [ 'terminal' => $form->get_value('terminal') ]);
56 # Setup DNS or NIS resolution
57 $ns = [ uc($form->get_value('resolv')) ];
58 if ($form->get_value('resolv') ne 'none') {
59 push(@$ns, [ 'domain_name' => $form->get_value("domain") ]);
60 foreach $n (split(/\s+/, $in{'server'})) {
61 $ip = &to_ipaddress($n);
62 push(@$ns, [ 'name_server' => "$n($ip)" ]);
65 push(@sysidcfg, [ 'name_service' => $ns ]);
67 # Set the NFS4 Domain as dynamic so that
68 # upon first boot we don't get asked
69 push(@sysidcfg, ['nfs4_domain' => "dynamic"]);
71 # Setup network interface config
72 push(@sysidcfg, [ 'security_policy' => 'NONE' ]);
73 if ($in{'hostname_def'}) {
74 $hostname = $form->get_value("name");
77 $hostname = $form->get_value("hostname");
79 if ($in{'address_def'}) {
80 push(@sysidcfg, [ 'network_interface' =>
81 [ "none", [ 'hostname' => $hostname ] ] ]);
84 &to_ipaddress($hostname) ||
85 $form->validate_redirect("create_form.cgi",
86 [ [ "hostname", $text{'create_eresolvname'} ] ]);
87 push(@sysidcfg, [ 'network_interface' =>
88 [ "primary", [ 'hostname' => $hostname ],
89 [ 'ip_address' => $in{'address'} ],
90 $in{'router_def'} ? ( ) : (
91 [ 'default_route' => $in{'router'} ] ) ] ]);
95 $p = new Webmin::Page(undef, $text{'create_title'});
97 $d1 = new Webmin::DynamicHTML(\&execute_create, undef, $text{'create_adding'});
101 $zinfo = &create_zone($form->get_value("name"), $path);
102 $p->add_message_after($d1, $text{'create_done'});
105 if (!$in{'address_def'}) {
106 # Set initial network address
107 $d2 = new Webmin::DynamicHTML(\&execute_address, undef, $text{'create_addingnet'});
111 $net = { 'keytype' => 'net',
112 'address' => $in{'address'},
113 'physical' => $in{'physical'} };
114 &create_zone_object($zinfo, $net);
115 $p->add_message_after($d2, $text{'create_done'});
119 # Add or remove extra package directories
120 # add for sparse root zone and remove for whole root zone
121 if ($in{'inherit'} eq '0' ) {
122 $d3 = new Webmin::DynamicHTML(\&remove_pkgs, undef, $text{'create_removingpkgs'});
126 $pkg = { 'keytype' => 'inherit-pkg-dir' };
127 &delete_zone_object($zinfo,$pkg);
128 $p->add_message_after($d3, $text{'create_done'});
133 $d3 = new Webmin::DynamicHTML(\&execute_pkgs, undef, $text{'create_addingpkgs'});
138 $pkg = { 'keytype' => 'inherit-pkg-dir',
140 &create_zone_object($zinfo, $pkg);
142 $p->add_message_after($d3, $text{'create_done'});
149 $d4 = new Webmin::DynamicHTML(\&create_brand,undef, $text{'create_brandmsg'});
154 &set_zone_variable($zinfo,"brand",$form->get_value("brand"));
155 $p->add_message_after($d4, $text{'create_done'});
159 if ($in{'install'}) {
161 $d5 = new Webmin::DynamicText(\&execute_install);
163 $d5->set_message($text{'create_installing'});
167 local $ok = &callback_zone_command($zinfo, "install",
168 \&Webmin::DynamicText::add_line, [ $d5 ]);
170 $p->add_message_after($d5, $text{'create_done'});
173 $p->add_error_after($d5, $text{'create_failed'});
177 # Save the sysidcfg file
178 &save_sysidcfg(\@sysidcfg, "$path/root/etc/sysidcfg");
180 if (-e "$path/root/etc/.UNCONFIGURED") {
181 # If the file .UNCONFIGURED is there remove it
182 &system_logged("rm -f $path/root/etc/.UNCONFIGUREED");
184 &config_zone_nfs($zinfo);
185 &run_zone_command($zinfo, "boot");
189 # Save sysidcfg for later install
191 &save_sysidcfg(\@sysidcfg, &zone_sysidcfg_file($in{'name'}));
195 if ($in{'install'} && $in{'webmin'}) {
196 # Create a Webmin setup script and run it
197 $d6 = new Webmin::DynamicText(\&execute_webmin);
199 $d6->set_message($text{'create_webmining'});
204 $script = &get_zone_root($zinfo)."/tmp/install-webmin";
205 $err = &create_webmin_install_script($zinfo, $script);
207 $p->add_error_after($d6, &text('created_wfailed', $err));
210 $ex = &run_in_zone_callback($zinfo, "/tmp/install-webmin",
211 \&Webmin::DynamicText::add_line, [ $d ]);
213 $p->add_message($text{'create_done'});
214 &post_webmin_install($zinfo);
217 $p->add_error($text{'create_failed'});
223 $p->add_footer("index.cgi", $text{'index_return'});
225 &webmin_log("create", "zone", $in{'name'});