|
|
|
@ -51,11 +51,11 @@ namespace Yavsc
|
|
|
|
public static string AvatarsDirName { private set; get; }
|
|
|
|
public static string AvatarsDirName { private set; get; }
|
|
|
|
public static string GitDirName { private set; get; }
|
|
|
|
public static string GitDirName { private set; get; }
|
|
|
|
public static string Authority { get; private set; }
|
|
|
|
public static string Authority { get; private set; }
|
|
|
|
public static string Temp { get; set; }
|
|
|
|
public static string Temp { get; set; }
|
|
|
|
public static SiteSettings SiteSetup { get; private set; }
|
|
|
|
public static SiteSettings SiteSetup { get; private set; }
|
|
|
|
public static GoogleServiceAccount GServiceAccount { get; private set; }
|
|
|
|
public static GoogleServiceAccount GServiceAccount { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public static string HostingFullName { get; set; }
|
|
|
|
public static string HostingFullName { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public static PayPalSettings PayPalSettings { get; private set; }
|
|
|
|
public static PayPalSettings PayPalSettings { get; private set; }
|
|
|
|
private static ILogger logger;
|
|
|
|
private static ILogger logger;
|
|
|
|
@ -66,9 +66,9 @@ namespace Yavsc
|
|
|
|
|
|
|
|
|
|
|
|
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
|
|
|
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var devtag = env.IsDevelopment()?"D":"";
|
|
|
|
var devtag = env.IsDevelopment() ? "D" : "";
|
|
|
|
var prodtag = env.IsProduction()?"P":"";
|
|
|
|
var prodtag = env.IsProduction() ? "P" : "";
|
|
|
|
var stagetag = env.IsStaging()?"S":"";
|
|
|
|
var stagetag = env.IsStaging() ? "S" : "";
|
|
|
|
|
|
|
|
|
|
|
|
HostingFullName = $"{appEnv.RuntimeFramework.FullName} [{env.EnvironmentName}:{prodtag}{devtag}{stagetag}]";
|
|
|
|
HostingFullName = $"{appEnv.RuntimeFramework.FullName} [{env.EnvironmentName}:{prodtag}{devtag}{stagetag}]";
|
|
|
|
// Set up configuration sources.
|
|
|
|
// Set up configuration sources.
|
|
|
|
@ -96,9 +96,9 @@ namespace Yavsc
|
|
|
|
|
|
|
|
|
|
|
|
var googleClientFile = Configuration["Authentication:Google:GoogleWebClientJson"];
|
|
|
|
var googleClientFile = Configuration["Authentication:Google:GoogleWebClientJson"];
|
|
|
|
var googleServiceAccountJsonFile = Configuration["Authentication:Google:GoogleServiceAccountJson"];
|
|
|
|
var googleServiceAccountJsonFile = Configuration["Authentication:Google:GoogleServiceAccountJson"];
|
|
|
|
if (googleClientFile!=null)
|
|
|
|
if (googleClientFile != null)
|
|
|
|
GoogleWebClientConfiguration = new ConfigurationBuilder().AddJsonFile(googleClientFile).Build();
|
|
|
|
GoogleWebClientConfiguration = new ConfigurationBuilder().AddJsonFile(googleClientFile).Build();
|
|
|
|
if (googleServiceAccountJsonFile!=null)
|
|
|
|
if (googleServiceAccountJsonFile != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var safile = new FileInfo(googleServiceAccountJsonFile);
|
|
|
|
var safile = new FileInfo(googleServiceAccountJsonFile);
|
|
|
|
GServiceAccount = JsonConvert.DeserializeObject<GoogleServiceAccount>(safile.OpenText().ReadToEnd());
|
|
|
|
GServiceAccount = JsonConvert.DeserializeObject<GoogleServiceAccount>(safile.OpenText().ReadToEnd());
|
|
|
|
@ -276,7 +276,7 @@ namespace Yavsc
|
|
|
|
services.AddTransient<IEmailSender, MailSender>();
|
|
|
|
services.AddTransient<IEmailSender, MailSender>();
|
|
|
|
services.AddTransient<IYavscMessageSender, YavscMessageSender>();
|
|
|
|
services.AddTransient<IYavscMessageSender, YavscMessageSender>();
|
|
|
|
services.AddTransient<IBillingService, BillingService>();
|
|
|
|
services.AddTransient<IBillingService, BillingService>();
|
|
|
|
services.AddTransient<IDataStore, FileDataStore>( (sp) => new FileDataStore("googledatastore",false) );
|
|
|
|
services.AddTransient<IDataStore, FileDataStore>((sp) => new FileDataStore("googledatastore", false));
|
|
|
|
services.AddTransient<ICalendarManager, CalendarManager>();
|
|
|
|
services.AddTransient<ICalendarManager, CalendarManager>();
|
|
|
|
|
|
|
|
|
|
|
|
// TODO for SMS: services.AddTransient<ISmsSender, AuthMessageSender>();
|
|
|
|
// TODO for SMS: services.AddTransient<ISmsSender, AuthMessageSender>();
|
|
|
|
@ -312,9 +312,9 @@ namespace Yavsc
|
|
|
|
SiteSetup = siteSettings.Value;
|
|
|
|
SiteSetup = siteSettings.Value;
|
|
|
|
Authority = siteSettings.Value.Authority;
|
|
|
|
Authority = siteSettings.Value.Authority;
|
|
|
|
var blogsDir = siteSettings.Value.Blog;
|
|
|
|
var blogsDir = siteSettings.Value.Blog;
|
|
|
|
if (blogsDir==null) throw new Exception ("blogsDir is not set.");
|
|
|
|
if (blogsDir == null) throw new Exception("blogsDir is not set.");
|
|
|
|
var billsDir = siteSettings.Value.Bills;
|
|
|
|
var billsDir = siteSettings.Value.Bills;
|
|
|
|
if (billsDir==null) throw new Exception ("billsDir is not set.");
|
|
|
|
if (billsDir == null) throw new Exception("billsDir is not set.");
|
|
|
|
|
|
|
|
|
|
|
|
AbstractFileSystemHelpers.UserFilesDirName = new DirectoryInfo(blogsDir).FullName;
|
|
|
|
AbstractFileSystemHelpers.UserFilesDirName = new DirectoryInfo(blogsDir).FullName;
|
|
|
|
AbstractFileSystemHelpers.UserBillsDirName = new DirectoryInfo(billsDir).FullName;
|
|
|
|
AbstractFileSystemHelpers.UserBillsDirName = new DirectoryInfo(billsDir).FullName;
|
|
|
|
@ -325,7 +325,7 @@ namespace Yavsc
|
|
|
|
// Create required directories
|
|
|
|
// Create required directories
|
|
|
|
foreach (string dir in new string[] { AbstractFileSystemHelpers.UserFilesDirName, AbstractFileSystemHelpers.UserBillsDirName, SiteSetup.TempDir })
|
|
|
|
foreach (string dir in new string[] { AbstractFileSystemHelpers.UserFilesDirName, AbstractFileSystemHelpers.UserBillsDirName, SiteSetup.TempDir })
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (dir==null) throw new Exception (nameof(dir));
|
|
|
|
if (dir == null) throw new Exception(nameof(dir));
|
|
|
|
|
|
|
|
|
|
|
|
DirectoryInfo di = new DirectoryInfo(dir);
|
|
|
|
DirectoryInfo di = new DirectoryInfo(dir);
|
|
|
|
if (!di.Exists) di.Create();
|
|
|
|
if (!di.Exists) di.Create();
|
|
|
|
@ -339,8 +339,9 @@ namespace Yavsc
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var logenvvar = Environment.GetEnvironmentVariable("ASPNET_LOG_LEVEL");
|
|
|
|
var logenvvar = Environment.GetEnvironmentVariable("ASPNET_LOG_LEVEL");
|
|
|
|
if (logenvvar!=null)
|
|
|
|
if (logenvvar != null)
|
|
|
|
switch (logenvvar) {
|
|
|
|
switch (logenvvar)
|
|
|
|
|
|
|
|
{
|
|
|
|
case "info":
|
|
|
|
case "info":
|
|
|
|
loggerFactory.MinimumLevel = LogLevel.Information;
|
|
|
|
loggerFactory.MinimumLevel = LogLevel.Information;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@ -399,7 +400,7 @@ namespace Yavsc
|
|
|
|
// before fixing the security protocol, let beleive our lib it's done with it.
|
|
|
|
// before fixing the security protocol, let beleive our lib it's done with it.
|
|
|
|
var cxmgr = ConnectionManager.Instance;
|
|
|
|
var cxmgr = ConnectionManager.Instance;
|
|
|
|
// then, fix it.
|
|
|
|
// then, fix it.
|
|
|
|
ServicePointManager.SecurityProtocol = (SecurityProtocolType) 0xC00; // Tls12, required by PayPal
|
|
|
|
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xC00; // Tls12, required by PayPal
|
|
|
|
|
|
|
|
|
|
|
|
app.UseIISPlatformHandler(options =>
|
|
|
|
app.UseIISPlatformHandler(options =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -410,17 +411,25 @@ namespace Yavsc
|
|
|
|
|
|
|
|
|
|
|
|
ConfigureOAuthApp(app, SiteSetup, logger);
|
|
|
|
ConfigureOAuthApp(app, SiteSetup, logger);
|
|
|
|
ConfigureFileServerApp(app, SiteSetup, env, authorizationService);
|
|
|
|
ConfigureFileServerApp(app, SiteSetup, env, authorizationService);
|
|
|
|
app.UseRequestLocalization(localizationOptions.Value, (RequestCulture) new RequestCulture((string)"en-US"));
|
|
|
|
app.UseRequestLocalization(localizationOptions.Value, (RequestCulture)new RequestCulture((string)"en-US"));
|
|
|
|
|
|
|
|
|
|
|
|
ConfigureWorkflow(app, SiteSetup, logger);
|
|
|
|
ConfigureWorkflow(app, SiteSetup, logger);
|
|
|
|
|
|
|
|
// Empty this odd chat user list from db
|
|
|
|
|
|
|
|
foreach (var p in dbContext.ChatConnection)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dbContext.Entry(p).State = EntityState.Deleted;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
ConfigureWebSocketsApp(app, SiteSetup, env);
|
|
|
|
ConfigureWebSocketsApp(app, SiteSetup, env);
|
|
|
|
|
|
|
|
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
routes.MapRoute(
|
|
|
|
routes.MapRoute(
|
|
|
|
name: "default",
|
|
|
|
name: "default",
|
|
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
logger.LogInformation("LocalApplicationData: "+Environment.GetFolderPath(SpecialFolder.LocalApplicationData, SpecialFolderOption.DoNotVerify));
|
|
|
|
logger.LogInformation("LocalApplicationData: " + Environment.GetFolderPath(SpecialFolder.LocalApplicationData, SpecialFolderOption.DoNotVerify));
|
|
|
|
app.Use(async (context, next) =>
|
|
|
|
app.Use(async (context, next) =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var liveCasting = context.Request.Path.StartsWithSegments(liveCastingPath);
|
|
|
|
var liveCasting = context.Request.Path.StartsWithSegments(liveCastingPath);
|
|
|
|
@ -432,9 +441,10 @@ namespace Yavsc
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!context.User.Identity.IsAuthenticated)
|
|
|
|
if (!context.User.Identity.IsAuthenticated)
|
|
|
|
context.Response.StatusCode = 403;
|
|
|
|
context.Response.StatusCode = 403;
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
// get the flow id from request path
|
|
|
|
// get the flow id from request path
|
|
|
|
var castid = long.Parse(context.Request.Path.Value.Substring(liveCastingPath.Value.Length+1));
|
|
|
|
var castid = long.Parse(context.Request.Path.Value.Substring(liveCastingPath.Value.Length + 1));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var uname = context.User.GetUserName();
|
|
|
|
var uname = context.User.GetUserName();
|
|
|
|
@ -443,21 +453,25 @@ namespace Yavsc
|
|
|
|
|
|
|
|
|
|
|
|
var uid = context.User.GetUserId();
|
|
|
|
var uid = context.User.GetUserId();
|
|
|
|
// get some setup from user
|
|
|
|
// get some setup from user
|
|
|
|
var flow = _dbContext.LiveFlow.Include(f=>f.Owner).SingleOrDefault(f=> (f.OwnerId==uid && f.Id == castid));
|
|
|
|
var flow = _dbContext.LiveFlow.Include(f => f.Owner).SingleOrDefault(f => (f.OwnerId == uid && f.Id == castid));
|
|
|
|
if (flow == null)
|
|
|
|
if (flow == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
context.Response.StatusCode = 400;
|
|
|
|
context.Response.StatusCode = 400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
LiveCastMeta meta=null;
|
|
|
|
{
|
|
|
|
|
|
|
|
LiveCastMeta meta = null;
|
|
|
|
if (LiveApiController.Casters.ContainsKey(uname))
|
|
|
|
if (LiveApiController.Casters.ContainsKey(uname))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
meta = LiveApiController.Casters[uname];
|
|
|
|
meta = LiveApiController.Casters[uname];
|
|
|
|
if (meta.Socket.State != WebSocketState.Closed) {
|
|
|
|
if (meta.Socket.State != WebSocketState.Closed)
|
|
|
|
|
|
|
|
{
|
|
|
|
// FIXME loosed connexion should be detected & disposed else where
|
|
|
|
// FIXME loosed connexion should be detected & disposed else where
|
|
|
|
meta.Socket.Dispose();
|
|
|
|
meta.Socket.Dispose();
|
|
|
|
meta.Socket = await context.WebSockets.AcceptWebSocketAsync();
|
|
|
|
meta.Socket = await context.WebSockets.AcceptWebSocketAsync();
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
meta.Socket.Dispose();
|
|
|
|
meta.Socket.Dispose();
|
|
|
|
// Accept the socket
|
|
|
|
// Accept the socket
|
|
|
|
meta.Socket = await context.WebSockets.AcceptWebSocketAsync();
|
|
|
|
meta.Socket = await context.WebSockets.AcceptWebSocketAsync();
|
|
|
|
@ -470,7 +484,8 @@ namespace Yavsc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.LogInformation("Accepted web socket");
|
|
|
|
logger.LogInformation("Accepted web socket");
|
|
|
|
// Dispatch the flow
|
|
|
|
// Dispatch the flow
|
|
|
|
try {
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -489,13 +504,20 @@ namespace Yavsc
|
|
|
|
|
|
|
|
|
|
|
|
var hubContext = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
|
|
|
|
var hubContext = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
|
|
|
|
|
|
|
|
|
|
|
|
hubContext.Clients.All.addPublicStream(new { id = flow.Id, sender = flow.Owner.UserName, title = flow.Title, url = flow.GetFileUrl(),
|
|
|
|
hubContext.Clients.All.addPublicStream(new
|
|
|
|
mediaType = flow.MediaType }, $"{flow.Owner.UserName} is starting a stream!");
|
|
|
|
{
|
|
|
|
|
|
|
|
id = flow.Id,
|
|
|
|
|
|
|
|
sender = flow.Owner.UserName,
|
|
|
|
|
|
|
|
title = flow.Title,
|
|
|
|
|
|
|
|
url = flow.GetFileUrl(),
|
|
|
|
|
|
|
|
mediaType = flow.MediaType
|
|
|
|
|
|
|
|
}, $"{flow.Owner.UserName} is starting a stream!");
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME do we really need to close those one in invalid state ?
|
|
|
|
// FIXME do we really need to close those one in invalid state ?
|
|
|
|
Stack<string> ToClose = new Stack<string>();
|
|
|
|
Stack<string> ToClose = new Stack<string>();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
while (received.MessageType != WebSocketMessageType.Close)
|
|
|
|
while (received.MessageType != WebSocketMessageType.Close)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
logger.LogInformation($"Echoing {received.Count} bytes received in a {received.MessageType} message; Fin={received.EndOfMessage}");
|
|
|
|
logger.LogInformation($"Echoing {received.Count} bytes received in a {received.MessageType} message; Fin={received.EndOfMessage}");
|
|
|
|
@ -527,7 +549,8 @@ namespace Yavsc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await meta.Socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "eof", CancellationToken.None);
|
|
|
|
await meta.Socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "eof", CancellationToken.None);
|
|
|
|
LiveApiController.Casters[uname] = null;
|
|
|
|
LiveApiController.Casters[uname] = null;
|
|
|
|
} catch (Exception ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
logger.LogError($"Exception occured : {ex.Message}");
|
|
|
|
logger.LogError($"Exception occured : {ex.Message}");
|
|
|
|
logger.LogError(ex.StackTrace);
|
|
|
|
logger.LogError(ex.StackTrace);
|
|
|
|
@ -535,8 +558,10 @@ namespace Yavsc
|
|
|
|
LiveApiController.Casters[uname] = null;
|
|
|
|
LiveApiController.Casters[uname] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // not meta.Socket != null && meta.Socket.State == WebSocketState.Open
|
|
|
|
else
|
|
|
|
if (meta.Socket != null) {
|
|
|
|
{ // not meta.Socket != null && meta.Socket.State == WebSocketState.Open
|
|
|
|
|
|
|
|
if (meta.Socket != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
logger.LogError($"meta.Socket.State not Open: {meta.Socket.State.ToString()} ");
|
|
|
|
logger.LogError($"meta.Socket.State not Open: {meta.Socket.State.ToString()} ");
|
|
|
|
meta.Socket.Dispose();
|
|
|
|
meta.Socket.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -550,14 +575,18 @@ namespace Yavsc
|
|
|
|
{
|
|
|
|
{
|
|
|
|
logger.LogError($"Unexpected end of stream");
|
|
|
|
logger.LogError($"Unexpected end of stream");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
logger.LogError($"Really unexpected end of stream");
|
|
|
|
logger.LogError($"Really unexpected end of stream");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await meta.Socket?.CloseAsync(WebSocketCloseStatus.EndpointUnavailable, ex.Message, CancellationToken.None);
|
|
|
|
await meta.Socket?.CloseAsync(WebSocketCloseStatus.EndpointUnavailable, ex.Message, CancellationToken.None);
|
|
|
|
meta.Socket?.Dispose();
|
|
|
|
meta.Socket?.Dispose();
|
|
|
|
LiveApiController.Casters[uname] = null;
|
|
|
|
LiveApiController.Casters[uname] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}}}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await next();
|
|
|
|
await next();
|
|
|
|
|