-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathsave_tmpl.cgi
executable file
·148 lines (133 loc) · 3.61 KB
/
save_tmpl.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/local/bin/perl
# Create, update or delete a template
require './virtual-server-lib.pl';
&can_edit_templates() || &error($text{'newtmpl_ecannot'});
&ReadParse();
&licence_status();
@tmpls = &list_templates();
if (!$in{'new'}) {
# Fetch existing template object
($tmpl) = grep { $_->{'id'} == $in{'id'} } @tmpls;
$tmpl || &error($text{'tmpl_egone'});
}
elsif ($in{'cloneof'}) {
# Fetch source for clone
($cloneof) = grep { $_->{'id'} == $in{'cloneof'} } @tmpls;
$tmpl = { %$cloneof };
$tmpl->{'id'} = undef;
$tmpl->{'standard'} = 0;
}
elsif ($in{'cp'}) {
# Fetch source for copy
($cloneof) = grep { $_->{'id'} == 0 } @tmpls;
$tmpl = { %$cloneof };
$tmpl->{'id'} = undef;
$tmpl->{'standard'} = 0;
$tmpl->{'default'} = 0;
}
else {
# Start with blank, with some sensible defaults
$tmpl = { 'web_php_suexec' => 3 };
}
if ($in{'delete'}) {
if ($in{'confirm'}) {
# Just delete this template
&delete_template($tmpl);
&webmin_log("delete", "template", $tmpl->{'name'});
&redirect("edit_newtmpl.cgi");
}
else {
# Ask first, and check for domains using it
&ui_print_header($tmpl->{'name'}, $text{'tmpl_title5'}, "");
@users = &get_domain_by("template", $tmpl->{'id'});
print &ui_confirmation_form(
"save_tmpl.cgi",
$text{'tmpl_deletewarn'},
[ [ "id", $in{'id'} ],
[ "delete", 1 ] ],
[ [ "confirm", $text{'tmpl_deleteconfirm'} ] ],
undef,
@users ? &text('tmpl_deleteusers', scalar(@users))
: '');
&ui_print_footer("edit_newtmpl.cgi", $text{'newtmpl_return'},
"", $text{'index_return'});
}
exit;
}
elsif ($in{'clone'}) {
# Re-direct to creation page, in clone mode
&redirect("edit_tmpl.cgi?new=1&clone=$in{'id'}");
exit;
}
# Get the editing mode in use
@editmodes = &list_template_editmodes($tmpl);
($editmode) = grep { $_->[0] eq $in{'editmode'} } @editmodes;
# Validate and store all inputs
$oldname = $tmpl->{'name'};
&error_setup($text{'tmpl_err'});
$pfunc = "parse_template_".$editmode->[0];
if (defined(&$pfunc)) {
&$pfunc($tmpl);
}
foreach my $p (@{$editmode->[2]}) {
&plugin_call($p, "template_parse", $tmpl, \%in);
}
# Check for name clash
if ($in{'new'} || lc($tmpl->{'name'}) ne lc($oldname)) {
($clash) = grep { lc($_->{'name'}) eq lc($tmpl->{'name'}) &&
$_->{'id'} ne $tmpl->{'id'} &&
!$_->{'deleted'} } @tmpls;
$clash && &error($text{'tmpl_eclash'});
}
# Create or update the template
&save_template($tmpl);
if ($in{'cloneof'} || $in{'cp'}) {
# Also copy template scripts
$scripts = &list_template_scripts($cloneof);
&save_template_scripts($tmpl, $scripts);
}
&webmin_log($in{'new'} ? "create" : "modify", "template", $tmpl->{'name'});
# Call post-save function
$psfunc = "postsave_template_".$in{'editmode'};
if (defined(&$psfunc)) {
&$psfunc($tmpl);
}
# Update all Webmin users for domains on this template, if a template
# section that effects Webmin users was changed
if (!$in{'new'} &&
&indexof($in{'editmode'}, @template_features_effecting_webmin) >= 0) {
&set_all_null_print();
&modify_all_webmin($tmpl->{'standard'} ? undef : $tmpl->{'id'});
&run_post_actions();
}
if ($in{'next'}) {
# And go to next section
$idx = &indexof($editmode, @editmodes);
if ($idx == @editmodes-1) {
$nextmode = $editmodes[0];
}
else {
$nextmode = $editmodes[$idx+1];
}
&redirect("edit_tmpl.cgi?id=$tmpl->{'id'}&editmode=$nextmode->[0]");
}
else {
# Return to template list
&redirect("edit_newtmpl.cgi");
}
# parse_none_def(name)
sub parse_none_def
{
if ($in{$_[0]."_mode"} == 0) {
return "none";
}
elsif ($in{$_[0]."_mode"} == 1) {
return undef;
}
else {
$in{$_[0]} =~ s/\t/ /g;
$in{$_[0]} =~ s/\r//g;
$in{$_[0]} =~ s/\n/\t/g;
return $in{$_[0]};
}
}