Beispiel #1
0
        public async Task <string> GetAllProcess(int botid)
        {
            var method = new BaseCommands
            {
                Method = "GetAllProcess"
            };
            var bot = new GetBotByIdQuery
            {
                Id = botid
            };
            var botlist = await _mediator.Send(bot);

            var response = CommandExecute.TcpConnects(botlist, JsonConvert.SerializeObject(method));

            return(response);
        }
        public async Task <IActionResult> DownloadFileAsync(BotDownloadFileModel model)
        {
            var query = new GetBotByIdQuery
            {
                Id = model.UserId
            };
            var bot = await _mediator.Send(query);

            GetFileVariables variables = new GetFileVariables
            {
                filePath = model.File
            };
            BaseCommands method = new BaseCommands
            {
                Method = "GetFile"
            };
            GetSourceFileCommand command = new GetSourceFileCommand
            {
                newBaseCommand = method,
                newVariables   = variables
            };

            try
            {
                var fullpath = "";
                if (!_env.WebRootFileProvider.GetDirectoryContents("files/Bots/" + bot.UserName + "_" + model.UserId).Exists)
                {
                    var path = _env.WebRootFileProvider.GetFileInfo("files/Bots")?.PhysicalPath;
                    Directory.CreateDirectory(path + "/" + bot.UserName + "_" + model.UserId);
                }
                else
                {
                    fullpath = _env.WebRootFileProvider.GetFileInfo("files/Bots")?.PhysicalPath + "/" + bot.UserName + "_" + model.UserId;
                }
                _client.DownLoadFileByWebRequest(bot.Domain, fullpath + "/" + model.File, JsonConvert.SerializeObject(command));
                var file = System.IO.File.OpenRead(fullpath + "/" + model.File);
                return(File(file, "application/octet-stream"));
            }
            catch { };
            return(Content("404 file not found"));
        }
        public async Task <IActionResult> Bot(int id)
        {
            try
            {
                appsettingsModel appsettings = JsonConvert.DeserializeAnonymousType(ServerFileManager.FileReader(GetPathes.Get_SolutionMainPath() + "/Alduin.Web/appsettings.json"), new appsettingsModel());
                var query = new GetBotByIdQuery
                {
                    Id = id
                };
                GetImgJsonModel ImagesJsonModel = JsonConvert.DeserializeAnonymousType(await _getBotImagesJsonServices.GetAllImg(id), new GetImgJsonModel());
                var             bot             = await _mediator.Send(query);

                DateTime DateNowUTC = DateTime.UtcNow.AddMinutes(-5);
                var      status     = _localizer["Offline"];
                if (bot.LastLoggedInUTC >= DateNowUTC)
                {
                    status = _localizer["Online"];
                }
                var botInquiryDeatils = new BotDeatilsInquiryModel
                {
                    Name            = bot.UserName,
                    Domain          = bot.Domain,
                    LastIPAddress   = bot.LastIPAddress,
                    LastLoggedInUTC = bot.LastLoggedInUTC,
                    Status          = status,
                    KeyCertified    = bot.KeyCertified,
                    KeyUnique       = appsettings.Stump.KeyCertified
                };
                var botmodel = new BotModel
                {
                    newImagesJsonModel        = ImagesJsonModel,
                    newBotDeatilsInquiryModel = botInquiryDeatils
                };
                return(View(botmodel));
            }
            catch
            {
                return(RedirectToAction(nameof(List)));
            };
        }
        public async Task <IActionResult> DownloadAllImg(int id)
        {
            var query = new GetBotByIdQuery
            {
                Id = id
            };
            var bot = await _mediator.Send(query);

            var             log = new LogModel();
            GetImgJsonModel ImagesJsonModel;

            try
            {
                var fullpath = "";
                if (!_env.WebRootFileProvider.GetDirectoryContents("img/Bots/" + bot.UserName + "_" + id).Exists)
                {
                    var path = _env.WebRootFileProvider.GetFileInfo("img/Bots")?.PhysicalPath;
                    Directory.CreateDirectory(path + "/" + bot.UserName + "_" + id);
                }
                else
                {
                    fullpath = _env.WebRootFileProvider.GetFileInfo("img/Bots")?.PhysicalPath + "/" + bot.UserName + "_" + id;
                }
                ImagesJsonModel = JsonConvert.DeserializeAnonymousType(await _getBotImagesJsonServices.GetAllImg(id), new GetImgJsonModel());
                for (var i = 0; i < ImagesJsonModel.Images.Count; i++)
                {
                    StringBuilder FileName = new StringBuilder();
                    for (var j = ImagesJsonModel.Images[i].LastIndexOf(@"\") + 1; j < ImagesJsonModel.Images[i].Length; j++)
                    {
                        FileName.Append(ImagesJsonModel.Images[i][j]);
                    }
                    GetImagesVariables variables = new GetImagesVariables
                    {
                        imagePath = ImagesJsonModel.Images[i]
                    };
                    BaseCommands command = new BaseCommands
                    {
                        Method = "GetImg"
                    };
                    GetImagesCommand model = new GetImagesCommand
                    {
                        newBaseCommand = command,
                        newVariables   = variables
                    };
                    _client.DownLoadFileByWebRequest(bot.Domain, fullpath + "/" + FileName.ToString(), JsonConvert.SerializeObject(model));
                }
                log = new LogModel()
                {
                    KeyUnique = bot.KeyUnique,
                    Message   = "Download Sucess",
                    Type      = "Sucess"
                };
            }
            catch {
                log = new LogModel()
                {
                    KeyUnique = bot.KeyUnique,
                    Message   = "Download Failed",
                    Type      = "Error"
                };
            };
            return(Json(log));
        }
        public async Task <IActionResult> Bot(int id)
        {
            try
            {
                var getImagesStatus = "";
#if (!DEBUG)
                // Release
                appsettingsModel appsettings = JsonConvert.DeserializeAnonymousType(ServerFileManager.FileReader(GetPathes.Get_SolutionMainPath() + "/appsettings.json"), new appsettingsModel());
#else
                // Debug
                appsettingsModel appsettings = JsonConvert.DeserializeAnonymousType(ServerFileManager.FileReader(GetPathes.Get_SolutionMainPath() + "/Alduin.Web/appsettings.json"), new appsettingsModel());
#endif
                GetImgJsonModel ImagesJsonModel;
                var             query = new GetBotByIdQuery
                {
                    Id = id
                };
                var bot = await _mediator.Send(query);

                if (_env.WebRootFileProvider.GetDirectoryContents("img/Bots/" + bot.UserName + "_" + id).Exists)
                {
                    var           fullpath = _env.WebRootFileProvider.GetFileInfo("img/Bots")?.PhysicalPath + "/" + bot.UserName + "_" + id;
                    var           files    = Directory.GetFiles(fullpath);//Wait to test
                    List <string> images   = new List <string>(files);
                    ImagesJsonModel = new GetImgJsonModel()
                    {
                        Images = images
                    };
                    getImagesStatus = "local";
                }
                else
                {
                    try
                    {
                        ImagesJsonModel = JsonConvert.DeserializeAnonymousType(await _getBotImagesJsonServices.GetAllImg(id), new GetImgJsonModel());
                        if (ImagesJsonModel.Images.Count == 0)
                        {
                            getImagesStatus = "nothing";
                        }
                        else
                        {
                            getImagesStatus = "network";
                        }
                    }
                    catch
                    {
                        ImagesJsonModel = JsonConvert.DeserializeAnonymousType("{'Images':[]}", new GetImgJsonModel());
                        getImagesStatus = "nothing";
                    };
                }
                DateTime DateNowUTC = DateTime.UtcNow.AddMinutes(-5);
                var      status     = _localizer["Offline"];
                if (bot.LastLoggedInUTC >= DateNowUTC)
                {
                    status = _localizer["Online"];
                }
                var botInquiryDeatils = new BotDeatilsInquiryModel
                {
                    Name            = bot.UserName,
                    Domain          = bot.Domain,
                    LastIPAddress   = bot.LastIPAddress,
                    LastLoggedInUTC = bot.LastLoggedInUTC,
                    Status          = status,
                    KeyCertified    = bot.KeyCertified,
                    KeyUnique       = appsettings.Stump.KeyCertified
                };
                var botmodel = new BotModel
                {
                    newImagesJsonModel        = ImagesJsonModel,
                    newBotDeatilsInquiryModel = botInquiryDeatils,
                    getImagesStatus           = getImagesStatus
                };
                ViewData["ID"] = id;
                return(View(botmodel));
            }
            catch (Exception e)
            {
                return(Content(e.ToString()));
            };
        }