예제 #1
0
        public async Task <IActionResult> Apply([FromQuery] string id, [FromQuery] bool confirm)
        {
            if (confirm)
            {
                bool backupResult = await DbBackupHelper.RestoreDbAsync(NodeSettings.Configs.MessengerDbConnection, id).ConfigureAwait(false);

                if (backupResult)
                {
                    return(Content("Backup was applied"));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status400BadRequest));
                }
            }
            return(Redirect(nameof(Index)));
        }
예제 #2
0
        public async Task <IActionResult> Create()
        {
            var backupsList = await DbBackupHelper.GetBackupsListAsync(NodeSettings.Configs.MessengerDbConnection).ConfigureAwait(false);

            string dbName       = NodeSettings.Configs.MessengerDbConnection.Database;
            string filename     = $"{dbName}_backup_{NodeSettings.Configs.Node.Id}_{DateTime.UtcNow.ToString("ddMMyyyy")}";
            int    backupsCount = backupsList.Count(opt => opt.FileId.Contains(filename));

            filename = $"{dbName}_backup_{NodeSettings.Configs.Node.Id}_{DateTime.UtcNow.ToString("ddMMyyyy")}_{backupsCount}";
            bool backupResult = await DbBackupHelper.CreateBackupAsync(NodeSettings.Configs.MessengerDbConnection, filename).ConfigureAwait(false);

            if (backupResult)
            {
                return(Redirect(nameof(Index)));
            }
            else
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
        }
예제 #3
0
        public async Task <IActionResult> Index()
        {
            ViewBag.BackupList = await DbBackupHelper.GetBackupsListAsync(NodeSettings.Configs.MessengerDbConnection).ConfigureAwait(false);

            return(View());
        }
예제 #4
0
        public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime)
        {
            AppServiceProvider.Instance      = (AppServiceProvider)app.ApplicationServices.GetService <IAppServiceProvider>();
            NodeData.NodeNoticeService       = app.ApplicationServices.GetService <INodeNoticeService>();
            NodeData.ConnectionsService      = app.ApplicationServices.GetService <IConnectionsService>();
            NodeConnector.ConnectionsService = app.ApplicationServices.GetService <IConnectionsService>();

            app.UseRequestLocalization();
            app.UseHsts();
            app.UseHttpsRedirection();
            app.UseMiddleware <IgnoreRouteMiddleware>();
            app.UseMiddleware <AdminSignOutMiddleware>();
            app.UseStaticFiles();
            applicationLifetime.ApplicationStopping.Register(OnShutdown);
            app.UseCors(builder =>
            {
                builder.AllowAnyHeader()
                .AllowAnyMethod()
                .AllowAnyOrigin();
            });
            app.UseWebSockets();
            if (NodeSettings.IsAppConfigured)
            {
                app.UseFluffySpoonLetsEncryptChallengeApprovalMiddleware();
            }

            if (NodeSettings.IsAppConfigured &&
                (NodeSettings.Configs.Certificate.Location != null &&
                 File.Exists(NodeSettings.Configs.Certificate.Location) ||
                 LetsEncryptRenewalService.Certificate != null))
            {
                app.UseHttpsRedirection();
            }
            app.UseCookiePolicy();
            app.UseAuthentication();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    "Default",
                    "{controller}/{action}",
                    new
                {
                    controller = "WebSocket",
                    action     = "Index"
                });
            });
            if (NodeSettings.IsAppConfigured)
            {
                try
                {
                    AppServiceProvider.Instance.NodesService.CreateOrUpdateNodeInformationAsync(NodeSettings.Configs.Node);
                    LicensorClient.Instance.AuthAsync().Wait(5000);
                    NodeSettings.Configs.License = LicensorClient.Instance.GetLicenseAsync().Result;
                    TasksHelper.StartUpdateLicenseTask();
                    TasksHelper.StartUpdateSessionKeyTask();
                    try
                    {
                        NodeSettings.Configs.Node = LicensorClient.Instance.EditNodeAsync(NodeSettings.Configs.Node).Result;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"An error ocurred while updating node information: {ex.Message}");
                    }
                    File.WriteAllText("Config/appsettings.json", ObjectSerializer.ObjectToJson(NodeSettings.Configs, true));
                    app.ApplicationServices.GetService <IPoolsService>().CheckNodePoolsAsync().Wait();
                    DbBackupHelper.StartDbBackupOperationAsync(NodeSettings.Configs.MessengerDbConnection);
                    InitializeNodeConnections();
                    TasksHelper.StartNodeConnectionsCheckTask();
                    DockerCleanHepler.Clear();
                    BlockchainSynchronizationService synchronizationService = new BlockchainSynchronizationService();
                    synchronizationService.CheckAndSyncBlockchainAsync().Wait();
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(ex);
                }
            }
        }