-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_tmpl.cgi
executable file
·74 lines (69 loc) · 1.86 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
#!/usr/local/bin/perl
# Create, update or delete some action template
use strict;
use warnings;
our (%access, %text, %in, %config);
require './virtualmin-init-lib.pl';
&ReadParse();
$access{'templates'} || &error($text{'tmpl_ecannot'});
my $tmpl;
if (!$in{'new'}) {
# Get the existing template
($tmpl) = grep { $_->{'id'} == $in{'id'} } &list_action_templates();
}
if ($in{'delete'}) {
# Just remove the action
&delete_action_template($tmpl);
&redirect("");
}
else {
# Validate inputs
&error_setup($text{'tmpl_err'});
$in{'desc'} =~ /\S/ || &error($text{'tmpl_edesc'});
$tmpl->{'desc'} = $in{'desc'};
$in{'start'} =~ s/\r//g;
$in{'start'} =~ /\S/ || &error($text{'tmpl_estart'});
$tmpl->{'start'} = $in{'start'};
if ($in{'stop_def'}) {
$tmpl->{'stop'} = ':kill';
}
else {
$in{'stop'} =~ s/\r//g;
$tmpl->{'stop'} = $in{'stop'};
}
if ($in{'xml_def'} || $config{'mode'} ne 'smf') {
delete($tmpl->{'xml'});
}
else {
$in{'xml'} =~ s/\r//g;
$in{'xml'} =~ /\S/ || &error($text{'tmpl_exml'});
$tmpl->{'xml'} = $in{'xml'};
}
# Validate user-definable parameters
for(my $i=0; defined($tmpl->{'pname_'.$i}); $i++) {
delete($tmpl->{'pname_'.$i});
delete($tmpl->{'ptype_'.$i});
delete($tmpl->{'pdesc_'.$i});
}
for(my $i=0; defined($in{'pname_'.$i}); $i++) {
next if (!$in{'pname_'.$i});
$in{'pname_'.$i} =~ /^[a-z0-9_]+$/i ||
&error(&text('tmpl_epname', $i+1));
$tmpl->{'pname_'.$i} = $in{'pname_'.$i};
$tmpl->{'ptype_'.$i} = $in{'ptype_'.$i};
$in{'pdesc_'.$i} =~ /\S/ ||
&error(&text('tmpl_epdesc', $i+1));
$tmpl->{'pdesc_'.$i} = $in{'pdesc_'.$i};
if ($tmpl->{'ptype_'.$i} == 3 || $tmpl->{'ptype_'.$i} == 4) {
-r $in{'popts_'.$i} ||
&error(&text('tmpl_epopts', $i+1));
$tmpl->{'popts_'.$i} = $in{'popts_'.$i};
}
else {
delete($tmpl->{'popts_'.$i});
}
}
# Create or save
&save_action_template($tmpl);
&redirect("");
}