Commit f8169c19 authored by Xavier Guimard's avatar Xavier Guimard

Notification system in progress :

 * File storage is running
 * DBI storage has not yet been tested
Documentation update
parent 7c1ff1d9
...@@ -162,7 +162,7 @@ ...@@ -162,7 +162,7 @@
tout va bien)</li> tout va bien)</li>
<li>error(language,code) : retourne le texte correspondant &agrave; <li>error(language,code) : retourne le texte correspondant &agrave;
l'erreur</li> l'erreur.</li>
</ul>Exemple de script client :<br /> </ul>Exemple de script client :<br />
<br /> <br />
...@@ -171,7 +171,7 @@ ...@@ -171,7 +171,7 @@
#!/usr/bin/perl -l #!/usr/bin/perl -l
use SOAP::Lite; use SOAP::Lite;
use Data::Dumper;<br /><br />my $soap = SOAP::Lite-&gt;proxy('http://auth.example.com/') use Data::Dumper;<br /><br />my $soap = SOAP::Lite-&gt;proxy('http://auth.example.com/')
-&gt;uri('urn:/Lemonldap/NG/Portal/SharedConf');<br /><br />my $r = $soap-&gt;getCookies( 'user', 'password' );<br /><br /># Catch SOAP errors -&gt;uri('urn:/Lemonldap/NG/Common/CGI/SOAPService');<br /><br />my $r = $soap-&gt;getCookies( 'user', 'password' );<br /><br /># Catch SOAP errors
<span class="java-keyword">if</span> ( $r-&gt;fault ) { <span class="java-keyword">if</span> ( $r-&gt;fault ) {
print STDERR <span class= print STDERR <span class=
"java-quote">"SOAP Error: "</span> . $r-&gt;fault-&gt;{faultstring}; "java-quote">"SOAP Error: "</span> . $r-&gt;fault-&gt;{faultstring};
......
...@@ -105,13 +105,15 @@ ...@@ -105,13 +105,15 @@
"wikiexternallink"><a href= "wikiexternallink"><a href=
"http://lemonldap.objectweb.org/NG/devel-doc/">learn "http://lemonldap.objectweb.org/NG/devel-doc/">learn
more</a></span>)<br /> more</a></span>)<br />
<img src="ok.png" alt="ok.png" /> Packages for RedHat/CentOS<br />
<h3 class="heading-1-1"><span id="HVersion1028200929">Version 1.0 <h3 class="heading-1-1"><span id="HVersion1028200929">Version 1.0
(2009)</span></h3><img src="warning_triangle.png" alt= (2009)</span></h3><img src="warning_triangle.png" alt=
"warning_triangle.png" /> Date and time parameters in access rules<br /> "warning_triangle.png" /> Date and time parameters in access rules<br />
<img src="warning_triangle.png" alt="warning_triangle.png" /> Monitoring <img src="warning_triangle.png" alt="warning_triangle.png" /> Monitoring
scripts (MRTG, Cacti, Nagios)<br /> scripts (MRTG, Cacti, Nagios)<br />
<img src="ok.png" alt="ok.png" /> Packages for RedHat/CentOS<br /> <img src="warning_triangle.png" alt="warning_triangle.png" /> Notification
system<br />
<img src="error.png" alt="error.png" /> Handler POST functionnalities, to <img src="error.png" alt="error.png" /> Handler POST functionnalities, to
fill authentication forms with login/password<br /> fill authentication forms with login/password<br />
<img src="error.png" alt="error.png" /> Portal and Manager trigger system, <img src="error.png" alt="error.png" /> Portal and Manager trigger system,
...@@ -135,7 +137,6 @@ ...@@ -135,7 +137,6 @@
<img src="error.png" alt="error.png" /> SNMP extensions for <img src="error.png" alt="error.png" /> SNMP extensions for
monitoring<br /> monitoring<br />
<img src="error.png" alt="error.png" /> Local password policy<br /> <img src="error.png" alt="error.png" /> Local password policy<br />
<img src="error.png" alt="error.png" /> Notification system<br />
<img src="error.png" alt="error.png" /> LQL parser (LDAP Query <img src="error.png" alt="error.png" /> LQL parser (LDAP Query
Language)<br /> Language)<br />
<img src="error.png" alt="error.png" /> Shared "grant" function<br /> <img src="error.png" alt="error.png" /> Shared "grant" function<br />
......
...@@ -91,6 +91,8 @@ lib/Lemonldap/NG/Portal/CDA.pm ...@@ -91,6 +91,8 @@ lib/Lemonldap/NG/Portal/CDA.pm
lib/Lemonldap/NG/Portal/Error.pm lib/Lemonldap/NG/Portal/Error.pm
lib/Lemonldap/NG/Portal/Menu.pm lib/Lemonldap/NG/Portal/Menu.pm
lib/Lemonldap/NG/Portal/Notification.pm lib/Lemonldap/NG/Portal/Notification.pm
lib/Lemonldap/NG/Portal/Notification/DBI.pm
lib/Lemonldap/NG/Portal/Notification/File.pm
lib/Lemonldap/NG/Portal/SharedConf.pm lib/Lemonldap/NG/Portal/SharedConf.pm
lib/Lemonldap/NG/Portal/Simple.pm lib/Lemonldap/NG/Portal/Simple.pm
lib/Lemonldap/NG/Portal/UserDBLDAP.pm lib/Lemonldap/NG/Portal/UserDBLDAP.pm
......
## @file
# DBI storage methods for notifications
## @class
# DBI storage methods for notifications
package Lemonldap::NG::Portal::Notification::DBI;
use strict;
## @method boolean prereq()
# Check if DBI parameters are set.
# @return true if all is OK
sub prereq {
my $self = shift;
$self->{dbiTable} = $self->{table} if ( $self->{table} );
unless ( $self->{dbiChain} ) {
$Lemonldap::NG::Common::Conf::msg =
'"dbiChain" is required in DBI notification type';
return 0;
}
print STDERR __PACKAGE__ . 'Warning: "dbiUser" parameter is not set'
unless ( $self->{dbiUser} );
1;
}
## @method hashref get(string uid,string ref)
# In file context, returns notifications corresponding to the user $uid.
# If $ref is set, returns only notification corresponding to this reference.
# @param $uid UID
# @param $ref Notification reference
# @return hashref where keys are internal reference and values are XML strings
sub get {
my ( $self, $uid, $ref ) = @_;
return () unless ($uid);
$uid =~ s/'/''/g;
$ref =~ s/'/''/g;
$self->_execute(
"SELECT * FROM $self->{dbiTable} WHERE done IS NULL AND uid='$uid'"
. ( $ref ? " AND ref='$ref'" : '' )
. "ORDER BY date" )
or return ();
my $result;
while ( my $h = $self->{sth}->fetchrow_hashref() ) {
$result->{ "$h->{date}#$h->{uid}#$h->{ref}", $h->{xml} };
}
$self->warn( $self->{sth}->err() ) if ( $self->{sth}->err() );
return $result;
}
## @method boolean delete(string myref)
# Mark a notification as done.
# @param $myref identifier returned by get
sub delete {
my ( $self, $myref ) = @_;
my ( $d, $u, $r );
unless ( ( $d, $u, $r ) = ( $myref =~ /^(\d+)#(.+?)#(.+)$/ ) ) {
$self->warn("Bad reference $myref");
return 0;
}
$u =~ s/'/''/g;
$r =~ s/'/''/g;
$d =~ s/'/''/g;
my @ts = localtime();
$ts[5] += 1900;
$ts[4]++;
return $self->_execute(
"UPDATE $self->{dbiTable} SET done='$ts[5]-$ts[4],$ts[3] $ts[2]:$ts[1]' WHERE done IS NULL AND date='$d' AND uid='$u' AND ref='$r'"
);
}
## @method boolean newNotif(string date, string uid, string ref, string xml)
# Insert a new notification
# @param date Date
# @param uid UID
# @param ref Reference of the notification
# @param xml XML notification
# @return true if succeed
sub newNotif {
my ( $self, $date, $uid, $ref, $xml ) = @_;
$uid =~ s/'/''/g;
$ref =~ s/'/''/g;
$date =~ s/'/''/g;
$xml = $xml->serialize();
$xml =~ s/'/''/g;
return $self->_execute(
"INSERT INTO $self->{dbiTable} (date,uid,ref,xml) VALUES('$date','$uid','$ref','$xml')"
);
}
## @method private object _execute(string query)
# Execute a query and catch errors
# @return number of lines touched or 1 if select succeed
sub _execute {
my ( $self, $query ) = @_;
my $dbh = $self->dbh() or return 0;
unless ( $self->{sth} = $dbh->prepare($query) ) {
$self->warn( $dbh->errstr() );
return 0;
}
my $tmp;
unless ( $tmp = $self->{sth}->execute() ) {
$self->warn( $self->{sth}->errstr() );
return 0;
}
return $tmp;
}
## @method object private dbh()
# Return the DBI object (build it if needed).
# @return database handle object
sub dbh {
my $self = shift;
$self->{dbiTable} ||= "notifications";
return $self->{dbh} if ( $self->{dbh} and $self->{dbh}->ping );
my $r = DBI->connect_cached(
$self->{dbiChain}, $self->{dbiUser},
$self->{dbiPassword}, { RaiseError => 0 }
);
print STDERR "$DBI::errstr\n" unless ($r);
return $r;
}
1;
## @file
# File storage methods for notifications
## @class
# File storage methods for notifications
package Lemonldap::NG::Portal::Notification::File;
use strict;
use MIME::Base64;
## @method boolean prereq()
# Check if parameters are set and if storage directory exists.
# @return true if all is OK
sub prereq {
my $self = shift;
unless ( $self->{dirName} ) {
$Lemonldap::NG::Portal::Notification::msg =
'"dirName" is required in "File" configuration type !';
return 0;
}
if ( $self->{table} ) {
$self->{dirName} =~ s/\/conf\/?$//;
$self->{dirName} .= "/$self->{table}";
}
unless ( -d $self->{dirName} ) {
$Lemonldap::NG::Portal::Notification::msg =
"Directory \"$self->{dirName}\" does not exist !";
return 0;
}
1;
}
## @method hashref get(string uid,string ref)
# In file context, returns notifications corresponding to the user $uid.
# If $ref is set, returns only notification corresponding to this reference.
# @param $uid UID
# @param $ref Notification reference
# @return hashref where keys are filenames and values are XML strings
sub get {
my ( $self, $uid, $ref ) = @_;
return () unless ($uid);
opendir D, $self->{dirName};
my @notif;
unless ($ref) {
@notif = grep /^\d{8}_${uid}_\S*\.xml$/, readdir(D);
}
else {
my $tmp = encode_base64( $ref, '' );
@notif = grep /^\d{8}_${uid}_$tmp.xml$/, readdir(D);
}
close D;
my $files;
foreach my $file (@notif) {
unless ( open F, $self->{dirName} . "/$file" ) {
print STDERR "Unable to read notification $self->{dirName}/$_\n";
next;
}
$files->{$file} = join( '', <F> );
}
return $files;
}
## @method boolean delete(string myref)
# Mark a notification as done.
# @param $file identifier returned by get
sub delete {
my ( $self, $file ) = @_;
my $new = ( $file =~ /(.*?)(?:\.xml)$/ )[0] . '.done';
return rename( $self->{dirName} . "/$file", $self->{dirName} . "/$new" );
}
## @method boolean newNotif(string date, string uid, string ref, string xml)
# Insert a new notification
# @param date Date
# @param uid UID
# @param ref Reference of the notification
# @param xml XML notification
# @return true if succeed
sub newNotif {
my ( $self, $date, $uid, $ref, $xml ) = @_;
$date =~ s/-//g;
return ( 0, "Bad date" ) unless ( $date =~ /^\d{8}/ );
my $filename =
$self->{dirName}
. "/${date}_${uid}_"
. encode_base64( $ref, '' ) . ".xml";
return ( 0, 'This notification still exists' ) if ( -e $filename );
my $old = ( $filename =~ /(.*?)(?:\.xml)$/ )[0] . '.done';
return ( 0, 'This notification has been done' ) if ( -e $old );
open my $F, ">$filename" or return ( 0, "Unable to create $filename ($!)" );
binmode($F);
$xml->toFH($F);
return ( 0, "Unable to close $filename ($!)" ) unless ( close $F );
return 1;
}
1;
...@@ -145,10 +145,11 @@ sub new { ...@@ -145,10 +145,11 @@ sub new {
$tmp = $self->{notificationStorage}; $tmp = $self->{notificationStorage};
} }
else { else {
$tmp = $self->{lmConf}; (%$tmp) = ( %{ $self->{lmConf} } );
$self->abort( "notificationStorage not defined", $self->abort( "notificationStorage not defined",
"This parameter is required to use notification system" ) "This parameter is required to use notification system" )
unless ( ref($tmp) ); unless ( ref($tmp) );
$tmp->{type} =~ s/.*:://;
$tmp->{table} = 'notifications'; $tmp->{table} = 'notifications';
} }
$self->{notifObject} = Lemonldap::NG::Portal::Notification->new($tmp); $self->{notifObject} = Lemonldap::NG::Portal::Notification->new($tmp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment