La fin d’année 2021 était la plus douce jamais mesurée https://meteofrance.com/actualites-et-dossiers/actualites/climat/la-fin-dannee-2021-est-la-plus-douce-jamais-mesureeBin on est le 28…

La fin d’année 2021 était la plus douce jamais mesurée meteofrance.com/actualites-et-

Bin on est le 28 novembre et ce matin j’étais en t-shirt dehors. C’est parti pour un nouveau record !!


Copié à partir de mamot.fr

Anonymiser les données de PrestaShop

Pour créer un environnement de développement, on duplique celui de production. Sauf qu’il ne faut pas garder les infos personnelles des clients. Déjà c’est dangereux, si vous gérez mal votre affaire vous risquez d’envoyer des mails aux clients et ça force tous les développeurs et intervenants à faire attention au RGPD.

Donc on anonymise tout, c’est plus simple.

Voici un script MariaDB qui anonymise les données clients : noms, prénoms, adresses, téléphones, e-mails, ip, communications. Il remplace les lettres par xxx en respectant la casse, les n° de téléphone par 0 en respectant le format et passe les IP en 127.0.0.1.

UPDATE ps_address pa SET pa.alias = REGEXP_REPLACE(REGEXP_REPLACE(pa.alias, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), pa.lastname = REGEXP_REPLACE(REGEXP_REPLACE(pa.lastname, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), pa.firstname = REGEXP_REPLACE(REGEXP_REPLACE(pa.firstname, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), pa.address1 = REGEXP_REPLACE(REGEXP_REPLACE(pa.address1, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), pa.address2 = REGEXP_REPLACE(REGEXP_REPLACE(pa.address2, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), pa.city = REGEXP_REPLACE(REGEXP_REPLACE(pa.city, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), pa.other = REGEXP_REPLACE(REGEXP_REPLACE(pa.other, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), pa.company = REGEXP_REPLACE(REGEXP_REPLACE(pa.company, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), pa.phone = REGEXP_REPLACE(pa.phone, '[0-9]', '0'), pa.phone_mobile = REGEXP_REPLACE(pa.phone_mobile, '[0-9]', '0'), pa.vat_number = REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(pa.vat_number, '[0-9]', '0'), '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), pa.dni = REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(pa.dni, '[0-9]', '0'), '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'); UPDATE ps_customer c SET c.lastname = REGEXP_REPLACE(REGEXP_REPLACE(c.lastname, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), c.firstname = REGEXP_REPLACE(REGEXP_REPLACE(c.firstname, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), c.email = CONCAT(c.id_customer, '@example.com'); UPDATE ps_customer c SET c.ip_registration_newsletter = '127.0.0.1' WHERE c.ip_registration_newsletter IS NOT NULL AND c.ip_registration_newsletter != '0'; UPDATE ps_customer_message cm SET cm.message = REGEXP_REPLACE(REGEXP_REPLACE(cm.message, '(?-i)[a-z]', 'x'), '(?-i)[A-Z]', 'X'), cm.ip_address = '2130706433'; UPDATE ps_customer_thread ct SET ct.email = CONCAT(IF(ct.id_customer > 0, ct.id_customer, '0'), '@example.com');
Langage du code : SQL (Structured Query Language) (sql)

La syntaxe de REGEXP_REPLACE n’est pas la même pour MySQL et MariaBD, donc il faudra adapter.

Avoir un point comme séparateur dans GNOME calculator

Je dois faire plein de calculs à coller dans un css, c’est très gênant d’avoir à corriger tous les résultats pour remplacer les virgules par des points.

Pour que la calculatrice d’Ubuntu utilise le point comme séparateur décimal, il faut la lancer comme suit dans un terminal :

LC_NUMERIC=en_US.UTF-8 gnome-calculator
Langage du code : Bash (bash)

Source : https://forums.linuxmint.com/viewtopic.php?p=1366261&sid=628026c11647ae21afbe12b8eec60941#p1366261

Sauvegarde automatique sur FTP

A force je pense avoir un script de sauvegarde FTP efficace.

Il sauvegarde les bases de données ainsi qu’un dossier du serveur et les envoi sur un serveur FTP. Si le serveur FTP est plein, il supprime les sauvegardes les plus anciennes jusqu’à avoir assez de place pour mettre la nouvelle.

Si une erreur arrive, il envoi un mail d’alerte.

Le script nécessite curlftpfs.

Utilisation :

  • Modifiez le script dans la partie configuration
  • Enregistrez le sur le serveur, par exemple dans /opt/scripts/backup.sh
  • Donnez les droits d’execution au fichier : chmod +x /opt/scripts/backup.sh
  • Ajoutez une tâche cron : 02 00 * * * /bin/bash /opt/scripts/backup.sh > /var/log/backup.log 2>&1

#!/bin/bash ### Configuration ### ### MYSQL ### MUSER="" # MySQL user, must can execute 'show databases' MPASS="" # MySQL password MHOST="" # MySQL host ### FTP ### FTPD="/" # FTP folder FTPUSER="" # FTP user FTPPASS="" # FTP password FTPHOST="" # FTP host FTPSIZE=107374182400 # Size of the FTP in Bytes (here 100 GB) ### Others ### EMAIL="" # Email to send alerts FILES_DIR="/home" # Directory to backup ### End of configuration ### ### Check system ### if ! [ -x "$(command -v tar)" ]; then echo 'Error: tar is not installed.' exit 1 fi if ! [ -x "$(command -v gzip)" ]; then echo 'Error: gzip is not installed.' exit 1 fi if ! [ -x "$(command -v mysql)" ]; then echo 'Error: mysql is not installed.' exit 1 fi if ! [ -x "$(command -v mysqldump)" ]; then echo 'Error: mysqldump is not installed.' exit 1 fi if ! [ -x "$(command -v curl)" ]; then echo 'Error: curl is not installed.' exit 1 fi if ! [ -x "$(command -v curlftpfs)" ]; then echo 'Error: curlftpfs is not installed.' exit 1 fi if ! [ -x "$(command -v fusermount)" ]; then echo 'Error: fusermount is not installed.' exit 1 fi if ! [ -d "$FILES_DIR" ]; then echo "Error: $FILES_DIR does not exists." exit 1 fi ### Start ### echo $(date +"%Y-%m-%d %T")" Start of process" NOW=$(date +%Y%m%d) # current date to have the file with the name-YYYYMMDD.tar.gz FTP_DIR=$(mktemp -d -t ftp-XXXXXXXXXX) # create local FTP directory # check if directory was created if [ -d "$FTP_DIR" ]; then echo $(date +"%Y-%m-%d %T")" Created local FTP directory $FTP_DIR" else echo "Error: Could not create local FTP directory $FTP_DIR" echo "Could not create local FTP directory $FTP_DIR" | mail -s "Backup Error" "#EMAIL" exit 1 fi BACKUP_DIR=$(mktemp -d -t bk-XXXXXXXXXX) # create backup directory if [ -d "$BACKUP_DIR" ]; then echo $(date +"%Y-%m-%d %T")" Created backup directory $BACKUP_DIR" else echo "Error: Could not create backup directory $BACKUP_DIR" echo "Could not create backup directory $BACKUP_DIR" | mail -s "Backup Error" "#EMAIL" rm -rf "$FTP_DIR" echo $(date +"%Y-%m-%d %T")" Deleted local FTP directory $FTP_DIR" exit 1 fi # deletes the temp directories when leaving the script function cleanup { if [ -d "$FTP_DIR" ]; then fusermount -u "$FTP_DIR" rmdir "$FTP_DIR" echo $(date +"%Y-%m-%d %T")" Deleted local FTP directory $FTP_DIR" fi if [ -d "$BACKUP_DIR" ]; then rm -rf "$BACKUP_DIR" echo $(date +"%Y-%m-%d %T")" Deleted backup directory $BACKUP_DIR" fi echo $(date +"%Y-%m-%d %T")" End of process" } # register the cleanup function to be called on the EXIT signal trap cleanup EXIT # implementation of script starts here curlftpfs ftp://$FTPHOST$FTPD -o user="$FTPUSER:$FTPPASS" "$FTP_DIR" echo $(date +"%Y-%m-%d %T")" FTP mounted in $FTP_DIR" ### Files backup ### echo $(date +"%Y-%m-%d %T")" Starting files backup" WORKING_DIR=$BACKUP_DIR/$NOW echo $(date +"%Y-%m-%d %T")" Create $WORKING_DIR directory" mkdir -p "$WORKING_DIR" echo $(date +"%Y-%m-%d %T")" Backup directory /etc to $WORKING_DIR/etc.tar" tar -cf "$WORKING_DIR/etc.tar" "/etc" # to simplify will copy it all echo $(date +"%Y-%m-%d %T")" Backup directory $FILES_DIR to $WORKING_DIR/files.tar" tar -cf "$WORKING_DIR/files.tar" "$FILES_DIR" ARCHIVE=$BACKUP_DIR/files-$NOW.tar.gz echo $(date +"%Y-%m-%d %T")" Compress directory $WORKING_DIR to $ARCHIVE" tar -zcf "$ARCHIVE" --remove-files "$WORKING_DIR" rm -rf "$WORKING_DIR" echo $(date +"%Y-%m-%d %T")" Files backup created in $ARCHIVE" ### check free space on ftp server ### ARCHIVE_SIZE=$(stat -c%s "$ARCHIVE") echo $(date +"%Y-%m-%d %T")" File size : $ARCHIVE_SIZE" FTP_DIR_SIZE=$(du -cb "$FTP_DIR" | awk 'END{print $1}') echo $(date +"%Y-%m-%d %T")" FTP space used $FTP_DIR_SIZE" while [ $(($FTP_DIR_SIZE+$ARCHIVE_SIZE)) -ge $FTPSIZE ]; do FILE_TO_DELETE=$(ls -t "$FTP_DIR" | tail -1) echo $(date +"%Y-%m-%d %T")" Delete $FILE_TO_DELETE from FTP" rm "$FTP_DIR/$FILE_TO_DELETE" FTP_DIR_SIZE=$(du -cb "$FTP_DIR" | awk 'END{print $1}') echo $(date +"%Y-%m-%d %T")" FTP space used $FTP_DIR_SIZE" done echo $(date +"%Y-%m-%d %T")" Copy $ARCHIVE to FTP" curl --user $FTPUSER:$FTPPASS --upload-file "$ARCHIVE" ftp://$FTPHOST$FTPD if [ $? != 0 ]; then echo "Error: Could not copy $ARCHIVE to FTP server" echo "Error when coping $ARCHIVE to FTP server" | mail -s "Backup Error" "#EMAIL" else echo $(date +"%Y-%m-%d %T")" Files backup moved to FTP" fi ### clear ### echo $(date +"%Y-%m-%d %T")" Delete $ARCHIVE" rm -rf "$ARCHIVE" echo $(date +"%Y-%m-%d %T")" End of files backup" ### Databases backup ### echo $(date +"%Y-%m-%d %T")" Starting databases backup" WORKING_DIR=$BACKUP_DIR/$NOW echo $(date +"%Y-%m-%d %T")" Create $WORKING_DIR directory" mkdir -p "$WORKING_DIR" ### Backup each databases ### DBS="$(mysql -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" if [ $? != 0 ]; then echo "Error: Could not list databases" echo "Could not list databases" | mail -s "Backup Error" "#EMAIL" return 1 fi for DB in $DBS do mkdir "$WORKING_DIR/$DB" DB_ARCHIVE=$WORKING_DIR/$DB/$DB.sql.gz echo $(date +"%Y-%m-%d %T")" Backup database $DB to $DB_ARCHIVE" MYSQL_PWD=$MPASS mysqldump --add-drop-table --single-transaction --skip-lock-tables --allow-keywords -q -c -u $MUSER -h $MHOST "$DB" | gzip -9 > "$DB_ARCHIVE" done ARCHIVE=$BACKUP_DIR/databases-$NOW.tar.gz echo $(date +"%Y-%m-%d %T")" Compress directory $WORKING_DIR to $ARCHIVE" tar -zcf "$ARCHIVE" --remove-files "$WORKING_DIR" rm -rf "$WORKING_DIR" echo $(date +"%Y-%m-%d %T")" Databases backup created in $ARCHIVE" ### check free space on ftp server ### ARCHIVE_SIZE=$(stat -c%s "$ARCHIVE") echo $(date +"%Y-%m-%d %T")" File size : $ARCHIVE_SIZE" FTP_DIR_SIZE=$(du -cb "$FTP_DIR" | awk 'END{print $1}') echo $(date +"%Y-%m-%d %T")" FTP space used $FTP_DIR_SIZE" while [ $(($FTP_DIR_SIZE+$ARCHIVE_SIZE)) -ge $FTPSIZE ]; do FILE_TO_DELETE=$(ls -t "$FTP_DIR" | tail -1) echo $(date +"%Y-%m-%d %T")" Delete $FILE_TO_DELETE from FTP" rm "$FTP_DIR/$FILE_TO_DELETE" FTP_DIR_SIZE=$(du -cb "$FTP_DIR" | awk 'END{print $1}') echo $(date +"%Y-%m-%d %T")" FTP space used $FTP_DIR_SIZE" done echo $(date +"%Y-%m-%d %T")" Copy $ARCHIVE to FTP" curl --user $FTPUSER:$FTPPASS --upload-file "$ARCHIVE" ftp://$FTPHOST$FTPD if [ $? != 0 ]; then echo "Error: Could not copy $ARCHIVE to FTP server" echo "Error when coping $ARCHIVE to FTP server" | mail -s "Backup Error" "#EMAIL" else echo $(date +"%Y-%m-%d %T")" Database backup moved to FTP" fi ### clear ### echo $(date +"%Y-%m-%d %T")" Delete $ARCHIVE" rm -rf "$ARCHIVE" echo $(date +"%Y-%m-%d %T")" End of databases backup"
Langage du code : Bash (bash)

Programmer les popups de Popup Builder

La version gratuite du plugin WordPress Popup Builder ne permet pas programmer l’affichage des popups. Cependant elle créé le filtre sgpbOtherConditions qui permet de les désactiver.

Ce filtre est appelé pour chaque popup qui peut s’afficher sur la page et si l’argument ‘status’ à false est ajouté à ceux existants, la popup ne s’affiche pas.

/** * Check Popup conditions * * @since 1.0.0 * * @return array * */ private function isSatisfyForOtherConditions() { $popup = $this->getPopup(); $popupOptions = $popup->getOptions(); $popupId = $popup->getId(); $dontAlowOpenPopup = apply_filters('sgpbOtherConditions', array('id' => $popupId, 'popupOptions' => $popupOptions, 'popupObj' => $popup)); return $dontAlowOpenPopup['status']; }
Langage du code : PHP (php)

Pour désactiver automatiquement vos popups, vous pouvez ajouter ce code à functions.php

add_filter('sgpbOtherConditions', 'my_sgpbOtherConditions', 10, 1); // update popin status function my_sgpbOtherConditions($args = array()) { // if popup is already unactive, do nothing if (isset($args['status']) && $args['status'] === false) { return $args; } switch ($args['id']) { case 17938: // summer holiday active between 2021-07-30 and 2021-08-01 $now = time() + 2 * 60 * 60; // for time zone, can be improved $from = strtotime('2021-07-30 00:00:00'); $to = strtotime('2021-08-02 00:00:00'); // if we are not between 2021-07-30 and 2021-08-01 desactivate the popup if (($now < $from) || ($now > $to)) { $args['status'] = false; } break; case 16412: // covid reassurance unactive between 2021-07-30 and 2021-08-01 $now = time() + 2 * 60 * 60; // for time zone, can be improved $from = strtotime('2021-07-30 00:00:00'); $to = strtotime('2021-08-02 00:00:00'); // if we are between 2021-07-30 and 2021-08-01 desactivate the popup if (($now >= $from) && ($now <= $to)) { $args['status'] = false; } break; } return $args; }
Langage du code : PHP (php)

Ainsi la popup 17938 ne sera active qu’entre le 30 juillet et le 1 août 2021 alors que la 16412 ne le sera que le reste du temps.