SP.Utilities.Utility.SendEmail returns “The e-mail message cannot be sent. Make sure the e-mail has a valid recipient.”

With Sharepoint you can use SP.Utilities.Utility.SendEmail to send email in JavaScript, however you could receive the below error:

“The e-mail message cannot be sent. Make sure the e-mail has a valid recipient.”

After searching the web, I found the solution: instead of using an email address for the recipients you have to use the userDomain with “i:0#.w|”.

For example, if the user is John Doe, and his email is john_doe@company.com, then you should use something like i:0#.w|domain\\john_doe.

mysqladmin with MariaDB returns “Access denied for user ‘root’@’localhost’ (using password: NO)”

When I want to reload my MariaDB server, I receive the below error:

/usr/bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’

The solution is to provide the root’s password in the file `/etc/mysql/debian.cnf` and then the error is gone!

Mise à jour d’un serveur Kimsufi (OVH) depuis Debian 8 (Jessie) vers Debian 9 (Stretch)

Il faut régulièrement penser à mettre à jour son serveur Kimsufi.

Je vais essayer d’expliquer brièvement les étapes à suivre pour cela.

  1. On va d’abord sauvegarder les données :
    1
    mkdir /root/svg_special; cp -R /var/lib/dpkg /root/svg_special/; cp /var/lib/apt/extended_states /root/svg_special/; dpkg --get-selections "*" > /root/svg_special/dpkg_get_selection; cp -R /etc /root/svg_special/etc
  2. Ensuite il est conseillé d’utiliser screen pour pouvoir se reconnecter (avec screen -r) à en cas de déconnexion :
    1
    screen
  3. On va effectuer une mise à jour des paquets avec apt-get update && apt-get upgrade
  4. Le processus de mise à niveau décrit sur le site de Debian a été conçu pour des mises à niveau des systèmes Jessie « purs » sans paquet provenant d’autres sources. Pour une meilleure fiabilité du processus de mise à niveau, vous pouvez supprimer ces paquets du système avant de commencer la mise à niveau. :
    1
    aptitude search '~i(!~ODebian)'
  5. On peut lancer la commande dpkg --audit pour s’assurer que tout est bon avant la migration. On peut également taper dpkg --get-selections "*" | more et vérifier qu’aucun paquet n’est en on hold
  6. Maintenant il faut remplacer tous les “jessie” de /etc/apt/sources.list par des “stretch”, ce qui va donner chez moi :
    1
    2
    3
    4
    5
    6
    7
    deb http://ftp.fr.debian.org/debian stretch main non-free
     
    deb http://debian.mirrors.ovh.net/debian/ stretch main
    deb-src http://debian.mirrors.ovh.net/debian/ stretch main
     
    deb http://security.debian.org/ stretch/updates main
    deb-src http://security.debian.org/ stretch/updates main

    On vérifiera aussi les autres fichiers qui peuvent se trouver dans /etc/apt/sources.list.d

  7. Si vous utilisez MySQL, sachez qu’avec Stretch vous pourriez passer sur MariaDB… Si vous souhaitez utiliser MySQL, on peut se référer à ce blog post
    • On ajoute/édite le fichier source pour mysql : nano /etc/apt/sources.list.d/mysql.list
    • On y ajoute les sources suivantes (pour mysql-5.7) :
      1
      2
      deb http://repo.mysql.com/apt/debian/ stretch mysql-5.7
      deb-src http://repo.mysql.com/apt/debian/ stretch mysql-5.7
    • On ajoute la clé publique de ce repo :
      1
      2
      3
      wget -O /tmp/RPM-GPG-KEY-mysql https://repo.mysql.com/RPM-GPG-KEY-mysql
      apt-key add /tmp/RPM-GPG-KEY-mysql
      rm /tmp/RPM-GPG-KEY-mysql
  8. Il est recommandé d’utiliser le programme /usr/bin/script pour enregistrer une transcription de la session de mise à niveau. Ainsi, quand un problème survient, on a un enregistrement de ce qui s’est passé. Pour démarrer un enregistrement, taper :
    1
    script -t 2>~/upgrade-stretch.time -a ~/upgrade-stretch.script
  9. On passe aux choses sérieuses, en commençant par mettre à jour les listes des paquets :
    1
    apt-get update
  10. On va vérifier qu’on a la place suffisante (un message explicite apparait sinon) :
    1
    apt-get -o APT::Get::Trivial-Only=true dist-upgrade
  11. On va maintenant faire une mise à jour minimale :
    1
    apt-get upgrade
  12. Et à partir de là le système va vous questionner… en général choisir l’option par défaut si vous ne savez pas quoi répondre
  13. Puis on continue avec
    apt-get dist-upgrade

Cette dernière étape va durer un certain temps. Une fois terminé, vous pouvez redémarrer le serveur pour s’assurer que tout va bien.

Avec phpmyadmin vous pourriez recevoir l’erreur suivante :

PHP Warning: require_once(): open_basedir restriction in effect. File(/usr/share/php/php-php-gettext/gettext.inc) is not within the allowed path(s): (/usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/) in /usr/share/phpmyadmin/libraries/common.inc.php on line 77
PHP Warning: require_once(/usr/share/php/php-php-gettext/gettext.inc): failed to open stream: Operation not permitted in /usr/share/phpmyadmin/libraries/common.inc.php on line 77

Dans ce cas là, il faut rajouter /usr/share/php/php-php-gettext/ dans le fichier /etc/phpmyadmin/apache.conf sur la ligne open_base_dir. Ce qui va donner la ligne : php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/

J’ai eu quelques soucis avec fail2ban qui ne démarrait pas. J’ai pu résoudre en consultant le Troubleshooting de leur wiki. Il s’agissait du fichier /etc/fail2ban/jail.d/defaults-debian.conf qui avait été créé avec une entrée invalide. Il a suffit de le supprimer.

Une fois les erreurs corrigées, on va nettoyer tous les paquets avec

1
apt-get autoremove

Invisible character with IE when using Intl.DateTimeFormat

As explained in some threads, Internet Explorer adds some invisible extra characters when returning a date from the JavaScript function new Intl.DateTimeformat.

1
2
3
4
5
var day = "Thursday";
var intlDay = new Intl.DateTimeFormat('en-US', {weekday:"long"}).format(new Date(2019,1,7));
console.log(day === intlDay); // return FALSE with IE
intlDay = intlDay.replace(/\u200E/g, ''); // replace \u200E
console.log(day === intlDay); // return TRUE with IE

The trick is to replace \u200E in the returned string.

Envoie d’email et spam (via OVH)

Si on envoie des emails depuis notre propre serveur, avec notre propre domaine, certaines mailbox (comme Gmail) pourraient vous détecter comme du spam !

Pour éviter cela, il faut prendre quelques précautions.

Type “SPF”

Tout d’abord, il faut ajouter une entrée SPF via le gestionnaire de domaine d’OVH. Le wizard va aider à composer la chaine qui sera enregistrée pour le domaine.

Il faudra fournir :

  • L’IPv4 du serveur qui envoie les emails
  • L’IPv6 du serveur qui envoie les emails
  • Inclure le MX d’OVH (include:mx.ovh.com)

Au final, le champ SPF devrait ressembler à ça :
300 IN TXT "v=spf1 a mx ip4:1.2.3.4 ip6:2001:41d0:a:abcd::1/128 include:mx.ovh.com -all"

Type “DKIM”

Cette fois on va ajouter une entrée de type “DKIM”.

Il faudra utiliser https://dkimcore.org/tools/ et :

  • Le sous domaine est fourni par l’outil (exemple : 1547992053.kodono._domainkey)
  • Choisir la version “DKIM 1”
  • Type de clé : RSA
  • La clé publique générée par l’outil dkimcore

Au final, le champ DKIM devrait ressembler à ça :
1547992053.kodono._domainkey.kodono.info. 0 DKIM v=DKIM1;k=rsa;p=MIGfMA0GCSqGSIb3DQE...anzmm2RIpt0tV3gwTGwuLQIDAQAB;t=s;

On pourra ensuite utiliser https://github.com/louisameline/php-mail-signature qui est une librairie PHP et qui aide à signer les emails qu’on envoie en PHP.

Type “DMARC”

Enfin, on ajoute une entrée de type “DMARC”.

Il faudra utiliser :

  1. Le sous-domaine doit être _dmarc
  2. Règle pour le domaine : none

Au final, le champ DMARC devrait ressemble à ça :
_dmarc.kodono.info. 0 DMARC v=DMARC1; p=none;

Ajout d’un reverse

Il va falloir ajouter un reverse (PTR) pour l’IPv4 et l’IPv6 du serveur. Cela se fait via la console de votre serveur (par exemple via le site Kimsufi si votre serveur est là bas).

Tester

Une fois vos emails créés, vous pouvez les tester grâce aux sites https://www.mail-tester.com/ et https://dkimvalidator.com/

Create a self-signed certificate for localhost testing with IE11 and Webpack

Sources:

If you develop with Webpack under Windows and you want to open your localhost server in HTTPS with IE11 you may receive a message like :

“Content was blocked because it was not signed by a valid security certificate.”

Below I explain the steps to make it work with IE11:

  1. Open Powershell in Administrator mode
  2. Type (no need to change anything, just copy/paste):
    1
    New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname localhost -FriendlyName "Dev localhost" -NotAfter (Get-Date).AddMonths(240) -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")

    It should return a Thumbprint:

    1
    2
    3
    4
    5
       PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\my
     
    Thumbprint                                Subject
    ----------                                -------
    1D97DFF290FBACE0871F16AD1B38172F253CA048  CN=localhost

    You may want to open certlm.msc to see the new certificate in Personal

  3. Export to .cer with the below Powershell command (make sure to replace 1D97DFF290FBACE0871F16AD1B38172F253CA048 with the Thumbprint you received before)… it will be exported to C:\localhost.cert (but you can change the path):
    1
    Export-Certificate -Cert Cert:\LocalMachine\MyD97DFF290FBACE0871F16AD1B38172F253CA048 -FilePath C:\localhost.cer (example: Export-Certificate -Cert Cert:\LocalMachine\My\PREVIOUS_Thumbprint_HERE -FilePath C:\localhost.cer)
  4. We now need to export to .pfx with the below Powershell commands:
    1
    2
    $CertPassword = ConvertTo-SecureString -String "YourPassword" -Force –AsPlainText
    Export-PfxCertificate -Cert cert:\LocalMachine\My79C7928D055B21AAA0Cfe2F6BE1A5C2CA83B30 -FilePath C:\localhost.pfx -Password $CertPassword
  5. Next we’ll use the opensource application called XCA: download and install it.
  6. Open XCA and go to : File > New Database
  7. Choose where you want to have this database and provide a password (to make it easy, you can choose the same “YourPassword” than before)
  8. Go to tab Certificates
  9. Click Import and select the previous created localhost.cer
  10. Once imported, right click the cert and Export > File, then select “*.crt” for the file format
  11. Go to the Private Keys tab and click on Import PFX
  12. Select the previously created PFX and click Import All
  13. Right click on “localhost_key” and Export > File, then select “PEM Private (*.pem)” for the file format
  14. Close XCA and go to the folder with all your files
  15. Double-click on the file localhost.crt you have just created
  16. Windows shows a popup with a "Install Certificate..." button; Click on this button
  17. Choose Current User, and next, click on “Place all certificates in the following store”, and browse to “Trusted Root Certification Authorities”
  18. Finally, in your Webpack config, you should enter something like the below:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    module.exports = {
      //...
      devServer: {
        https: {
          key: fs.readFileSync('C:\\localhost.pem'),
          cert: fs.readFileSync('C:\\localhost.crt')
        }
      }
    };

Launch your webpack server and open IE to your localhost server. It should work…

If you need to do CORS request, you may need to open IE settings, then go to Security and make sure to add localhost in the Local Intranet/Trusted Sites, then click on “Custom Level…”, go to “Miscellaneous” and select “Enable” for “Access data sources across domains”.

Sharepoint DateRangesOverlap value

(this is a copy of a post that is not available anymore)

DateRangesOverlap Value Type

I don’t know if any back-end developers have run into this same issue when working with the SPQuery to pull expanded recurrence date, but from here, not all DateRangesOverlap Value types work the way they should. And they’re cryptically-documented, where mentioned at all. The basics are that you can return dates that “overlap” a given scenario. The overlapping varies depending on scenario, as follows:

<Year />
This is supposed to get all events within:
(a) Today’s year (if no CalendarDate is passed), or
(b) the date passed in QueryOptions as CalendarDate.

Actually, it returns all dates from [Today] into the future. It ignores:
(a) the CalendarDate, and
(b) the end of the current year

<Month />
Performs consistently as expected, with the exception that its definition of “month” is more of a “month view.” A month view consists of all of the weeks which contain days in that month. In other words, the month view for May 2012 begins on April 29, 2012, because May 1 is on a Tuesday and the “month view” consists of full weeks. Likewise, the May 2012 month view ends on June 5, 2012. This means that pulling all of the dates for May 2012 will return all events for April 29 – June 5.

However, even though April 29 is the beginning of the May month view, when passed as the CalendarDate, it will return the April month view. See below for how this affects date calculations based on pulling data for a given month.

<Week />
Performs exactly like <Month />, but only returns the corresponding week for:
(a) Today, or
(b) CalendarDate

<Today />
Returns just the events for Today.

<Now />
Contrary to most documentation, <Now /> doesn’t “work” but rather defaults to the same results as <Year />.

In fact, <Year /> is the default. If you leave off the entire WHERE clause, but include the RecurrenceDate and fRecurrence fields and the QueryOptions (CalendarDate will be ignored), you get the same results as <Year />.

CalendarDate

In QueryOptions, if the CalendarDate is set, it needs the date to be a string in the format:
yyyy-mm-ddThh:mm:ssZ

In most cases, setting the CalendarDatewhen needed to the real date on which you want to base your range will work just fine, as long as you set the time in the Z-notation to noon. The reason for the noontime setting is to make allowance for all-day events within the given range. These tend to get messed up when viewing is based on a midnight or early morning time. Basing the range on noon alleviates the issue. (At least it does for US time zones; I confess that I haven’t tested them all.)

Interclassement MySQL pour le français

Quel interclassement (dit aussi collation) choisir pour sa base MySQL afin d’y enregistrer des caractères français (entre autres) ?

L’interclassement a deux fonctions :

  1. Permettre l’ordonnancement correct d’une liste de caractères (pour indiquer que le “é” vient après le “e”, ou que les majuscules viennent avant les minuscules, etc)
  2. Permettre de savoir quand un caractère est “équivalent” à un autre (dans les requêtes WHERE que, par exemple, le caractère “e” est équivalent à “E”, “é”, “è” ou “ê”)

Sur fluxbb on retrouve une très bonne explication. Je copie qu’une partie, mais allez lire cet article vraiment complet :

MySQL permet de choisir comment les données seront classées (ORDER BY) par ce qui est appelé une « collation » (COLLATE). Ceci permet de répondre, par exemple, au problème classique de la sensibilité à la casse :

  • Les majuscules doivent-elles précéder les minuscules, ou bien faut-il considérer A et a comme de même valeur ?
  • La sensibilité aux accents : comptent-ils dans le tri ? Font-ils une différence lors de la recherche ?
  • La possibilité qu’un caractère (ligature oe) puisse correspondre à plusieurs (o suivi de e) : c’est ce qu’Unicode appelle « l’expansion ».

Toutes les collations ont un nom qui commence par le jeu de caractère auquel elles sont liées, et se terminent par l’une de ces trois abréviations :

  • _bin comme binary : les caractères sont dans l’ordre de leurs numéros de code (ce qui donne d’abord toutes les majuscules, puis toutes les minuscules, puis les lettres accentuées, en vrac).
  • _cs comme case sensitive : les caractères sont triés selon le ou les langages de référence, mais de manière sensible à la casse.
  • _ci comme case insensitive : idem, mais en ignorant la casse.

Il est possible de définir plusieurs niveaux : de la colonne jusqu’à toute la base de données. Ainsi on peut définir une collation pour une colonne qui sera différente de celle de la table.

Au final, on peut utiliser utf8_unicode_ci : utf8 indique qu’on peut enregistrer une large palette de caractères (on utilisera utf8mb4 si on souhaite enregistrer des émoticones en plus), unicode_ci va permettre un bon tri tout en ignorant la casse.

Content Security Policy (CSP) blocks scripts from Violentmonkey / Greasemonkey

I wanted to inject some codes on Github, however I received Content Security Policy errors. It’s because Github blocks this kind of injected code.

To bypass this restriction I installed the addon Content Security Policy Override (if you have Firefox you can install this Chrome addon using Chrome Store Foxified) then I applied the below rule in the addon’s settings :

[
  ["https://github\\.com/*", [
    ["script-src", "script-src 'self' 'unsafe-inline' 'unsafe-eval'"]
  ]]
]

Now my Violentmonkey script works.