Ejemplo n.º 1
0
        private RconServer validateRconServer(RconServer rconServer)
        {
            if (!rconServer.UseSsh && !rconServer.UseTelnet)
            {
                throw new SaveServerException("UseSsh", "You need at least one connection type! Please choose SSH or Telnet.");
            }

            if (!RconHelper.IsMD5(rconServer.Password))
            {
                if (String.IsNullOrEmpty(rconServer.Password))
                {
                    throw new SaveServerException("Password", "The telnet password is required!");
                }
                rconServer.Password = RconHelper.CreateMD5(rconServer.Password);
            }

            if (rconServer.UseSsh)
            {
                if (rconServer.SshPort <= 0)
                {
                    throw new SaveServerException("SshPort", "If you use SSH you will need a SSH port!");
                }

                if (String.IsNullOrEmpty(rconServer.SshUsername))
                {
                    throw new SaveServerException("SshUsername", "If you use SSH you will need a username!");
                }

                if (String.IsNullOrEmpty(rconServer.SshPassword) && String.IsNullOrEmpty(rconServer.SshKeyFileName))
                {
                    throw new SaveServerException("SshPassword", "If you use SSH you will need at least a password or a key file!");
                }
            }

            return(rconServer);
        }
        public async Task IsValidOnly(PavlovServer pavlovServer, bool parseMd5 = true)
        {
            if (string.IsNullOrEmpty(pavlovServer.TelnetPassword) && pavlovServer.Id != 0)
            {
                pavlovServer.TelnetPassword = (await FindOne(pavlovServer.Id)).TelnetPassword;
            }
            if (!RconHelper.IsMD5(pavlovServer.TelnetPassword))
            {
                if (string.IsNullOrEmpty(pavlovServer.TelnetPassword))
                {
                    throw new ValidateException("Password", "The telnet password is required!");
                }

                if (parseMd5)
                {
                    pavlovServer.TelnetPassword = RconHelper.CreateMD5(pavlovServer.TelnetPassword);
                }
            }

            if (pavlovServer.SshServer.SshPort <= 0)
            {
                throw new ValidateException("SshPort", "You need a SSH port!");
            }

            if (string.IsNullOrEmpty(pavlovServer.SshServer.SshUsername))
            {
                throw new ValidateException("SshUsername", "You need a username!");
            }


            if (string.IsNullOrEmpty(pavlovServer.SshServer.SshPassword) &&
                (pavlovServer.SshServer.SshKeyFileName == null || !pavlovServer.SshServer.SshKeyFileName.Any()))
            {
                throw new ValidateException("SshPassword", "You need at least a password or a key file!");
            }
        }