)) {
+ if($ligne =~ m/License is for/){
+ $nbrusermax = $ligne;
+ $nbrusermax =~ s/.+License is for //g;
+ $nbrusermax =~ s/ Win32 MAPI users$//g;
+ $nbrusermax =~ s/ total users$//g;
+ last;
+ }
+ }
+ close(REVERSE);
+
+ # Affichage
+ # Display
+ print "$clef $key - $nbrusermax $nbrusertxt";
+ return 0;
+}
+
+# valid_keys est utilisé pour vérifier si la clef-CD rentré pour renregistré zarafa est valide
+##############################################################################################
+# valid_keys is used to verify if the CD-key enter for registered Zarafa is correct
+
+sub valid_keys {
+
+ my ($fm, $cd_key) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('INVALID_KEY');
+
+ if($cd_key =~ m/^\w{$licensekey}$/){
+ return "OK";
+ }
+ else {
+ return $return_error;
+ }
+}
+
+# display_cal sert à afficher un tableau contenant le nom des CAL ainsi que la clef associée
+############################################################################################
+# display_cal is used to display an array which contain all CAl and the key associated
+
+sub display_cal {
+
+ my $self = shift;
+ my $q = $self->{cgi};
+
+ # Localisation
+ my $calname = $self->localise('CALNAME');
+ my $calkey = $self->localise('CALKEY');
+ my $caldelete = $self->localise('DELETE');
+
+ # Affichage de l'en-tête du tableau
+ # Display of the header
+ print " \n \n ";
+ print $q->start_table ({-CLASS => "sme-border"}),"\n ";
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q, $calname,"header"),
+ esmith::cgi::genSmallCell($q, $calkey,"header"));
+
+
+ # Récupération du nom des fichiers CAL
+ # Recovery of the CAL file name
+ my $filekey;
+ opendir(OPENDIR, "/etc/zarafa/license") or die "Impossible d'ouvrir /etc/zarafa/license";
+ my @all_files = readdir (OPENDIR);
+ close(OPENDIR);
+
+ # Affichage du nom et de la clef
+ # Display of the name and the key
+ my @out = sort @all_files;
+ foreach my $file (@out) {
+ unless($file eq 'base' or $file eq '..' or $file eq '.'){
+ open(FILE, "/etc/zarafa/license/$file") or die "Impossible d'ouvrir $file";
+ $filekey = ;
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q, $file,"normal"),
+ esmith::cgi::genSmallCell($q, $filekey,"normal"));
+ close(FILE);
+ }
+ }
+
+ print qq( |
\n);
+
+ # Localisation
+ my $createCal = $self->localise('CAL_BUTTON');
+ my $createCal_bubble = $self->localise('CAL_BUTTON_BUBBLE');
+
+ # Affichage bouton ajouter CAL
+ # Display the CAL's create button
+ my $out ="$createCal";
+
+return $out;
+}
+
+# display_create_button permet d'afficher un bouton avec le texte "Ajouter Clé"
+###############################################################################
+# display_create_button is used to display a button with "Add key" text
+
+sub display_create_button {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ my $button = $self->localise('CREATE_BUTTON');
+ $self->print_button("$button");
+}
+
+# create_cal permet de rajouter un CAL à zarafa
+###############################################
+# create_cal is used to add a CAL to zarafa
+
+sub create_cal {
+
+ my $self = shift;
+ my $cgi = $self->{cgi};
+
+ # Récupération du nom du CAL et de la clef
+ # Recovery of the CAL name and the key
+ my $calname = $cgi->param('user_name_cal');
+ if ($calname =~ /^([-\@\w.]+)$/) {
+ $calname = $1; # $data now untainted
+ }
+ else {
+ die "bad data in $calname";
+ }
+
+ my $calkey = $cgi->param('user_key_cal');
+ if ($calkey =~ /^([-\@\w.]+)$/) {
+ $calkey = $1; # $data now untainted
+ }
+ else {
+ die "bad data in $calkey";
+ }
+
+ # Ecriture du fichier
+ # Writing of the file
+ open(CREATE, ">/etc/zarafa/license/$calname");
+ print CREATE $calkey;
+ close(CREATE);
+
+ $self->success('MODIFY_CONFIG_SUCCESS');
+
+ # Redémarrage des services Zarafa
+ # Restart of the zarafa services
+ system("/etc/e-smith/events/actions/zarafa-services restart > /dev/null");
+}
+
+# unique_cal sert a vérifier si le nom du CAL est déjà pris
+###########################################################
+# unique_cal is used to verify if the CAL name is already taken
+
+sub unique_name {
+
+ my ($fm, $calname) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('EXIST_CALNAME');
+
+ # Récupération des noms des CAL existant
+ # Recovery of all existing CAL names
+ opendir(OPENDIR, "/etc/zarafa/license") or die "Impossible d'ouvrir /etc/zarafa/license";
+ my @all_files = readdir (OPENDIR);
+ close(OPENDIR);
+
+ # On vérifie si le nom est déja pris
+ # CAL name have been already taken ?
+ my $exist = 0;
+ foreach my $file (@all_files){
+ if($file eq $calname){
+ $exist = 1;
+ }
+ }
+ if($exist == 1){
+ return $return_error;
+ }
+ else {
+ return "OK";
+ }
+}
+
+# unique_key sert a vérifier si la clef du CAL est déjà prise
+#############################################################
+# unique_key is used to verify if the CAL key is already taken
+
+sub unique_key {
+
+
+ my ($fm, $calkey) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('EXIST_CALKEY');
+
+ my $exist = 0;
+ my $filekey;
+
+ # Récupération des noms des CAL existant
+ # Recovery of all existing CAL names
+ opendir(OPENDIR, "/etc/zarafa/license") or die "Impossible d'ouvrir /etc/zarafa/license";
+ my @all_files = readdir (OPENDIR);
+ close(OPENDIR);
+
+ # Parcours de chaque fichier
+ # Read of all files
+ foreach my $file (@all_files) {
+ # Vérification
+ # Verification
+ open(FILE, "/etc/zarafa/license/$file") or die "Impossible d'ouvrir $file";
+ $filekey = ;
+ if($filekey =~ m/$calkey/){
+ $exist = 1;
+ }
+ close(FILE);
+ }
+
+ if($exist == 1){
+ return $return_error;
+ }
+ else {
+ return "OK";
+ }
+}
+
+# valid_cal est utilisé pour vérifier si la clef rentré est valide lors de la création d'un CAL
+###############################################################################################
+# valid_cal is used to verify if the key enter for create a CAL is correct
+
+sub valid_cal {
+
+ my ($fm, $cd_key) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('INVALID_KEY');
+
+ if($cd_key =~ m/^\w{$CALkey}$/){
+ return "OK";
+ }
+ else {
+ return $return_error;
+ }
+}
+
+# display_value est utilisé pour affiché les valeurs de fichiers de configuration MySQL dans l'interface
+########################################################################################################
+# display_value is used to display MySQL configuration values into the interface
+
+sub display_value {
+
+ my $self = shift;
+ my $cgi = $self->{cgi};
+
+ # Affichage d'une checkbox pour la fonction InnoDB
+ # Display of a checkbox for the InnoDB function
+ my $enabled = $self->localise('ENABLED');
+ my $out = "\n "
+ . "InnoDB"
+ . " | \n \n"
+ . " \n | \n
\n";
+
+ # Récupération et affichage des valeurs du fichier de configuration
+ # Recovery and display of the configuration file values
+ my $ligne;
+ open(MYCNF, "/etc/e-smith/templates/etc/my.cnf/009innodb") or die "Impossible d'ouvrir 0009innodb";
+ while(){
+ $ligne = $_;
+ if($ligne =~ m/buffer_pool_size/){
+ $ligne =~ s/^\s+\$OUT\s\.\=\s\"\w+\s\=\s//g;
+ $ligne =~ s/M\\n\"\;$//g;
+ $cgi->param(-name=>'buffer_pool_size', -value=>$ligne);
+ }
+ elsif($ligne =~ m/additional_mem_pool_size/){
+ $ligne =~ s/^\s+\$OUT\s\.\=\s\"\w+\s\=\s//g;
+ $ligne =~ s/M\\n\"\;$//g;
+ $cgi->param(-name=>'additional_mem_pool_size', -value=>$ligne);
+ }
+ elsif($ligne =~ m/log_file_size/){
+ $ligne =~ s/^\s+\$OUT\s\.\=\s\"\w+\s\=\s//g;
+ $ligne =~ s/M\\n\"\;$//g;
+ $cgi->param(-name=>'log_file_size', -value=>$ligne);
+ }
+ elsif($ligne =~ m/log_buffer_size/){
+ $ligne =~ s/^\s+\$OUT\s\.\=\s\"\w+\s\=\s//g;
+ $ligne =~ s/M\\n\"\;$//g;
+ $cgi->param(-name=>'log_buffer_size', -value=>$ligne);
+ }
+ }
+ close(MYCNF);
+
+return $out;
+}
+
+# modify_mysql permet de modifier les valeurs du fichier de configuration MySQL
+###############################################################################
+# modify_mysql is used to modify the value of the MySQL configuration file
+
+sub modify_mysql {
+
+ my $self = shift;
+ my $cgi = $self->{cgi};
+
+ # Récupération de la valeur courante et du réglage utilisateur de InnoDB
+ # Recovery of the current value and user value of InnoDB
+ my $innodb = $cgi->param('InnoDB');
+ my $current_innodb = $configdb->get_prop('mysqld','InnoDB');
+
+ # Si l'utilisateur désactive le service InnoDB
+ # If the user disable the InnoDB service
+ if($current_innodb eq 'enabled' && !$innodb){
+ # Arrêt des services MySQL et Zarafa
+ # Stop of MySQL and Zarafa services
+ system("/etc/e-smith/events/actions/zarafa-services stop > /dev/null");
+ system("/sbin/service mysqld stop > /dev/null");
+ # Suppression des fichiers MySQL
+ # Deleting MySQL file
+ system("rm -R -f /var/lib/mysql/ib_logfile0");
+ system("rm -R -f /var/lib/mysql/ib_logfile1");
+ system("rm -R -f /var/lib/mysql/ibdata1");
+
+ # Rechargement des paramêtres par défaut de MySQL
+ # Reload MySQL defaults adjustements
+ open(MYCNF, "/etc/e-smith/templates/etc/my.cnf/009innodb") or die "Impossible d'ouvrir 0009innodb";
+ my @contenu = ;
+ close(MYCNF);
+
+ foreach my $ligne (@contenu){
+ if($ligne =~ m/buffer_pool_size/){
+ $ligne =~ s/\d+/16/g;
+ }
+ elsif($ligne =~ m/additional_mem_pool_size/){
+ $ligne =~ s/\d+/2/g;
+ }
+ elsif($ligne =~ m/log_file_size/){
+ $ligne =~ s/\d+/5/g;
+ }
+ elsif($ligne =~ m/log_buffer_size/){
+ $ligne =~ s/\d+/8/g;
+ }
+ }
+ open(ECRIRE, ">/etc/e-smith/templates/etc/my.cnf/009innodb");
+ foreach my $ligne (@contenu) {
+ chomp $ligne;
+ print ECRIRE "$ligne\n";
+ }
+ close(ECRIRE);
+
+ # Suppression de l'InnoDB et redémarrage des services
+ # Delete of InnoDB and restart services
+ system("/sbin/e-smith/db configuration delprop mysqld InnoDB");
+ system("/sbin/e-smith/expand-template /etc/my.cnf");
+ system("/sbin/service mysqld start > /dev/null");
+ system("/etc/e-smith/events/actions/zarafa-services start > /dev/null");
+
+ $self->success('MODIFY_CONFIG_SUCCESS');
+ }
+ # Activation du service InnoDB
+ # Activation of InnoDB service
+ elsif(!$current_innodb && $innodb eq 'enabled'){
+ # Ajout de l'InnoDB, arrêt des services MySQL et Zarafa et suppression des fichiers MySQL
+ # Add the InnoDB, stop MySQL and Zarafa service and delete MySQL file
+ system("/sbin/e-smith/db configuration setprop mysqld InnoDB enabled");
+ system("/etc/e-smith/events/actions/zarafa-services stop > /dev/null");
+ system("/sbin/service mysqld stop > /dev/null");
+ system("rm -R -f /var/lib/mysql/ib_logfile0");
+ system("rm -R -f /var/lib/mysql/ib_logfile1");
+ system("rm -R -f /var/lib/mysql/ibdata1");
+
+ # Récupération du contenu du fichier configuration MySQL, modification des valeurs et écriture
+ # Recovery of the MysQL configuration file, values modification and writing
+ open(MYCNF, "/etc/e-smith/templates/etc/my.cnf/009innodb") or die "Impossible d'ouvrir 0009innodb";
+ my @contenu = ;
+ close(MYCNF);
+
+ my $buffer_pool_size = $cgi->param('buffer_pool_size');
+ my $additional_mem_pool_size = $cgi->param('additional_mem_pool_size');
+ my $log_file_size = $cgi->param('log_file_size');
+ my $log_buffer_size = $cgi->param('log_buffer_size');
+
+ foreach my $ligne (@contenu){
+ if($ligne =~ m/buffer_pool_size/){
+ $ligne =~ s/\d+/$buffer_pool_size/g;
+ }
+ elsif($ligne =~ m/additional_mem_pool_size/){
+ $ligne =~ s/\d+/$additional_mem_pool_size/g;
+ }
+ elsif($ligne =~ m/log_file_size/){
+ $ligne =~ s/\d+/$log_file_size/g;
+ }
+ elsif($ligne =~ m/log_buffer_size/){
+ $ligne =~ s/\d+/$log_buffer_size/g;
+ }
+ }
+
+ open(ECRIRE, ">/etc/e-smith/templates/etc/my.cnf/009innodb");
+ foreach my $ligne (@contenu) {
+ chomp $ligne;
+ print ECRIRE "$ligne\n";
+ }
+ close(ECRIRE);
+
+ # Génération du fichier configuration et redémarrage des services
+ # Configuration file generation and restart services
+ system("/sbin/e-smith/expand-template /etc/my.cnf");
+ system("/sbin/service mysqld start > /dev/null");
+ system("/etc/e-smith/events/actions/zarafa-services start > /dev/null");
+
+ $self->success('MODIFY_CONFIG_SUCCESS');
+ }
+ # Simple modifications des valeurs
+ # Only values modifications
+ elsif($current_innodb eq 'enabled' && $innodb eq 'enabled'){
+ # Arrêt des services MySQL et Zarafa
+ # Stop of MySQL and Zarafa services
+ system("/etc/e-smith/events/actions/zarafa-services stop > /dev/null");
+ system("/sbin/service mysqld stop > /dev/null");
+ # Suppression des fichiers MySQL
+ # Deleting MySQL file
+ system("rm -R -f /var/lib/mysql/ib_logfile0");
+ system("rm -R -f /var/lib/mysql/ib_logfile1");
+ system("rm -R -f /var/lib/mysql/ibdata1");
+
+
+ # Récupération du contenu du fichier configuration MySQL, modification des valeurs et écriture
+ # Recovery of the MysQL configuration file, values modification and writing
+ open(MYCNF, "/etc/e-smith/templates/etc/my.cnf/009innodb") or die "Impossible d'ouvrir 0009innodb";
+ my @contenu = ;
+ close(MYCNF);
+
+ my $buffer_pool_size = $cgi->param('buffer_pool_size');
+ my $additional_mem_pool_size = $cgi->param('additional_mem_pool_size');
+ my $log_file_size = $cgi->param('log_file_size');
+ my $log_buffer_size = $cgi->param('log_buffer_size');
+
+ foreach my $ligne (@contenu){
+ if($ligne =~ m/buffer_pool_size/){
+ $ligne =~ s/\d+/$buffer_pool_size/g;
+ }
+ elsif($ligne =~ m/additional_mem_pool_size/){
+ $ligne =~ s/\d+/$additional_mem_pool_size/g;
+ }
+ elsif($ligne =~ m/log_file_size/){
+ $ligne =~ s/\d+/$log_file_size/g;
+ }
+ elsif($ligne =~ m/log_buffer_size/){
+ $ligne =~ s/\d+/$log_buffer_size/g;
+ }
+ }
+
+ open(ECRIRE, ">/etc/e-smith/templates/etc/my.cnf/009innodb");
+ foreach my $ligne (@contenu) {
+ chomp $ligne;
+ print ECRIRE "$ligne\n";
+ }
+ close(ECRIRE);
+
+ # Génération du fichier configuration et redémarrage des services
+ # Configuration file generation and restart services
+ system("/sbin/e-smith/expand-template /etc/my.cnf");
+ system("/sbin/service mysqld start > /dev/null");
+ system("/etc/e-smith/events/actions/zarafa-services start > /dev/null");
+
+ $self->success('MODIFY_CONFIG_SUCCESS');
+ }
+ else {
+ $self->success('NO_MODIFICATION_ASKED');
+ }
+}
+
+# only_num permet de vérifier si une valeur ne contient bien que des chiffres
+#############################################################################
+# only_num is used to verify if a value is only a numeric value
+
+sub only_num {
+
+ my ($fm, $value) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('NOT_NUM');
+
+ if ($value =~ /^\d+$/){
+ return "OK";
+ }
+ else {
+ return $return_error;
+ }
+}
+
+sub print_message {
+
+ my ($fm, $word) = @_;
+ $word = $fm->localise($word);
+ print qq($word |
);
+ return undef;
+
+}
\ No newline at end of file
diff -urN smeserver-zarafa-0.9.0.orig/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/zarafaUI.pm smeserver-zarafa-0.9.0/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/zarafaUI.pm
--- smeserver-zarafa-0.9.0.orig/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/zarafaUI.pm 1970-01-01 10:00:00.000000000 +1000
+++ smeserver-zarafa-0.9.0/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/zarafaUI.pm 2009-06-01 21:15:18.000000000 +1000
@@ -0,0 +1,1934 @@
+#!/usr/bin/perl -w
+
+package esmith::FormMagick::Panel::zarafaUI;
+
+ use strict;
+ use warnings;
+ use esmith::ConfigDB;
+ use esmith::AccountsDB;
+ use esmith::FormMagick;
+ use esmith::cgi;
+ use File::Basename;
+ use esmith::util;
+ use Exporter;
+ use esmith::DB;
+
+ our $accountdb = esmith::AccountsDB->open();
+ our $configdb = esmith::ConfigDB->open();
+
+ our @ISA = qw(esmith::FormMagick Exporter);
+
+ our @EXPORT = qw();
+
+ our $VERSION = sprintf '%d.%03d', q$Revision: 1.1 $ =~ /: (\d+).(\d+)/;
+
+
+ our $multicompany_enabled;
+ open(LIRE, "/etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg");
+ while(){
+ my $ligne = $_;
+ if($ligne =~ m/^enable_hosted_zarafa/){
+ $multicompany_enabled = $ligne;
+ $multicompany_enabled =~ s/enable_hosted_zarafa\s+\=\s//g;
+ }
+ }
+ close(LIRE);
+
+
+# Ce fichier contient les fonction nécessaire pour gérer l'interface entre le serveur SME et la configuration des utilisateurs
+# et des groupes du module Zarafa.
+# Ce fichier regroupe des fonctions d'affichage, de modifications et de vérifications de données contenu dans Zarafa.
+#################################################################################################################################
+# This file contains the required functions in order to handle the interface between SME server and Zarafa configuration module's
+# for users and groups.
+# It contains display, modify, create and verification functions for Zarafa.
+
+
+# La fonction show_users permet d'afficher un tableaux reprenant l'enssemble des utilisateurs de Zarafa sur la page principale
+# avec possibilité de supprimer et de modifier les utilisateurs présents.
+##############################################################################################################################################
+# The show_users function allow you to display an array which contains all the users of zarafa with links to modify and delete users functions
+
+sub show_users {
+
+ my $self = shift;
+ my $q = $self->{cgi};
+
+ if ($multicompany_enabled =~ m/false/){
+
+ # Initialisation
+ my $ligne = 5;
+ my $nbrligne = `zarafa-admin -l | wc -l`;
+ my $scriptname = basename($0);
+
+ # Localisation
+ my $username = $self->localise('USERNAME');
+ my $fullname = $self->localise('FULLNAME');
+ my $delete = $self->localise('DELETE');
+
+ # Affichage de l'en-tête du tableau
+ # Display of the header
+ print " \n \n ";
+ print $q->start_table ({-CLASS => "sme-border"}),"\n ";
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q, $username,"header"),
+ esmith::cgi::genSmallCell($q, $fullname,"header"),
+ esmith::cgi::genSmallCell($q, $delete,"header"));
+
+
+ # Affichage des utilisateurs et des liens correspondants
+ # Display users and corresponding links
+ my @usertab;
+ my $nbr = 0;
+ while ($ligne < $nbrligne) {
+ $usertab[$nbr] = `zarafa-admin -l | cut -f2 | awk 'NR == $ligne'`;
+ $ligne ++;
+ $nbr ++;
+ }
+ my @out = sort @usertab;
+ foreach my $user (@out){
+ chomp $user;
+ if ($user =~ /^([-\@\w.]+)$/) {
+ $user = $1; # $data now untainted
+ }
+ else {
+ die "bad data in $user";
+ }
+ my $modify = "$user";
+ my $delete_user = "$delete";
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q,$modify ,"normal")," ",
+ esmith::cgi::genSmallCell($q, `zarafa-admin --details \"$user\" | cut -f3 | awk 'NR == 2'`,"normal"),
+ esmith::cgi::genSmallCell($q,$delete_user,"normal"));
+ }
+
+
+ print qq( |
\n);
+
+ # Localisation
+ my $add_user = $self->localise('ADD_USER');
+ my $add_user_bubble = $self->localise('ADD_USER_BUBBLE');
+
+ # Affichage bouton ajouter utilisateur
+ # Display the user's create button
+ my $out ="$add_user
";
+
+
+ return $out;
+ }
+
+ elsif ($multicompany_enabled =~ m/true/){
+
+ # Initialisation
+ my $ligne = 4;
+ my $nbrligne = `zarafa-admin --list-companies | wc -l`;
+ $nbrligne ++;
+ my $scriptname = basename($0);
+
+ # Localisation
+ my $companyname = $self->localise('COMPANYNAME');
+ my $delete = $self->localise('DELETE');
+
+ # Affichage de l'en-tête du tableau
+ # Display of the header
+ print " \n \n ";
+ print $q->start_table ({-CLASS => "sme-border"}),"\n ";
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q, $companyname,"header"),
+ esmith::cgi::genSmallCell($q, $delete,"header"));
+
+ # Affichage des utilisateurs et des liens correspondants
+ # Display users and corresponding links
+ my @usertab;
+ my $nbr = 0;
+ while ($ligne < $nbrligne) {
+ $usertab[$nbr] = `zarafa-admin --list-companies | cut -f2 | awk 'NR == $ligne'`;
+ $ligne ++;
+ $nbr ++;
+ }
+ my @out = sort @usertab;
+ foreach my $company (@out){
+ chomp $company;
+ if ($company =~ /^([-\@\w.]+)$/) {
+ $company = $1; # $data now untainted
+ }
+ else {
+ die "bad data in $company";
+ }
+ my $modify = "$company";
+ my $delete_company = "$delete";
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q,$modify ,"normal")," ",
+ esmith::cgi::genSmallCell($q,$delete_company,"normal"));
+ }
+
+
+ print qq( |
\n);
+
+ # Localisation
+ my $add_comp = $self->localise('ADD_COMP');
+ my $add_comp_bubble = $self->localise('ADD_COMP_BUBBLE');
+
+ # Affichage bouton ajouter utilisateur
+ # Display the user's create button
+ my $out ="$add_comp
";
+
+ return $out;
+ }
+}
+
+# La fonction transfer_page est requise lors de l'utilisation de lien afin de renvoyer l'utilisateur sur la bonne page.
+# Elle récupére le nom de la page demandé et redirige automatiquement l'utilisateur.
+#############################################################################################################################
+# The transfer_page function is use when the user do an action which need another page in order to redirect to the next page.
+
+sub transfer_page {
+
+ my ($self, $next_page) = @_;
+
+ $self->{cgi}->param(-name => 'wherenext', -value => $next_page);
+
+}
+
+# display_user_details affiche les détails de l'utilisateur passé en paramétre dans des champs modifiables
+##########################################################################################################
+# display_user_details display the details of the username pass in parameter into editable fields.
+
+sub display_user_details {
+
+
+ my $self = shift;
+ my $cgi = $self->{cgi};
+
+ # Récupération du nom de l'utilisateur et vérification de sa fiabilité
+ # recovery of the username and test is reliability
+ my $recept_user = $cgi->param('actUsr');
+ if ($recept_user =~ /^([-\@\w.]+)$/) {
+ $recept_user = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$recept_user'";
+ }
+ my ($user, $Emailaddress, $active, $admin, $meeting_req, $quota_overr,
+ $warnlvl, $softlvl, $hardlvl, $store_size, $decline_dbl, $decline_recur);
+
+ # Récupération des informations de l'utilisateur
+ # recovery of user's information
+ open(DETAILS, "zarafa-admin --details \"$recept_user\" |") or die "probléme ouverture fichier";
+ while (){
+ if(m/^Fullname/){
+ $user = $_;
+ $user =~ s/^\w+:\t*//;
+ }
+ if(m/^Emailaddress/){
+ $Emailaddress = $_;
+ $Emailaddress =~ s/^\w+:\t*//;
+ }
+ if(m/^Active/){
+ $active = $_;
+ chomp $active;
+ $active =~ s/^\w+:\t*//;
+ }
+ if(m/^Administrator/){
+ $admin = $_;
+ chomp $admin;
+ $admin =~ s/^\w+:\t*//;
+ }
+ if(m/^Auto-accept/){
+ $meeting_req = $_;
+ chomp $meeting_req;
+ $meeting_req =~ s/.+://;
+ }
+ if(m/^Decline dbl/){
+ $decline_dbl = $_;
+ chomp $decline_dbl;
+ $decline_dbl =~ s/Decline dbl meetingreq:\t*//;
+ }
+ if(m/^Decline recur/){
+ $decline_recur = $_;
+ chomp $decline_recur;
+ $decline_recur =~ s/Decline recur meet\.req:\t*//;
+ }
+ if(m/^Quota overrides/){
+ $quota_overr = $_;
+ chomp $quota_overr;
+ $quota_overr =~ s/Quota overrides:\t*//;
+ }
+ if(m/^Warning level/){
+ $warnlvl = $_;
+ chomp $warnlvl;
+ $warnlvl =~ s/Warning level:\t*//;
+ if($warnlvl =~ m/KB/){
+ $warnlvl =~ s/.{3}$//g;
+ $warnlvl = $warnlvl / 1024;
+ }
+ }
+ if(m/^Soft level/){
+ $softlvl = $_;
+ chomp $softlvl;
+ $softlvl =~ s/Soft level:\t*//;
+ if($softlvl =~ m/KB/){
+ $softlvl =~ s/.{3}$//g;
+ $softlvl = $softlvl / 1024;
+ }
+ }
+ if(m/^Hard level/){
+ $hardlvl = $_;
+ chomp $hardlvl;
+ $hardlvl =~ s/Hard level:\t*//;
+ if($hardlvl =~ m/KB/){
+ $hardlvl =~ s/.{3}$//g;
+ $hardlvl = $hardlvl / 1024;
+ }
+ }
+ if(m/^Current store size/){
+ $store_size = $_;
+ chomp $store_size;
+ $store_size =~ s/Current store size:\t*//;
+ if($store_size =~ m/B/){
+ $store_size =~ s/\sB//i;
+ $store_size /= 1048576;
+ $store_size =~ s/(\.\d{5})\d*/$1/;
+ $store_size .= " Mo";
+ }
+ if($store_size =~ m/KB/){
+ $store_size =~ s/\sKB//i;
+ $store_size /= 1024;
+ $store_size .= " Mo";
+ }
+ }
+ }
+ close(DETAILS);
+
+ # Vérification de la présence de l'utilisateur dans la BD serveur
+ # Verify if the user is in the Server's DB
+ my $zarafa_text = $self->localise('CAUTION_NOT_DB');
+ my $present = 0;
+
+ my $test = $accountdb->get("$recept_user");
+ if($test){
+ $zarafa_text = $self->localise('IN_DB');
+ $present = 1;
+ }
+
+ # Remplissage des champs de l'interface avec les données récupérés
+ # Filling of user's field with the previous data
+ $cgi->param(-name=>'Username', -value=>$recept_user);
+ $cgi->param(-name=>'Fullname', -value=>$user);
+ $cgi->param(-name=>'EmailAddress', -value=>$Emailaddress);
+ $cgi->param(-name=>'Admin', -value=>$admin);
+ $cgi->param(-name=>'quota', -value=>$quota_overr);
+ $cgi->param(-name=>'Warnlvl', -value=>$warnlvl);
+ $cgi->param(-name=>'Softlvl', -value=>$softlvl);
+ $cgi->param(-name=>'Hardlvl', -value=>$hardlvl);
+ $cgi->param(-name=>'auto_meeting_req', -value=>$meeting_req);
+ $cgi->param(-name=>'dbl_meeting', -value=>$decline_dbl);
+ $cgi->param(-name=>'decline_recur_meeting', -value=>$decline_recur);
+
+ # Localisation
+ my $enabled = $self->localise('ENABLED');
+ my $disabled = $self->localise('DISABLED');
+
+
+ # Affichage de l'option zarafa pour ceux qui sont dans la BD
+ # Display of the zarafa's button if the user is in the server's DB
+ my $zarafa_status;
+ my $out;
+ if($present == 1){
+ unless($configdb->get_prop("zarafa-server",'GlobalForward')){
+ $zarafa_status = $accountdb->get_prop("$recept_user",'zarafa');
+
+ $out = "\n "
+ . "Zarafa"
+ . " | \n \n"
+ . " \n | \n
\n";
+ }
+
+
+ # Affichage de l'option SortSpam pour ceux qui sont dans la BD
+ # Display of the SortSpam's button if the user is in the server's DB
+ my $sortspam = $accountdb->get_prop("$recept_user",'SortSpam');
+ $out .= "\n "
+ . "SortSpam"
+ . " | \n \n"
+ . " \n | \n
\n";
+ }
+
+
+ # Localisation
+ # Localization
+ my $details = $self->localise('DETAILS');
+ my $stock_use = $self->localise('STOCK_USE');
+ my $active_user = $self->localise('ACTIVE_USER');
+
+ print "$details $recept_user - $user - $stock_use $store_size $active_user $active - $zarafa_text";
+
+return $out;
+}
+
+# display_modify_button permet l'affichage d'un bouton 'Modify'
+############################################################################
+# display_modify_button is use to display a button with 'modify' text inside
+
+sub display_modify_button {
+
+ my ($self) = @_;
+
+ my $cgi = $self->{cgi};
+
+ my $button = $self->localise('MODIFY_BUTTON');
+
+ $self->print_button("$button");
+
+}
+
+# display_create_button permet l'affichage d'un bouton 'Create'
+############################################################################
+# display_create_button is use to display a button with 'Create' text inside
+
+sub display_create_button {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ my $button = $self->localise('CREATE_BUTTON');
+ $self->print_button("$button");
+}
+
+# display_delete_button permet l'affichage d'information sur l'utilisateur ainsi qu'un bouton 'Delete'
+######################################################################################################
+# display_delete_button is use to display some user information and a button with 'Delete' text inside
+
+sub display_delete_button {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ my $recept_user = $cgi->param('actUsr');
+ if ($recept_user =~ /^([-\@\w.]+)$/) {
+ $recept_user = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$recept_user'";
+ }
+
+ my $user = `zarafa-admin --details $recept_user | awk 'NR == 2'`;
+ $user =~ s/Fullname:\t\t//g;
+
+ my $store_size = `zarafa-admin --details $recept_user | awk 'NR == 11'`;
+ $store_size =~ s/Current store size:\t//g;
+ if($store_size =~ m/B/){
+ $store_size =~ s/\sB//i;
+ $store_size /= 1048576;
+ $store_size .= " Mb";
+ }
+ if($store_size =~ m/KB/){
+ $store_size =~ s/\sKB//i;
+ $store_size /= 1024;
+ $store_size .= " Mb";
+ }
+
+
+ my $active = `zarafa-admin --details $recept_user | awk 'NR == 4'`;
+ $active =~ s/Active:\t\t\t//g;
+
+
+ # Localisation
+ # Localization
+ my $details = $self->localise('DETAILS');
+ my $stock_use = $self->localise('STOCK_USE');
+ my $active_user = $self->localise('ACTIVE_USER');
+ my $button = $self->localise('DELETE_BUTTON');
+
+ print "$details $recept_user - $user - $stock_use $store_size - $active_user $active";
+
+ $self->print_button("$button");
+}
+
+# La fonction modify_user récupére le contenu de multiple champs afin de mettre à jour le contenu de Zarafa
+###########################################################################################################
+# The modify_user function recover the content of multiple fields in order to update Zarafa's content
+
+sub modify_user {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ # Récupération de l'utilisateur à modifier
+ # Recovery of the user for modified
+ my $user = $cgi->param('actUsr');
+ if ($user =~ /^([-\@\w.]+)$/) {
+ $user = $1; # $data now untainted
+ }
+ else {
+ die "bad data in $user";
+ }
+
+ # Récupération du contenu des champs
+ # Recovery of fields contents
+ my $user_id = $self->{cgi}->param('Username');
+ if ($user_id =~ /^([-\@\w.]+)$/) {
+ $user_id = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_id'";
+ }
+
+ my $user_fullname = $self->{cgi}->param('Fullname');
+ chomp $user_fullname;
+ $user_fullname =~ s/ /@/g;
+ if ($user_fullname =~ /^([-\@\w.]+)$/) {
+ $user_fullname = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_fullname'";
+ }
+ $user_fullname =~ s/@/ /g;
+ $user_fullname = "\"".$user_fullname."\"";
+
+ my $user_address = $self->{cgi}->param('EmailAddress');
+ if ($user_address =~ /^([-\@\w.]+)$/) {
+ $user_address = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_address'";
+ }
+
+ my $user_admin = $self->{cgi}->param('Admin');
+ if ($user_admin =~ /^([-\@\w.]+)$/) {
+ $user_admin = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_admin'";
+ }
+
+ my $user_quota = $self->{cgi}->param('quota');
+ if ($user_quota =~ /^([-\@\w.]+)$/) {
+ $user_quota = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_quota'";
+ }
+
+ my $user_warnlvl = $self->{cgi}->param('Warnlvl');
+ unless ($user_warnlvl)
+ {$user_warnlvl = 0;}
+ if ($user_warnlvl =~ /^([-\@\w.]+)$/) {
+ $user_warnlvl = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_warnlvl'";
+ }
+
+ my $user_softlvl = $self->{cgi}->param('Softlvl');
+ unless ($user_softlvl)
+ {$user_softlvl = 0;}
+ if ($user_softlvl =~ /^([-\@\w.]+)$/) {
+ $user_softlvl = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_softlvl'";
+ }
+
+
+ my $user_hardlvl = $self->{cgi}->param('Hardlvl');
+ unless ($user_hardlvl)
+ {$user_hardlvl = 0;}
+ if ($user_hardlvl =~ /^([-\@\w.]+)$/) {
+ $user_hardlvl = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_hardlvl'";
+ }
+
+
+ my $user_meeting = $self->{cgi}->param('auto_meeting_req');
+ if ($user_meeting =~ /^([-\@\w.]+)$/) {
+ $user_meeting = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_meeting'";
+ }
+
+ my $user_dbl = $self->{cgi}->param('dbl_meeting');
+ if ($user_dbl =~ /^([-\@\w.]+)$/) {
+ $user_dbl = $1;
+ }
+ else {
+ die "Bad data in '$user_dbl'";
+ }
+
+ my $user_recur_meeting = $self->{cgi}->param('decline_recur_meeting');
+ if ($user_recur_meeting =~ /^([-\@\w.]+)$/) {
+ $user_recur_meeting = $1;
+ }
+ else {
+ die "Bad data in '$user_recur_meeting'";
+ }
+
+
+ # Récupération d'un nouveau mot de passe et remplacement de l'ancien
+ # Recovery of a new password and replacement of the old password
+ my $user_new_password = $self->{cgi}->param('new_password');
+ if ($user_new_password){
+ if ($user_new_password =~ /^([-\@\w.]+)$/) {
+ $user_new_password = $1;
+ }
+ else {
+ die "Bad data in '$user_new_password'";
+ }
+ system("zarafa-admin -u $user -p $user_new_password > /dev/null") == 0
+ or die "Une erreur est survenue lors du changement de password de l'utilisateur $user";
+ }
+
+ my $fm = shift;
+ my $q = $fm->{'cgi'};
+
+ my $zarafa_enabled = $q->param('zarafa');
+ if($zarafa_enabled){
+ if($zarafa_enabled eq 'enabled'){
+ system("/sbin/e-smith/db accounts setprop \"$user_id\" zarafa enabled");
+ system("/etc/e-smith/events/actions/qmail-update-user");
+
+ }
+ elsif($zarafa_enabled eq 'disabled'){
+ system("/sbin/e-smith/db accounts delprop \"$user_id\" zarafa");
+ system("/etc/e-smith/events/actions/qmail-update-user");
+ }
+ }
+
+ # Ajout des modifications dans la base de données Zarafa
+ # Modify information added into Zarafa database
+ if ($user eq $user_id){
+ system("zarafa-admin -u $user -f $user_fullname -e $user_address -a $user_admin --qo $user_quota --qw $user_warnlvl --qs $user_softlvl --qh $user_hardlvl --mr-accept $user_meeting --mr-decline-conflict $user_dbl --mr-decline-recurring $user_recur_meeting > /dev/null") == 0
+ or die "Une erreur est survenue lors de la modification de l'utilisateur";
+ }
+ else {
+ system("zarafa-admin -u $user -U $user_id -f $user_fullname -e $user_address -a $user_admin --qo $user_quota --qw $user_warnlvl --qs $user_softlvl --qh $user_hardlvl --mr-accept $user_meeting --mr-decline-conflict $user_dbl --mr-decline-recurring $user_recur_meeting> /dev/null") == 0
+ or die "Une erreur est survenue lors de la modificatoin de l'utilisateur";
+ }
+
+
+ my $sortspam = $q->param('sortspam');
+ if($sortspam eq 'enabled'){
+ system("/sbin/e-smith/db accounts setprop \"$user_id\" SortSpam disabled");
+ system("/sbin/e-smith/signal-event user-modify \"$user_id\"");
+ }
+ else{
+ system("/sbin/e-smith/db accounts delprop \"$user_id\" SortSpam");
+ system("/sbin/e-smith/signal-event user-modify \"$user_id\"");
+ }
+
+ # Opération sur les groupes d'utilisateurs
+ # Operation on user's groups
+ my $eval = "";
+ # Parcours de la liste des groupes
+ # Browse of the group liste
+ open(LISTGRP, "zarafa-admin -L | awk 'NR > 4' |");
+ while(){
+ my $groupeparam = $_;
+ $groupeparam =~ s/^\t//g;
+ chomp $groupeparam;
+ $groupeparam =~ s/ /_/g;
+ if ($groupeparam =~ /^([-\@\w.]+)$/) {
+ $groupeparam = $1;
+ }
+ else {
+ $groupeparam = $1;
+ }
+
+ my $present = 0;
+ if($groupeparam){
+ $groupeparam =~ s/_/ /g;
+ unless ($eval eq $groupeparam){
+ # Si le bouton radio est sur oui ...
+ # If the radio button is 'on' ...
+ my $yesNo = $q->param("$groupeparam");
+ if($yesNo eq 'Yes'){
+ # On regarde si l'utilisateur est déja dans le groupe ...
+ # The user is allready in the group ? ...
+ open(ADDUSR, "zarafa-admin -l --details \"$groupeparam\" --type group |");
+ while(){
+ if(m/^\t$user/){
+ $present = 1;
+ }
+ }
+ # Si il n'y est pas on le rajoute
+ # If it's not in the group, add it
+ unless($present == 1){
+ system("zarafa-admin -b $user -i \"$groupeparam\" > /dev/null") == 0
+ or die "Impossible de rajouter l'utilisateur $user dans le groupe $groupeparam";
+ }
+ }
+ close(ADDUSR);
+ # Si le bouton radio est sur non ...
+ # If the radio button is 'off'...
+ if($yesNo eq 'No'){
+ # On regarde si l'utilisateur est dans le groupe ...
+ # Is the user in the group ? ...
+ open(DELUSR, "zarafa-admin -l --details \"$groupeparam\" --type group |");
+ while(){
+ if(m/^\t$user/){
+ $present = 1;
+ }
+ }
+ # Si il y est on l'en enléve
+ # If it's in, remove it
+ if($present == 1){
+ system("zarafa-admin -B $user -i \"$groupeparam\" > /dev/null") == 0
+ or die "Impossible de supprimer l'utilisateur $user du groupe $groupeparam";
+ }
+ close(DELUSR);
+ }
+ $eval = $groupeparam;
+ }
+ }
+ }
+ close(LISTGRP);
+
+ $self->success('MODIFY_USER_SUCCESS');
+
+# Option possible pour mettre à jour ou créer des utilisateurs avec zarafa-admin
+# Zarafa-admin option for update and creation for users
+#-U username
+#-p password
+#-f fullname
+#-e emailaddress
+#-a admin
+#-n active user
+#--qo quota override
+#--qw quota warning
+#--qs quota soft
+#--qh quota hard
+#--mr-accept meeting request
+#--mr-decline-conflict
+#--mr-decline-recurring
+}
+
+# La fonction Create_user récupére le contenu de plusieurs champs afin de créer un utilisateurs zarafa avec ces derniers
+########################################################################################################################
+# The Create_user function recover the content of many fields in order to create a zarafa's user with them
+
+sub Create_user {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ # Récuperation du contenu des champs
+ # Recovery of content's fields
+ my $user_id = $self->{cgi}->param('Username');
+ if ($user_id =~ /^([-\@\w.]+)$/) {
+ $user_id = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in $user_id";
+ }
+
+ my $user_fullname = $self->{cgi}->param('Fullname');
+ chomp $user_fullname;
+ $user_fullname =~ s/ /@/g;
+ if ($user_fullname =~ /^([-\@\w.]+)$/) {
+ $user_fullname = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_fullname'";
+ }
+ $user_fullname =~ s/@/ /g;
+ $user_fullname = "\"".$user_fullname."\"";
+
+ my $user_psswrd = $self->{cgi}->param('Password');
+ if ($user_psswrd =~ /^([-\@\w.]+)$/) {
+ $user_psswrd = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_psswrd'";
+ }
+
+ my $user_address = $self->{cgi}->param('EmailAddress');
+ if ($user_address =~ /^([-\@\w.]+)$/) {
+ $user_address = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_address'";
+ }
+
+ my $user_admin = $self->{cgi}->param('Admin');
+ if ($user_admin =~ /^([-\@\w.]+)$/) {
+ $user_admin = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_admin'";
+ }
+
+ my $user_quota = $self->{cgi}->param('quota');
+ if ($user_quota =~ /^([-\@\w.]+)$/) {
+ $user_quota = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_quota'";
+ }
+
+ my $user_warnlvl = $self->{cgi}->param('Warnlvl');
+ unless ($user_warnlvl)
+ {$user_warnlvl = 0;}
+ if ($user_warnlvl =~ /^([-\@\w.]+)$/) {
+ $user_warnlvl = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_warnlvl'";
+ }
+
+
+ my $user_softlvl = $self->{cgi}->param('Softlvl');
+ unless ($user_softlvl)
+ {$user_softlvl = 0;}
+ if ($user_softlvl =~ /^([-\@\w.]+)$/) {
+ $user_softlvl = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_softlvl'";
+ }
+
+
+ my $user_hardlvl = $self->{cgi}->param('Hardlvl');
+ unless ($user_hardlvl)
+ {$user_hardlvl = 0;}
+ if ($user_hardlvl =~ /^([-\@\w.]+)$/) {
+ $user_hardlvl = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_hardlvl'";
+ }
+
+ my $user_active = $self->{cgi}->param('Active');
+ if ($user_active =~ /^([-\@\w.]+)$/) {
+ $user_active = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user_active'";
+ }
+
+ # Création de l'utilisateur
+ # User's creation
+ system("zarafa-admin -c $user_id -f $user_fullname -p $user_psswrd -e $user_address -a $user_admin -n $user_active --qo $user_quota --qw $user_warnlvl --qs $user_softlvl --qh $user_hardlvl > /dev/null") == 0
+ or die "Une erreur est survenue lors de la création de l'utilisateur";
+
+ # Ajout dans la BD Accounts du serveur SME
+ system("/sbin/e-smith/db accounts setprop \"$user_id\" zarafa enabled");
+ system("/etc/e-smith/events/actions/qmail-update-user");
+
+
+ # Attribution des groupes
+ # groups allocation
+ my $fm = shift;
+ my $q = $fm->{'cgi'};
+
+ my $eval = "";
+ # Parcours de la liste des groupes
+ # Browse groups' list
+ open(LISTGRP, "zarafa-admin -L | awk 'NR > 4' |");
+ while(){
+ my $groupeparam = $_;
+ $groupeparam =~ s/^\t//g;
+ chomp $groupeparam;
+ $groupeparam =~ s/ /_/g;
+ if ($groupeparam =~ /^([-\@\w.]+)$/) {
+ $groupeparam = $1;
+ }
+ else {
+ $groupeparam = $1;
+ }
+ $groupeparam =~ s/_/ /g;
+ if($groupeparam){
+ unless ($eval eq $groupeparam){
+ my $yesNo = $q->param("$groupeparam");
+ # Si le bouton radio est sur oui, on ajoute l'utilisateur au groupe
+ # If the radio button is 'on', the user is added to the group
+ if($yesNo eq 'Yes'){
+ system("zarafa-admin -b $user_id -i \"$groupeparam\" > /dev/null") == 0
+ or die "Impossible de rajouter l'utilisateur $user_id dans le groupe $groupeparam";
+ }
+ }
+ $eval = $groupeparam;
+ }
+ }
+ close(LISTGRP);
+
+ $self->success('CREATE_USER_SUCCESS');
+
+}
+
+# delete_user permet de supprimer un utilisateur de la base de données Zarafa
+#############################################################################
+# delete_user is use to delete an user from the Zarafa database
+
+sub delete_user {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ my $user = $cgi->param('actUsr');
+ if ($user =~ /^([-\@\w.]+)$/) {
+ $user = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user'";
+ }
+
+ system("zarafa-admin -d $user > /dev/null") == 0
+ or die "Impossible de supprimer cet utilisateur.";
+
+ # Suppression dans la BD Accounts du serveur SME
+ system("/sbin/e-smith/db accounts delprop \"$user\" zarafa enabled");
+ system("/etc/e-smith/events/actions/qmail-update-user");
+
+ $self->success('DELETE_USER_SUCCESS');
+
+}
+
+# modify_user_groups affiche une liste de tout les groupes et indique si l'utilisateur dont il est question appartient au groupe ou non
+#######################################################################################################################################
+# modify_user_groups display a list of all groups and show if the user belongs to groups or not
+
+sub display_user_groups {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+if ($multicompany_enabled =~ m/false/){
+ # Récupération du nom d'utilisateur
+ # Recover username
+ my $user = $cgi->param('actUsr');
+ if ($user =~ /^([-\@\w.]+)$/) {
+ $user = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user'";
+ }
+
+ my $fm = shift;
+ my $groups;
+ my $eval = "";
+ my $checkedYes = "";
+ my $display_group = $self->localise('GROUP_TEXT_DISPLAY');
+
+ my $out = "\n "
+ . "$display_group"
+ . " | \n \n"
+ . " \n | \n
\n";
+ close(LIRE);
+ return $out;
+ }
+
+elsif ($multicompany_enabled =~ m/true/){
+
+ # Récupération du nom d'utilisateur
+ # Recover username
+ my $user = $cgi->param('actUsr');
+ if ($user =~ /^([-\@\w.]+)$/) {
+ $user = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user'";
+ }
+
+ my $fm = shift;
+ my $groups;
+ my $eval = "";
+ my $checkedYes = "";
+ my $display_group = $self->localise('GROUP_TEXT_DISPLAY');
+
+ my $out = "\n "
+ . "$display_group"
+ . " | \n \n"
+ . " \n | \n
\n";
+ close(LIRE);
+ return $out;
+ }
+
+}
+
+# Create_group permet la création de groupe d'utilisateur en récupérant un nom saisi par l'utilisateur
+######################################################################################################
+# Create_group allow to create an user's group with a name recover from the user
+
+sub Create_group {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ # Récuperation du nom de groupe
+ # Recover the groupname
+ my $group = $self->{cgi}->param('Groupname');
+ $group =~ s/ /_/g;
+ if ($group =~ /^([-\@\w.]+)$/) {
+ $group = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$group'";
+ }
+ $group =~ s/_/ /g;
+
+
+ # Création du groupe
+ # Group creation
+ system("zarafa-admin -g \"$group\" > /dev/null") == 0
+ or die "Impossible de créer le groupe";
+
+ $self->success('CREATE_GROUP_SUCCESS');
+
+}
+
+# show_group affiche une liste de tout les groupe dans un tableau avec un lien pour les modifier et un autre pour les supprimer
+###############################################################################################################################
+# show_group display a list of all groups into an array with two links in order to modify an delete them
+
+sub show_group {
+
+ my $self = shift;
+ my $q = $self->{cgi};
+
+
+ if ($multicompany_enabled =~ m/false/){
+
+ my $nbrligne = `zarafa-admin -L | wc -l`;
+ my $scriptname = basename($0);
+ my $ligne = 4;
+
+ # Localisation
+ # Localization
+ my $groupname = $self->localise('GROUP_NAME_ARRAY');
+ my $suppr = $self->localise('DELETE');
+
+ # Affichage de l'en-tête du tableau
+ # Display the header
+ print " \n \n ";
+ print $q->start_table ({-CLASS => "sme-border"}),"\n ";
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q, $groupname,"header"),
+ esmith::cgi::genSmallCell($q, $suppr,"header"));
+
+ # Parcours de la liste des groupes avec affichage dans le tableau de chacun, création et affichage des liens correspondant
+ # Browse the group's list and display them into the array, create and diplay the links
+ my @grouptab;
+ my $nbr = 0;
+ while ($ligne < $nbrligne) {
+ $grouptab[$nbr] = `zarafa-admin -L | awk 'NR == $ligne'`;
+ $nbr ++;
+ $ligne ++;
+ }
+
+ my @out = sort @grouptab;
+ foreach my $group (@out){
+ unless($group =~ m/^\tEveryone/){
+ my $delete = "$suppr";
+ my $modify = "$group";
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q,$modify ,"normal")," ",
+ esmith::cgi::genSmallCell($q,$delete,"normal"));
+ }
+ }
+
+ print qq( |
\n);
+
+ my $add_group = $self->localise('ADD_GROUP');
+ my $add_group_bubble = $self->localise('ADD_GROUP_BUBBLE');
+
+ my $out ="$add_group
";
+
+
+ return $out;
+ }
+
+ else {
+ return 0;
+ }
+}
+
+# delete_group permet de supprimer un groupe passé en paramétre
+###############################################################
+# delete_group is use to delete the group passed in parameter
+
+sub delete_group {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ # Récupération du nom du groupe
+ # Recover the groupname
+ my $group = $cgi->param('actGrp');
+ $group =~ s/ /_/g;
+ if ($group =~ /^([-\@\w.]+)$/) {
+ $group = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$group'";
+ }
+ $group =~ s/_/ /g;
+
+ # Suppression du groupe
+ # Deleting group
+ system("zarafa-admin -G \"$group\" > /dev/null") == 0
+ or die "Impossible de supprimer ce groupe.";
+
+ $self->success('DELETE_GROUP_SUCCESS');
+
+}
+
+# Cette fonction affiche un bouton contenant le texte 'Delete'
+#############################################################
+# Thus function dispay a button with 'Delete' text inside
+
+sub display_delete_group_button {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ my $group = $cgi->param('actGrp');
+ $group =~ s/ /_/g;
+ if ($group =~ /^([-\@\w.]+)$/) {
+ $group = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$group'";
+ }
+ $group =~ s/_/ /g;
+ $self->print_button("DELETE");
+
+}
+
+# display_user_in_group affiche la liste de tout les utilisateurs et indique ceux qui appartiennent au groupe passé en paramétre
+################################################################################################################################
+# display_user_in_group display a list of all users and show those are in the group passed in parameter, or not
+
+sub display_user_in_group {
+
+ my $self = shift;
+ my $cgi = $self->{cgi};
+
+ # Récupération du nom du groupe
+ # Recovery of the groupename
+ my $group = $cgi->param('actGrp');
+ $group =~ s/ /_/g;
+ if ($group =~ /^([-\@\w.]+)$/) {
+ $group = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$group'";
+ }
+ $group =~ s/_/ /g;
+
+ my $grouptext = $self->localise('MODIFY_GROUP_TEXT');
+ print "$grouptext $group";
+ my ($user, $fullname);
+ my $out = "\n "
+ . "$group"
+ . " | \n \n"
+ . " \n | \n
\n";
+
+ return $out;
+
+}
+
+# display_modify_group_button affiche un bouton contenant 'Modify' pour la gestion des groupes
+##################################################################################################
+# display_modify_group_button display a button with 'Modify' text specially for group's management
+
+sub display_modify_group_button {
+
+ my ($self) = @_;
+
+ my $cgi = $self->{cgi};
+
+ $self->print_button("MODIFY_BUTTON");
+
+}
+
+# Cette fonction permet de modifier les utilisateurs appartenant a un groupe passé en paramétre
+###############################################################################################
+# This function is use to modify the users belong to a group passed in parameter
+
+sub modify_user_group {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+ my $group = $cgi->param('actGrp');
+
+ my $fm = shift;
+ my $q = $fm->{'cgi'};
+
+ # Parcours de la liste des utilisateurs
+ # Browse the user list
+ open(LISTUSR, "zarafa-admin -l | awk 'NR > 4' |");
+ while(){
+ my $user = $_;
+ $user =~ s/\t{2}.*$//g;
+ $user =~ s/^\t//g;
+ chomp $user;
+ chomp $group;
+
+ if($user){
+ if ($user =~ /^([-\@\w.]+)$/) {
+ $user = $1;
+ }
+ else {
+ die "bad data in $user";
+ }
+
+ my $present = 0;
+ my $yesNo = $q->param("$user");
+ # Si le bouton radio est sur 'oui' ...
+ # If the radio button is 'on' ...
+ if($yesNo eq 'yes'){
+ open(ADDUSR, "zarafa-admin -l --details \"$group\" --type group |");
+ while(){
+ if(m/^\t$user/){
+ $present = 1;
+ }
+ }
+ # Et si l'utilisateur n'est pas dans le groupe, alors on le rajoute
+ # And if the user is not in the group, then add him into the group
+ unless($present == 1){
+ system("zarafa-admin -b $user -i \"$group\" > /dev/null") == 0
+ or die "Impossible de rajouter l'utilisateur $user dans le groupe $group";
+ }
+ close(ADDUSR);
+ }
+ # Si le bouton radio est sur 'non' ...
+ # If the radio button is 'off' ...
+ if($yesNo eq 'no'){
+ open(DELUSR, "zarafa-admin -l --details $user |");
+ while(){
+ # Et si l'utilisateur appartient au groupe, alors on le supprime du groupe
+ # And if the user is in the group, then delete him from the group
+ if(m/^\t$group$/){
+ system("zarafa-admin -B $user -i \"$group\" > /dev/null") == 0
+ or die "Impossible de supprimer l'utilisateur $user du groupe $group";
+ }
+ }
+ close(DELUSR);
+ }
+ }
+ }
+ close(LISTUSR);
+
+ $self->success('MODIFY_GROUP_SUCCESS');
+}
+
+# display_create_user_group permet d'afficher la liste de tout les groupes en précochant l'apartenance de l'utilisateur à tout les groupes.
+# Utilisé pour l'affichage de la création d'un utilisateur.
+#####################################################################################################################################################
+# display_create_user_group is use to display a list of all group set to 'no' by default for the user. It will be use into the display of create user.
+
+sub display_create_user_group {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ my $fm = shift;
+ my $groups;
+ my $eval = "";
+
+ my $exist_group = $self->localise('EXIST_GROUP');
+ my $out = "\n "
+ . $exist_group
+ . " | \n \n"
+ . " \n | \n
\n";
+ close(LIRE);
+ return $out;
+}
+
+# Les fonctions suivantes servent à vérifié se que l'utilisateur saisi dans divers champs, afin d'éviter toute erreur de sa part ou tentative de sabotage de la part de personne malveillante.
+##############################################################################################################################################################################################
+# The functions below is use to analyse and find error in the fields the user have fill in order to securise the software.
+
+# Cette fonction est principalement utilisé pour vérifié la composition d'un Nom complet rentré par l'utilisateur, ou bien pour le nom des groupes.
+###################################################################################################################################################
+# This function is mainly use to verify the composition of a Fullname enter by an user or a group name.
+
+sub fullname {
+
+ my ($fm, $fullname) = @_;
+ my $self = shift;
+
+ my $return_error = $self->localise('FULLNAME_VERIF_ERROR');
+ if ($fullname =~ m/^\w+((\.|\-|\s+)?\w+)*$/){
+ return "OK";
+ }
+ else {
+ return $return_error;
+ }
+}
+
+# Cette fonction est principalement utilisé pour vérifié la composition d'un mot de passe saisi par l'utilisateur
+#################################################################################################################
+# This function is mainly use to verify the composition of a password enter by an user.
+
+sub my_password {
+
+ my ($fm, $password, $minlength) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('MY_PASSWORD_VERIF_ERROR');
+ if ($password =~ /^\w+$/i and length($password) >= $minlength){
+ return "OK";
+ }
+ elsif($password eq ''){
+ return "OK";
+ }
+ else {
+ return $return_error;
+ }
+}
+
+# quota_test est utilisé pour testé si la valeur des quota saisi par l'utilisateur sont des valeurs correcte.
+#############################################################################################################
+# quota_test is use in order to test if the user has enter a correct value into quota fields
+
+sub quota_test {
+
+ my ($fm, $quotalvl) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('QUOTA_TEST_VERIF_ERROR');
+ if ($quotalvl =~ /^\d*$/ or $quotalvl =~ m/unlimited/i){
+ return "OK";
+ }
+ else {
+ return $return_error;
+ }
+}
+
+# sup_quota_inter test si la valeur saisi dans le soft level est bien supérieur à celle du warning level ou équivalente
+# dans le cas d'une valeur à zéro ou bien d'un unlimited
+#########################################################################################################################
+# sup_quota_inter is use to test if the value of the soft level is superior to the value of the warning level or the same
+# in case of an 'unlimited' or a value at 0.
+
+sub sup_quota_inter {
+
+ my ($fm, $softlvl) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('SOFT_INF_WARN');
+ my $cgi = $self->{cgi};
+ my $warnlvl = $cgi->param('Warnlvl');
+
+ if (!$softlvl && !$warnlvl){
+ return "OK";
+ }
+ elsif ($softlvl eq 'unlimited' && $warnlvl eq 'unlimited'){
+ return "OK";
+ }
+ elsif ($softlvl == '0' && $warnlvl == '0'){
+ return "OK";
+ }
+ elsif ($softlvl > $warnlvl){
+ return "OK";
+ }
+ else {
+ return $return_error;
+ }
+}
+
+# sup_quota_inter test si la valeur saisi dans le hard level est bien supérieur à celle du soft level ou équivalente
+# dans le cas d'une valeur à zéro ou bien d'un unlimited
+#######################################################################################################################
+# sup_quota_inter is used to test if the value of the hard level is superior to the value of the soft level or the same
+# in case of an 'unlimited' or a value at 0.
+
+sub sup_quota_hard {
+
+ my ($fm, $hardlvl) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('HARD_INF_OTHER');
+ my $cgi = $self->{cgi};
+ my $warnlvl = $cgi->param('Warnlvl');
+ my $softlvl = $cgi->param('Softlvl');
+
+ if (!$softlvl && !$hardlvl){
+ return "OK";
+ }
+ elsif ($softlvl eq 'unlimited' && $warnlvl eq 'unlimited') {
+ return "OK";
+ }
+ elsif ($softlvl == '0' && $hardlvl == '0'){
+ return "OK";
+ }
+ elsif ($hardlvl > $softlvl){
+ return "OK";
+ }
+ else {
+ return $return_error;
+ }
+}
+
+# unique_username est utilisé pour vérifié si le nom d'utilisateur est bien unique dans le cas d'une création d'utilisateur
+################################################################################################################################
+# unique_username is used to verify if the username in the username's field is already taken or notin case of an user's creation
+
+sub unique_username {
+
+ my ($fm, $user_get) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('MULTIPLE_USERNAME');
+ my $present = 0;
+ open(USER, "zarafa-admin -l | awk 'NR > 4' |");
+ while(){
+ my $user = $_;
+ if ($user =~ m/$user_get\t/){
+ $present = 1;
+ }
+ }
+ close(USER);
+ if($present == 1){
+ return $return_error;
+ }
+ else {
+ return "OK";
+ }
+}
+
+# unique_email est utilisé pour vérifié si l'email de l'utilisateur est bien unique dans le cas d'une création d'utilisateur
+############################################################################################################################
+# unique_email is used to verify if the email in the email's field is already taken or not in case of an user's creation
+
+sub unique_email {
+
+ my ($fm, $email_get) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('MULTIPLE_EMAIL');
+ my $cgi = $self->{cgi};
+ my $present = 0;
+ open(USER, "zarafa-admin -l | awk 'NR > 3' |");
+ while(){
+ my $user = $_;
+ $user =~ s/\t{2}.*$//g;
+ $user =~ s/^\t{1}//g;
+ chomp $user;
+ if($user) {
+ if ($user =~ /^([-\@\w.]+)$/) {
+ $user = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user'";
+ }
+ open(EMAIL, "zarafa-admin --details \"$user\" |");
+ while(){
+ my $ligne = $_;
+ if ($ligne =~ m/$email_get/){
+ $present = 1;
+ }
+ }
+ }
+ close(EMAIL);
+ }
+ close(USER);
+ if($present == 1){
+ return $return_error;
+ }
+ else {
+ return "OK";
+ }
+}
+
+# unique_username_modify est utilisé pour vérifié si le nom d'utilisateur est bien unique dans le cas d'une modification
+#########################################################################################################################################
+# unique_username_modify is used to verify if the username in the username's field is already taken or not in case of user's modification
+
+sub unique_username_modify {
+
+ my ($fm, $user_get) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('MULTIPLE_USERNAME');
+ my $cgi = $self->{cgi};
+ my $param_user = $cgi->param('actUsr');
+ my $present = 0;
+
+ if($user_get eq $param_user){
+ return "OK";
+ }
+ else {
+ open(USER, "zarafa-admin -l | awk 'NR > 4' |");
+ while(){
+ my $user = $_;
+ if ($user =~ m/$user_get\t/){
+ $present = 1;
+ }
+ }
+ close(USER);
+ if($present == 1){
+ return $return_error;
+ }
+ else {
+ return "OK";
+ }
+ }
+}
+
+# unique_email_modify est utilisé pour vérifié si l'email utilisateur est bien unique dans le cas d'une modification
+################################################################################################################################
+# unique_email_modify is used to verify if the email in the email's field is already taken or not in case of user's modification
+
+sub unique_email_modify {
+
+ my ($fm, $email_get) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('MULTIPLE_EMAIL');
+ my $cgi = $self->{cgi};
+ my $param_user = $cgi->param('actUsr');
+ my $present = 0;
+
+ open(MAIL, "zarafa-admin --details \"$param_user\" |");
+ while(){
+ my $ligne = $_;
+ if ($ligne =~ m/$email_get/){
+ return "OK";
+ }
+ }
+ close(MAIL);
+
+ open(USER, "zarafa-admin -l | awk 'NR > 3' |");
+ while(){
+ my $user = $_;
+ $user =~ s/\t{2}.*$//g;
+ $user =~ s/^\t{1}//g;
+ chomp $user;
+ if($user) {
+ if ($user =~ /^([-\@\w.]+)$/) {
+ $user = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$user'";
+ }
+ open(EMAIL, "zarafa-admin --details \"$user\" |");
+ while(){
+ my $mail = $_;
+ if ($mail =~ m/$email_get/){
+ $present = 1;
+ }
+ }
+ }
+ close(EMAIL);
+ }
+ close(USER);
+
+ if($present == 1){
+ return $return_error;
+ }
+ else {
+ return "OK";
+ }
+}
+
+# unique_groupname est utilisé pour vérifié si le nom du groupe est bien unique dans le cas d'une création de groupe
+####################################################################################################################
+# unique_groupname is used to verify if the groupnamed is already taken or not in case of an group's creation
+
+sub unique_groupname {
+
+ my ($fm, $groupname) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('MULTIPLE_GROUPNAME');
+ my $present = 0;
+
+ open(GROUP, "zarafa-admin -L | awk 'NR > 3' |");
+ while(){
+ my $ligne = $_;
+ if ($ligne =~ m/$groupname/i){
+ $present = 1;
+ }
+ }
+ close(GROUP);
+
+ if($present == 1){
+ return $return_error;
+ }
+ else {
+ return "OK";
+ }
+}
+
+# Cette fonction est principalement utilisé pour vérifié la composition d'un nom d'utilisateur saisi par l'utilisateur
+######################################################################################################################
+# This function is mainly use to verify the composition of an username enter by an user.
+
+sub my_username {
+
+ my ($fm, $username) = @_;
+ my $self = shift;
+ my $return_error = $self->localise('FALSE_USERNAME');
+
+ if ($username) {
+ if($username =~ m/^\w+((\.|\-|@)?\w+)*$/){
+ return "OK";
+ }
+ else {
+ return $return_error;
+ }
+ }
+ else {
+ return $return_error;
+ }
+}
+
+sub show_company_users {
+
+ my $self = shift;
+ my $q = $self->{cgi};
+
+ my $company = $q->param('actComp');
+ if ($company =~ /^([-\@\w.]+)$/) {
+ $company = $1; # $data now untainted
+ }
+ else {
+ die "bad data in $company";
+ }
+ my $scriptname = basename($0);
+
+ # Localisation
+ # Localization
+ my $username = $self->localise('USER_NAME_ARRAY');
+ my $suppr = $self->localise('DELETE');
+
+ # Affichage de l'en-tête du tableau
+ # Display the header
+ print " \n \n ";
+ print $q->start_table ({-CLASS => "sme-border"}),"\n ";
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q, $username,"header"),
+ esmith::cgi::genSmallCell($q, $suppr,"header"));
+
+ # Parcours de la liste des groupes avec affichage dans le tableau de chacun, création et affichage des liens correspondant
+ # Browse the group's list and display them into the array, create and diplay the links
+ open(LIRE, "zarafa-admin -l | cut -f2 |");
+ my $user;
+ my $nbr = 0;
+ while () {
+ if (m/\w+\@$company/) {
+ $user = $_;
+ my $delete = "$suppr";
+ my $modify = "$user";
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q,$modify ,"normal")," ",
+ esmith::cgi::genSmallCell($q,$delete,"normal"));
+ }
+ }
+ close(LIRE);
+
+ print qq( |
\n);
+
+ my $add_user = $self->localise('ADD_USER');
+ my $add_user_bubble = $self->localise('ADD_USER_BUBBLE');
+
+ my $out ="$add_user
";
+
+
+return $out;
+}
+
+sub print_message {
+
+ my ($fm, $word) = @_;
+ $word = $fm->localise($word);
+ print qq($word |
);
+ return undef;
+
+}
+
+sub create_company {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ my $companyname = $self->{cgi}->param('createcompanyname');
+ if ($companyname =~ /^([-\@\w.]+)$/) {
+ $companyname = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$companyname'";
+ }
+
+
+ system("zarafa-admin --create-company \"$companyname\" > /dev/null") == 0
+ or die "Impossible de créer la companie $companyname";
+
+ $self->success('CREATE_COMPANY_SUCCESS');
+
+}
+
+sub delete_company {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ my $companyname = $self->{cgi}->param('actComp');
+ if ($companyname =~ /^([-\@\w.]+)$/) {
+ $companyname = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$companyname'";
+ }
+
+ system("zarafa-admin --delete-company \"$companyname\" > /dev/null") == 0
+ or die "Impossible de créer la companie $companyname";
+
+ $self->success('DELETE_COMPANY_SUCCESS');
+}
+
+sub display_delete_comp_button {
+
+ my ($self) = @_;
+ my $cgi = $self->{cgi};
+
+ my $group = $cgi->param('actComp');
+ if ($group =~ /^([-\@\w.]+)$/) {
+ $group = $1; # $data now untainted
+ }
+ else {
+ die "Bad data in '$group'";
+ }
+
+ $self->print_button("DELETE");
+
+}
\ No newline at end of file