diff --git a/build/lemonldap-ng/Makefile b/build/lemonldap-ng/Makefile index ef983c685..650bb2def 100644 --- a/build/lemonldap-ng/Makefile +++ b/build/lemonldap-ng/Makefile @@ -514,7 +514,7 @@ debian-packages: debian-dist rm -rf lemonldap-ng-$$version && \ tar xzf lemonldap-ng_$$version.orig.tar.gz && \ cd lemonldap-ng-$$version && \ - debuild + export LOCALBUILD=1; debuild diff: @# Portal diff --git a/build/lemonldap-ng/debian/rules b/build/lemonldap-ng/debian/rules index ffdad8e43..521d43347 100755 --- a/build/lemonldap-ng/debian/rules +++ b/build/lemonldap-ng/debian/rules @@ -75,6 +75,8 @@ install: build find $(CURDIR)/debian/tmp -type f -regex '.*/jquery-[0-9].*\.js' -delete find $(CURDIR)/debian/tmp -type f -name jquery.js -delete rm -f $(CURDIR)/debian/tmp$(LMSHAREDIR)*-skins/*/jquery.js + #test -n "$$LOCALBUILD" || ./scripts/minifierjs $$(find debian/tmp/ -name '*.js') + #test -n "$$LOCALBUILD" || ./scripts/minifiercss $$(find debian/tmp/ -name '*.css') perl -i -pe 's#src=(["'"'"']).*?jquery(-\d[\.\w\-]*?)?.js#src=$$1/javascript/jquery/jquery.js#i' \ $(CURDIR)/debian/tmp/examples/manager/*.pl \ $(CURDIR)/debian/tmp$(LMSHAREDIR)manager-skins/default/*.tpl \ diff --git a/build/lemonldap-ng/scripts/CSS/Minifier.pm b/build/lemonldap-ng/scripts/CSS/Minifier.pm new file mode 100644 index 000000000..5bc9b2b2b --- /dev/null +++ b/build/lemonldap-ng/scripts/CSS/Minifier.pm @@ -0,0 +1,345 @@ +package CSS::Minifier; + +use strict; +use warnings; + +require Exporter; +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(minify); + +our $VERSION = '0.01'; + +# ----------------------------------------------------------------------------- + +sub isSpace { + my $x = shift; + return ($x eq ' ' || $x eq "\t"); +} + +sub isEndspace { + my $x = shift; + return ($x eq "\n" || $x eq "\r" || $x eq "\f"); +} + +sub isWhitespace { + my $x = shift; + return (isSpace($x) || isEndspace($x)); +} + +# whitespace characters before or after these characters can be removed. +sub isInfix { + my $x = shift; + return ($x eq '{' || $x eq '}' || $x eq ';' || $x eq ':'); +} + +# whitespace characters after these characters can be removed. +sub isPrefix { + my $x = shift; + return (isInfix($x)); +} + +# whitespace characters before these characters can removed. +sub isPostfix { + my $x = shift; + return (isInfix($x)); +} + +# ----------------------------------------------------------------------------- + +sub _get { + my $s = shift; + if ($s->{inputType} eq 'file') { + return getc($s->{input}); + } + elsif ($s->{inputType} eq 'string') { + if ($s->{'inputPos'} < length($s->{input})) { + return substr($s->{input}, $s->{inputPos}++, 1); + } + else { # Simulate getc() when off the end of the input string. + return undef; + } + } + else { + die "no input"; + } +} + +sub _put { + my $s = shift; + my $x = shift; + my $outfile = ($s->{outfile}); + if (defined($s->{outfile})) { + print $outfile $x; + } + else { + $s->{output} .= $x; + } +} + +# ----------------------------------------------------------------------------- +# print a +# new b +# +# i.e. print a and advance +sub action1 { + my $s = shift; + $s->{last} = $s->{a}; + _put($s, $s->{a}); + action2($s); +} + +# move b to a +# new b +# +# i.e. delete a and advance +sub action2 { + my $s = shift; + $s->{a} = $s->{b}; + $s->{b} = $s->{c}; + $s->{c} = _get($s); +} + +# ----------------------------------------------------------------------------- + +# put string literals +# when this sub is called, $s->{a} is on the opening delimiter character +sub putLiteral { + my $s = shift; + my $delimiter = $s->{a}; # ' or " + + action1($s); + do { + while (defined($s->{a}) && $s->{a} eq '\\') { # escape character escapes only the next one character + action1($s); + action1($s); + } + action1($s); + } until ($s->{last} eq $delimiter || !defined($s->{a})); + if ($s->{last} ne $delimiter) { # ran off end of file before printing the closing delimiter + die 'unterminated ' . ($delimiter eq '\'' ? 'single quoted string' : 'double quoted string') . ' literal, stopped'; + } +} + +# ----------------------------------------------------------------------------- + +# If $s->{a} is a whitespace then collapse all following whitespace. +# If any of the whitespace is a new line then ensure $s->{a} is a new line +# when this function ends. +sub collapseWhitespace { + my $s = shift; + while (defined($s->{a}) && isWhitespace($s->{a}) && + defined($s->{b}) && isWhitespace($s->{b})) { + if (isEndspace($s->{a}) || isEndspace($s->{b})) { + $s->{a} = "\n"; + } + action2($s); # delete b + } +} + +# Advance $s->{a} to non-whitespace or end of file. +# Doesn't print any of this whitespace. +sub skipWhitespace { + my $s = shift; + while (defined($s->{a}) && isWhitespace($s->{a})) { + action2($s); + } +} + +# #s->{a} should be on whitespace when this function is called +sub preserveWhitespace { + my $s = shift; + collapseWhitespace($s); + if (defined($s->{a}) && defined($s->{b}) && !isPostfix($s->{b})) { + action1($s); # print the whitespace character + } + skipWhitespace($s); +} + +# ----------------------------------------------------------------------------- + +sub minify { + my %h = @_; + # Immediately turn hash into a hash reference so that notation is the same in this function + # as others. Easier refactoring. + my $s = \%h; # hash reference for "state". This module is functional programming and the state is passed between functions. + + # determine if the the input is a string or a file handle. + my $ref = \$s->{input}; + if (defined($ref) && ref($ref) eq 'SCALAR'){ + $s->{inputPos} = 0; + $s->{inputType} = 'string'; + } + else { + $s->{inputType} = 'file'; + } + + # Determine if the output is to a string or a file. + if (!defined($s->{outfile})) { + $s->{output} = ''; + } + + # Print the copyright notice first + if ($s->{copyright}) { + _put($s, '/* ' . $s->{copyright} . ' */'); + } + + # Initialize the buffer. + do { + $s->{a} = _get($s); + } while (defined($s->{a}) && isWhitespace($s->{a})); + $s->{b} = _get($s); + $s->{c} = _get($s); + $s->{last} = undef; + + # local variables + my $firstCommentSeen=0; + my $macIeCommentHackFlag = 0; # marks if a have recently seen a comment with an escaped close like this /* foo \*/ + # and have not yet seen a regular comment to close this like /* bar */ + + while (defined($s->{a})) { # on this line $s->{a} should always be a non-whitespace character or undef (i.e. end of file) + + if (isWhitespace($s->{a})) { # check that this program is running correctly + die 'minifier bug: minify while loop starting with whitespace, stopped'; + } + + # Each branch handles trailing whitespace and ensures $s->{a} is on non-whitespace or undef when branch finishes + if ($s->{a} eq '/' && defined($s->{b}) && $s->{b} eq '*') { # a comment + do { + if($firstCommentSeen){ + action2($s); # advance buffer by one + } + else { + action1($s); + } + # if a is \, b is *, c is /, hack flag false + # Mac/IE hack start + # set hack flag true + # print /*\*/ + if ($s->{a} eq '\\' && + defined($s->{b}) && $s->{b} eq '*' && + defined($s->{c}) && $s->{c} eq '/' && + !$macIeCommentHackFlag) { + $macIeCommentHackFlag = 1; + _put($s, '/*\\*/'); + $s->{last} = '/'; + } + # if a is not \, b is *, c is /, hack flag true + # Mac/IE hack end + # set hack flag false + # print /**/ + if ($s->{a} ne '\\' && + defined($s->{b}) && $s->{b} eq '*' && + defined($s->{c}) && $s->{c} eq '/' && + $macIeCommentHackFlag) { + $macIeCommentHackFlag = 0; + _put($s, '/**/'); + $s->{last} = '/'; + } + + } until (!defined($s->{b}) || ($s->{a} eq '*' && $s->{b} eq '/')); + if (defined($s->{b})) { # $s->{a} is asterisk and $s->{b} is forward slash + if($firstCommentSeen){ + action2($s); # the * + $s->{a} = ' '; # the / + skipWhitespace($s); + } + else{ + action1($s); + $firstCommentSeen++; + } + } + else { + die 'unterminated comment, stopped'; + } + } + elsif ($s->{a} eq '\'' || $s->{a} eq '"') { + putLiteral($s); + if (defined($s->{a}) && isWhitespace($s->{a})) { + preserveWhitespace($s); # can this be skipWhitespace? + } + } + elsif (isPrefix($s->{a})) { + action1($s); + skipWhitespace($s); + } + else { # anything else just prints + action1($s); + if (defined($s->{a}) && isWhitespace($s->{a})) { + preserveWhitespace($s); + } + } + } + + if (!defined($s->{outfile})) { + return $s->{output}; + } + +} + +# ----------------------------------------------------------------------------- + +1; +__END__ + +# Below is stub documentation for your module. You'd better edit it! + +=head1 NAME + +CSS::Minifier - Perl extension for minifying CSS + +=head1 SYNOPSIS + +To minify a CSS file and have the output written directly to another file + + use CSS::Minifier qw(minify); + open(INFILE, 'myStylesheet.css') or die; + open(OUTFILE, 'myStylesheet.css') or die; + minify(input => *INFILE, outfile => *OUTFILE); + close(INFILE); + close(OUTFILE); + +To minify a CSS string literal. Note that by omitting the outfile parameter a the minified code is returned as a string. + + my minifiedCSS = minify(input => 'div {font-family: serif;}'); + +To include a copyright comment at the top of the minified code. + + minify(input => 'div {font-family: serif;}', copyright => 'BSD License'); + +The "input" parameter is manditory. The "output" and "copyright" parameters are optional and can be used in any combination. + +=head1 DESCRIPTION + +This module removes unnecessary whitespace from CSS. The primary requirement developing this module is to not break working stylesheets: if working CSS is in input then working CSS is output. The Mac/Internet Explorer comment hack will be minimized but not stripped and so will continue to function. + +This module understands space, horizontal tab, new line, carriage return, and form feed characters to be whitespace. Any other characters that may be considered whitespace are not minimized. These other characters include paragraph separator and vertical tab. + +For static CSS files, it is recommended that you minify during the build stage of web deployment. If you minify on-the-fly then it might be a good idea to cache the minified file. Minifying static files on-the-fly repeatedly is wasteful. + +=head2 EXPORT + +None by default. + +Exportable on demand: minifiy() + + +=head1 SEE ALSO + +This project is developed using an SVN repository. To check out the repository +svn co http://dev.michaux.ca/svn/random/CSS-Minifier + +You may also be interested in the JavaScript::Minifier module also available on CPAN. + + +=head1 AUTHORS + +Peter Michaux, Epetermichaux@gmail.comE + + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2007 by Peter Michaux + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.8.6 or, +at your option, any later version of Perl 5 you may have available. diff --git a/build/lemonldap-ng/scripts/JavaScript/Minifier.pm b/build/lemonldap-ng/scripts/JavaScript/Minifier.pm new file mode 100644 index 000000000..f636d0d97 --- /dev/null +++ b/build/lemonldap-ng/scripts/JavaScript/Minifier.pm @@ -0,0 +1,435 @@ +package JavaScript::Minifier; + +use strict; +use warnings; + +require Exporter; +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(minify); + +our $VERSION = '1.05'; + +# ----------------------------------------------------------------------------- + +#return true if the character is allowed in identifier. +sub isAlphanum { + my $x = shift; + return ($x =~ /[\w\$\\]/ || ord($x) > 126); +} + +sub isSpace { + my $x = shift; + return ($x eq ' ' || $x eq "\t"); +} + +sub isEndspace { + my $x = shift; + return ($x eq "\n" || $x eq "\r" || $x eq "\f"); +} + +sub isWhitespace { + my $x = shift; + return (isSpace($x) || isEndspace($x)); +} + +# New line characters before or after these characters can be removed. +# Not + - / in this list because they require special care. +sub isInfix { + my $x = shift; + $x =~ /[,;:=&%*<>\?\|\n]/; +} + +# New line characters after these characters can be removed. +sub isPrefix { + my $x = shift; + return ($x =~ /[\{\(\[!]/ || isInfix($x)); +} + +# New line characters before these characters can removed. +sub isPostfix { + my $x = shift; + return ($x =~ /[\}\)\]]/ || isInfix($x)); +} + +# ----------------------------------------------------------------------------- + +sub _get { + my $s = shift; + if ($s->{inputType} eq 'file') { + return getc($s->{input}); + } + elsif ($s->{inputType} eq 'string') { + if ($s->{'inputPos'} < length($s->{input})) { + return substr($s->{input}, $s->{inputPos}++, 1); + } + else { # Simulate getc() when off the end of the input string. + return undef; + } + } + else { + die "no input"; + } +} + +sub _put { + my $s = shift; + my $x = shift; + my $outfile = ($s->{outfile}); + if (defined($s->{outfile})) { + print $outfile $x; + } + else { + $s->{output} .= $x; + } +} + +# ----------------------------------------------------------------------------- + +# print a +# move b to a +# move c to b +# move d to c +# new d +# +# i.e. print a and advance +sub action1 { + my $s = shift; + if (!isWhitespace($s->{a})) { + $s->{lastnws} = $s->{a}; + } + $s->{last} = $s->{a}; + action2($s); +} + +# sneeky output $s->{a} for comments +sub action2 { + my $s = shift; + _put($s, $s->{a}); + action3($s); +} + +# move b to a +# move c to b +# move d to c +# new d +# +# i.e. delete a +sub action3 { + my $s = shift; + $s->{a} = $s->{b}; + action4($s); +} + +# move c to b +# move d to c +# new d +# +# i.e. delete b +sub action4 { + my $s = shift; + $s->{b} = $s->{c}; + $s->{c} = $s->{d}; + $s->{d} = _get($s); +} + +# ----------------------------------------------------------------------------- + +# put string and regexp literals +# when this sub is called, $s->{a} is on the opening delimiter character +sub putLiteral { + my $s = shift; + my $delimiter = $s->{a}; # ', " or / + action1($s); + do { + while (defined($s->{a}) && $s->{a} eq '\\') { # escape character only escapes only the next one character + action1($s); + action1($s); + } + action1($s); + } until ($s->{last} eq $delimiter || !defined($s->{a})); + if ($s->{last} ne $delimiter) { # ran off end of file before printing the closing delimiter + die 'unterminated ' . ($delimiter eq '\'' ? 'single quoted string' : $delimiter eq '"' ? 'double quoted string' : 'regular expression') . ' literal, stopped'; + } +} + +# ----------------------------------------------------------------------------- + +# If $s->{a} is a whitespace then collapse all following whitespace. +# If any of the whitespace is a new line then ensure $s->{a} is a new line +# when this function ends. +sub collapseWhitespace { + my $s = shift; + while (defined($s->{a}) && isWhitespace($s->{a}) && + defined($s->{b}) && isWhitespace($s->{b})) { + if (isEndspace($s->{a}) || isEndspace($s->{b})) { + $s->{a} = "\n"; + } + action4($s); # delete b + } +} + +# Advance $s->{a} to non-whitespace or end of file. +# Doesn't print any of this whitespace. +sub skipWhitespace { + my $s = shift; + while (defined($s->{a}) && isWhitespace($s->{a})) { + action3($s); + } +} + +# Advance $s->{a} to non-whitespace or end of file +# If any of the whitespace is a new line then print one new line. +sub preserveEndspace { + my $s = shift; + collapseWhitespace($s); + if (defined($s->{a}) && isEndspace($s->{a}) && defined($s->{b}) && !isPostfix($s->{b}) ) { + action1($s); + } + skipWhitespace($s); +} + +sub onWhitespaceConditionalComment { + my $s = shift; + return (defined($s->{a}) && isWhitespace($s->{a}) && + defined($s->{b}) && $s->{b} eq '/' && + defined($s->{c}) && ($s->{c} eq '/' || $s->{c} eq '*') && + defined($s->{d}) && $s->{d} eq '@'); +} + +# ----------------------------------------------------------------------------- + +sub minify { + my %h = @_; + # Immediately turn hash into a hash reference so that notation is the same in this function + # as others. Easier refactoring. + my $s = \%h; # hash reference for "state". This module is functional programming and the state is passed between functions. + + # determine if the the input is a string or a file handle. + my $ref = \$s->{input}; + if (defined($ref) && ref($ref) eq 'SCALAR'){ + $s->{inputPos} = 0; + $s->{inputType} = 'string'; + } + else { + $s->{inputType} = 'file'; + } + + # Determine if the output is to a string or a file. + if (!defined($s->{outfile})) { + $s->{output} = ''; + } + + # Print the copyright notice first + if ($s->{copyright}) { + _put($s, '/* ' . $s->{copyright} . ' */'); + } + + # Initialize the buffer. + do { + $s->{a} = _get($s); + } while (defined($s->{a}) && isWhitespace($s->{a})); + $s->{b} = _get($s); + $s->{c} = _get($s); + $s->{d} = _get($s); + $s->{last} = undef; # assign for safety + $s->{lastnws} = undef; # assign for safety + + # local variables + my $firstCommentSeen; + my $ccFlag; # marks if a comment is an Internet Explorer conditional comment and should be printed to output + + while (defined($s->{a})) { # on this line $s->{a} should always be a non-whitespace character or undef (i.e. end of file) + + if (isWhitespace($s->{a})) { # check that this program is running correctly + die 'minifier bug: minify while loop starting with whitespace, stopped'; + } + + # Each branch handles trailing whitespace and ensures $s->{a} is on non-whitespace or undef when branch finishes + if ($s->{a} eq '/') { # a division, comment, or regexp literal + if (defined($s->{b}) && $s->{b} eq '/') { # slash-slash comment + $ccFlag = defined($s->{c}) && $s->{c} eq '@'; # tests in IE7 show no space allowed between slashes and at symbol + do { + $ccFlag ? action2($s) : action3($s); + } until (!defined($s->{a}) || isEndspace($s->{a})); + if (defined($s->{a})) { # $s->{a} is a new line + if ($ccFlag) { + action1($s); # cannot use preserveEndspace($s) here because it might not print the new line + skipWhitespace($s); + } + elsif (defined($s->{last}) && !isEndspace($s->{last}) && !isPrefix($s->{last})) { + preserveEndspace($s); + } + else { + skipWhitespace($s); + } + } + } + elsif (defined($s->{b}) && $s->{b} eq '*') { # slash-star comment + $ccFlag = defined($s->{c}) && $s->{c} eq '@'; # test in IE7 shows no space allowed between star and at symbol + do { + $ccFlag or !$firstCommentSeen ? action2($s) : action3($s); + } until (!defined($s->{b}) || ($s->{a} eq '*' && $s->{b} eq '/')); + if (defined($s->{b})) { # $s->{a} is asterisk and $s->{b} is foreslash + if ($ccFlag or !$firstCommentSeen) { + action2($s); # the * + action2($s); # the / + # inside the conditional comment there may be a missing terminal semi-colon + preserveEndspace($s); + $firstCommentSeen++; + } + else { # the comment is being removed + action3($s); # the * + $s->{a} = ' '; # the / + collapseWhitespace($s); + if (defined($s->{last}) && defined($s->{b}) && + ((isAlphanum($s->{last}) && (isAlphanum($s->{b})||$s->{b} eq '.')) || + ($s->{last} eq '+' && $s->{b} eq '+') || ($s->{last} eq '-' && $s->{b} eq '-'))) { # for a situation like 5-/**/-2 or a/**/a + # When entering this block $s->{a} is whitespace. + # The comment represented whitespace that cannot be removed. Therefore replace the now gone comment with a whitespace. + action1($s); + } + elsif (defined($s->{last}) && !isPrefix($s->{last})) { + preserveEndspace($s); + } + else { + skipWhitespace($s); + } + } + } + else { + die 'unterminated comment, stopped'; + } + } + elsif (defined($s->{lastnws}) && ($s->{lastnws} eq ')' || $s->{lastnws} eq ']' || + $s->{lastnws} eq '.' || isAlphanum($s->{lastnws}))) { # division + action1($s); + collapseWhitespace($s); + # don't want a division to become a slash-slash comment with following conditional comment + onWhitespaceConditionalComment($s) ? action1($s) : preserveEndspace($s); + } + else { # regexp literal + putLiteral($s); + collapseWhitespace($s); + # don't want closing delimiter to become a slash-slash comment with following conditional comment + onWhitespaceConditionalComment($s) ? action1($s) : preserveEndspace($s); + } + } + elsif ($s->{a} eq '\'' || $s->{a} eq '"' ) { # string literal + putLiteral($s); + preserveEndspace($s); + } + elsif ($s->{a} eq '+' || $s->{a} eq '-') { # careful with + + and - - + action1($s); + collapseWhitespace($s); + if (defined($s->{a}) && isWhitespace($s->{a})) { + (defined($s->{b}) && $s->{b} eq $s->{last}) ? action1($s) : preserveEndspace($s); + } + } + elsif (isAlphanum($s->{a})) { # keyword, identifiers, numbers + action1($s); + collapseWhitespace($s); + if (defined($s->{a}) && isWhitespace($s->{a})) { + # if $s->{b} is '.' could be (12 .toString()) which is property invocation. If space removed becomes decimal point and error. + (defined($s->{b}) && (isAlphanum($s->{b}) || $s->{b} eq '.')) ? action1($s) : preserveEndspace($s); + } + } + elsif ($s->{a} eq ']' || $s->{a} eq '}' || $s->{a} eq ')') { # no need to be followed by space but maybe needs following new line + action1($s); + preserveEndspace($s); + } + elsif ($s->{stripDebug} && $s->{a} eq ';' && + defined($s->{b}) && $s->{b} eq ';' && + defined($s->{c}) && $s->{c} eq ';') { + action3($s); # delete one of the semi-colons + $s->{a} = '/'; # replace the other two semi-colons + $s->{b} = '/'; # so the remainder of line is removed + } + else { # anything else just prints and trailing whitespace discarded + action1($s); + skipWhitespace($s); + } + } + + if (!defined($s->{outfile})) { + return $s->{output}; + } + +} # minify() + +# ----------------------------------------------------------------------------- + +1; +__END__ + + +=head1 NAME + +JavaScript::Minifier - Perl extension for minifying JavaScript code + + +=head1 SYNOPSIS + +To minify a JavaScript file and have the output written directly to another file + + use JavaScript::Minifier qw(minify); + open(INFILE, 'myScript.js') or die; + open(OUTFILE, '>myScript-min.js') or die; + minify(input => *INFILE, outfile => *OUTFILE); + close(INFILE); + close(OUTFILE); + +To minify a JavaScript string literal. Note that by omitting the outfile parameter a the minified code is returned as a string. + + my minifiedJavaScript = minify(input => 'var x = 2;'); + +To include a copyright comment at the top of the minified code. + + minify(input => 'var x = 2;', copyright => 'BSD License'); + +To treat ';;;' as '//' so that debugging code can be removed. This is a common JavaScript convention for minification. + + minify(input => 'var x = 2;', stripDebug => 1); + +The "input" parameter is manditory. The "output", "copyright", and "stripDebug" parameters are optional and can be used in any combination. + + +=head1 DESCRIPTION + +This module removes unnecessary whitespace from JavaScript code. The primary requirement developing this module is to not break working code: if working JavaScript is in input then working JavaScript is output. It is ok if the input has missing semi-colons, snips like '++ +' or '12 .toString()', for example. Internet Explorer conditional comments are copied to the output but the code inside these comments will not be minified. + +The ECMAScript specifications allow for many different whitespace characters: space, horizontal tab, vertical tab, new line, carriage return, form feed, and paragraph separator. This module understands all of these as whitespace except for vertical tab and paragraph separator. These two types of whitespace are not minimized. + +For static JavaScript files, it is recommended that you minify during the build stage of web deployment. If you minify on-the-fly then it might be a good idea to cache the minified file. Minifying static files on-the-fly repeatedly is wasteful. + + +=head2 EXPORT + +None by default. + +Exportable on demand: minifiy() + + +=head1 SEE ALSO + +This project is developed using an SVN repository. To check out the repository +svn co http://dev.michaux.ca/svn/random/JavaScript-Minifier + +This module is inspired by Douglas Crockford's JSMin: +http://www.crockford.com/javascript/jsmin.html + +You may also be interested in the CSS::Minifier module also available on CPAN. + + +=head1 AUTHORS + +Peter Michaux, Epetermichaux@gmail.comE +Eric Herrera, Eherrera@10east.comE + + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2007 by Peter Michaux + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.8.6 or, +at your option, any later version of Perl 5 you may have available. diff --git a/build/lemonldap-ng/scripts/minifiercss b/build/lemonldap-ng/scripts/minifiercss new file mode 100755 index 000000000..762991b7f --- /dev/null +++ b/build/lemonldap-ng/scripts/minifiercss @@ -0,0 +1,21 @@ +#!/usr/bin/perl -Iscripts + +use CSS::Minifier 'minify'; + +foreach my $f (@ARGV) { + unless(-e $f) { + print STDERR "$f doesn't exists, skipping\n"; + next; + } + unless(-w $f) { + print STDERR "$f is not writeable, skipping\n"; + next; + } + my $s=''; + open F, $f; + $s = minify(input => *F); + close F; + open F, ">$f"; + print F $s; + close F; +} diff --git a/build/lemonldap-ng/scripts/minifierjs b/build/lemonldap-ng/scripts/minifierjs new file mode 100755 index 000000000..431257f32 --- /dev/null +++ b/build/lemonldap-ng/scripts/minifierjs @@ -0,0 +1,21 @@ +#!/usr/bin/perl -Iscripts + +use JavaScript::Minifier 'minify'; + +foreach my $f (@ARGV) { + unless(-e $f) { + print STDERR "$f doesn't exists, skipping\n"; + next; + } + unless(-w $f) { + print STDERR "$f is not writeable, skipping\n"; + next; + } + my $s=''; + open F, $f; + $s = minify(input => *F); + close F; + open F, ">$f"; + print F $s; + close F; +} diff --git a/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/CGI.pm b/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/CGI.pm index 1c0732a95..62eff60e5 100644 --- a/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/CGI.pm +++ b/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/CGI.pm @@ -95,7 +95,7 @@ sub lmLog { } } else { - print STDERR "$mess\n" unless ( $level =~ /^(?:debug|info)$/ ); + print STDERR "$mess\n" unless ( $level =~ /^(?:debug)$/ ); } } @@ -114,6 +114,7 @@ sub setApacheUser { $self->r->connection->user($user); } } + $ENV{REMOTE_USER} = $user; } ## @method void soapTest(string soapFunctions, object obj) @@ -248,7 +249,7 @@ sub userLog { # @param $mess string to log sub userInfo { my ( $self, $mess ) = @_; - $mess = "Lemonldap::NG portal: $mess ($ENV{REMOTE_ADDR})"; + $mess = "Lemonldap::NG : $mess ($ENV{REMOTE_ADDR})"; $self->userLog( $mess, 'info' ); } @@ -258,7 +259,7 @@ sub userInfo { # @param $mess string to log sub userNotice { my ( $self, $mess ) = @_; - $mess = "Lemonldap::NG portal: $mess ($ENV{REMOTE_ADDR})"; + $mess = "Lemonldap::NG : $mess ($ENV{REMOTE_ADDR})"; $self->userLog( $mess, 'notice' ); } @@ -268,7 +269,7 @@ sub userNotice { # @param $mess string to log sub userError { my ( $self, $mess ) = @_; - $mess = "Lemonldap::NG portal: $mess ($ENV{REMOTE_ADDR})"; + $mess = "Lemonldap::NG : $mess ($ENV{REMOTE_ADDR})"; $self->userLog( $mess, 'warn' ); } diff --git a/modules/lemonldap-ng-manager/example/images/xlib.js b/modules/lemonldap-ng-manager/example/images/xlib.js deleted file mode 100644 index 7e586bb2a..000000000 --- a/modules/lemonldap-ng-manager/example/images/xlib.js +++ /dev/null @@ -1,196 +0,0 @@ -/* Compiled from X 4.18 by XC 1.07 on 17Feb09 */ -function xEvent(evt){var e=evt||window.event;if(!e)return;this.type=e.type;this.target=e.target||e.srcElement;this.relatedTarget=e.relatedTarget;/*@cc_on if(e.type=='mouseover')this.relatedTarget=e.fromElement;else if(e.type=='mouseout')this.relatedTarget=e.toElement;@*/if(xDef(e.pageX)){this.pageX=e.pageX;this.pageY=e.pageY;}else if(xDef(e.clientX)){this.pageX=e.clientX+xScrollLeft();this.pageY=e.clientY+xScrollTop();}if(xDef(e.offsetX)){this.offsetX=e.offsetX;this.offsetY=e.offsetY;}else if(xDef(e.layerX)){this.offsetX=e.layerX;this.offsetY=e.layerY;}else{this.offsetX=this.pageX-xPageX(this.target);this.offsetY=this.pageY-xPageY(this.target);}this.keyCode=e.keyCode||e.which||0;this.shiftKey=e.shiftKey;this.ctrlKey=e.ctrlKey;this.altKey=e.altKey;if(typeof e.type=='string'){if(e.type.indexOf('click')!=-1){this.button=0;}else if(e.type.indexOf('mouse')!=-1){this.button=e.button;/*@cc_on if(e.button&1)this.button=0;else if(e.button&4)this.button=1;else if(e.button&2)this.button=2;@*/}}}xLibrary={version:'4.18',license:'GNU LGPL',url:'http://cross-browser.com/'};function xAddEventListener(e,eT,eL,cap){if(!(e=xGetElementById(e)))return;eT=eT.toLowerCase();if(e.addEventListener)e.addEventListener(eT,eL,cap||false);else if(e.attachEvent)e.attachEvent('on'+eT,eL);else{var o=e['on'+eT];e['on'+eT]=typeof o=='function'?function(v){o(v);eL(v);}:eL;}}function xCamelize(cssPropStr){var i,c,a=cssPropStr.split('-');var s=a[0];for(i=1;iw.innerWidth)v-=16;}return v;}function xClientWidth(){var v=0,d=document,w=window;if((!d.compatMode||d.compatMode=='CSS1Compat')&&!w.opera&&d.documentElement&&d.documentElement.clientWidth){v=d.documentElement.clientWidth;}else if(d.body&&d.body.clientWidth){v=d.body.clientWidth;}else if(xDef(w.innerWidth,w.innerHeight,d.height)){v=w.innerWidth;if(d.height>w.innerHeight)v-=16;}return v;}function xDef(){for(var i=0;i=eX+l&&x<=eX+xWidth(e)-r&&y>=eY+t&&y<=eY+xHeight(e)-b);}function xHeight(e,h){if(!(e=xGetElementById(e)))return 0;if(xNum(h)){if(h<0)h=0;else h=Math.round(h);}else h=-1;var css=xDef(e.style);if(e==document||e.tagName.toLowerCase()=='html'||e.tagName.toLowerCase()=='body'){h=xClientHeight();}else if(css&&xDef(e.offsetHeight)&&xStr(e.style.height)){if(h>=0){var pt=0,pb=0,bt=0,bb=0;if(document.compatMode=='CSS1Compat'){var gcs=xGetComputedStyle;pt=gcs(e,'padding-top',1);if(pt!==null){pb=gcs(e,'padding-bottom',1);bt=gcs(e,'border-top-width',1);bb=gcs(e,'border-bottom-width',1);}else if(xDef(e.offsetHeight,e.style.height)){e.style.height=h+'px';pt=e.offsetHeight-h;}}h-=(pt+pb+bt+bb);if(isNaN(h)||h<0)return;else e.style.height=h+'px';}h=e.offsetHeight;}else if(css&&xDef(e.style.pixelHeight)){if(h>=0)e.style.pixelHeight=h;h=e.style.pixelHeight;}return h;}function xLeft(e,iX){if(!(e=xGetElementById(e)))return 0;var css=xDef(e.style);if(css&&xStr(e.style.left)){if(xNum(iX))e.style.left=iX+'px';else{iX=parseInt(e.style.left);if(isNaN(iX))iX=xGetComputedStyle(e,'left',1);if(isNaN(iX))iX=0;}}else if(css&&xDef(e.style.pixelLeft)){if(xNum(iX))e.style.pixelLeft=iX;else iX=e.style.pixelLeft;}return iX;}function xMoveTo(e,x,y){xLeft(e,x);xTop(e,y);}function xNum(){for(var i=0;i=0){var pl=0,pr=0,bl=0,br=0;if(document.compatMode=='CSS1Compat'){var gcs=xGetComputedStyle;pl=gcs(e,'padding-left',1);if(pl!==null){pr=gcs(e,'padding-right',1);bl=gcs(e,'border-left-width',1);br=gcs(e,'border-right-width',1);}else if(xDef(e.offsetWidth,e.style.width)){e.style.width=w+'px';pl=e.offsetWidth-w;}}w-=(pl+pr+bl+br);if(isNaN(w)||w<0)return;else e.style.width=w+'px';}w=e.offsetWidth;}else if(css&&xDef(e.style.pixelWidth)){if(w>=0)e.style.pixelWidth=w;w=e.style.pixelWidth;}return w;}/* Compiled from X 4.18 by XC 1.07 on 17Feb09 */ -function xEvent(evt){var e=evt||window.event;if(!e)return;this.type=e.type;this.target=e.target||e.srcElement;this.relatedTarget=e.relatedTarget;/*@cc_on if(e.type=='mouseover')this.relatedTarget=e.fromElement;else if(e.type=='mouseout')this.relatedTarget=e.toElement;@*/if(xDef(e.pageX)){this.pageX=e.pageX;this.pageY=e.pageY;}else if(xDef(e.clientX)){this.pageX=e.clientX+xScrollLeft();this.pageY=e.clientY+xScrollTop();}if(xDef(e.offsetX)){this.offsetX=e.offsetX;this.offsetY=e.offsetY;}else if(xDef(e.layerX)){this.offsetX=e.layerX;this.offsetY=e.layerY;}else{this.offsetX=this.pageX-xPageX(this.target);this.offsetY=this.pageY-xPageY(this.target);}this.keyCode=e.keyCode||e.which||0;this.shiftKey=e.shiftKey;this.ctrlKey=e.ctrlKey;this.altKey=e.altKey;if(typeof e.type=='string'){if(e.type.indexOf('click')!=-1){this.button=0;}else if(e.type.indexOf('mouse')!=-1){this.button=e.button;/*@cc_on if(e.button&1)this.button=0;else if(e.button&4)this.button=1;else if(e.button&2)this.button=2;@*/}}}xLibrary={version:'4.18',license:'GNU LGPL',url:'http://cross-browser.com/'};function xAddEventListener(e,eT,eL,cap){if(!(e=xGetElementById(e)))return;eT=eT.toLowerCase();if(e.addEventListener)e.addEventListener(eT,eL,cap||false);else if(e.attachEvent)e.attachEvent('on'+eT,eL);else{var o=e['on'+eT];e['on'+eT]=typeof o=='function'?function(v){o(v);eL(v);}:eL;}}function xPreventDefault(e){if(e&&e.preventDefault)e.preventDefault();else if(window.event)window.event.returnValue=false;}function xRemoveEventListener(e,eT,eL,cap){if(!(e=xGetElementById(e)))return;eT=eT.toLowerCase();if(e.removeEventListener)e.removeEventListener(eT,eL,cap||false);else if(e.detachEvent)e.detachEvent('on'+eT,eL);else e['on'+eT]=null;}function xStopPropagation(evt){if(evt&&evt.stopPropagation)evt.stopPropagation();else if(window.event)window.event.cancelBubble=true;}// xEnableDrag r8, Copyright 2002-2007 Michael Foster (Cross-Browser.com) -// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL - -function xEnableDrag(id,fS,fD,fE) -{ - var mx = 0, my = 0, el = xGetElementById(id); - if (el) { - el.xDragEnabled = true; - xAddEventListener(el, 'mousedown', dragStart, false); - } - // Private Functions - function dragStart(e) - { - if (el.xDragEnabled) { - var ev = new xEvent(e); - xPreventDefault(e); - mx = ev.pageX; - my = ev.pageY; - xAddEventListener(document, 'mousemove', drag, false); - xAddEventListener(document, 'mouseup', dragEnd, false); - if (fS) { - fS(el, ev.pageX, ev.pageY, ev); - } - } - } - function drag(e) - { - var ev, dx, dy; - xPreventDefault(e); - ev = new xEvent(e); - dx = ev.pageX - mx; - dy = ev.pageY - my; - mx = ev.pageX; - my = ev.pageY; - if (fD) { - fD(el, dx, dy, ev); - } - else { - xMoveTo(el, xLeft(el) + dx, xTop(el) + dy); - } - } - function dragEnd(e) - { - var ev = new xEvent(e); - xPreventDefault(e); - xRemoveEventListener(document, 'mouseup', dragEnd, false); - xRemoveEventListener(document, 'mousemove', drag, false); - if (fE) { - fE(el, ev.pageX, ev.pageY, ev); - } - if (xEnableDrag.drop) { - xEnableDrag.drop(el, ev); - } - } -} - -xEnableDrag.drops = []; // static property -// xFirstChild r4, Copyright 2004-2007 Michael Foster (Cross-Browser.com) -// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL - -function xFirstChild(e,t) -{ - e = xGetElementById(e); - var c = e ? e.firstChild : null; - while (c) { - if (c.nodeType == 1 && (!t || c.nodeName.toLowerCase() == t.toLowerCase())){break;} - c = c.nextSibling; - } - return c; -} -// xNextSib r4, Copyright 2005-2007 Michael Foster (Cross-Browser.com) -// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL - -function xNextSib(e,t) -{ - e = xGetElementById(e); - var s = e ? e.nextSibling : null; - while (s) { - if (s.nodeType == 1 && (!t || s.nodeName.toLowerCase() == t.toLowerCase())){break;} - s = s.nextSibling; - } - return s; -} -// xSplitter r3, Copyright 2006-2007 Michael Foster (Cross-Browser.com) -// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL - -function xSplitter(sSplId, uSplX, uSplY, uSplW, uSplH, bHorizontal, uBarW, uBarPos, uBarLimit1, uBarLimit2, bBarEnabled, uSplBorderW, oSplChild1, oSplChild2) -{ - // Private - - var pane1, pane2, splW, splH; - var splEle, barPos, barLim1, barLim2, barEle; - - function barOnDrag(ele, dx, dy) - { - var bp; - if (bHorizontal) - { - bp = barPos + dx; - if (bp < barLim1 || bp > splW - barLim2) { return; } - xWidth(pane1, xWidth(pane1) + dx); - xLeft(barEle, xLeft(barEle) + dx); - xWidth(pane2, xWidth(pane2) - dx); - xLeft(pane2, xLeft(pane2) + dx); - barPos = bp; - } - else - { - bp = barPos + dy; - if (bp < barLim1 || bp > splH - barLim2) { return; } - xHeight(pane1, xHeight(pane1) + dy); - xTop(barEle, xTop(barEle) + dy); - xHeight(pane2, xHeight(pane2) - dy); - xTop(pane2, xTop(pane2) + dy); - barPos = bp; - } - if (oSplChild1) { oSplChild1.paint(xWidth(pane1), xHeight(pane1)); } - if (oSplChild2) { oSplChild2.paint(xWidth(pane2), xHeight(pane2)); } - } - - // Public - - this.paint = function(uNewW, uNewH, uNewBarPos, uNewBarLim1, uNewBarLim2) // uNewBarPos and uNewBarLim are optional - { - if (uNewW == 0) { return; } - var w1, h1, w2, h2; - splW = uNewW; - splH = uNewH; - barPos = uNewBarPos || barPos; - barLim1 = uNewBarLim1 || barLim1; - barLim2 = uNewBarLim2 || barLim2; - xMoveTo(splEle, uSplX, uSplY); - xResizeTo(splEle, uNewW, uNewH); - if (bHorizontal) - { - w1 = barPos; - h1 = uNewH - 2 * uSplBorderW; - w2 = uNewW - w1 - uBarW - 2 * uSplBorderW; - h2 = h1; - xMoveTo(pane1, 0, 0); - xResizeTo(pane1, w1, h1); - xMoveTo(barEle, w1, 0); - xResizeTo(barEle, uBarW, h1); - xMoveTo(pane2, w1 + uBarW, 0); - xResizeTo(pane2, w2, h2); - } - else - { - w1 = uNewW - 2 * uSplBorderW;; - h1 = barPos; - w2 = w1; - h2 = uNewH - h1 - uBarW - 2 * uSplBorderW; - xMoveTo(pane1, 0, 0); - xResizeTo(pane1, w1, h1); - xMoveTo(barEle, 0, h1); - xResizeTo(barEle, w1, uBarW); - xMoveTo(pane2, 0, h1 + uBarW); - xResizeTo(pane2, w2, h2); - } - if (oSplChild1) - { - pane1.style.overflow = 'hidden'; - oSplChild1.paint(w1, h1); - } - if (oSplChild2) - { - pane2.style.overflow = 'hidden'; - oSplChild2.paint(w2, h2); - } - }; - - // Constructor - - splEle = xGetElementById(sSplId); // we assume the splitter has 3 DIV children and in this order: - pane1 = xFirstChild(splEle, 'DIV'); - pane2 = xNextSib(pane1, 'DIV'); - barEle = xNextSib(pane2, 'DIV'); - // --- slightly dirty hack - pane1.style.zIndex = 2; - pane2.style.zIndex = 2; - barEle.style.zIndex = 1; - // --- - barPos = uBarPos; - barLim1 = uBarLimit1; - barLim2 = uBarLimit2; - this.paint(uSplW, uSplH); - if (bBarEnabled) - { - xEnableDrag(barEle, null, barOnDrag, null); - barEle.style.cursor = bHorizontal ? 'e-resize' : 'n-resize'; - } - splEle.style.visibility = 'visible'; - -} // end xSplitter diff --git a/modules/lemonldap-ng-manager/example/skins/default/manager.js b/modules/lemonldap-ng-manager/example/skins/default/manager.js index 4a4216e19..70625b936 100644 --- a/modules/lemonldap-ng-manager/example/skins/default/manager.js +++ b/modules/lemonldap-ng-manager/example/skins/default/manager.js @@ -69,6 +69,7 @@ function display(div,title) { $('#newkb,#newrb,#delkb,#newkbr,#newrbr,#bdelvh').hide(); } function none(id) { + currentId=id; display('default',''); } function hashRoot(){ diff --git a/modules/lemonldap-ng-manager/example/skins/default/xlib.js b/modules/lemonldap-ng-manager/example/skins/default/xlib.js deleted file mode 100644 index 7e586bb2a..000000000 --- a/modules/lemonldap-ng-manager/example/skins/default/xlib.js +++ /dev/null @@ -1,196 +0,0 @@ -/* Compiled from X 4.18 by XC 1.07 on 17Feb09 */ -function xEvent(evt){var e=evt||window.event;if(!e)return;this.type=e.type;this.target=e.target||e.srcElement;this.relatedTarget=e.relatedTarget;/*@cc_on if(e.type=='mouseover')this.relatedTarget=e.fromElement;else if(e.type=='mouseout')this.relatedTarget=e.toElement;@*/if(xDef(e.pageX)){this.pageX=e.pageX;this.pageY=e.pageY;}else if(xDef(e.clientX)){this.pageX=e.clientX+xScrollLeft();this.pageY=e.clientY+xScrollTop();}if(xDef(e.offsetX)){this.offsetX=e.offsetX;this.offsetY=e.offsetY;}else if(xDef(e.layerX)){this.offsetX=e.layerX;this.offsetY=e.layerY;}else{this.offsetX=this.pageX-xPageX(this.target);this.offsetY=this.pageY-xPageY(this.target);}this.keyCode=e.keyCode||e.which||0;this.shiftKey=e.shiftKey;this.ctrlKey=e.ctrlKey;this.altKey=e.altKey;if(typeof e.type=='string'){if(e.type.indexOf('click')!=-1){this.button=0;}else if(e.type.indexOf('mouse')!=-1){this.button=e.button;/*@cc_on if(e.button&1)this.button=0;else if(e.button&4)this.button=1;else if(e.button&2)this.button=2;@*/}}}xLibrary={version:'4.18',license:'GNU LGPL',url:'http://cross-browser.com/'};function xAddEventListener(e,eT,eL,cap){if(!(e=xGetElementById(e)))return;eT=eT.toLowerCase();if(e.addEventListener)e.addEventListener(eT,eL,cap||false);else if(e.attachEvent)e.attachEvent('on'+eT,eL);else{var o=e['on'+eT];e['on'+eT]=typeof o=='function'?function(v){o(v);eL(v);}:eL;}}function xCamelize(cssPropStr){var i,c,a=cssPropStr.split('-');var s=a[0];for(i=1;iw.innerWidth)v-=16;}return v;}function xClientWidth(){var v=0,d=document,w=window;if((!d.compatMode||d.compatMode=='CSS1Compat')&&!w.opera&&d.documentElement&&d.documentElement.clientWidth){v=d.documentElement.clientWidth;}else if(d.body&&d.body.clientWidth){v=d.body.clientWidth;}else if(xDef(w.innerWidth,w.innerHeight,d.height)){v=w.innerWidth;if(d.height>w.innerHeight)v-=16;}return v;}function xDef(){for(var i=0;i=eX+l&&x<=eX+xWidth(e)-r&&y>=eY+t&&y<=eY+xHeight(e)-b);}function xHeight(e,h){if(!(e=xGetElementById(e)))return 0;if(xNum(h)){if(h<0)h=0;else h=Math.round(h);}else h=-1;var css=xDef(e.style);if(e==document||e.tagName.toLowerCase()=='html'||e.tagName.toLowerCase()=='body'){h=xClientHeight();}else if(css&&xDef(e.offsetHeight)&&xStr(e.style.height)){if(h>=0){var pt=0,pb=0,bt=0,bb=0;if(document.compatMode=='CSS1Compat'){var gcs=xGetComputedStyle;pt=gcs(e,'padding-top',1);if(pt!==null){pb=gcs(e,'padding-bottom',1);bt=gcs(e,'border-top-width',1);bb=gcs(e,'border-bottom-width',1);}else if(xDef(e.offsetHeight,e.style.height)){e.style.height=h+'px';pt=e.offsetHeight-h;}}h-=(pt+pb+bt+bb);if(isNaN(h)||h<0)return;else e.style.height=h+'px';}h=e.offsetHeight;}else if(css&&xDef(e.style.pixelHeight)){if(h>=0)e.style.pixelHeight=h;h=e.style.pixelHeight;}return h;}function xLeft(e,iX){if(!(e=xGetElementById(e)))return 0;var css=xDef(e.style);if(css&&xStr(e.style.left)){if(xNum(iX))e.style.left=iX+'px';else{iX=parseInt(e.style.left);if(isNaN(iX))iX=xGetComputedStyle(e,'left',1);if(isNaN(iX))iX=0;}}else if(css&&xDef(e.style.pixelLeft)){if(xNum(iX))e.style.pixelLeft=iX;else iX=e.style.pixelLeft;}return iX;}function xMoveTo(e,x,y){xLeft(e,x);xTop(e,y);}function xNum(){for(var i=0;i=0){var pl=0,pr=0,bl=0,br=0;if(document.compatMode=='CSS1Compat'){var gcs=xGetComputedStyle;pl=gcs(e,'padding-left',1);if(pl!==null){pr=gcs(e,'padding-right',1);bl=gcs(e,'border-left-width',1);br=gcs(e,'border-right-width',1);}else if(xDef(e.offsetWidth,e.style.width)){e.style.width=w+'px';pl=e.offsetWidth-w;}}w-=(pl+pr+bl+br);if(isNaN(w)||w<0)return;else e.style.width=w+'px';}w=e.offsetWidth;}else if(css&&xDef(e.style.pixelWidth)){if(w>=0)e.style.pixelWidth=w;w=e.style.pixelWidth;}return w;}/* Compiled from X 4.18 by XC 1.07 on 17Feb09 */ -function xEvent(evt){var e=evt||window.event;if(!e)return;this.type=e.type;this.target=e.target||e.srcElement;this.relatedTarget=e.relatedTarget;/*@cc_on if(e.type=='mouseover')this.relatedTarget=e.fromElement;else if(e.type=='mouseout')this.relatedTarget=e.toElement;@*/if(xDef(e.pageX)){this.pageX=e.pageX;this.pageY=e.pageY;}else if(xDef(e.clientX)){this.pageX=e.clientX+xScrollLeft();this.pageY=e.clientY+xScrollTop();}if(xDef(e.offsetX)){this.offsetX=e.offsetX;this.offsetY=e.offsetY;}else if(xDef(e.layerX)){this.offsetX=e.layerX;this.offsetY=e.layerY;}else{this.offsetX=this.pageX-xPageX(this.target);this.offsetY=this.pageY-xPageY(this.target);}this.keyCode=e.keyCode||e.which||0;this.shiftKey=e.shiftKey;this.ctrlKey=e.ctrlKey;this.altKey=e.altKey;if(typeof e.type=='string'){if(e.type.indexOf('click')!=-1){this.button=0;}else if(e.type.indexOf('mouse')!=-1){this.button=e.button;/*@cc_on if(e.button&1)this.button=0;else if(e.button&4)this.button=1;else if(e.button&2)this.button=2;@*/}}}xLibrary={version:'4.18',license:'GNU LGPL',url:'http://cross-browser.com/'};function xAddEventListener(e,eT,eL,cap){if(!(e=xGetElementById(e)))return;eT=eT.toLowerCase();if(e.addEventListener)e.addEventListener(eT,eL,cap||false);else if(e.attachEvent)e.attachEvent('on'+eT,eL);else{var o=e['on'+eT];e['on'+eT]=typeof o=='function'?function(v){o(v);eL(v);}:eL;}}function xPreventDefault(e){if(e&&e.preventDefault)e.preventDefault();else if(window.event)window.event.returnValue=false;}function xRemoveEventListener(e,eT,eL,cap){if(!(e=xGetElementById(e)))return;eT=eT.toLowerCase();if(e.removeEventListener)e.removeEventListener(eT,eL,cap||false);else if(e.detachEvent)e.detachEvent('on'+eT,eL);else e['on'+eT]=null;}function xStopPropagation(evt){if(evt&&evt.stopPropagation)evt.stopPropagation();else if(window.event)window.event.cancelBubble=true;}// xEnableDrag r8, Copyright 2002-2007 Michael Foster (Cross-Browser.com) -// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL - -function xEnableDrag(id,fS,fD,fE) -{ - var mx = 0, my = 0, el = xGetElementById(id); - if (el) { - el.xDragEnabled = true; - xAddEventListener(el, 'mousedown', dragStart, false); - } - // Private Functions - function dragStart(e) - { - if (el.xDragEnabled) { - var ev = new xEvent(e); - xPreventDefault(e); - mx = ev.pageX; - my = ev.pageY; - xAddEventListener(document, 'mousemove', drag, false); - xAddEventListener(document, 'mouseup', dragEnd, false); - if (fS) { - fS(el, ev.pageX, ev.pageY, ev); - } - } - } - function drag(e) - { - var ev, dx, dy; - xPreventDefault(e); - ev = new xEvent(e); - dx = ev.pageX - mx; - dy = ev.pageY - my; - mx = ev.pageX; - my = ev.pageY; - if (fD) { - fD(el, dx, dy, ev); - } - else { - xMoveTo(el, xLeft(el) + dx, xTop(el) + dy); - } - } - function dragEnd(e) - { - var ev = new xEvent(e); - xPreventDefault(e); - xRemoveEventListener(document, 'mouseup', dragEnd, false); - xRemoveEventListener(document, 'mousemove', drag, false); - if (fE) { - fE(el, ev.pageX, ev.pageY, ev); - } - if (xEnableDrag.drop) { - xEnableDrag.drop(el, ev); - } - } -} - -xEnableDrag.drops = []; // static property -// xFirstChild r4, Copyright 2004-2007 Michael Foster (Cross-Browser.com) -// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL - -function xFirstChild(e,t) -{ - e = xGetElementById(e); - var c = e ? e.firstChild : null; - while (c) { - if (c.nodeType == 1 && (!t || c.nodeName.toLowerCase() == t.toLowerCase())){break;} - c = c.nextSibling; - } - return c; -} -// xNextSib r4, Copyright 2005-2007 Michael Foster (Cross-Browser.com) -// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL - -function xNextSib(e,t) -{ - e = xGetElementById(e); - var s = e ? e.nextSibling : null; - while (s) { - if (s.nodeType == 1 && (!t || s.nodeName.toLowerCase() == t.toLowerCase())){break;} - s = s.nextSibling; - } - return s; -} -// xSplitter r3, Copyright 2006-2007 Michael Foster (Cross-Browser.com) -// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL - -function xSplitter(sSplId, uSplX, uSplY, uSplW, uSplH, bHorizontal, uBarW, uBarPos, uBarLimit1, uBarLimit2, bBarEnabled, uSplBorderW, oSplChild1, oSplChild2) -{ - // Private - - var pane1, pane2, splW, splH; - var splEle, barPos, barLim1, barLim2, barEle; - - function barOnDrag(ele, dx, dy) - { - var bp; - if (bHorizontal) - { - bp = barPos + dx; - if (bp < barLim1 || bp > splW - barLim2) { return; } - xWidth(pane1, xWidth(pane1) + dx); - xLeft(barEle, xLeft(barEle) + dx); - xWidth(pane2, xWidth(pane2) - dx); - xLeft(pane2, xLeft(pane2) + dx); - barPos = bp; - } - else - { - bp = barPos + dy; - if (bp < barLim1 || bp > splH - barLim2) { return; } - xHeight(pane1, xHeight(pane1) + dy); - xTop(barEle, xTop(barEle) + dy); - xHeight(pane2, xHeight(pane2) - dy); - xTop(pane2, xTop(pane2) + dy); - barPos = bp; - } - if (oSplChild1) { oSplChild1.paint(xWidth(pane1), xHeight(pane1)); } - if (oSplChild2) { oSplChild2.paint(xWidth(pane2), xHeight(pane2)); } - } - - // Public - - this.paint = function(uNewW, uNewH, uNewBarPos, uNewBarLim1, uNewBarLim2) // uNewBarPos and uNewBarLim are optional - { - if (uNewW == 0) { return; } - var w1, h1, w2, h2; - splW = uNewW; - splH = uNewH; - barPos = uNewBarPos || barPos; - barLim1 = uNewBarLim1 || barLim1; - barLim2 = uNewBarLim2 || barLim2; - xMoveTo(splEle, uSplX, uSplY); - xResizeTo(splEle, uNewW, uNewH); - if (bHorizontal) - { - w1 = barPos; - h1 = uNewH - 2 * uSplBorderW; - w2 = uNewW - w1 - uBarW - 2 * uSplBorderW; - h2 = h1; - xMoveTo(pane1, 0, 0); - xResizeTo(pane1, w1, h1); - xMoveTo(barEle, w1, 0); - xResizeTo(barEle, uBarW, h1); - xMoveTo(pane2, w1 + uBarW, 0); - xResizeTo(pane2, w2, h2); - } - else - { - w1 = uNewW - 2 * uSplBorderW;; - h1 = barPos; - w2 = w1; - h2 = uNewH - h1 - uBarW - 2 * uSplBorderW; - xMoveTo(pane1, 0, 0); - xResizeTo(pane1, w1, h1); - xMoveTo(barEle, 0, h1); - xResizeTo(barEle, w1, uBarW); - xMoveTo(pane2, 0, h1 + uBarW); - xResizeTo(pane2, w2, h2); - } - if (oSplChild1) - { - pane1.style.overflow = 'hidden'; - oSplChild1.paint(w1, h1); - } - if (oSplChild2) - { - pane2.style.overflow = 'hidden'; - oSplChild2.paint(w2, h2); - } - }; - - // Constructor - - splEle = xGetElementById(sSplId); // we assume the splitter has 3 DIV children and in this order: - pane1 = xFirstChild(splEle, 'DIV'); - pane2 = xNextSib(pane1, 'DIV'); - barEle = xNextSib(pane2, 'DIV'); - // --- slightly dirty hack - pane1.style.zIndex = 2; - pane2.style.zIndex = 2; - barEle.style.zIndex = 1; - // --- - barPos = uBarPos; - barLim1 = uBarLimit1; - barLim2 = uBarLimit2; - this.paint(uSplW, uSplH); - if (bBarEnabled) - { - xEnableDrag(barEle, null, barOnDrag, null); - barEle.style.cursor = bHorizontal ? 'e-resize' : 'n-resize'; - } - splEle.style.visibility = 'visible'; - -} // end xSplitter diff --git a/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Uploader.pm b/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Uploader.pm index f6795e2fe..e59814b9c 100644 --- a/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Uploader.pm +++ b/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Uploader.pm @@ -30,22 +30,25 @@ sub confUpload { $$rdata =~ s///g; $$rdata =~ s/
  • //g; - # Apply XSLT stylesheet to returned datas + # 1. ANALYSE DATAS + + # 1.1 Apply XSLT stylesheet to returned datas my $result = $self->stylesheet->transform( $self->parser->parse_string( '' . $$rdata . '' ) ) ->documentElement(); - # Get configuration number + # 1.2 Get configuration number unless ( $self->{cfgNum} = $result->getChildrenByTagName('conf')->[0]->getAttribute('value') ) { die "No configuration number found"; } my $newConf = { cfgNum => $self->{cfgNum} }; - - # Loading returned parameters my $errors = {}; + + # 1.3 Load and test returned parameters + # => begin loop foreach ( @{ $result->getChildrenByTagName('element') } ) { my ( $id, $name, $value ) = ( $_->getAttribute('id'), @@ -74,8 +77,13 @@ sub confUpload { if ( $test->{'*'} and $id =~ /\// ) { $test = $test->{'*'} } - # Tests (no test for hash root nodes) + # 1.3.1 Tests: + + # No tests for some keys unless ( $test->{keyTest} and ( $id !~ /\// or $test->{'*'} ) ) { + + # 1.3.1.1 Tests that return an error + # (parameter will not be stored in $newConf) if ( $test->{keyTest} ) { ( $res, $m ) = $self->applyTest( $test->{keyTest}, $name ); unless ($res) { @@ -90,6 +98,8 @@ sub confUpload { next; } } + + # 1.3.1.2 Tests that return a warning if ( $test->{warnKeyTest} ) { ( $res, $m ) = $self->applyTest( $test->{warnKeyTest}, $name ); unless ($res) { @@ -103,13 +113,15 @@ sub confUpload { } } } + + # 1.3.2 Store accepted parameter in $newConf $self->setKeyToH( $newConf, $confKey, $test->{keyTest} ? ( ( $id !~ /\// or $test->{'*'} ) ? {} : ( $name => $value ) ) : $value ); - } + } # END LOOP - # Loading unchanged parameters (ajax nodes not open) + # 1.4 Loading unchanged parameters (ajax nodes not open) foreach ( @{ $result->getChildrenByTagName('ignore') } ) { my $node = $_->getAttribute('value'); $node =~ s/^.*node=(.*?)(?:&.*)?\}$/$1/; @@ -125,38 +137,73 @@ sub confUpload { } } - # Author attributes - $newConf->{cfgAuthor} = $ENV{AUTH_USER} || 'anonymous'; + # 1.5 Author attributes for accounting + $newConf->{cfgAuthor} = $ENV{REMOTE_USER} || 'anonymous'; $newConf->{cfgAuthorIP} = $ENV{REMOTE_ADDR}; $newConf->{cfgDate} = time(); - #print STDERR Dumper( $newConf, $errors ); + # 2. SAVE CONFIGURATION + + $errors->{result}->{other} = ''; + + # 2.1 Don't store configuration if a syntax error was detected if ( $errors->{errors} ) { $errors->{result}->{cfgNum} = 0; $errors->{result}->{msg} = $self->translate('syntaxError'); + $self->_sub( 'userInfo', + "Configuration rejected for $newConf->{cfgAuthor}: syntax error" ); } + + # 2.2 Try to save configuration else { + + # if "force" is set, Lemonldap::NG::Common::Conf accept it even if + # conf database is locked or conf number isn't current number (used to + # restore an old configuration) $self->confObj->{force} = 1 if ( $self->param('force') ); + + # Call saveConf() $errors->{result}->{cfgNum} = $self->confObj->saveConf($newConf); - $errors->{result}->{other} = ''; - $errors->{result}->{msg} = ( - $errors->{result}->{cfgNum} > 0 - ? $self->translate('confSaved') - : $self->translate( - { - CONFIG_WAS_CHANGED, 'confWasChanged', - UNKNOWN_ERROR, 'unknownError', - DATABASE_LOCKED, 'databaseLocked', - UPLOAD_DENIED, 'uploadDenied', - SYNTAX_ERROR, 'syntaxError', - }->{ $errors->{result}->{cfgNum} } - ) - ); + + # 2.2.1 Prepare response + my $msg; + + # case "success" + if ( $errors->{result}->{cfgNum} > 0 ) { + + # Store accounting datas to the response $errors->{cfgDatas} = { cfgAuthor => $newConf->{cfgAuthor}, cfgAuthorIP => $newConf->{cfgAuthorIP}, cfgDate => $newConf->{cfgDate} }; + $msg = 'confSaved'; + + # Log success using Lemonldap::NG::Common::CGI::userNotice(): + # * in system logs if "syslog" is set + # * in apache errors file otherwise + $self->_sub( 'userNotice', +"Conf $errors->{result}->{cfgNum} saved by $newConf->{cfgAuthor}" + ); + } + + # other cases + else { + $msg = { + CONFIG_WAS_CHANGED, 'confWasChanged', + UNKNOWN_ERROR, 'unknownError', + DATABASE_LOCKED, 'databaseLocked', + UPLOAD_DENIED, 'uploadDenied', + SYNTAX_ERROR, 'syntaxError', + }->{ $errors->{result}->{cfgNum} }; + + # Log failure using Lemonldap::NG::Common::CGI::userError() + $self->_sub( 'userError', + "Configuration rejected for $newConf->{cfgAuthor}: $msg" ); + } + + # Translate msg returned + $errors->{result}->{msg} = $self->translate($msg); if ( $errors->{result}->{cfgNum} == CONFIG_WAS_CHANGED or $errors->{result}->{cfgNum} == DATABASE_LOCKED ) { @@ -164,6 +211,8 @@ sub confUpload { . $self->translate('clickHereToForce') . ''; } } + + # 3. PREPARE JSON RESPONSE my $buf = '{'; my $i = 0; while ( my ( $type, $h ) = each %$errors ) { @@ -181,6 +230,8 @@ sub confUpload { $i++; } $buf .= '}'; + + # 4. SEND JSON RESPONSE print $self->header( -type => 'application/json', -Content_Length => length($buf)