LEMONLDAP::NG : Javascript correction ('z' was added sometimes on rules)

This commit is contained in:
Xavier Guimard 2007-06-19 20:27:49 +00:00
parent 74fce152f8
commit b30f5a8ef8
5 changed files with 52 additions and 41 deletions

View File

@ -2,7 +2,7 @@ lemonldap-ng (0.8.2.4) unstable; urgency=low
* Bug in manager javascript. * Bug in manager javascript.
-- Xavier Guimard <x.guimard@free.fr> Mon, 18 Jun 2007 22:28:53 +0200 -- Xavier Guimard <x.guimard@free.fr> Tue, 19 Jun 2007 22:25:10 +0200
lemonldap-ng (0.8.2.3) unstable; urgency=low lemonldap-ng (0.8.2.3) unstable; urgency=low

View File

@ -1,6 +1,6 @@
Revision history for Perl extension Lemonldap::NG::Manager. Revision history for Perl extension Lemonldap::NG::Manager.
0.71 Mon jun 18 22:24:33 2007 0.71 Mon jun 19 22:22:33 2007
- Bug in javascript : a 'z' is added in regexp - Bug in javascript : a 'z' is added in regexp
0.7 Tue jun 12 22:20:54 2007 0.7 Tue jun 12 22:20:54 2007

View File

@ -16,7 +16,7 @@ use MIME::Base64;
our @ISA = qw(Lemonldap::NG::Manager::Base); our @ISA = qw(Lemonldap::NG::Manager::Base);
our $VERSION = '0.71'; our $VERSION = '0.72';
sub new { sub new {
my ( $class, $args ) = @_; my ( $class, $args ) = @_;
@ -146,6 +146,7 @@ sub buildTree {
my $self = shift; my $self = shift;
my $config = $self->config->getConf( @_ ); my $config = $self->config->getConf( @_ );
$config = $self->default unless ($config); $config = $self->default unless ($config);
my $indice = 1;
my $tree = { my $tree = {
id => '0', id => '0',
item => { item => {
@ -237,7 +238,8 @@ sub buildTree {
if ( $config->{exportedVars} ) { if ( $config->{exportedVars} ) {
while ( my ( $n, $att ) = each( %{ $config->{exportedVars} } ) ) { while ( my ( $n, $att ) = each( %{ $config->{exportedVars} } ) ) {
$exportedVars->{$n} = $self->xmlField( "both", $att, $n ); $exportedVars->{"ev_$indice"} = $self->xmlField( "both", $att, $n );
$indice++;
} }
} }
else { else {
@ -264,22 +266,24 @@ sub buildTree {
my $virtualHost = $tree->{item}->{item}->{virtualHosts}->{item}; my $virtualHost = $tree->{item}->{item}->{virtualHosts}->{item};
# TODO: split locationRules into 2 arrays # TODO: split locationRules into 2 arrays
while ( my ( $host, $rules ) = each( %{ $config->{locationRules} } ) ) { while ( my ( $host, $rules ) = each( %{ $config->{locationRules} } ) ) {
$virtualHost->{$host} = $self->xmlField( "text", 'i', $host ); my $vh_id = "vh_$indice";
$indice++;
$virtualHost->{$vh_id} = $self->xmlField( "text", 'i', $host );
my ( $ih, $ir ) = my ( $ih, $ir ) =
( "exportedHeaders_$indice", "locationRules_$indice" ); ( "exportedHeaders_$indice", "locationRules_$indice" );
$virtualHost->{$host}->{item} = { $virtualHost->{$vh_id}->{item} = {
"$ih" => { text => &txt_httpHeaders, }, "$ih" => { text => &txt_httpHeaders, },
"$ir" => { text => &txt_locationRules, }, "$ir" => { text => &txt_locationRules, },
}; };
while ( my ( $reg, $expr ) = each(%$rules) ) { while ( my ( $reg, $expr ) = each(%$rules) ) {
my $type = ( $reg eq 'default' ) ? 'value' : 'both'; my $type = ( $reg eq 'default' ) ? 'value' : 'both';
$virtualHost->{$host}->{item}->{$ir}->{item}->{"r_$indice"} = $virtualHost->{$vh_id}->{item}->{$ir}->{item}->{"r_$indice"} =
$self->xmlField( $type, $expr, $reg ); $self->xmlField( $type, $expr, $reg );
$indice++; $indice++;
} }
my $headers = $config->{exportedHeaders}->{$host}; my $headers = $config->{exportedHeaders}->{$host};
while ( my ( $h, $expr ) = each(%$headers) ) { while ( my ( $h, $expr ) = each(%$headers) ) {
$virtualHost->{$host}->{item}->{$ih}->{item}->{"h_$indice"} = $virtualHost->{$vh_id}->{item}->{$ih}->{item}->{"h_$indice"} =
$self->xmlField( "both", $expr, $h ); $self->xmlField( "both", $expr, $h );
$indice++; $indice++;
} }
@ -289,14 +293,16 @@ sub buildTree {
$tree->{item}->{item}->{groups}->{item} = {}; $tree->{item}->{item}->{groups}->{item} = {};
my $groups = $tree->{item}->{item}->{groups}->{item}; my $groups = $tree->{item}->{item}->{groups}->{item};
while ( my ( $group, $expr ) = each( %{ $config->{groups} } ) ) { while ( my ( $group, $expr ) = each( %{ $config->{groups} } ) ) {
$groups->{$group} = $self->xmlField( 'both', $expr, $group ); $groups->{"g_$indice"} = $self->xmlField( 'both', $expr, $group );
$indice++;
} }
} }
if ( $config->{macros} and %{ $config->{macros} } ) { if ( $config->{macros} and %{ $config->{macros} } ) {
$tree->{item}->{item}->{generalParameters}->{item}->{macros}->{item} = {}; $tree->{item}->{item}->{generalParameters}->{item}->{macros}->{item} = {};
my $macros = $tree->{item}->{item}->{generalParameters}->{item}->{macros}->{item}; my $macros = $tree->{item}->{item}->{generalParameters}->{item}->{macros}->{item};
while ( my ( $macro, $expr ) = each( %{ $config->{macros} } ) ) { while ( my ( $macro, $expr ) = each( %{ $config->{macros} } ) ) {
$macros->{$macro} = $self->xmlField( 'both', $expr, $macro ); $macros->{"m_$indice"} = $self->xmlField( 'both', $expr, $macro );
$indice++;
} }
} }
return $tree; return $tree;
@ -350,7 +356,7 @@ sub tree2conf {
$config->{groups}->{ $h->{text} } = $h->{value}; $config->{groups}->{ $h->{text} } = $h->{value};
} }
# Load virtualHosts # Load virtualHosts
while ( my ( $vh, $h ) = each( %{ $tree->{virtualHosts} } ) ) { while ( my ( $k, $h ) = each( %{ $tree->{virtualHosts} } ) ) {
next unless ( ref($h) ); next unless ( ref($h) );
my $lr; my $lr;
my $eh; my $eh;
@ -358,6 +364,7 @@ sub tree2conf {
$lr = $h->{$_} if ( $_ =~ /locationRules/ ); $lr = $h->{$_} if ( $_ =~ /locationRules/ );
$eh = $h->{$_} if ( $_ =~ /exportedHeaders/ ); $eh = $h->{$_} if ( $_ =~ /exportedHeaders/ );
} }
my $vh = $h->{text};
# TODO: split locationRules into 2 arrays # TODO: split locationRules into 2 arrays
LR: foreach my $r ( values(%$lr) ) { LR: foreach my $r ( values(%$lr) ) {
next LR unless ( ref($r) ); next LR unless ( ref($r) );
@ -431,7 +438,7 @@ sub checkConf {
print STDERR "$k is not authorized in macro names. Change it!\n"; print STDERR "$k is not authorized in macro names. Change it!\n";
return 0; return 0;
} }
if( $k !~ /^\w+$/ ) { if( $k !~ /^[a-zA-Z]\w*$/ ) {
print STDERR "$k is not a valid macro name\n"; print STDERR "$k is not a valid macro name\n";
return 0; return 0;
} }
@ -458,7 +465,7 @@ sub checkConf {
} }
# Test rules # Test rules
while( my($vh, $rules) = each( %{ $config->{locationRules} } ) ) { while( my($vh, $rules) = each( %{ $config->{locationRules} } ) ) {
unless( $vh =~ /^[-\w\.]+$/ ) { unless( $vh =~ /^\w[-\w\.]*$/ ) {
print STDERR "$vh is not a valid virtual host name\n"; print STDERR "$vh is not a valid virtual host name\n";
return 0; return 0;
} }
@ -482,7 +489,7 @@ sub checkConf {
} }
# Test exported headers # Test exported headers
while( my($vh, $headers) = each( %{ $config->{exportedHeaders} } ) ) { while( my($vh, $headers) = each( %{ $config->{exportedHeaders} } ) ) {
unless( $vh =~ /^[-\w\.]+$/ ) { unless( $vh =~ /^\w[-\w\.]*$/ ) {
print STDERR "$vh is not a valid virtual host name\n"; print STDERR "$vh is not a valid virtual host name\n";
return 0; return 0;
} }

View File

@ -5,8 +5,6 @@ no strict 'refs';
use Data::Dumper; use Data::Dumper;
use Lemonldap::NG::Manager::Conf::Constants; use Lemonldap::NG::Manager::Conf::Constants;
$Data::Dumper::Indent = 0;
$Data::Dumper::Varname = "data";
our $VERSION = 0.5; our $VERSION = 0.5;
our @ISA; our @ISA;
@ -42,6 +40,8 @@ sub saveConf {
return CONFIG_WAS_CHANGED if( $conf->{cfgNum} != $self->lastCfg or $self->isLocked ); return CONFIG_WAS_CHANGED if( $conf->{cfgNum} != $self->lastCfg or $self->isLocked );
$self->lock or return DATABASE_LOCKED; $self->lock or return DATABASE_LOCKED;
my $fields; my $fields;
local $Data::Dumper::Indent = 0;
local $Data::Dumper::Varname = "data";
while ( my ( $k, $v ) = each(%$conf) ) { while ( my ( $k, $v ) = each(%$conf) ) {
if ( ref($v) ) { if ( ref($v) ) {
$fields->{$k} = Dumper($v); $fields->{$k} = Dumper($v);

View File

@ -8,7 +8,7 @@ use AutoLoader qw(AUTOLOAD);
require Lemonldap::NG::Manager::_i18n; require Lemonldap::NG::Manager::_i18n;
use Lemonldap::NG::Manager::Conf::Constants; use Lemonldap::NG::Manager::Conf::Constants;
our $VERSION = '0.29'; our $VERSION = '0.28';
# TODO: Delete buttons in headers and rules if 'read-only' # TODO: Delete buttons in headers and rules if 'read-only'
@ -120,7 +120,7 @@ function win_onresize(){
s3.paint(w,h,w/4,w/5); s3.paint(w,h,w/4,w/5);
} }
var indice=-1; var indice=1;
function onNodeSelect(nodeId) { function onNodeSelect(nodeId) {
var k,v; var k,v;
@ -128,17 +128,15 @@ function onNodeSelect(nodeId) {
switch(tree.getUserData(nodeId,"modif")) { switch(tree.getUserData(nodeId,"modif")) {
case 'text': case 'text':
k='valeur'; k='valeur';
v='<input value="'+nodeId+'" onChange="var tmp=this.value.replace(/^([^a-z])/i,\\'z\$1\\');tmp=tmp.replace(/^([a-zA-Z0-9_\\.\\-]*).*\$/,\\'\$1\\');tree.setItemText('+"'"+nodeId+"'"+',tmp);tree.changeItemId('+"'"+nodeId+"'"+',tmp);this.value=tmp">'; v='<input value="'+tree.getItemText(nodeId)+'" onChange="tree.setItemText('+"'"+nodeId+"'"+',this.value);">';
break; break;
case 'both': case 'both':
k='<input value="'+tree.getItemText(nodeId)+'" onChange="tree.setItemText('+"'"+nodeId+"'"+',this.value)">'; k='<input value="'+tree.getItemText(nodeId)+'" onChange="tree.setItemText('+"'"+nodeId+"'"+',this.value)">';
v='<textarea cols=40 rows=2 onChange="tree.setUserData('+"'"+nodeId+"'"+','+"'"+'value'+"'"+',this.value)">'+tree.getUserData(nodeId,'value')+'</textarea>'; v='<textarea cols=50 rows=5 onChange="tree.setUserData('+"'"+nodeId+"'"+','+"'"+'value'+"'"+',this.value)">'+tree.getUserData(nodeId,'value')+'</textarea>';
//v='<input size=80 name="value" value="'+tree.getUserData(nodeId,'value')+'" onChange="tree.setUserData('+"'"+nodeId+"'"+','+"'"+'value'+"'"+',this.value)">';
break; break;
case 'value': case 'value':
k=tree.getItemText(nodeId); k=tree.getItemText(nodeId);
v='<textarea cols=40 rows=2 onChange="tree.setUserData('+"'"+nodeId+"'"+','+"'"+'value'+"'"+',this.value)">'+tree.getUserData(nodeId,'value')+'</textarea>'; v='<textarea cols=50 rows=5 onChange="tree.setUserData('+"'"+nodeId+"'"+','+"'"+'value'+"'"+',this.value)">'+tree.getUserData(nodeId,'value')+'</textarea>';
//v='<input size=80 name="value" value="'+tree.getUserData(nodeId,'value')+'" onChange="tree.setUserData('+"'"+nodeId+"'"+','+"'"+'value'+"'"+',this.value)">';
break; break;
case 'ro': case 'ro':
k=tree.getItemText(nodeId); k=tree.getItemText(nodeId);
@ -233,9 +231,11 @@ function button(text,func,nodeId){
return '<input type=button value="'+text+'" onclick="'+func+'('+"'"+nodeId+"'"+')"> &nbsp; '; return '<input type=button value="'+text+'" onclick="'+func+'('+"'"+nodeId+"'"+')"> &nbsp; ';
} }
function insertNewChild(a,b,c) { function insertNewChild(a,c) {
tree.insertNewChild(a,b,c); indice++;
tree.setItemColor(b,"\#000000","\#0000FF"); tree.insertNewChild(a,'js_'+indice,c);
tree.setItemColor('js_'+indice,"\#000000","\#0000FF");
return 'js_'+indice;
} }
function newVirtualHost() { function newVirtualHost() {
@ -245,16 +245,21 @@ function newVirtualHost() {
alert('$text{invalidVirtualHostName}'); alert('$text{invalidVirtualHostName}');
return 0; return 0;
} }
insertNewChild('virtualHosts',rep,rep) var tmp=insertNewChild('virtualHosts',rep)
tree.setUserData(rep,'modif','text'); tree.setUserData(tmp,'modif','text');
insertNewChild(rep,rep+'_exportedHeaders','$text{httpHeaders}'); //var tmp_eh=insertNewChild(tmp,'$text{httpHeaders}');
insertNewChild(rep+'_exportedHeaders',rep+'_exportedHeaders_1','Auth-User'); var tmp_eh=tmp+'_exportedHeaders';
tree.setUserData(rep+'_exportedHeaders_1','modif','both'); tree.insertNewChild(tmp,tmp_eh,'$text{httpHeaders}');
tree.setUserData(rep+'_exportedHeaders_1','value','\$uid'); tree.setItemColor(tmp_eh,"\#000000","\#0000FF");
insertNewChild(rep,rep+'_locationRules','$text{locationRules}'); var tmp_eh1=insertNewChild(tmp_eh,'Auth-User');
insertNewChild(rep+'_locationRules',rep+'_locationRules_default','default'); tree.setUserData(tmp_eh1,'modif','both');
tree.setUserData(rep+'_locationRules_default','modif','value'); tree.setUserData(tmp_eh1,'value','\$uid');
tree.setUserData(rep+'_locationRules_default','value','deny'); var tmp_lr=tmp+'_locationRules';
tree.insertNewChild(tmp,tmp_lr,'$text{locationRules}');
tree.setItemColor(tmp_lr,"\#000000","\#0000FF");
var tmp_lr1=insertNewChild(tmp_lr,'default');
tree.setUserData(tmp_lr1,'modif','value');
tree.setUserData(tmp_lr1,'value','deny');
} }
} }
@ -264,11 +269,10 @@ function deleteVirtualHost(id) {
} }
function newValue(id,text,type,value){ function newValue(id,text,type,value){
indice--; var tmp=insertNewChild(id,text);
insertNewChild(id,'j_'+indice,text); tree.setUserData(tmp,'modif',type);
tree.setUserData('j_'+indice,'modif',type); tree.setUserData(tmp,'value',value);
tree.setUserData('j_'+indice,'value',value); tree.selectItem(tmp,true);
tree.selectItem('j_'+indice,true);
} }
function newRule(id){ function newRule(id){