Handle hostnames with upper-case letters
[webmin.git] / fdisk / save_part.cgi
1 #!/usr/local/bin/perl
2 # save_part.cgi
3 # Save changes to an existing or new partition
4
5 require './fdisk-lib.pl';
6 &error_setup($text{'save_err'});
7 &ReadParse();
8
9 @dlist = &list_disks_partitions();
10 $dinfo = $dlist[$in{'disk'}];
11 &can_edit_disk($dinfo->{'device'}) ||
12         &error($text{'save_ecannot'});
13 @plist = @{$dinfo->{'parts'}};
14 if ($in{'delete'} && $in{'confirm'}) {
15         # deleting a partition
16         $pinfo = $plist[$in{'part'}];
17         &delete_partition($dinfo->{'device'}, $pinfo->{'number'});
18         &webmin_log("delete", "part", $dinfo->{'device'}, \%in);
19         &redirect("edit_disk.cgi?device=$dinfo->{'device'}");
20         }
21 elsif ($in{'delete'}) {
22         # Ask the user if he really wants to delete the partition
23         &ui_print_header(undef, $text{'delete_title'}, "");
24
25         $pinfo = $plist[$in{'part'}];
26         $dname = &mount::device_name($pinfo->{'device'});
27         print "<center><form action=save_part.cgi>\n";
28         print "<input type=hidden name=disk value='$in{'disk'}'>\n";
29         print "<input type=hidden name=part value='$in{'part'}'>\n";
30         print "<input type=hidden name=delete value=1>\n";
31         print "<b>",&text('delete_rusure', $dname,
32                           "<tt>$pinfo->{'device'}</tt>"),"</b><p>\n";
33         print "<input type=submit name=confirm value='$text{'delete_ok'}'>\n";
34         print "</form></center>\n";
35
36         &ui_print_footer("edit_disk.cgi?device=$dinfo->{'device'}",
37                          $text{'disk_return'});
38         }
39 elsif (!$in{'new'}) {
40         # Changing existing partition type and label
41         $pinfo = $plist[$in{'part'}];
42         if ($pinfo->{'edittype'}) {
43                 &change_type($dinfo->{'device'}, $pinfo->{'number'},
44                              $in{'type'});
45                 $pinfo->{'type'} = $in{'type'};
46                 }
47         if (defined($in{'label'}) && &supports_label($pinfo)) {
48                 &set_label($pinfo->{'device'}, $in{'label'});
49                 }
50         if (defined($in{'name'}) && &supports_name($dinfo)) {
51                 &set_name($dinfo, $pinfo, $in{'name'});
52                 }
53         &webmin_log("modify", "part", $dinfo->{'device'}, \%in);
54         &redirect("edit_disk.cgi?device=$dinfo->{'device'}");
55         }
56 else {
57         # Adding new partition
58         $in{start} =~ /^\d+$/ ||
59                 &error(&text('save_estart', $in{'start'}));
60         $in{end} =~ /^\d+$/ ||
61                 &error(&text('save_eend', $in{'end'}));
62         $in{start} >= $in{'min'} ||
63                 &error(&text('save_emin', $in{'min'}));
64         $in{end} <= $in{'max'} ||
65                 &error(&text('save_emax', $in{'max'}));
66         $in{start} < $in{end} ||
67                 &error($text{'save_eminmax'});
68
69         # Check for partition overlap..
70         foreach $pinfo (@plist) {
71                 if (($in{'start'} >= $pinfo->{'start'} &&
72                      $in{'start'} <= $pinfo->{'end'} ||
73                      $in{'end'} >= $pinfo->{'start'} &&
74                      $in{'end'} <= $pinfo->{'end'}) &&
75                      !($in{'new'}==2 && $pinfo->{'extended'})) {
76                         &error(&text('save_eoverlap', $pinfo->{'number'},
77                                      $pinfo->{'start'}, $pinfo->{'end'}));
78                         }
79                 }
80         if ($in{'new'} == 3) {
81                 &create_extended($dinfo->{'device'}, $in{'newpart'},
82                                 $in{'start'}, $in{'end'});
83                 &webmin_log("create", "part", $dinfo->{'device'}, \%in);
84                 }
85         else {
86                 &create_partition($dinfo->{'device'}, $in{'newpart'},
87                                   $in{'start'}, $in{'end'}, $in{'type'});
88                 $pinfo = { 'type' => $in{'type'},
89                            'number' => $in{'newpart'} };
90                 if ($in{'label'} && &supports_label($pinfo)) {
91                         local $dev = $dinfo->{'prefix'}.$in{'newpart'};
92                         &set_label($dev, $in{'label'});
93                         }
94                 if ($in{'name'} && &supports_name($dinfo)) {
95                         &set_name($dinfo, $pinfo, $in{'name'});
96                         }
97                 &webmin_log("create", "part", $dinfo->{'device'}, \%in);
98                 }
99         if (&need_reboot($dinfo)) {
100                 &ask_reboot($dinfo);
101                 }
102         else {
103                 &redirect("edit_disk.cgi?device=$dinfo->{'device'}");
104                 }
105         }
106
107 # ask_reboot(disk)
108 # Display a form asking for a reboot
109 sub ask_reboot
110 {
111 &ui_print_header(undef, $text{'reboot_title'}, "");
112 local $what = &text('select_device', uc($_[0]->{'type'}),
113                     uc(substr($_[0]->{'device'}, -1)));
114 print "<b>",&text('reboot_why', $what),"</b> <p>\n";
115 print &ui_form_start("reboot.cgi");
116 print &ui_form_end([ [ undef, $text{'reboot_ok'} ] ]);
117
118 &ui_print_footer("", $text{'index_return'});
119 }
120