Merge pull request #1928 from MalteKiefer/master

added LibRAavatar
This commit is contained in:
Hylke Bons 2020-02-15 22:41:19 +01:00 committed by GitHub
commit c1b62da1c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 24 deletions

1
.github/AUTHORS.md vendored
View file

@ -20,6 +20,7 @@ Code:
Luis Cordova <cordoval@gmail.com>
Łukasz Jernaś <deejay1@srem.org>
Markus Stoll <post@mstoll.de>
Malte Kiefer <malte.kiefer@mailgermania.de>
Michael Monreal <michael.monreal@gmail.com>
Nick Richards <nick@nickr.org>
Oleg Khlystov <pktfag@gmail.com>

View file

@ -32,10 +32,11 @@ namespace SparkleShare
static List<string> skipped_avatars = new List<string> ();
public static string GetAvatar (string email, int size, string target_path)
public static string GetAvatar (string email, int size, string target_path, string provider)
{
#if __MonoCS__
ServicePointManager.ServerCertificateValidationCallback = GetAvatarValidationCallBack;
if (provider == "gravatar")
ServicePointManager.ServerCertificateValidationCallback = GetGravatarValidationCallBack;
#endif
email = email.ToLower ();
@ -68,7 +69,12 @@ namespace SparkleShare
}
var client = new WebClient ();
string url = "https://gravatar.com/avatar/" + email.MD5 () + ".png?s=" + size + "&d=404";
string url = "";
if (provider == "libravatar")
url = "https://seccdn.libravatar.org/avatar/" + email.MD5 () + ".png?s=" + size + "&d=404";
else
url = "https://secure.gravatar.com/avatar/" + email.MD5 () + ".png?s=" + size + "&d=404";
try {
byte [] buffer = client.DownloadData (url);
@ -107,7 +113,7 @@ namespace SparkleShare
}
private static bool GetAvatarValidationCallBack (Object sender,
private static bool GetGravatarValidationCallBack (Object sender,
X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
X509Certificate2 certificate2 = new X509Certificate2 (certificate.GetRawCertData ());
@ -115,9 +121,9 @@ namespace SparkleShare
// On some systems (mostly Linux) we can't assume the needed certificates are
// available, so we have to check the certificate's SHA-1 fingerprint manually.
//
// SHA1 fingerprinter obtained from https://www.gravatar.com/ on Oct 16 2015
// Set to expire on Oct 14 2018
string gravatar_cert_fingerprint = "1264B3F00814C6077D3853238771EE67FB6321C9";
// SHA1 fingerprinter obtained from https://www.gravatar.com/ on Feb 14 2020
// Set to expire on Sep 05 2020
string gravatar_cert_fingerprint = "3011C8954A672A01557E804AFF2F3D006D9BBD7C";
if (!certificate2.Thumbprint.Equals (gravatar_cert_fingerprint)) {
Logger.LogInfo ("Avatars", "Invalid certificate for https://www.gravatar.com/");

View file

@ -153,6 +153,16 @@ namespace SparkleShare {
}
}
public string AvatarsProvider {
get {
string avatars_provider_string = Config.GetConfigOption ("avatars_provider");
if (avatars_provider_string == null)
return "gravatar";
return avatars_provider_string;
}
}
// Path where the plugins are kept
public abstract string PresetsPath { get; }
@ -451,8 +461,16 @@ namespace SparkleShare {
};
repo.NewChangeSet += delegate (ChangeSet change_set) {
if (AvatarsEnabled)
change_set.User.AvatarFilePath = Avatars.GetAvatar (change_set.User.Email, 48, Config.DirectoryPath);
if (AvatarsEnabled) {
string provider = "gravatar";
if (AvatarsProvider == "libravatar")
provider = AvatarsProvider;
change_set.User.AvatarFilePath = Avatars.GetAvatar (change_set.User.Email, 48, Config.DirectoryPath, provider);
}
NotificationRaised (change_set);
};

View file

@ -598,7 +598,7 @@ namespace SparkleShare {
if (!SparkleShare.Controller.AvatarsEnabled)
return "<!-- $pixmaps-path -->/user-icon-default.png";
string fetched_avatar = Avatars.GetAvatar (user.Email, 48, SparkleShare.Controller.Config.DirectoryPath);
string fetched_avatar = Avatars.GetAvatar (user.Email, 48, SparkleShare.Controller.Config.DirectoryPath, SparkleShare.Controller.AvatarsProvider);
if (!string.IsNullOrEmpty (fetched_avatar))
return "file://" + fetched_avatar.Replace ("\\", "/");

View file

@ -39,8 +39,7 @@ namespace SparkleShare {
SparkleShare.Controller.ShowNoteWindowEvent += OnNoteWindowEvent;
if (SparkleShare.Controller.AvatarsEnabled && !SparkleShare.Controller.FirstRun)
AvatarFilePath = Avatars.GetAvatar (SparkleShare.Controller.CurrentUser.Email,
48, SparkleShare.Controller.Config.DirectoryPath);
AvatarFilePath = Avatars.GetAvatar (SparkleShare.Controller.CurrentUser.Email, 48, SparkleShare.Controller.Config.DirectoryPath, SparkleShare.Controller.AvatarsProvider);
}

View file

@ -43,6 +43,7 @@ namespace Sparkles {
public readonly string FilePath;
public readonly string TmpPath;
public readonly string BinPath;
public string AvatarProvider;
public readonly string LogFilePath;