-
Notifications
You must be signed in to change notification settings - Fork 3
/
save_manual.cgi
48 lines (43 loc) · 1.18 KB
/
save_manual.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
# Update one config file
use strict;
use warnings;
require 'virtualmin-nginx-lib.pl';
&ReadParseMime();
our (%text, %in, %access);
&error_setup($text{'manual_err'});
$access{'global'} || &error($text{'index_eglobal'});
my @files = &get_all_config_files();
&indexof($in{'file'}, @files) >= 0 || &error($text{'manual_efile'});
# Follow links to get the real file
while(-l $in{'file'}) {
$in{'file'} = readlink($in{'file'});
}
$in{'file'} || &error($text{'manual_elink'});
$in{'data'} =~ s/\r//g;
my $fh = "CONF";
if ($in{'test'}) {
# Backup the file, write to it, and then test the config
my $temp = &transname();
©_source_dest($in{'file'}, $temp);
&open_lock_tempfile($fh, ">$in{'file'}");
&print_tempfile($fh, $in{'data'});
&close_tempfile($fh);
my $err = &test_config();
if ($err) {
# Bad config .. roll back
©_source_dest($temp, $in{'file'});
&unlink_file($temp);
&error(&text('restart_etest',
"<tt>".&html_escape($err)."</tt>"));
}
&unlink_file($temp);
}
else {
# Just write out
&open_lock_tempfile($fh, ">$in{'file'}");
&print_tempfile($fh, $in{'data'});
&close_tempfile($fh);
}
&webmin_log("manual", undef, $in{'file'});
&redirect("");