Ejemplo n.º 1
0
        public async Task <bool> AllClientsDoActionAsync(string address, WebsocketAction action)
        {
            var result = await FunctionUtil.TRY(async() =>
            {
                using (var resp = await(address + "/RemoteOP/AllClientsDoAction")
                                  .AsHttp("POST", action)
                                  .Config(new RequestOptions {
                    ContentType = "application/json"
                })
                                  .SendAsync())
                {
                    if (resp.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        var result = resp.Deserialize <dynamic>();

                        if ((bool)result.success)
                        {
                            return(true);
                        }
                    }

                    return(false);
                }
            }, 5);

            await _sysLogService.AddSysLogSync(new SysLog
            {
                LogTime = DateTime.Now,
                LogType = result ? SysLogType.Normal : SysLogType.Warn,
                LogText = $"通知节点{address}所有客户端:{action.Action} 响应:{(result ? "成功" : "失败")}"
            });

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Add([FromBody] AppVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var oldApp = await _appService.GetAsync(model.Id);

            if (oldApp != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "应用Id已存在,请重新输入。"
                }));
            }

            var app = new App();

            app.Id         = model.Id;
            app.Name       = model.Name;
            app.Secret     = model.Secret;
            app.Enabled    = model.Enabled;
            app.CreateTime = DateTime.Now;
            app.UpdateTime = null;

            var result = await _appService.AddAsync(app);

            if (result)
            {
                await _sysLogService.AddSysLogSync(new SysLog
                {
                    LogTime = DateTime.Now,
                    LogType = SysLogType.Normal,
                    LogText = $"新增应用【AppId:{app.Id}】【AppName:{app.Name}】"
                });
            }

            return(Json(new
            {
                success = result,
                message = !result ? "新建应用失败,请查看错误日志" : ""
            }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Add([FromBody] ServerNodeVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            model.Address = model.Address.TrimEnd('/');
            var oldNode = await _serverNodeService.GetAsync(model.Address);

            if (oldNode != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "节点已存在,请重新输入。"
                }));
            }

            var node = new ServerNode();

            node.Address    = model.Address.TrimEnd('/');
            node.Remark     = model.Remark;
            node.Status     = NodeStatus.Offline;
            node.CreateTime = DateTime.Now;

            var result = await _serverNodeService.AddAsync(node);

            if (result)
            {
                await _sysLogService.AddSysLogSync(new SysLog
                {
                    LogTime = DateTime.Now,
                    LogType = SysLogType.Normal,
                    LogText = $"新增节点:{node.Address}"
                });
            }

            return(Json(new
            {
                success = result,
                message = !result ? "添加节点失败,请查看错误日志" : ""
            }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Add([FromBody] ConfigVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var oldConfig = await _configService.GetByAppIdKey(model.AppId, model.Group, model.Key);

            if (oldConfig != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "配置已存在,请更改输入的信息。"
                }));
            }

            var config = new Config();

            config.Id           = Guid.NewGuid().ToString("N");
            config.Key          = model.Key;
            config.AppId        = model.AppId;
            config.Description  = model.Description;
            config.Value        = model.Value;
            config.Group        = model.Group;
            config.Status       = ConfigStatus.Enabled;
            config.CreateTime   = DateTime.Now;
            config.UpdateTime   = null;
            config.OnlineStatus = OnlineStatus.WaitPublish;

            var result = await _configService.AddAsync(config);

            if (result)
            {
                //add syslog
                await _sysLogService.AddSysLogSync(new SysLog
                {
                    LogTime = DateTime.Now,
                    LogType = SysLogType.Normal,
                    AppId   = config.AppId,
                    LogText = $"新增配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】"
                });

                //add modify log
                await _modifyLogService.AddAsync(new ModifyLog
                {
                    Id         = Guid.NewGuid().ToString("N"),
                    ConfigId   = config.Id,
                    Key        = config.Key,
                    Group      = config.Group,
                    Value      = config.Value,
                    ModifyTime = config.CreateTime
                });
            }

            return(Json(new
            {
                success = result,
                message = !result ? "新建配置失败,请查看错误日志" : ""
            }));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Login([FromForm] string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                ViewBag.ErrorMessage = "密码不能为空";
                return(View());
            }

            var result = await _settingService.ValidateAdminPassword(password);

            if (result)
            {
                var claims = new List <Claim>
                {
                    new Claim("UserName", "Administrator")
                };

                var claimsIdentity = new ClaimsIdentity(
                    claims, CookieAuthenticationDefaults.AuthenticationScheme);

                var authProperties = new AuthenticationProperties
                {
                    //AllowRefresh = <bool>,
                    // Refreshing the authentication session should be allowed.

                    //ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10),
                    // The time at which the authentication ticket expires. A
                    // value set here overrides the ExpireTimeSpan option of
                    // CookieAuthenticationOptions set with AddCookie.

                    //IsPersistent = true,
                    // Whether the authentication session is persisted across
                    // multiple requests. Required when setting the
                    // ExpireTimeSpan option of CookieAuthenticationOptions
                    // set with AddCookie. Also required when setting
                    // ExpiresUtc.

                    //IssuedUtc = <DateTimeOffset>,
                    // The time at which the authentication ticket was issued.

                    //RedirectUri = <string>
                    // The full path or absolute URI to be used as an http
                    // redirect response value.
                };

                await HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    new ClaimsPrincipal(claimsIdentity),
                    authProperties);

                //addlog
                await _sysLogService.AddSysLogSync(new Data.Entity.SysLog
                {
                    LogTime = DateTime.Now,
                    LogType = Data.Entity.SysLogType.Normal,
                    LogText = $"管理员登录成功"
                });

                return(Redirect("/"));
            }

            ViewBag.ErrorMessage = "登录失败:密码不正确";
            return(View());
        }