From 8184dd3acabe4d765ad608445875a361e0d8b4ad Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Tue, 27 Mar 2012 17:35:28 -0700 Subject: [PATCH] Disallow editing of virtualmin-controlled settings in APache module https://sourceforge.net/tracker/?func=detail&atid=117457&aid=3511530&group_id=17457 --- apache/CHANGELOG | 2 ++ apache/apache-lib.pl | 18 +++++++++++++++++- apache/edit_virt.cgi | 10 +++++++++- apache/lang/en | 1 + apache/save_virt.cgi | 8 ++++++++ apache/virt_index.cgi | 6 +++++- 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/apache/CHANGELOG b/apache/CHANGELOG index 14b8f140a..ac4d7506e 100644 --- a/apache/CHANGELOG +++ b/apache/CHANGELOG @@ -49,3 +49,5 @@ Fixed bug that preventing saving of virtual hosts with multiple addresses, one o Full Bulgarian translation, thanks to King. ---- Changes since 1.510 ---- The default port on the Create virtual host tab is now set to better match the name-based virtual host ports. +---- Changes since 1.580 ---- +Apache virtual hosts owned by Virtualmin can no longer have their address, port, name or document directory changed. diff --git a/apache/apache-lib.pl b/apache/apache-lib.pl index cb0d39b9d..a3dd672d2 100755 --- a/apache/apache-lib.pl +++ b/apache/apache-lib.pl @@ -827,7 +827,7 @@ else { } } -# generate_inputs(&editors, &directives) +# generate_inputs(&editors, &directives, [&skip]) # Displays a 2-column list of options, for use inside a table sub generate_inputs { @@ -1963,5 +1963,21 @@ else { } } +# is_virtualmin_domain(&virt) +# Returns the domain hash if some virtualhost is managed by Virtualmin +sub is_virtualmin_domain +{ +local ($virt) = @_; +local $n = &find_directive("ServerName", $virt->{'members'}); +return undef if (!$n); +return undef if (!&foreign_check("virtual-server")); +&foreign_require("virtual-server"); +local $d = &virtual_server::get_domain_by("dom", $n); +return $d if ($d); +$n =~ s/^www\.//i; +local $d = &virtual_server::get_domain_by("dom", $n); +return $d; +} + 1; diff --git a/apache/edit_virt.cgi b/apache/edit_virt.cgi index 5ef02ec21..1cfc3a850 100755 --- a/apache/edit_virt.cgi +++ b/apache/edit_virt.cgi @@ -28,7 +28,15 @@ print &ui_hidden("virt", $in{'virt'}); print &ui_hidden("type", $in{'type'}); print &ui_table_start(&text('virt_header2', $text{"type_$in{'type'}"}, &virtual_name($v)), "width=100%", 4); -&generate_inputs(\@dirs, $conf); +if ($in{'type'} == 5 && &is_virtualmin_domain($v)) { + @dirs = grep { $_->{'name'} ne 'DocumentRoot' && + $_->{'name'} ne 'ServerPath' } @dirs; + } +elsif ($in{'type'} == 1 && &is_virtualmin_domain($v)) { + @dirs = grep { $_->{'name'} ne 'ServerName' && + $_->{'name'} ne 'ServerAlias' } @dirs; + } +&generate_inputs(\@dirs, $conf, \@skip); print &ui_table_end(); print &ui_form_end([ [ "", $text{'save'} ] ]); diff --git a/apache/lang/en b/apache/lang/en index 54bd7365c..3bfe54822 100644 --- a/apache/lang/en +++ b/apache/lang/en @@ -124,6 +124,7 @@ virt_euser=You are not allowed to change the user or group for this virtual serv virt_header2=$1 for $2 vserv_title=Virtual Server Configuration +vserv_virtualmin=This Apache virtual host belongs to the Virtualmin server $1, so the address, port, base directory and hostname cannot be changed here. vserv_ecannot=You cannot edit this virtual server's address vserv_addr=Address vserv_addrs=Addresses diff --git a/apache/save_virt.cgi b/apache/save_virt.cgi index 05b658174..dd822d35f 100755 --- a/apache/save_virt.cgi +++ b/apache/save_virt.cgi @@ -13,6 +13,14 @@ $in{'type'} == 8 && !$access{'vuser'} && if (!$in{'virt'}) { @edit = grep { !$_->{'virtualonly'} } @edit; } +if ($in{'type'} == 5 && &is_virtualmin_domain($v)) { + @edit = grep { $_->{'name'} ne 'DocumentRoot' && + $_->{'name'} ne 'ServerPath' } @edit; + } +elsif ($in{'type'} == 1 && &is_virtualmin_domain($v)) { + @edit = grep { $_->{'name'} ne 'ServerName' && + $_->{'name'} ne 'ServerAlias' } @edit; + } &error_setup(&text('efailed', $text{"type_$in{'type'}"})); &parse_inputs(\@edit, $conf, &get_config()); diff --git a/apache/virt_index.cgi b/apache/virt_index.cgi index 9cb82f95b..5f055c215 100755 --- a/apache/virt_index.cgi +++ b/apache/virt_index.cgi @@ -85,7 +85,8 @@ print &ui_table_row($text{'virt_path'}, print &ui_table_end(); print &ui_form_end([ [ "", $text{'create'} ] ]); -if ($in{'virt'} && $access{'vaddr'}) { +$d = &is_virtualmin_domain($v); +if ($in{'virt'} && $access{'vaddr'} && !$d) { # Show form for changing virtual server print &ui_hr(); print &ui_form_start("save_vserv.cgi"); @@ -154,6 +155,9 @@ if ($in{'virt'} && $access{'vaddr'}) { print &ui_form_end([ [ undef, $text{'save'} ], [ "delete", $text{'delete'} ] ]); } +elsif ($in{'virt'} && $access{'vaddr'} && $d) { + print "",&text('vserv_virtualmin', $d->{'dom'}),"

\n"; + } &ui_print_footer("", $text{'index_return'});