-
Notifications
You must be signed in to change notification settings - Fork 3
/
save_location.cgi
101 lines (90 loc) · 2.59 KB
/
save_location.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl
# Create, update or delete a location block
use strict;
use warnings;
require 'virtualmin-nginx-lib.pl';
our (%text, %in, %config, %access);
&error_setup($text{'location_err'});
&ReadParse();
# Get the current location
&lock_all_config_files();
my $server = &find_server($in{'id'});
$server || &error($text{'server_egone'});
&can_edit_server($server) || &error($text{'server_ecannot'});
my $conf = &get_config();
my @locations = &find("location", $server);
my $location;
my $old_name;
my @words = ( $in{'path'} );
unshift(@words, $in{'match'}) if ($in{'match'});
if ($in{'new'}) {
$location = { 'name' => 'location',
'type' => 1,
'words' => \@words,
'members' => [ ] };
}
else {
$location = &find_location($server, $in{'oldpath'});
$location || &error($text{'location_egone'});
}
# Check for clash
if ($in{'new'} || $in{'oldpath'} ne $in{'path'}) {
foreach my $l (@locations) {
$l->{'words'}->[0] eq $in{'path'} &&
&error($text{'location_eclash'});
}
}
my $action;
my $name;
if ($in{'delete'}) {
if ($in{'confirm'}) {
# Got confirmation, delete it
&save_directive($server, [ $location ], [ ]);
$action = 'delete';
}
else {
# Ask for confirmation first
&ui_print_header(&location_desc($server, $location),
$text{'location_edit'}, "");
print &ui_confirmation_form("save_location.cgi",
&text('location_rusure',
"<tt>".&html_escape($location->{'words'}->[0])."</tt>"),
[ [ 'id', $in{'id'} ],
[ 'oldpath', $in{'oldpath'} ],
[ 'delete', 1 ] ],
[ [ 'confirm', $text{'server_confirm'} ] ],
);
&ui_print_footer("edit_location.cgi?id=".&urlize($in{'id'}).
"&path=".&urlize($in{'oldpath'}),
$text{'server_return'});
}
}
else {
# Validate path
$in{'path'} =~ /^\S+$/ || &error($text{'location_epath'});
if ($in{'new'}) {
# Create a new location object
&save_directive($server, [ ], [ $location ]);
$action = 'create';
}
else {
# Update path in existing one
$location->{'words'} = \@words;
&save_directive($server, [ $location ], [ $location ]);
$action = 'modify';
}
# Update root directory
&nginx_text_parse("root", $location, undef, '^\/\S+$');
&can_directory($in{'root'}) ||
&error(&text('location_ecannot',
"<tt>".&html_escape($in{'root'})."</tt>",
"<tt>".&html_escape($access{'root'})."</tt>"));
}
&flush_config_file_lines();
&unlock_all_config_files();
if ($action) {
my $name = &find_value("server_name", $server);
&webmin_log($action, 'location', $location->{'words'}->[0],
{ 'server' => $name });
&redirect("edit_server.cgi?id=".&urlize($in{'id'}));
}