mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Send an e-mail when a device report is received.
This commit is contained in:
@@ -40,6 +40,8 @@ using System.Web.Http;
|
||||
using System.Xml.Serialization;
|
||||
using DiscImageChef.CommonTypes.Metadata;
|
||||
using DiscImageChef.Server.Models;
|
||||
using MailKit.Net.Smtp;
|
||||
using MimeKit;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DiscImageChef.Server.Controllers
|
||||
@@ -72,9 +74,34 @@ namespace DiscImageChef.Server.Controllers
|
||||
return response;
|
||||
}
|
||||
|
||||
ctx.Reports.Add(new UploadedReport(new DeviceReportV2(newReport)));
|
||||
DeviceReportV2 reportV2 = new DeviceReportV2(newReport);
|
||||
StringWriter jsonSw = new StringWriter();
|
||||
jsonSw.Write(JsonConvert.SerializeObject(reportV2, Formatting.Indented,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
}));
|
||||
string reportV2String = jsonSw.ToString();
|
||||
jsonSw.Close();
|
||||
|
||||
ctx.Reports.Add(new UploadedReport(reportV2));
|
||||
ctx.SaveChanges();
|
||||
|
||||
MimeMessage message = new MimeMessage
|
||||
{
|
||||
Subject = "New device report (old version)",
|
||||
Body = new TextPart("plain") {Text = reportV2String}
|
||||
};
|
||||
message.From.Add(new MailboxAddress("DiscImageChef", "dic@claunia.com"));
|
||||
message.To.Add(new MailboxAddress("Natalia Portillo", "claunia@claunia.com"));
|
||||
|
||||
using(SmtpClient client = new SmtpClient())
|
||||
{
|
||||
client.Connect("mail.claunia.com", 25, false);
|
||||
client.Send(message);
|
||||
client.Disconnect(true);
|
||||
}
|
||||
|
||||
response.Content = new StringContent("ok", Encoding.UTF8, "text/plain");
|
||||
return response;
|
||||
}
|
||||
@@ -104,7 +131,8 @@ namespace DiscImageChef.Server.Controllers
|
||||
HttpRequest request = HttpContext.Current.Request;
|
||||
|
||||
StreamReader sr = new StreamReader(request.InputStream);
|
||||
DeviceReportV2 newReport = JsonConvert.DeserializeObject<DeviceReportV2>(sr.ReadToEnd());
|
||||
string reportJson = sr.ReadToEnd();
|
||||
DeviceReportV2 newReport = JsonConvert.DeserializeObject<DeviceReportV2>(reportJson);
|
||||
|
||||
if(newReport == null)
|
||||
{
|
||||
@@ -115,6 +143,20 @@ namespace DiscImageChef.Server.Controllers
|
||||
ctx.Reports.Add(new UploadedReport(newReport));
|
||||
ctx.SaveChanges();
|
||||
|
||||
MimeMessage message = new MimeMessage
|
||||
{
|
||||
Subject = "New device report", Body = new TextPart("plain") {Text = reportJson}
|
||||
};
|
||||
message.From.Add(new MailboxAddress("DiscImageChef", "dic@claunia.com"));
|
||||
message.To.Add(new MailboxAddress("Natalia Portillo", "claunia@claunia.com"));
|
||||
|
||||
using(SmtpClient client = new SmtpClient())
|
||||
{
|
||||
client.Connect("mail.claunia.com", 25, false);
|
||||
client.Send(message);
|
||||
client.Disconnect(true);
|
||||
}
|
||||
|
||||
response.Content = new StringContent("ok", Encoding.UTF8, "text/plain");
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BouncyCastle.Crypto, Version=1.8.2.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
|
||||
<HintPath>..\packages\BouncyCastle.1.8.2\lib\BouncyCastle.Crypto.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@@ -77,11 +81,19 @@
|
||||
<HintPath>..\packages\Highsoft.Highcharts.6.2.0.67\lib\net40\Highcharts.Web.Mvc.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="MailKit, Version=2.1.0.0, Culture=neutral, PublicKeyToken=4e064fe7c44a8f1b">
|
||||
<HintPath>..\packages\MailKit.2.1.1\lib\net45\MailKit.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Markdig, Version=0.15.5.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\packages\Markdig.0.15.5\lib\net40\Markdig.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="MimeKit, Version=2.1.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814">
|
||||
<HintPath>..\packages\MimeKit.2.1.1\lib\net45\MimeKit.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="MySql.Data, Version=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
|
||||
<HintPath>..\packages\MySql.Data.8.0.13\lib\net452\MySql.Data.dll</HintPath>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Antlr" version="3.5.0.2" targetFramework="net461" />
|
||||
<package id="BouncyCastle" version="1.8.2" targetFramework="net461" />
|
||||
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
|
||||
<package id="Google.Protobuf" version="3.5.1" targetFramework="net461" />
|
||||
<package id="Highsoft.Highcharts" version="6.2.0.67" targetFramework="net461" />
|
||||
<package id="MailKit" version="2.1.1" targetFramework="net461" />
|
||||
<package id="Markdig" version="0.15.5" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="5.2.4" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.4" targetFramework="net461" />
|
||||
@@ -17,6 +19,7 @@
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.4" targetFramework="net461" />
|
||||
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net461" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
|
||||
<package id="MimeKit" version="2.1.1" targetFramework="net461" />
|
||||
<package id="MySql.Data" version="8.0.13" targetFramework="net461" />
|
||||
<package id="MySql.Data.EntityFramework" version="8.0.13" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="11.0.1" targetFramework="net461" />
|
||||
|
||||
Reference in New Issue
Block a user