From 06608896265ab86ff444c9231ebe708001e17cde Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sat, 3 Nov 2007 22:08:38 +0000 Subject: [PATCH] Finished off new API for block updates --- apache/apache-lib.pl | 9 +++++++-- apache/change_dir.cgi | 24 ++++++++++-------------- apache/change_files.cgi | 22 +++++++++------------- apache/create_dir.cgi | 34 +++++++++++++++++++--------------- apache/create_files.cgi | 23 ++++++++++++++--------- apache/remove_vserv.pl | 4 +--- 6 files changed, 60 insertions(+), 56 deletions(-) diff --git a/apache/apache-lib.pl b/apache/apache-lib.pl index f83a08dcc..0d1258b3d 100644 --- a/apache/apache-lib.pl +++ b/apache/apache-lib.pl @@ -535,8 +535,10 @@ local @newlines = $newdir ? &directive_lines($newdir) : ( ); if ($olddir && $newdir) { # Update in place if ($first) { - # Just changing first line, like virtualhost IP + # Just changing first and last line, like virtualhost IP $lref->[$olddir->{'line'}] = $newlines[0]; + $lref->[$olddir->{'eline'}] = $newlines[$#newlines]; + $olddir->{'name'} = $newdir->{'name'}; $olddir->{'value'} = $newdir->{'value'}; } else { @@ -573,9 +575,12 @@ elsif (!$olddir && $newdir) { $addpos = scalar(@$pconf); } else { - for($addpos=0; $pconf->[$addpos]->{'file'} eq $file;$addpos++) { + for($addpos=0; $addpos < scalar(@$pconf) && + $pconf->[$addpos]->{'file'} eq $file; + $addpos++) { # Find last parent directive in same file } + $addpos--; $addline = $pconf->[$addpos]->{'eline'}+1; } $newdir->{'file'} = $file; diff --git a/apache/change_dir.cgi b/apache/change_dir.cgi index 0460ce7a7..eb6a25090 100755 --- a/apache/change_dir.cgi +++ b/apache/change_dir.cgi @@ -9,15 +9,11 @@ require './apache-lib.pl'; $d = $vconf->[$in{'idx'}]; &lock_file($d->{'file'}); &before_changing(); -$lref = &read_file_lines($d->{'file'}); +$conf = &get_config(); if ($in{'delete'}) { # deleting a directive - $conf = &get_config(); - $gap = $d->{'eline'} - $d->{'line'} + 1; - splice(@$lref, $d->{'line'}, $d->{'eline'} - $d->{'line'} + 1); - splice(@$vconf, $in{'idx'}, 1); - &renumber($conf, $d->{'line'}, $d->{'file'}, -$gap); + &save_directive_struct($d, undef, $vconf, $conf); } else { # changing a directive @@ -28,24 +24,24 @@ else { if ($in{'regexp'}) { $in{'type'} eq 'Proxy' && &error($text{'cdir_eproxy'}); if ($httpd_modules{'core'} >= 1.3) { - $newdir = "<$in{'type'}Match \"$in{'path'}\">"; - $enddir = ""; + $d->{'name'} = $in{'type'}."Match"; + $d->{'value'} = "\"$in{'path'}\""; } else { - $newdir = "<$in{'type'} ~ \"$in{'path'}\">"; - $enddir = ""; + $d->{'name'} = $in{'type'}; + $d->{'value'} = "~ \"$in{'path'}\""; } } else { - $newdir = "<$in{'type'} \"$in{'path'}\">"; - $enddir = ""; + $d->{'name'} = $in{'type'}; + $d->{'value'} = "\"$in{'path'}\""; } - $lref->[$d->{'line'}] = $newdir; - $lref->[$d->{'eline'}] = $enddir; + &save_directive_struct($d, $d, $vconf, $conf, 1); } &flush_file_lines(); &unlock_file($d->{'file'}); &after_changing(); + &webmin_log("dir", $in{'delete'} ? 'delete' : 'save', &virtual_name($v, 1).":".$d->{'words'}->[0], \%in); &redirect("virt_index.cgi?virt=$in{'virt'}"); diff --git a/apache/change_files.cgi b/apache/change_files.cgi index 37f52ba43..2080061a2 100755 --- a/apache/change_files.cgi +++ b/apache/change_files.cgi @@ -11,37 +11,33 @@ $hconf = &get_htaccess_config($in{'file'}); $d = $hconf->[$in{'idx'}]; &lock_file($d->{'file'}); &before_changing(); -$lref = &read_file_lines($d->{'file'}); if ($in{'delete'}) { # deleting a directive - $gap = $d->{'eline'} - $d->{'line'} + 1; - splice(@$lref, $d->{'line'}, $d->{'eline'} - $d->{'line'} + 1); - splice(@$hconf, $in{'idx'}, 1); - &renumber($hconf, $d->{'line'}, $d->{'file'}, -$gap); + &save_directive_struct($d, undef, $hconf, $hconf); } else { # changing a directive if ($in{'regexp'}) { if ($httpd_modules{'core'} >= 1.3) { - $newdir = ""; - $enddir = ""; + $d->{'name'} = 'FilesMatch'; + $d->{'value'} = "\"$in{'path'}\""; } else { - $newdir = ""; - $enddir = ""; + $d->{'name'} = 'Files'; + $d->{'value'} = "~ \"$in{'path'}\""; } } else { - $newdir = ""; - $enddir = ""; + $d->{'name'} = 'Files'; + $d->{'value'} = "\"$in{'path'}\""; } - $lref->[$d->{'line'}] = $newdir; - $lref->[$d->{'eline'}] = $enddir; + &save_directive_struct($d, $d, $hconf, $hconf, 1); } &flush_file_lines(); &unlock_file($d->{'file'}); &after_changing(); + &webmin_log("files", $in{'delete'} ? 'delete' : 'save', "$in{'file'}:$d->{'words'}->[0]", \%in); &redirect("htaccess_index.cgi?file=".&urlize($in{'file'})); diff --git a/apache/create_dir.cgi b/apache/create_dir.cgi index 6c66b61b8..02944f328 100755 --- a/apache/create_dir.cgi +++ b/apache/create_dir.cgi @@ -7,34 +7,38 @@ require './apache-lib.pl'; &error_setup($text{'cdir_err'}); ($vconf, $v) = &get_virtual_config($in{'virt'}); &can_edit_virt($v) || &error($text{'virt_ecannot'}); -$f = $vconf->[0]->{'file'}; -for($j=0; $vconf->[$j]->{'file'} eq $f; $j++) { } -$l = $vconf->[$j-1]->{'eline'}+1; -&lock_file($f); -&before_changing(); -$lref = &read_file_lines($f); -$in{'path'} || &error($text{'cdir_epath'}); +&lock_file($vconf->[0]->{'file'}); +&before_changing(); + +# Validate inputs +$in{'path'} || &error($text{'cdir_epath'}); $in{'type'} eq 'Proxy' || &allowed_doc_dir($in{'path'}) || &error($text{'cdir_ecannot'}); + +# Create the file structure +$dir = { 'type' => 1 }; if ($in{'regexp'}) { $in{'type'} eq 'Proxy' && &error($text{'cdir_eproxy'}); if ($httpd_modules{'core'} >= 1.3) { - $newdir = "<$in{'type'}Match \"$in{'path'}\">"; - $enddir = ""; + $dir->{'name'} = $in{'type'}."Match"; + $dir->{'value'} = "\"$in{'path'}\""; } else { - $newdir = "<$in{'type'} ~ \"$in{'path'}\">"; - $enddir = ""; + $dir->{'name'} = $in{'type'}; + $dir->{'value'} = "~ \"$in{'path'}\""; } } else { - $newdir = "<$in{'type'} \"$in{'path'}\">"; - $enddir = ""; + $dir->{'name'} = $in{'type'}; + $dir->{'value'} = "\"$in{'path'}\""; } -splice(@$lref, $l, 0, ($newdir, $enddir)); + +# Add to file +&save_directive_struct(undef, $dir, $vconf, $conf); &flush_file_lines(); -&unlock_file($f); +&unlock_file($vconf->[0]->{'file'}); + &after_changing(); &webmin_log("dir", "create", &virtual_name($v, 1).":$in{'path'}", \%in); &redirect("virt_index.cgi?virt=$in{'virt'}"); diff --git a/apache/create_files.cgi b/apache/create_files.cgi index 8d6dbd9da..42c113730 100755 --- a/apache/create_files.cgi +++ b/apache/create_files.cgi @@ -7,27 +7,32 @@ $access{'global'} || &error($text{'htaccess_ecannot'}); &allowed_auth_file($in{'file'}) || &error($text{'htindex_ecannot'}); &ReadParse(); +$hconf = &get_htaccess_config($in{'file'}); &lock_file($in{'file'}); &before_changing(); -$lref = &read_file_lines($in{'file'}); + +# Create the directive +$dir = { 'type' => 1 }; if ($in{'regexp'}) { if ($httpd_modules{'core'} >= 1.3) { - $newdir = ""; - $enddir = ""; + $dir->{'name'} = 'FilesMatch'; + $dir->{'value'} = "\"$in{'path'}\""; } else { - $newdir = ""; - $enddir = ""; + $dir->{'name'} = 'Files'; + $dir->{'value'} = "~ \"$in{'path'}\""; } } else { - $newdir = ""; - $enddir = ""; + $dir->{'name'} = 'Files'; + $dir->{'value'} = "\"$in{'path'}\""; } -push(@$lref, $newdir); -push(@$lref, $enddir); + +# Add to file +&save_directive_struct(undef, $dir, $hconf, $hconf); &flush_file_lines(); &unlock_file($in{'file'}); + &after_changing(); &webmin_log("files", "create", "$in{'file'}:$in{'path'}", \%in); &redirect("htaccess_index.cgi?file=".&urlize($in{'file'})); diff --git a/apache/remove_vserv.pl b/apache/remove_vserv.pl index bb11def1e..b6170c0b9 100755 --- a/apache/remove_vserv.pl +++ b/apache/remove_vserv.pl @@ -18,9 +18,7 @@ foreach $v (@virts) { local $sn = &find_directive("ServerName", $v->{'members'}); if ($sn eq $ARGV[0]) { # Found the one to delete .. - $lref = &read_file_lines($v->{'file'}); - splice(@$lref, $v->{'line'}, - $v->{'eline'} - $v->{'line'} + 1); + &save_directive_struct($v, undef, $conf, $conf); &flush_file_lines(); print "Delete virtual server from $v->{'file'} at line ", ($v->{'line'}+1),"\n";