Migrated to latest libs and .net core 3.1 fingers crossed...

This commit is contained in:
2020-06-08 22:05:40 +00:00
parent 2b5fc45add
commit 4e13b3c9bb
4 changed files with 247 additions and 89 deletions

View File

@@ -1,5 +1,11 @@
using Microsoft.AspNetCore; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace rockfishCore namespace rockfishCore
{ {
@@ -7,17 +13,45 @@ namespace rockfishCore
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
BuildWebHost(args).Run(); CreateHostBuilder(args).Build().Run();
} }
public static IWebHost BuildWebHost(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
.UseUrls("http://*:3001") .ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseUrls("http://*:3001")
.CaptureStartupErrors(true) .CaptureStartupErrors(true)
.UseSetting("detailedErrors", "true") .UseSetting("detailedErrors", "true")
.UseKestrel() .UseKestrel()
.UseContentRoot(System.IO.Directory.GetCurrentDirectory()) .UseContentRoot(System.IO.Directory.GetCurrentDirectory());
.UseStartup<Startup>() });
.Build();
} }
} }
// namespace rockfishCore
// {
// public class Program
// {
// public static void Main(string[] args)
// {
// BuildWebHost(args).Run();
// }
// public static IWebHost BuildWebHost(string[] args) =>
// WebHost.CreateDefaultBuilder(args)
// .UseUrls("http://*:3001")
// .CaptureStartupErrors(true)
// .UseSetting("detailedErrors", "true")
// .UseKestrel()
// .UseContentRoot(System.IO.Directory.GetCurrentDirectory())
// .UseStartup<Startup>()
// .Build();
// }
// }

View File

@@ -4,92 +4,90 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
//manually added
using Microsoft.EntityFrameworkCore;
using rockfishCore.Models; using rockfishCore.Models;
using rockfishCore.Util;
using Microsoft.EntityFrameworkCore;
using System.IO;
using System.Reflection;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using rockfishCore.Util;
//added when upgrade to v2 of .netcore
using Microsoft.AspNetCore.Authentication;
//this comment added in windows with notepad++ using Microsoft.AspNetCore.Http;
//this comment added in Linux with vscode using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.Extensions.Options;
namespace rockfishCore namespace rockfishCore
{ {
public class Startup public class Startup
{ {
public Startup(IHostingEnvironment env) public Startup(IConfiguration configuration)
{ {
var builder = new ConfigurationBuilder() Configuration = configuration;
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
} }
public IConfigurationRoot Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddControllers();
services.AddDbContext<rockfishContext>(options =>
{
options.UseSqlite(Configuration.GetConnectionString("rfdb")).EnableSensitiveDataLogging(false);
services.AddDbContext<rockfishContext>( });
options =>
{
options.UseSqlite(Configuration.GetConnectionString("rfdb"));
options.EnableSensitiveDataLogging(false);
}
);
//Added this so that can access configuration from anywhere else
//See authcontroller for usage
services.AddSingleton<IConfiguration>(Configuration);
services.AddMvc();
//get the key from the appsettings.json file
var secretKey = Configuration.GetSection("JWT").GetValue<string>("secret"); var secretKey = Configuration.GetSection("JWT").GetValue<string>("secret");
var signingKey = new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes(secretKey)); var signingKey = new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes(secretKey));
services.AddAuthentication(options => services.AddAuthentication(options =>
{ {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options => }).AddJwtBearer(options =>
{ {
// options.AutomaticAuthenticate = true; options.TokenValidationParameters = new TokenValidationParameters
// options.AutomaticChallenge = true; {
options.TokenValidationParameters = new TokenValidationParameters // Token signature will be verified using a private key.
{ ValidateIssuerSigningKey = true,
// Token signature will be verified using a private key. RequireSignedTokens = true,
ValidateIssuerSigningKey = true, IssuerSigningKey = signingKey,
RequireSignedTokens = true, ValidateIssuer = true,
IssuerSigningKey = signingKey, ValidIssuer = "rockfishCore",
ValidateIssuer = true, ValidateAudience = false,
ValidIssuer = "rockfishCore",
ValidateAudience = false, //Note: these are all enabled in AyaNOva but were origionally disabled in rf
// ValidAudience = "https://yourapplication.example.com", // // Token will only be valid if not expired yet, with 5 minutes clock skew.
// ValidateLifetime = true,
// RequireExpirationTime = true,
// ClockSkew = new TimeSpan(0, 5, 0),
};
});
// Token will only be valid if not expired yet, with 5 minutes clock skew.
// ValidateLifetime = true,
// RequireExpirationTime = true,
// ClockSkew = new TimeSpan(0, 5, 0),
};
});
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, rockfishContext dbContext) public void Configure(IApplicationBuilder app, IWebHostEnvironment env, rockfishContext dbContext)
{ {
loggerFactory.AddConsole(Configuration.GetSection("Logging")); if (env.IsDevelopment())
loggerFactory.AddDebug(); {
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles(); app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions app.UseStaticFiles(new StaticFileOptions
{ {
@@ -103,20 +101,145 @@ namespace rockfishCore
} }
}); });
app.UseAuthentication(); app.UseAuthentication();
app.UseMvc();
//Check schema //Check schema
RfSchema.CheckAndUpdate(dbContext); RfSchema.CheckAndUpdate(dbContext);
//bool bMM=RfMail.MailIsMirroringProperly(); app.UseHttpsRedirection();
// try
// {
// var test = OpsDiagnostics.VerifyBackups();
// }
// catch (Exception ex)
// {
// string res = ex.Message;
// }
}//eof app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
} }
} }
// using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Threading.Tasks;
// using Microsoft.AspNetCore.Builder;
// using Microsoft.AspNetCore.Hosting;
// using Microsoft.Extensions.Configuration;
// using Microsoft.Extensions.DependencyInjection;
// using Microsoft.Extensions.Logging;
// //manually added
// using Microsoft.EntityFrameworkCore;
// using rockfishCore.Models;
// using Microsoft.AspNetCore.Authentication.JwtBearer;
// using Microsoft.IdentityModel.Tokens;
// using rockfishCore.Util;
// //added when upgrade to v2 of .netcore
// using Microsoft.AspNetCore.Authentication;
// //this comment added in windows with notepad++
// //this comment added in Linux with vscode
// namespace rockfishCore
// {
// public class Startup
// {
// public Startup(IHostingEnvironment env)
// {
// var builder = new ConfigurationBuilder()
// .SetBasePath(env.ContentRootPath)
// .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
// .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
// .AddEnvironmentVariables();
// Configuration = builder.Build();
// }
// public IConfigurationRoot Configuration { get; }
// // This method gets called by the runtime. Use this method to add services to the container.
// public void ConfigureServices(IServiceCollection services)
// {
// services.AddDbContext<rockfishContext>(
// options =>
// {
// options.UseSqlite(Configuration.GetConnectionString("rfdb"));
// options.EnableSensitiveDataLogging(false);
// }
// );
// //Added this so that can access configuration from anywhere else
// //See authcontroller for usage
// services.AddSingleton<IConfiguration>(Configuration);
// services.AddMvc();
// //get the key from the appsettings.json file
// var secretKey = Configuration.GetSection("JWT").GetValue<string>("secret");
// var signingKey = new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes(secretKey));
// services.AddAuthentication(options =>
// {
// options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
// options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
// }).AddJwtBearer(options =>
// {
// // options.AutomaticAuthenticate = true;
// // options.AutomaticChallenge = true;
// options.TokenValidationParameters = new TokenValidationParameters
// {
// // Token signature will be verified using a private key.
// ValidateIssuerSigningKey = true,
// RequireSignedTokens = true,
// IssuerSigningKey = signingKey,
// ValidateIssuer = true,
// ValidIssuer = "rockfishCore",
// ValidateAudience = false,
// // ValidAudience = "https://yourapplication.example.com",
// // Token will only be valid if not expired yet, with 5 minutes clock skew.
// // ValidateLifetime = true,
// // RequireExpirationTime = true,
// // ClockSkew = new TimeSpan(0, 5, 0),
// };
// });
// }
// public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, rockfishContext dbContext)
// {
// loggerFactory.AddConsole(Configuration.GetSection("Logging"));
// loggerFactory.AddDebug();
// app.UseDefaultFiles();
// app.UseStaticFiles(new StaticFileOptions
// {
// OnPrepareResponse = context =>
// {
// if (context.File.Name == "default.htm")
// {
// context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
// context.Context.Response.Headers.Add("Expires", "-1");
// }
// }
// });
// app.UseAuthentication();
// app.UseMvc();
// //Check schema
// RfSchema.CheckAndUpdate(dbContext);
// //bool bMM=RfMail.MailIsMirroringProperly();
// // try
// // {
// // var test = OpsDiagnostics.VerifyBackups();
// // }
// // catch (Exception ex)
// // {
// // string res = ex.Message;
// // }
// }//eof
// }
// }

View File

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="wwwroot\" /> <Folder Include="wwwroot\" />
@@ -8,12 +8,13 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<!-- <PackageReference Include="AWSSDK.S3" Version="3.3.20" /> --> <PackageReference Include="AWSSDK.S3" Version="3.3.111.9" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" /> <!-- <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" /> -->
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.4" />
<PackageReference Include="jose-jwt" Version="2.4.0" /> <PackageReference Include="jose-jwt" Version="2.5.0" />
<PackageReference Include="mailkit" Version="2.0.5" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.4" />
<PackageReference Include="mailkit" Version="2.7.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -119,8 +119,8 @@ namespace rockfishCore.Util
bool trackDeliveryStatus = false, string CustomHeader = "", string CustomHeaderValue = "") bool trackDeliveryStatus = false, string CustomHeader = "", string CustomHeaderValue = "")
{ {
var message = new MimeMessage(); var message = new MimeMessage();
message.From.Add(new MailboxAddress(MessageFrom)); message.From.Add(new MailboxAddress("",MessageFrom));
message.To.Add(new MailboxAddress(MessageTo)); message.To.Add(new MailboxAddress("",MessageTo));
message.Subject = MessageSubject; message.Subject = MessageSubject;
message.Body = new TextPart("plain") message.Body = new TextPart("plain")
@@ -273,12 +273,12 @@ namespace rockfishCore.Util
case rfMailAccount.sales: case rfMailAccount.sales:
from_account = MAIL_ACCOUNT_SALES; from_account = MAIL_ACCOUNT_SALES;
from_account_password = MAIL_ACCOUNT_PASSWORD_SALES; from_account_password = MAIL_ACCOUNT_PASSWORD_SALES;
from = new MailboxAddress(from_account); from = new MailboxAddress("",from_account);
break; break;
default: default:
from_account = MAIL_ACCOUNT_SUPPORT; from_account = MAIL_ACCOUNT_SUPPORT;
from_account_password = MAIL_ACCOUNT_PASSWORD_SUPPORT; from_account_password = MAIL_ACCOUNT_PASSWORD_SUPPORT;
from = new MailboxAddress(from_account); from = new MailboxAddress("",from_account);
break; break;
} }
reply.From.Add(from); reply.From.Add(from);
@@ -520,7 +520,7 @@ namespace rockfishCore.Util
string CustomHeader = "", string CustomHeaderValue = "") string CustomHeader = "", string CustomHeaderValue = "")
{ {
var message = new MimeMessage(); var message = new MimeMessage();
message.From.Add(new MailboxAddress(MessageFrom)); message.From.Add(new MailboxAddress("",MessageFrom));
//case 3512 handle more than one email in the address //case 3512 handle more than one email in the address
@@ -530,13 +530,13 @@ namespace rockfishCore.Util
var addrs = MessageTo.Split(','); var addrs = MessageTo.Split(',');
foreach (string addr in addrs) foreach (string addr in addrs)
{ {
mbAll.Add(new MailboxAddress(addr.Trim())); mbAll.Add(new MailboxAddress("",addr.Trim()));
} }
message.To.AddRange(mbAll); message.To.AddRange(mbAll);
} }
else else
{ {
message.To.Add(new MailboxAddress(MessageTo)); message.To.Add(new MailboxAddress("",MessageTo));
} }