-
Notifications
You must be signed in to change notification settings - Fork 9
/
save.cgi
executable file
·120 lines (111 loc) · 3.18 KB
/
save.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
#!/usr/local/bin/perl
# Create, update or delete a registrar account
use strict;
no strict 'refs';
use warnings;
our (%access, %text, %in);
our $registrar_accounts_dir;
require './virtualmin-registrar-lib.pl';
$access{'registrar'} || &error($text{'edit_ecannot'});
&ReadParse();
&error_setup($text{'save_err'});
my @accounts = &list_registrar_accounts();
# Get the account object and registrar type
my $account;
my $reg;
if ($in{'registrar'}) {
$reg = $in{'registrar'};
$account = { 'id' => time().$$,
'registrar' => $reg };
}
else {
($account) = grep { $_->{'id'} eq $in{'id'} } @accounts;
$account || &error($text{'edit_egone'});
$reg = $account->{'registrar'};
}
if ($in{'delete'}) {
# Check if in use by any Virtualmin domains - if so, we can't delete
&error_setup($text{'save_err2'});
my @doms = &find_account_domains($account);
if (@doms && @accounts < 2) {
&error(&text('save_edoms',
join(" ", map { "<tt>$_->{'dom'}</tt>" } @doms)));
}
if ($in{'confirm'}) {
# Just delete it
&lock_file($account->{'file'});
&delete_registrar_account($account);
&unlock_file($account->{'file'});
# Update domains to new use registrar
foreach my $d (@doms) {
$d->{'registrar_account'} = $in{'transfer'};
&virtual_server::save_domain($d);
}
}
else {
# Ask first
&ui_print_header(undef, $text{'save_dtitle'}, "");
print &ui_form_start("save.cgi", "post");
print &ui_hidden("id", $in{'id'});
print &ui_hidden("delete", 1);
print "<center>";
print &text('save_drusure',
"<i>$account->{'desc'}</i>"),"<p>\n",
&ui_submit($text{'save_dok'}, 'confirm'),"<p>\n";
# Ask which account to transfer to
if (@doms) {
print "<b>",&text('save_transfer', scalar(@doms))," ",
&ui_select("transfer", undef,
[ map { [ $_->{'id'}, $_->{'desc'} ] }
grep { $_->{'id'} ne $account->{'id'} }
@accounts ]),"</b><p>\n";
}
print "</center>\n";
print &ui_form_end();
&ui_print_footer("", $text{'index_return'});
}
}
else {
# Validate inputs
$in{'desc'} =~ /\S/ || &error($text{'save_edesc'});
$account->{'desc'} = $in{'desc'};
$account->{'enabled'} = $in{'enabled'};
if ($in{'doms_def'}) {
delete($account->{'doms'});
}
else {
$in{'doms'} =~ /\S/ || &error($text{'save_etopdoms'});
foreach my $tld (split(/\s+/, $in{'doms'})) {
$tld =~ /^\.[a-z0-9\.\-]+$/ ||
&error(&text('save_etopdoms2', $tld));
}
$account->{'doms'} = $in{'doms'};
}
if ($in{'ns_def'}) {
delete($account->{'ns'});
}
else {
my @ns = split(/\s+/, $in{'ns'});
foreach my $ns (@ns) {
&to_ipaddress($ns) ||
&error(&text('save_ens', $ns));
&check_ipaddress($ns) &&
&error(&text('save_ensip', $ns));
}
@ns || &error(&text('save_enss'));
$account->{'ns'} = join(" ", @ns);
}
my $pfunc = "type_".$reg."_edit_parse";
my $perr = &$pfunc($account, $in{'registrar'}, \%in);
&error($perr) if ($perr);
# Make sure the login actually works
my $vfunc = "type_".$reg."_validate";
my $verr = &$vfunc($account);
&error($verr) if ($verr);
# Save or create
&lock_file($account->{'file'} ||
"$registrar_accounts_dir/$account->{'id'}");
&save_registrar_account($account);
&unlock_file($account->{'file'});
&redirect("index.cgi");
}