From dcabfce2e85518687a663c51e0f4c19e29e5b1c9 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sat, 29 Aug 2020 13:19:16 +0430 Subject: [PATCH 1/3] #1 basic model for PoemNarration --- .../Models/GanjoorAudio/AudioSyncStatus.cs | 39 ++++ RMuseum/Models/GanjoorAudio/PoemNarration.cs | 152 +++++++++++++++ RMuseum/RMuseum.xml | 179 ++++++++++++++++++ 3 files changed, 370 insertions(+) create mode 100644 RMuseum/Models/GanjoorAudio/AudioSyncStatus.cs create mode 100644 RMuseum/Models/GanjoorAudio/PoemNarration.cs diff --git a/RMuseum/Models/GanjoorAudio/AudioSyncStatus.cs b/RMuseum/Models/GanjoorAudio/AudioSyncStatus.cs new file mode 100644 index 00000000..c03c33ca --- /dev/null +++ b/RMuseum/Models/GanjoorAudio/AudioSyncStatus.cs @@ -0,0 +1,39 @@ +namespace RMuseum.Models.GanjoorAudio +{ + /// + /// Audio Synchronization Status (binary combination is acceptable) + /// + public enum AudioSyncStatus + { + /// + /// no changed + /// + Synchronized = 0, + + /// + /// new upload + /// + NewItem = 1, + + /// + /// meta data should be updated + /// + MetadataChanged = 2, + + /// + /// sound files should be reuploaded + /// + SoundFilesChanged = 4, + + /// + /// Xml file should be reuploaded + /// + XmlFileChanged = 8, + + /// + /// Item is deleted + /// + Deleted = 16 + + } +} diff --git a/RMuseum/Models/GanjoorAudio/PoemNarration.cs b/RMuseum/Models/GanjoorAudio/PoemNarration.cs new file mode 100644 index 00000000..fa074e5d --- /dev/null +++ b/RMuseum/Models/GanjoorAudio/PoemNarration.cs @@ -0,0 +1,152 @@ +using RSecurityBackend.Models.Auth.Db; +using System; + + +namespace RMuseum.Models.GanjoorAudio +{ + /// + /// Poem Narration + /// + public class PoemNarration + { + /// + /// Id + /// + public Guid Id { get; set; } + + /// + /// Owner User + /// + public RAppUser Owner { get; set; } + + /// + /// Owner User Id + /// + public Guid OwnerId { get; set; } + + /// + /// Ganjoor Post Id + /// + public int GanjoorPostId { get; set; } + + /// + /// This determines where an audio is displayed between a list of sounds related to a specfic poem + /// + public int AudioOrder { get; set; } + + /// + /// Final data is actually exported to a MySQL database which this auto increment field is its key + /// + public int GanjoorAudioId { get; set; } + + /// + /// Using this field content you would determine xml, mp3 and ogg file names + /// + public string FileNameWithoutExtension { get; set; } + + /// + /// combining this with + .ext would preduce relative path of sound files on our file server the full path would become [HOMEPath] + '/i/' + this value + /// + /// + /// "a2" + /// + /// + /// We had previously used different pathes because when a directory became overcrowded our connection time would increase unbearably due to IRAN internet problems, so it is sensible to store it per record and not as a global option value + /// + public string SoundFilesFolder { get; set; } + + /// + /// MP3 File Path + /// + public string Mp3FilePath { get { return $"/i/{SoundFilesFolder}/{FileNameWithoutExtension}.mp3"; } } + + /// + /// MP3 url + /// + public string Mp3Url { get { return $"https://i.ganjoor.net/{SoundFilesFolder}/{FileNameWithoutExtension}.mp3"; } } + + + /// + /// OGG File Path + /// + public string OggFilePath { get { return $"/i/{SoundFilesFolder}/{FileNameWithoutExtension}.ogg"; } } + + /// + /// OGG url + /// + public string OggUrl { get { return $"https://i.ganjoor.net/{SoundFilesFolder}/{FileNameWithoutExtension}.ogg"; } } + + /// + /// This is also a legacy field + /// + /// + /// "/i/a2/x" + /// + public string XMLFilePath { get { return $"/i/{SoundFilesFolder}/x/{FileNameWithoutExtension}.xml"; } } + + /// + /// Audio Title + /// + public string AudioTitle { get; set; } + + /// + /// Audio Artist + /// + public string AudioArtist { get; set; } + + /// + /// Audio Artist Url + /// + public string AudioArtistUrl { get; set; } + + /// + /// Audio Source + /// + public string AudioSrc { get; set; } + + /// + /// Audio Src Url + /// + public string AudioSrcUrl { get; set; } + + /// + /// Legacy Audio Guid + /// + public Guid LegacyAudioGuid { get; set; } + + /// + /// Audio File CheckSum + /// + public string Mp3FileCheckSum { get; set; } + + /// + /// mp3 size in bytes + /// + public int Mp3SizeInBytes { get; set; } + + /// + /// ogg size in bytes + /// + public int OggSizeInBytes { get; set; } + + /// + /// Audio Date + /// + public DateTime UploadDate { get; set; } + + /// + /// MP3 File temporary pass on Windows Server + /// + public string TemporaryUploadedMp3FilePath { get; set; } + + /// + /// XML File temporary pass on Windows Server + /// + public string TemporaryUploadedXmlFilePath { get; set; } + + /// + /// Value is one or a combination of + /// + public int AudioSyncStatus { get; set; } + } +} diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index f44a4d22..b2f7c194 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1495,6 +1495,185 @@ User Note + + + Audio Synchronization Status (binary combination is acceptable) + + + + + no changed + + + + + new upload + + + + + meta data should be updated + + + + + sound files should be reuploaded + + + + + Xml file should be reuploaded + + + + + Item is deleted + + + + + Poem Narration + + + + + Id + + + + + Owner User + + + + + Owner User Id + + + + + Ganjoor Post Id + + + + + This determines where an audio is displayed between a list of sounds related to a specfic poem + + + + + Final data is actually exported to a MySQL database which this auto increment field is its key + + + + + Using this field content you would determine xml, mp3 and ogg file names + + + + + combining this with + .ext would preduce relative path of sound files on our file server the full path would become [HOMEPath] + '/i/' + this value + + + "a2" + + + We had previously used different pathes because when a directory became overcrowded our connection time would increase unbearably due to IRAN internet problems, so it is sensible to store it per record and not as a global option value + + + + + MP3 File Path + + + + + MP3 url + + + + + OGG File Path + + + + + OGG url + + + + + This is also a legacy field + + + "/i/a2/x" + + + + + Audio Title + + + + + Audio Artist + + + + + Audio Artist Url + + + + + Audio Source + + + + + Audio Src Url + + + + + Legacy Audio Guid + + + + + Audio File CheckSum + + + + + mp3 size in bytes + + + + + ogg size in bytes + + + + + Audio Date + + + + + MP3 File temporary pass on Windows Server + + + + + XML File temporary pass on Windows Server + + + + + Value is one or a combination of + + ganjoor link for artifacts and items From 6cc34968b53c367ed3c03dc8aca1544981b71a72 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sat, 29 Aug 2020 19:20:31 +0430 Subject: [PATCH 2/3] #1 Model improvements --- .../Models/GanjoorAudio/AudioReviewStatus.cs | 23 ++++++++ .../Models/GanjoorAudio/AudioSyncStatus.cs | 2 +- RMuseum/Models/GanjoorAudio/PoemNarration.cs | 38 +++++++----- RMuseum/RMuseum.xml | 58 ++++++++++++++----- 4 files changed, 93 insertions(+), 28 deletions(-) create mode 100644 RMuseum/Models/GanjoorAudio/AudioReviewStatus.cs diff --git a/RMuseum/Models/GanjoorAudio/AudioReviewStatus.cs b/RMuseum/Models/GanjoorAudio/AudioReviewStatus.cs new file mode 100644 index 00000000..16d730da --- /dev/null +++ b/RMuseum/Models/GanjoorAudio/AudioReviewStatus.cs @@ -0,0 +1,23 @@ +namespace RMuseum.Models.GanjoorAudio +{ + /// + /// Audio Review Status + /// + public enum AudioReviewStatus + { + /// + /// pending for review + /// + Pending = 0, + + /// + /// approved + /// + Approved = 1, + + /// + /// Rejected + /// + Rejected = 2 + } +} diff --git a/RMuseum/Models/GanjoorAudio/AudioSyncStatus.cs b/RMuseum/Models/GanjoorAudio/AudioSyncStatus.cs index c03c33ca..6dcc29b0 100644 --- a/RMuseum/Models/GanjoorAudio/AudioSyncStatus.cs +++ b/RMuseum/Models/GanjoorAudio/AudioSyncStatus.cs @@ -8,7 +8,7 @@ /// /// no changed /// - Synchronized = 0, + SynchronizedOrRejected = 0, /// /// new upload diff --git a/RMuseum/Models/GanjoorAudio/PoemNarration.cs b/RMuseum/Models/GanjoorAudio/PoemNarration.cs index fa074e5d..788400b7 100644 --- a/RMuseum/Models/GanjoorAudio/PoemNarration.cs +++ b/RMuseum/Models/GanjoorAudio/PoemNarration.cs @@ -24,6 +24,11 @@ namespace RMuseum.Models.GanjoorAudio /// public Guid OwnerId { get; set; } + /// + /// Final data is actually exported to a MySQL database which this auto increment field is its key + /// + public int GanjoorAudioId { get; set; } + /// /// Ganjoor Post Id /// @@ -34,11 +39,6 @@ namespace RMuseum.Models.GanjoorAudio /// public int AudioOrder { get; set; } - /// - /// Final data is actually exported to a MySQL database which this auto increment field is its key - /// - public int GanjoorAudioId { get; set; } - /// /// Using this field content you would determine xml, mp3 and ogg file names /// @@ -58,7 +58,7 @@ namespace RMuseum.Models.GanjoorAudio /// /// MP3 File Path /// - public string Mp3FilePath { get { return $"/i/{SoundFilesFolder}/{FileNameWithoutExtension}.mp3"; } } + public string RemoteMp3FilePath { get { return $"/i/{SoundFilesFolder}/{FileNameWithoutExtension}.mp3"; } } /// /// MP3 url @@ -69,7 +69,7 @@ namespace RMuseum.Models.GanjoorAudio /// /// OGG File Path /// - public string OggFilePath { get { return $"/i/{SoundFilesFolder}/{FileNameWithoutExtension}.ogg"; } } + public string RemoteOggFilePath { get { return $"/i/{SoundFilesFolder}/{FileNameWithoutExtension}.ogg"; } } /// /// OGG url @@ -82,7 +82,7 @@ namespace RMuseum.Models.GanjoorAudio /// /// "/i/a2/x" /// - public string XMLFilePath { get { return $"/i/{SoundFilesFolder}/x/{FileNameWithoutExtension}.xml"; } } + public string RemoteXMLFilePath { get { return $"/i/{SoundFilesFolder}/x/{FileNameWithoutExtension}.xml"; } } /// /// Audio Title @@ -130,23 +130,35 @@ namespace RMuseum.Models.GanjoorAudio public int OggSizeInBytes { get; set; } /// - /// Audio Date + /// Upload Date /// public DateTime UploadDate { get; set; } /// - /// MP3 File temporary pass on Windows Server + /// Review Date (Approve or Reject) /// - public string TemporaryUploadedMp3FilePath { get; set; } + public DateTime ReviewDate{ get; set; } /// - /// XML File temporary pass on Windows Server + /// MP3 File local path on Windows Server (if item is not rejected probably it is not valid and it is deleted) /// - public string TemporaryUploadedXmlFilePath { get; set; } + public string LocalMp3FilePath { get; set; } + + /// + /// XML File local path on Windows Server (if item is not rejected probably it is not valid and it is deleted) + /// + public string LocalXmlFilePath { get; set; } /// /// Value is one or a combination of /// public int AudioSyncStatus { get; set; } + + /// + /// Review Status + /// + public AudioReviewStatus ReviewStatus { get; set; } + + } } diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index b2f7c194..85cf51b4 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1495,12 +1495,32 @@ User Note + + + Audio Review Status + + + + + pending for review + + + + + approved + + + + + Rejected + + Audio Synchronization Status (binary combination is acceptable) - + no changed @@ -1550,6 +1570,11 @@ Owner User Id + + + Final data is actually exported to a MySQL database which this auto increment field is its key + + Ganjoor Post Id @@ -1560,11 +1585,6 @@ This determines where an audio is displayed between a list of sounds related to a specfic poem - - - Final data is actually exported to a MySQL database which this auto increment field is its key - - Using this field content you would determine xml, mp3 and ogg file names @@ -1581,7 +1601,7 @@ We had previously used different pathes because when a directory became overcrowded our connection time would increase unbearably due to IRAN internet problems, so it is sensible to store it per record and not as a global option value - + MP3 File Path @@ -1591,7 +1611,7 @@ MP3 url - + OGG File Path @@ -1601,7 +1621,7 @@ OGG url - + This is also a legacy field @@ -1656,17 +1676,22 @@ - Audio Date + Upload Date - + - MP3 File temporary pass on Windows Server + Review Date (Approve or Reject) - + - XML File temporary pass on Windows Server + MP3 File local path on Windows Server (if item is not rejected probably it is not valid and it is deleted) + + + + + XML File local path on Windows Server (if item is not rejected probably it is not valid and it is deleted) @@ -1674,6 +1699,11 @@ Value is one or a combination of + + + Review Status + + ganjoor link for artifacts and items From b83dfe32748b4da0aae5ee4eda91a0b03351583d Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sat, 29 Aug 2020 19:50:55 +0430 Subject: [PATCH 3/3] Fixed a horrible password exposure (the exposed password is now changed and password is moved to configution file which has different values on the production server from source) --- RMuseum/RMuseum.xml | 5 --- .../Implementation/MailKitEmailSender.cs | 33 -------------- RMuseum/appsettings.json | 13 +++++- RSecurityBackend/RSecurityBackend.xml | 18 +++++--- ...ailSenderBase.cs => MailKitEmailSender.cs} | 45 +++++++++++++------ 5 files changed, 54 insertions(+), 60 deletions(-) delete mode 100644 RMuseum/Services/Implementation/MailKitEmailSender.cs rename RSecurityBackend/Services/Implementation/{MailKitEmailSenderBase.cs => MailKitEmailSender.cs} (64%) diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 85cf51b4..4ed7ebf5 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -3710,11 +3710,6 @@ - - - SmptConfig - - manipulating picture files diff --git a/RMuseum/Services/Implementation/MailKitEmailSender.cs b/RMuseum/Services/Implementation/MailKitEmailSender.cs deleted file mode 100644 index 8b858e37..00000000 --- a/RMuseum/Services/Implementation/MailKitEmailSender.cs +++ /dev/null @@ -1,33 +0,0 @@ -using RSecurityBackend.Models.Mail; -using RSecurityBackend.Services.Implementation; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace RMuseum.Services.Implementation -{ - public class MailKitEmailSender : MailKitEmailSenderBase - { - /// - /// SmptConfig - /// - public override SmptConfig SmptConfig - { - get - { - return - new SmptConfig() - { - port = 25, - server = "ganjgah.ir", - smtpUsername = "noreply@ganjgah.ir", - smtpPassword = "sahY%6&$OnD67i0978", - from = "noreply@ganjgah.ir", - useSsl = false - }; - } - } - } - -} diff --git a/RMuseum/appsettings.json b/RMuseum/appsettings.json index 8e7270f1..5405574b 100644 --- a/RMuseum/appsettings.json +++ b/RMuseum/appsettings.json @@ -25,5 +25,14 @@ "Secret": "k4Fy7pDsc0LgXQ8PCCfZtwmju5Ed8asc", "DefaultTokenExpirationInSeconds": "2502000" }, - "AllowedHosts": "*" - } + "SmptConfig": { + "Server": "smtp.gmail.com", + "Port": "465", + "UseSsl": "true", + "Username": "test@gmail.com", + "Password": "password", + "From": "test@gmail.com" + }, + + "AllowedHosts": "*" +} diff --git a/RSecurityBackend/RSecurityBackend.xml b/RSecurityBackend/RSecurityBackend.xml index df14a63e..7f5fbf08 100644 --- a/RSecurityBackend/RSecurityBackend.xml +++ b/RSecurityBackend/RSecurityBackend.xml @@ -2571,27 +2571,33 @@ - + mail sender using MailKit - + constructor + - + + + Configuration + + + options - + SmptConfig - + send email @@ -2600,7 +2606,7 @@ - + diff --git a/RSecurityBackend/Services/Implementation/MailKitEmailSenderBase.cs b/RSecurityBackend/Services/Implementation/MailKitEmailSender.cs similarity index 64% rename from RSecurityBackend/Services/Implementation/MailKitEmailSenderBase.cs rename to RSecurityBackend/Services/Implementation/MailKitEmailSender.cs index 3c97f607..07929f5a 100644 --- a/RSecurityBackend/Services/Implementation/MailKitEmailSenderBase.cs +++ b/RSecurityBackend/Services/Implementation/MailKitEmailSender.cs @@ -1,6 +1,6 @@ using MailKit.Net.Smtp; using Microsoft.AspNetCore.Identity.UI.Services; -using Microsoft.Extensions.Options; +using Microsoft.Extensions.Configuration; using MimeKit; using RSecurityBackend.Models.Mail; using System.Threading.Tasks; @@ -10,38 +10,55 @@ namespace RSecurityBackend.Services.Implementation /// /// mail sender using MailKit /// - public class MailKitEmailSenderBase : IEmailSender + public class MailKitEmailSender : IEmailSender { /// /// constructor /// - public MailKitEmailSenderBase() + /// + public MailKitEmailSender(IConfiguration configuration) { + Configuration = configuration; Options = SmptConfig; + } + /// + /// Configuration + /// + protected IConfiguration Configuration { get; } + /// /// options /// public SmptConfig Options { get; } //set only via Secret Manager + + private SmptConfig _SmptConfig = null; + /// /// SmptConfig /// - public virtual SmptConfig SmptConfig + public SmptConfig SmptConfig { get { - return - new SmptConfig() - { - port = 465, - server = "smtp.gmail.com", - smtpUsername = "nonexistingganjoor@gmail.com", - smtpPassword = "APasswordHere", - from = "nonexistingganjoor@gmail.com", - useSsl = true - }; + if (_SmptConfig == null) + { + _SmptConfig = + new SmptConfig() + { + server = $"{Configuration.GetSection("SmptConfig")["Server"]}", + port = int.Parse($"{Configuration.GetSection("SmptConfig")["Port"]}"), + useSsl = bool.Parse($"{Configuration.GetSection("SmptConfig")["UseSsl"]}"), + smtpUsername = $"{ Configuration.GetSection("SmptConfig")["Username"] }", + smtpPassword = $"{Configuration.GetSection("SmptConfig")["Password"]}", + from = $"{ Configuration.GetSection("SmptConfig")["From"] }" + + }; + } + return _SmptConfig; + } }