Handle hostnames with upper-case letters
[webmin.git] / zones / save_zone.cgi
1 #!/usr/local/bin/perl
2 # Update, reboot or delete a zone
3
4 require './zones-lib.pl';
5 do 'forms-lib.pl';
6 &ReadParse();
7 $zinfo = &get_zone($in{'zone'});
8 $zinfo || &error($text{'edit_egone'});
9
10 if ($in{'reboot'}) {
11         # Reboot after asking for confirmation
12         $p = &get_confirm_page(\%in, "reboot", $zinfo, $in{'list'});
13         if ($p->get_confirm()) {
14                 # Do it
15                 $p = &get_execute_page("reboot", $zinfo, $in{'list'});
16                 $p->print();
17                 }
18         elsif ($p->get_cancel()) {
19                 # Cancelled
20                 &redirect($p->get_footer(0));
21                 }
22         else {
23                 $p->print();
24                 }
25         }
26 elsif ($in{'boot'}) {
27         # Just bootup now
28         $p = &get_execute_page("boot", $zinfo, $in{'list'});
29         $p->print();
30         }
31 elsif ($in{'halt'}) {
32         # Shutdown after asking for confirmation
33         $p = &get_confirm_page(\%in, "halt", $zinfo, $in{'list'});
34         if ($p->get_confirm()) {
35                 # Do it
36                 $p = &get_execute_page("halt", $zinfo, $in{'list'});
37                 $p->print();
38                 }
39         elsif ($p->get_cancel()) {
40                 # Cancelled
41                 &redirect($p->get_footer(0));
42                 }
43         else {
44                 $p->print();
45                 }
46         }
47 elsif ($in{'install'}) {
48         # Install system now
49         $p = new Webmin::Page(&zone_title($zinfo->{'name'}), $text{'install_title'});
50         $d = new Webmin::DynamicText(\&execute_install);
51         $p->add_form($d);
52         $d->set_message($text{'install_doing'});
53         $d->set_wait(1);
54         if ($in{'list'}) {
55                 $p->add_footer("index.cgi", $text{'index_return'});
56                 }
57         else {
58                 $p->add_footer("edit_zone.cgi?zone=$zinfo->{'name'}",
59                                $text{'edit_return'});
60                 }
61         $p->print();
62         }
63 elsif ($in{'delete'}) {
64         # Delete after confirming
65         $p = &get_confirm_page(\%in, "delete", $zinfo, $in{'list'});
66         if ($p->get_confirm()) {
67                 # Do it
68                 $p = &get_execute_page("delete", $zinfo, $in{'list'});
69                 $p->print();
70                 }
71         elsif ($p->get_cancel()) {
72                 # Cancelled
73                 &redirect($p->get_footer(0));
74                 }
75         else {
76                 $p->print();
77                 }
78         }
79 elsif ($in{'uninstall'}) {
80         # Un-install after confirming
81         $p = &get_confirm_page(\%in, "uninstall", $zinfo, $in{'list'});
82         if ($p->get_confirm()) {
83                 # Do it
84                 $p = &get_execute_page("uninstall", $zinfo, $in{'list'}, "-F");
85                 $p->print();
86                 }
87         elsif ($p->get_cancel()) {
88                 # Cancelled
89                 &redirect($p->get_footer(0));
90                 }
91         else {
92                 $p->print();
93                 }
94         }
95 elsif ($in{'wupgrade'} || $in{'winstall'}) {
96         # Install Webmin now
97         $p = new Webmin::Page(&zone_title($in{'zone'}), $text{'webmin_title'});
98         $d = new Webmin::DynamicText(\&execute_webmin);
99         $p->add_form($d);
100         $d->set_message($text{'create_webmining'});
101         $d->set_wait(1);
102         $p->add_footer("edit_zone.cgi?zone=$zinfo->{'name'}",
103                        $text{'edit_return'});
104         $p->print();
105         }
106 elsif ($in{'webmin'}) {
107         # Redirect to Webmin in the zone
108         $url = &zone_running_webmin($zinfo);
109         &error($text{'save_ewebmin'}) if (!$url);
110         &redirect($url);
111         }
112 else {
113         # Just update autoboot and pool
114         $gform = &get_zone_form(\%in, $zinfo);
115         $gform->validate_redirect("edit_zone.cgi");
116         &set_zone_variable($zinfo, "autoboot", $gform->get_value('autoboot'));
117         &set_zone_variable($zinfo, "pool", $gform->get_value('pool'));
118         &webmin_log("save", "zone", $in{'zone'});
119         &redirect("");
120         }
121
122 # execute_install(&dynamic)
123 sub execute_install
124 {
125 my ($d) = @_;
126 local $ok = &callback_zone_command($zinfo, "install",
127                                    \&Webmin::DynamicText::add_line, [ $d ]);
128 if ($ok) {
129         $p->add_message($text{'create_done'});
130         $sysidcfg = &zone_sysidcfg_file($in{'zone'});
131         if (-r $sysidcfg) {
132                 # Copy sysidcfg into place, for later boot
133                 # We Copy instead of Move just incase we
134                 # uninstall the zone but want to reinstall it
135                 # at a later time.
136                 &system_logged("cp $sysidcfg $zinfo->{'zonepath'}/root/etc/sysidcfg");
137                 }
138         &config_zone_nfs($zinfo);
139         &webmin_log("install", "zone", $in{'zone'});
140         }
141 else {
142         $p->add_error($text{'create_failed'});
143         }
144 }
145
146 sub execute_webmin
147 {
148 my ($d) = @_;
149 $script = &get_zone_root($zinfo)."/tmp/install-webmin";
150 $err = &create_webmin_install_script($zinfo, $script);
151 if ($err) {
152         $p->add_error(&text('created_wfailed', $err));
153         }
154 else {
155         $ex = &run_in_zone_callback($zinfo, "/tmp/install-webmin",
156                               \&Webmin::DynamicText::add_line, [ $d ]);
157         if (!$ex) {
158                 $p->add_message($text{'create_done'});
159                 &post_webmin_install($zinfo);
160                 }
161         else {
162                 $p->add_error($text{'create_failed'});
163                 }
164         }
165 }
166