Handle hostnames with upper-case letters
[webmin.git] / lilo / save_image.cgi
1 #!/usr/local/bin/perl
2 # save_image.cgi
3
4 require './lilo-lib.pl';
5 &ReadParse();
6
7 &lock_file($config{'lilo_conf'});
8 $conf = &get_lilo_conf();
9 if ($in{'delete'}) {
10         # deleting an existing image
11         $image = $conf->[$in{'idx'}];
12         &save_directive($conf, $image);
13         &flush_file_lines();
14         &unlock_file($config{'lilo_conf'});
15         &webmin_log("delete", "image",
16                     &find_value("label", $image->{'members'}), \%in);
17         &redirect("");
18         exit;
19         }
20 elsif ($in{'new'}) {
21         # creating a new kernel image
22         $image = { 'name' => 'image',
23                    'members' => [ ] };
24         }
25 else {
26         # updating an existing image
27         $oldimage = $image = $conf->[$in{'idx'}];
28         }
29
30 # Validate and store inputs
31 $in{'label'} =~ /\S+/ || &error($text{'image_ename'});
32 &save_subdirective($image, "label", $in{'label'});
33 $in{'optional'} || -r $in{'image'} ||
34         &error(&text('image_ekernel', $in{'image'}));
35 $image->{'value'} = $in{'image'};
36 if ($in{'opts'} == 0) {
37         &save_subdirective($image, "append");
38         &save_subdirective($image, "literal");
39         }
40 elsif ($in{'opts'} == 1) {
41         &save_subdirective($image, "append", "\"$in{'append'}\"");
42         &save_subdirective($image, "literal");
43         }
44 else {
45         &save_subdirective($image, "append");
46         &save_subdirective($image, "literal", "\"$in{'append'}\"");
47         }
48 if ($in{'rmode'} == 0) {
49         &save_subdirective($image, "root");
50         }
51 elsif ($in{'rmode'} == 1) {
52         &save_subdirective($image, "root", "current");
53         }
54 elsif ($in{'rmode'} == 2) {
55         &save_subdirective($image, "root", $in{'root'});
56         }
57 if ($in{'initrd_def'}) {
58         &save_subdirective($image, "initrd");
59         }
60 else {
61         -r $in{'initrd'} || &error(&text('image_einitrd', $in{'initrd'}));
62         &save_subdirective($image, "initrd", $in{'initrd'});
63         }
64 &save_subdirective($image, "read-only", $in{'ro'} == 1 ? "" : undef);
65 &save_subdirective($image, "read-write", $in{'ro'} == 2 ? "" : undef);
66 if ($in{'vga'} eq "") {
67         &save_subdirective($image, "vga");
68         }
69 elsif ($in{'vga'} eq "other") {
70         $in{'vgaother'} =~ /^\d+$/ ||
71                 &error("VGA text mode must be an integer");
72         &save_subdirective($image, "vga", $in{'vgaother'});
73         }
74 else {
75         &save_subdirective($image, "vga", $in{'vga'});
76         }
77 if ($in{'passmode'} == 0) {
78         &save_subdirective($image, "password");
79         }
80 else {
81         &save_subdirective($image, "password", $in{'password'});
82         }
83 &save_subdirective($image, "restricted", $in{'restricted'} ? "" : undef);
84 &save_subdirective($image, "lock", $in{'lock'} ? "" : undef);
85 &save_subdirective($image, "optional", $in{'optional'} ? "" : undef);
86
87 # Save the actual image structure
88 &save_directive($conf, $oldimage, $image);
89 &flush_file_lines();
90 &unlock_file($config{'lilo_conf'});
91 &webmin_log($in{'new'} ? 'create' : 'modify', "image",
92             &find_value("label", $image->{'members'}), \%in);
93 &redirect("");
94