#!/usr/local/bin/perl # save_domain.cgi # Update or delete a domain require './virtual-server-lib.pl'; &require_bind() if ($config{'dns'}); &require_useradmin(); &require_mail() if ($config{'mail'}); &ReadParse(); $d = &get_domain($in{'dom'}); &can_config_domain($d) || &error($text{'edit_ecannot'}); $oldd = { %$d }; $tmpl = &get_template($in{'template'}); # Validate inputs &error_setup($text{'save_err'}); if (&has_home_quotas() && !$d->{'parent'} && &can_edit_quotas($d)) { if ($in{'quota'} eq -1) { $in{'quota'} = $in{'otherquota'} }; if ($in{'uquota'} eq -1) { $in{'uquota'} = $in{'otheruquota'} }; $in{'quota_def'} || $in{'quota'} =~ /^[0-9\.]+$/ || &error($text{'save_equota'}); $in{'uquota_def'} || $in{'uquota'} =~ /^[0-9\.]+$/ || &error($text{'save_euquota'}); } if ($config{'bw_active'} && !$d->{'parent'} && &can_edit_bandwidth()) { $d->{'bw_limit'} = &parse_bandwidth("bw", $text{'save_ebwlimit'}); if ($config{'bw_disable'}) { $d->{'bw_no_disable'} = $in{'bw_no_disable'}; } } $d->{'db'} = &database_name($d) if (!$d->{'db'}); if ($d->{'template'} != $tmpl->{'id'}) { $d->{'template'} = $tmpl->{'id'}; if (!&master_admin() && !&reseller_admin() && !$t->{'for_users'} || !&can_use_template($t)) { # Cannot use this template! &error($text{'save_etemplate'}); } } $in{'owner'} =~ /:/ && &error($text{'setup_eowner'}); # Check if the prefix has been changed if (defined($in{'prefix'})) { $in{'prefix'} =~ /^[a-z0-9\.\-]+$/i || &error($text{'setup_eprefix'}); if ($in{'prefix'} ne $d->{'prefix'}) { $pclash = &get_domain_by("prefix", $in{'prefix'}); $pclash && &error($text{'setup_eprefix2'}); $d->{'prefix'} = $in{'prefix'}; } } # Check if the password was changed, and if so is it valid if (!$d->{'parent'} && !$in{'passwd_def'}) { local $fakeuser = { 'user' => $d->{'user'}, 'plainpass' => $in{'passwd'} }; $err = &check_password_restrictions($fakeuser, $d->{'webmin'}); &error($err) if ($err); } # Work out which features are relevant @dom_features = &domain_features($d); # Work around possible bad 'db' name if (!$d->{'mysql'} && $in{'mysql'} && &check_mysql_clash($d, 'db')) { $d->{'db'} = &database_name($d); } # Check for various clashes %newdom = %$d; if (&has_home_quotas() && !$d->{'parent'} && &can_edit_quotas($d)) { $newdom{'uquota'} = $in{'uquota_def'} ? undef : "a_parse('uquota', "home"); $newdom{'quota'} = $in{'quota_def'} ? undef : "a_parse('quota', "home"); } if (!$d->{'disabled'}) { foreach $f (@dom_features, @feature_plugins) { if ($in{$f}) { $newdom{$f} = 1; if (!$d->{$f}) { $check{$f}++; } } else { $newdom{$f} = 0; } } &set_chained_features(\%newdom, $d); } if (!$config{'all_namevirtual'} && !$d->{'alias'} && &can_use_feature("virt")) { $newdom{'virt'} = $in{'virt'}; } $derr = &virtual_server_depends(\%newdom); &error($derr) if ($derr); $cerr = &virtual_server_clashes(\%newdom, \%check); &error($cerr) if ($cerr); $lerr = &virtual_server_limits(\%newdom, $oldd); &error($lerr) if ($lerr); if (!$d->{'alias'} && &can_use_feature("virt")) { if ($config{'all_namevirtual'}) { # Make sure any new IP *is* assigned &check_ipaddress($in{'ip'}) || &error($text{'setup_eip'}); if ($d->{'ip'} ne $in{'ip'} && !&check_virt_clash($in{'ip'})) { &error(&text('setup_evirtclash2')); } } elsif ($in{'virt'} && !$d->{'virt'}) { # An IP is being added local %racl = $d->{'reseller'} ? &get_reseller_acl($d->{'reseller'}) : (); if ($racl{'ranges'}) { # Allocate the IP from the server's reseller's range $in{'ip'} = &free_ip_address(\%racl); $in{'ip'} || &text('setup_evirtalloc2'); } elsif ($tmpl->{'ranges'} ne "none") { # Allocate the IP from the template $in{'ip'} = &free_ip_address($tmpl); $in{'ip'} || &text('setup_evirtalloc'); } else { # Make sure the IP isn't assigned yet &check_ipaddress($in{'ip'}) || &error($text{'setup_eip'}); if (&check_virt_clash($in{'ip'})) { &error(&text('setup_evirtclash')); } } } } # Check if any features are being deleted, and if so ask the user if # he is sure if (!$in{'confirm'} && !$d->{'disabled'}) { local @losing; foreach $f (@dom_features) { if ($config{$f} && $d->{$f} && !$newdom{$f}) { push(@losing, $f); } } foreach $f (@feature_plugins) { if ($d->{$f} && !$newdom{$f}) { push(@plosing, $f); } } if (@losing || @plosing) { &ui_print_header(&domain_in($d), $text{'save_title'}, ""); print "
",&text('save_rusure',"$d->{'dom'}"),"
\n"; print "
\n"; # Run the after command &run_post_actions(); &set_domain_envs($d, "MODIFY_DOMAIN"); &made_changes(); &reset_domain_envs($d); &webmin_log("modify", "domain", $d->{'dom'}, $d); # Call any theme post command if (defined(&theme_post_save_domain)) { &theme_post_save_domain($d, 'modify'); } &ui_print_footer("edit_domain.cgi?dom=$in{'dom'}", $text{'edit_return'}, "", $text{'index_return'});