Commit 50727aa3 authored by Clément OUDOT's avatar Clément OUDOT

Initial import from SF and other sources

parents
#!/usr/bin/perl -w
#use strict;
###################################################################
#
sub getStyle {
my $style = $_[0];
if ($style =~ /map/i) {
$_[1] = 0;
return "conf_style";
}
if ($style =~ /lectro/i) {
$_[1] = 1;
return "simpage";
}
if ($style =~ /golf/i) {
$_[1] = 2;
return "golf_style";
}
}
###################################################################
#
sub main {
my $icheck = -1;
$ch = getStyle("electro", $icheck);
print( "Resultat:\n" );
print( "-- style = $ch\n" );
print( "-- check = $icheck\n" );
}
###################################################################
#
main;
#
###################################################################
#!/usr/bin/perl -w
#use strict;
###################################################################
#
sub getStyle {
if ($_[0] =~ /map/i) {
return ("conf_style", 0);
}
if ($_[0] =~ /lectro/i) {
return ("simpage", 1);
}
if ($_[0] =~ /golf/i) {
return ("golf_style", 2);
}
}
###################################################################
#
sub main {
($ch, $icheck) = getStyle("electro");
print( "Resultat:\n" );
print( "-- style = $ch\n" );
print( "-- check = $icheck\n" );
}
###################################################################
#
main;
#
###################################################################
#!/usr/bin/perl -w
#use strict;
use Template;
use CGI;
use Data::Dumper;
require './lemonldap-lib.pl';
my $tt = Template->new( {# ABSOLUTE => 1,
PREC_CHOMP =>1,
POST_CHOMP =>1, } );
##########################################
# chargement des infos de la page #
##########################################
my $message = 0;
my $dump1;
if (defined (CGI::param ('submitAddCluster')) ) { ## traitement d un nouveau node
my $new_clexml = CGI::param('idn');
if( !length($new_clexml)){
$message = $text{ 'lab_error_8' };
} else {
my $location = CGI::param('Locationn') ;
my $address = CGI::param('Addressn') ;
my $hash = {} ;
$hash->{'location'} = $location if $location;
$hash->{'address'} = $address if $address;
my $xmlemon = getXML( $config{'XML_file'} );
my $chapter = getChapterXML( $xmlemon, 'cluster' );
my $id = CGI::param('id');
my $clust = $chapter->{ $id } ;
if( defined( $clust->{ 'node' }->{ $new_clexml } ) ){
$message = $text{ 'lab_error_9' };
}else {
$clust->{ 'node' }->{ $new_clexml } = $hash;
###### ecriture par XMLOUT #############
&writeXML( $xmlemon, $config{'XML_file'});
}
}
}
## vars pour affichage de caract. du node selectionn / supprim
my $nodeID = 0;
my $nodeSimple = 0;
my $nodeLoc = 0;
if (defined (CGI::param ('RemoveNode')) ) { ## SUPPRESSION d un node
my $clenode = CGI::param('idn');
$nodeID = $clenode;
$nodeSimple = CGI::param('Addressn') ;
$nodeLoc = CGI::param('Locationn') ;
my $xmlemon = getXML( $config{'XML_file'} );
my $chapter = getChapterXML( $xmlemon, 'cluster' );
my $id = CGI::param('id');
my $clust = $chapter->{ $id } ;
my @knodes = keys( %{$clust->{'node'}} );
$dump1 = Dumper( @knodes );
delete( $clust->{ 'node' }->{ $clenode } );
if( @knodes == 1 ){
delete( $clust->{ 'node' } );
}
###### ecriture par XMLOUT #############
&writeXML( $xmlemon, $config{'XML_file'});
}
if (! defined (CGI::param ("submitCluster")) ) {
my $conf = &getXmlPage( "cluster" );
my $filethtml = $conf->{template};
my $title = $text{ &dePourCent( $conf->{title} ) };
my $_style = CGI::param('style')||$config{Style};
my $tabular = [];
$mode = 'Expert' ;
$tabular = &getTab( $conf->{tabs}->{expert} );
$tabular = &polyGlotTab( $tabular, \%text );
$tabular = &ajustLink ($tabular,$mode,$_style);
$flipflop = 'Normal';
$styl = $config{'Style'};
my $composs = &getAllComposants( $conf->{composants}->{expert} );
$composs = &polyGlotTab( $composs, \%text );
my $xmlemon = getXML( $config{'XML_file'} );
my $chapter = getChapterXML( $xmlemon, "cluster" );
my @f = keys %{$chapter};
my $first = $f[0];
&TransformVars( $composs, $chapter );
############### I collect node info #####
my @combonodes;
if($chapter->{$first}->{node} ) {
my $node = $chapter->{$first}->{ "node" };
my @nodes = keys( %{$node} );
@nodes = sort( @nodes );
for( @nodes ) {
my $item = { "labOption" => $_, "idValue" => $_ };
push( @combonodes, $_ );
}
# list of node
# just label and add bouton
} else {
# just label and add bouton
}
my $flagShowRemo = 0;
if( defined (CGI::param('listNodes') )){
$nodeID = CGI::param('listNodes');
$nodeSimple = $chapter->{ $first }->{ 'node' }->{$nodeID}->{ 'address' };
$nodeLoc = $chapter->{ $first }->{ 'node' }->{$nodeID}->{ 'location' };
$flagShowRemo= 1;
}
$vars= { style => $styl,
title => $title,
mode => $mode,
css => $_style,
label => $flipflop,
parent => $0,
tab_about => $tabular,
langa => \%text,
composall => $composs,
combonodes => \@combonodes,
message => $message,
nodeID => $nodeID,
nodeSimple => $nodeSimple,
nodeLoc => $nodeLoc,
flagShowRemo => $flagShowRemo
};
$vars->{style} = &getStyle($styl, $vars->{checked});
print "Content-type: text/html\n";
$tt->process($filethtml,$vars) || die $tt->error();
print( "<HR> $dump1 <HR>" );
} else { ## Traitement du "SUBMIT"
##########################################################
# print "Content-type: text/html\n";
# print( "\n" );
# my @lo =CGI::param();
# my $l =Dumper(@lo);
# print "$l";
# print( "<BR>" );
my $_style = CGI::param('style');
my $mode = CGI::param('mode');
my $old_clexml = CGI::param('_id');
my $new_clexml = CGI::param('id');
my $location = CGI::param('Location') ;
my $address = CGI::param('Address') ;
my $hash = {} ;
$hash->{'location'} = $location if $location;
$hash->{'address'} = $address if $address;
$hash->{'node'} = $node if $node;
my $xmlemon = getXML( $config{'XML_file'} );
my $chapter = getChapterXML( $xmlemon, "cluster" );
my $l= Dumper ($chapter);
delete $chapter->{$old_clexml};
if($new_clexml ) {
$xmlemon->{cluster}->{$new_clexml}= $hash;
}
else {
delete $xmlemon->{cluster} ;
}
###### ecriture par XMLOUT #############
&writeXML( $xmlemon, $config{'XML_file'});
#### affichage de la page ttconfig sur param
# $l= Dumper ($xmlemon);
# print "final $l";
&redirect( "index.cgi?mode=$mode&style=$_style" );
}
#
############ C FINI
#!/usr/bin/perl
use Data::Dumper;
use XML::Simple;
sub getXML {
my $confile = $_[0];
my $pxml = XMLin( $confile, "ForceArray" => "1" );
return( $pxml );
}
sub writeXML {
my $pxml = $_[0];
my $namef = $_[1];
my $rootN = $_[2] || "lemonldapconfig";
open( $fout, ">$namef" ) || die("Oops !! couldn't open $namef !!??");
XMLout( $pxml, OutputFile => $fout,
AttrIndent => 1,
RootName => $rootN,
KeyAttr => { session =>'id',
cache =>'id',
handler =>'id',
application =>'id',
domain =>'id',
cluster =>'id',
node => 'id',
} );
close( $fout );
}
##----------------------------------------------------------------------------------------
## MAJ DU XML
sub videhash {
my $h = $_[ 0 ];
my $pxml = $_[ 1 ];
if (exists ($h->{lemonldapdomain})) {
my $id_handler = $h->{ 'lemonldaphandlerid' };
my $id_domain = $h->{ 'lemonldapdomain' };
###################################
## maj
print( "DOMAINE : $id_domain \t --> $id_handler\n" );
if( length($h->{ 'ipadress' } )) {
$pxml->{ 'domain' }->{$id_domain}->{ 'handler' }->{ $id_handler }->{ 'VirtualHost' } = 'byIPAdress';
$pxml->{ 'domain' }->{$id_domain}->{ 'handler' }->{ $id_handler }->{ 'IPAdress' } = $h->{ 'ipadress' };
}
else {
$pxml->{ 'domain' }->{$id_domain}->{ 'handler' }->{ $id_handler }->{ 'VirtualHost' } = 'byName';
}
my %kk = ( 'lemonldapportal' => ['Portal' , ''] ,
'lemonldapbasepub' => ['BasePub' , ''] ,
'lemonldapbasepriv' => ['BasePriv' , ''] ,
'lemonldapenabledproxy' => ['EnableLWPProxy', '0'] ,
'lemonldapattrldap' => ['Organization', ''] ,
'lemonldapcodeappli' => ['AppliCode' , ''] ,
'lemonldapdisabled' => ['DisableAccessControl', '0'] ,
'lemonldapstopcookie' => ['StopCookie' , '0'] ,
'lemonldaprecursive' => ['ChaseRedirect', '0'] ,
'lemonldapproxyext' => ['ProxyExt' , ''] ,
'lemonldapics' => ['ProxyPatterns', ''] ,
'lemonldapmultihoming' => ['MultiHoming' , -1] ,
'lemonldaplwptimeout' => ['LWPTimeout' , ''] ,
'lemonldapsoftcontrol' => ['SoftControl' , '0'] ,
'lemonldapheader' => ['Header' , ''] ,
'lemonldapallow' => ['Allow' , ''] ,
'lemonldappluginpolicy' => ['PolicyPlugIn', ''] ,
'lemonldappluginhtml' => ['RewritePlugIn', ''] ,
'lemonldappluginheader' => ['HeaderPlugIn', ''] ,
'lemonldappluginbackend' => ['BackendPlugIn','']
);
my @kapa = keys( %kk );
for( @kapa ){
my $k = $_;
my $igp = $kk{ $k }[0];
my $def = $kk{ $k }[1];
if( length( $h->{ $k } )){
$pxml->{ 'domain' }->{$id_domain}->{ 'handler' }->{ $id_handler }->{ $igp } = $h->{ $k };
} else {
if( $def == -1 ){
delete( $pxml->{ 'domain' }->{$id_domain}->{ 'handler' }->{ $id_handler }->{ $igp } );
} else {
$pxml->{ 'domain' }->{$id_domain}->{ 'handler' }->{ $id_handler }->{ $igp } = $def;
}
}
}
}
}
##-------------------------------------------------------------------------------------------
## MISE A JOUR DES NOMS DE VARIABLES
sub MajVarNames {
my $pxml = $_[0];
## CACHE.configIpcKey --> CACHE.ConfigFile
##------------------------------------------
my @confs = keys( %{$pxml->{'cache'} } );
for( @confs ){
my $conf = $_;
my $ipc = $pxml->{'cache'}->{ $conf }->{'configIpcKey'};
if( $ipc ){
delete( $pxml->{'cache'}->{ $conf }->{'configIpcKey'} );
$pxml->{'cache'}->{ $conf }->{'ConfigFile'} = $ipc;
print(" Cache -> $conf \t\t configIpcKey -> $conf TO ConfigFile\n");
}
}
## Domain.Session --> Domain.SessionStore
##------------------------------------------
my @doms = keys( %{ $pxml->{'domain'} } );
for( @doms ){
# domaine
my $dom = $_;
my $sess = $pxml->{'domain'}->{ $dom }->{ 'Session' };
if( $sess ){
delete( $pxml->{'domain'}->{ $dom }->{ 'Session' } );
$pxml->{'domain'}->{ $dom }->{ 'SessionStore' } = $sess;
print(" Domaine -> $dom \t\t Session -> $sess TO SessionStore\n");
}
## HANDLERS
##---------------------------------
# recup ts les handlers d un domaine
my @hands = keys( %{ $pxml->{'domain'}->{ $dom }->{ 'handler' } } );
for( @hands ){
my $hand = $_;
my $enabledProxy = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'Enabledproxy' } ;
my $attrLdap = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'AttrLdap' } ;
my $codeAppli = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'CodeAppli' } ;
my $disabled = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'Disabled' } ;
my $plugHtml = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'PlugInHtml' } ;
my $plugBackend = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'PlugInBackend' } ;
my $plugHeader = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'PlugInHeader' } ;
my $plugPolicy = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'PlugInPolicy' } ;
my $ics = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'Ics' } ;
my $recursive = $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'Recursive' } ;
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'Enabledproxy' } );
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'AttrLdap' } );
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'CodeAppli' } );
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'Disabled' } );
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'PlugInHtml' } );
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'PlugInBackend' });
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'PlugInHeader' } );
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'PlugInPolicy' } );
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'Ics' } );
delete( $pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'Recursive' } );
if($enabledProxy ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'EnableLWPProxy' } = $enabledProxy;
print(" Domaine -> $dom \t Handler -> $hand\t Enabledproxy TO EnableLWPProxy\n");
}
if($attrLdap ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'Organization' } = $attrLdap ;
print(" Domaine -> $dom \t Handler -> $hand\t AttrLdap TO Organization\n");
}
if($codeAppli ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'AppliCode' } = $codeAppli ;
print(" Domaine -> $dom \t Handler -> $hand\t CodeAppli TO AppliCode\n");
}
if($disabled ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'DisableAccessControl' } = $disabled ;
print(" Domaine -> $dom \t Handler -> $hand\t Disabled TO DisableAccessControl\n");
}
if($plugHtml ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'RewritePlugIn' } = $plugHtml ;
print(" Domaine -> $dom \t Handler -> $hand\t PlugInHtml TO RewritePlugIn\n");
}
if($plugBackend ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'BackendPlugIn' } = $plugBackend ;
print(" Domaine -> $dom \t Handler -> $hand\t PlugInBackend TO BackendPlugIn\n");
}
if($plugHeader ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'HeaderPlugIn' } = $plugHeader ;
print(" Domaine -> $dom \t Handler -> $hand\t PlugInHeader TO HeaderPlugIn\n");
}
if($plugPolicy ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'PolicyPlugIn' } = $plugPolicy ;
print(" Domaine -> $dom \t Handler -> $hand\t PlugInPolicy TO PolicyPlugIn\n");
}
if($ics ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'ProxyPatterns' } = $ics ;
print(" Domaine -> $dom \t Handler -> $hand\t Ics TO ProxyPatterns\n");
}
if($recursive ) {
$pxml->{'domain'}->{ $dom }->{ 'handler' }->{ $hand }->{ 'ChaseRedirect' } = $recursive ;
print(" Domaine -> $dom \t Handler -> $hand\t Recursive TO ChaseRedirect\n");
}
}
}
}
sub main {
my $confile = $_[0];
my $xmlfile = $_[1];
my %hash;
my $pxml = getXML( $xmlfile );
print( "\nVAR NAMES UPDATED :\n\n" );
MajVarNames( $pxml );
print( "\nHANDLERS UPDATED :\n\n" );
my $HF;
open( $HF, $confile ) || die("Couldn' open $confile !!\n");
while ( <$HF> ) {
chomp $_;
if (/\<virtual/i) {
# debut vh
if(%hash) {
videhash(\%hash, $pxml);
%hash =();
}
($hash{ipadress}) = /\s(\d.+).$/;
}
if(/<\/virtual/i && %hash ) {
videhash(\%hash, $pxml) ;
%hash =();
}
if( /perlsetvar/i ) {
my ($filler, $nom, $valeur) = /(perlsetvar)\s+(.+)\s+(.+)$/i ;
$nom=~ s/^\s+//g;
$nom=~ s/\s+$//g;
$valeur=~ s/^\s+//g;
$valeur=~ s/\s+$//g;
$valeur=~ s/^'+//g;
$valeur=~ s/'+$//g;
$nom=lc($nom);
$hash{$nom} = $valeur ;
}
}
## REWRITE XML FILE
##------------------
writeXML( $pxml, $xmlfile );
}
############################################
if( @ARGV != 2 ){
print("-------------------------------------------------\n\n");
print("USAGE: conf2xml config_file_name xml_file_name (names with complete path)\n\n\n");
} else {
main($ARGV[0], $ARGV[1] );
print( "\n" );
}
############################################
XML_file=/opt/apache/conf/application_new.xml
httpd_conf=/opt/apache/conf/lemon.conf
XML_DTD=/opt/apache/conf/lemonldap.dtd
XML_file=/opt/apache/conf/application_new.xml
httpd_conf=/opt/apache/conf/lemon.conf
XML_DTD=/opt/apache/conf/lemonldap.dtd
XML_file=/opt/apache/conf/application_new.xml
httpd_conf=/opt/apache/conf/lemon.conf
XML_DTD=/opt/apache/conf/lemonldap.dtd
line1=Configurable options,11
XML_file=Full path to XML config file,0
httpd_conf=Full path to conf.d,0
Style= Style of GUI,1,maps-Old Maps,Electro-Electro,Golf-Golf
pid_file=Path to Apache PID file,0
start_cmd=Command to start apache,0
stop_cmd=Command to stop apache,0
restart_cmd=Command to restart apache,0
#!/usr/bin/perl
# configcache.cgi
# Display the icons for various types of lemonldapconfig options
use Data::Dumper;
require './lemonldap-lib.pl';
# Check if lemonlap is installed
&header($text{'index_title'}, "", undef, 1, 1, 0,
&help_search_link("lemonldap", "man", "doc", "google"));
print "<hr>\n";