Finished off new API for block updates

This commit is contained in:
Jamie Cameron
2007-11-03 22:08:38 +00:00
parent 7c8e2a888b
commit 0660889626
6 changed files with 60 additions and 56 deletions

View File

@@ -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;

View File

@@ -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 = "</$in{'type'}Match>";
$d->{'name'} = $in{'type'}."Match";
$d->{'value'} = "\"$in{'path'}\"";
}
else {
$newdir = "<$in{'type'} ~ \"$in{'path'}\">";
$enddir = "</$in{'type'}>";
$d->{'name'} = $in{'type'};
$d->{'value'} = "~ \"$in{'path'}\"";
}
}
else {
$newdir = "<$in{'type'} \"$in{'path'}\">";
$enddir = "</$in{'type'}>";
$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'}");

View File

@@ -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 = "<FilesMatch \"$in{'path'}\">";
$enddir = "</FilesMatch>";
$d->{'name'} = 'FilesMatch';
$d->{'value'} = "\"$in{'path'}\"";
}
else {
$newdir = "<Files ~ \"$in{'path'}\">";
$enddir = "</Files>";
$d->{'name'} = 'Files';
$d->{'value'} = "~ \"$in{'path'}\"";
}
}
else {
$newdir = "<Files \"$in{'path'}\">";
$enddir = "</Files>";
$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'}));

View File

@@ -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 = "</$in{'type'}Match>";
$dir->{'name'} = $in{'type'}."Match";
$dir->{'value'} = "\"$in{'path'}\"";
}
else {
$newdir = "<$in{'type'} ~ \"$in{'path'}\">";
$enddir = "</$in{'type'}>";
$dir->{'name'} = $in{'type'};
$dir->{'value'} = "~ \"$in{'path'}\"";
}
}
else {
$newdir = "<$in{'type'} \"$in{'path'}\">";
$enddir = "</$in{'type'}>";
$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'}");

View File

@@ -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 = "<FilesMatch \"$in{'path'}\">";
$enddir = "</FilesMatch>";
$dir->{'name'} = 'FilesMatch';
$dir->{'value'} = "\"$in{'path'}\"";
}
else {
$newdir = "<Files ~ \"$in{'path'}\">";
$enddir = "</Files>";
$dir->{'name'} = 'Files';
$dir->{'value'} = "~ \"$in{'path'}\"";
}
}
else {
$newdir = "<Files \"$in{'path'}\">";
$enddir = "</Files>";
$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'}));

View File

@@ -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";