public ActionResult Edit(PPPSecret secret)
        {
            var user = _ctx.GetUser(secret.UserId);
            secret.Name = user.UserName;
            secret.Password = user.Password;

            if (_secretService.GetPPPSecret(secret.UserId) == null)
            {
                secret.Client = _ctx.GetClient(secret.UserId);

                if (_secretService.CreatePPPSecret(secret))
                {
                    _sshSecretService.CreatePPPSecret(secret.UserId);
                }
            }
            else
            {
                if (_secretService.EditPPPSecret(secret))
                {
                    _sshSecretService.EditPPPSecret(secret.UserId);
                }
            }
            //if (ModelState.IsValid)
            return RedirectToAction("Edit", "User", new { id = secret.UserId, area = "Users" });
            //TODO: Return nothing for dialog and exception info display
            //return View(secret);
        }
        public string ip_firewall_nat_add(PPPSecret secret)
        {
            var command = new StringBuilder("ip firewall nat add ");
            command.Append(BuildCommand("chain", "srcnat"))
                .Append(BuildCommand("action", "masquerade"))
                .Append(BuildCommand("src-address", secret.DHCPAddress))
                .Append(BuildCommand("comment", secret.Name));

            _sshStream.Write(command.ToString());
            return ParseResponse(_sshStream.ReadResponse(), command.ToString());
        }
 public bool EditPPPSecret(PPPSecret secret)
 {
     try
     {
         _secretRepository.EditPPPSecret(secret);
     }
     catch (Exception ex)
     {
         _validationDictionary.AddError("_FORM", "PPP Secret is not saved. " + ex.Message);
         return false;
     }
     return true;
 }
        public string ppp_secret_add(PPPSecret secret)
        {
            var command = new StringBuilder("ppp secret add ");
            command.Append(Repository.BuildCommand("name", secret.Name))
                .Append(Repository.BuildCommand("password", secret.Password))
                .Append(Repository.BuildCommand("profile", secret.Profile.Name))
                .Append(Repository.BuildCommand("service", secret.Service))
                .Append(Repository.BuildCommand("local-address", secret.LocalAddress))
                .Append(Repository.BuildCommand("remote-address", secret.RemoteAddress))
                .Append(Repository.BuildCommand("comment", secret.Comment))
                .Append(Repository.BuildCommand("disabled", secret.Disabled.ToString().ToLower()));

            return Repository.RunCommand(command.ToString());
        }
        public ActionResult Edit(Guid id)
        {
            var secret = _secretService.GetPPPSecret(id);
            if (secret == null)
            {
                var user = _ctx.GetUser(id);
                secret = new PPPSecret
                             {
                                 Name = user.UserName,
                                 UserId = id,
                                 Password = user.Password
                             };
            }

            return View(secret);
        }
        public Client BuildClient(PPPSecret secret)
        {
            Status status;
            if (secret.Disabled.HasValue)
                status = StatusService.GetStatus(secret.Disabled.Value ? STATUSES.Inactive : STATUSES.Active);
            else
                status = StatusService.GetStatus(STATUSES.Active);

            var client = GetClient(secret.UserId) ?? new Client();

            //client.UserId = secret.UserId;
            client.UserName = secret.Name;
            client.Password = secret.Password;
            client.Role = ROLES.client.ToString();
            client.Status = status;

            return client;
        }
        public List<PPPSecret> BuildPPPSecrets(string ppp)
        {
            var pppSec = new List<PPPSecret>();
            foreach (var val in Regex.Split(ppp, @"\r\n\s?(?:\d+)"))
            {
                var pppS = new PPPSecret();
                var properties = Repository.BuildProperties(val);
                pppS.Name = Repository.GetValue(properties, "name");

                if (string.IsNullOrEmpty(pppS.Name)) continue;

                pppS.Password = Repository.GetValue(properties, "password");
                pppS.ProfileName = Repository.GetValue(properties, "profile");
                pppS.LocalAddress = Repository.GetValue(properties, "local-address");
                pppS.RemoteAddress = Repository.GetValue(properties, "remote-address");
                pppS.Disabled = Repository.GetValue(properties, "status").Equals("0");
                pppS.Comment = Repository.GetValue(properties, "comment");
                pppSec.Add(pppS);
            }
            return pppSec;
        }
 public string ip_firewall_nat_remove(PPPSecret secret)
 {
     throw new System.NotImplementedException();
 }
 public string queue_simple_remove(PPPSecret secret)
 {
     throw new System.NotImplementedException();
 }
        public string queue_simple_add(PPPSecret secret)
        {
            secret.mkt_PPPProfilesReference.Load();
            var command = new StringBuilder("queue simple add ");
            command.Append(BuildCommand("name", secret.Name))
                .Append(BuildCommand("target-addresses", secret.DHCPAddress))
                .Append(BuildCommand("max-limit", secret.mkt_PPPProfilesReference.Value.RateLimit));

            _sshStream.Write(command.ToString());
            return ParseResponse(_sshStream.ReadResponse(), command.ToString());
        }
        public bool UpdateSystemService(PPPSecret secret)
        {
            //UpdateSystemService(secret, REAL_IP, secret.SystemRealIP);
            //UpdateSystemService(secret, STAY_ONLINE, secret.SystemStayOnline);

            return true;
        }
Exemplo n.º 12
0
        private PPPSecret BuildSecret(PPPSecret secret)
        {
            var _secret = SecretService.GetPPPSecret(secret.UserId) ?? new PPPSecret();
            _secret.CallerId = secret.CallerId;
            _secret.Comment = secret.Comment;
            _secret.Disabled = secret.Disabled;
            _secret.LimitBytesIn = secret.LimitBytesIn;
            _secret.LimitBytesOut = secret.LimitBytesOut;
            _secret.Name = secret.Name;
            _secret.Password = secret.Password;
            _secret.RemoteAddress = secret.RemoteAddress;
            _secret.Routes = secret.Routes;
            _secret.Service = secret.Service;
            _secret.Client = ClientService.GetClient(secret.UserId);
            _secret.Profile = SecretService.ProfileService.GetProfile(secret.ProfileName);

            return _secret;
        }
Exemplo n.º 13
0
        private Client BuildClient(PPPSecret secret)
        {
            Status status;
            if (secret.Disabled.HasValue)
                status = StatusService.GetStatus(secret.Disabled.Value ? STATUSES.Inactive : STATUSES.Active);
            else
                status = StatusService.GetStatus(STATUSES.Active);

            var client = ClientService.GetClient(secret.UserId) ??
                new Client
                  {
                      User = UserService.GetUser(secret.Name),
                      Credit = decimal.Zero,

                  };
            client.Status = status;

            return client;
        }
Exemplo n.º 14
0
 public bool ValidateContact(PPPSecret secret, bool creatingUser)
 {
     var model = new ClientViewModel
                     {
                         UserName = secret.Name,
                         Password = secret.Password
                     };
     return ValidateContact(model, creatingUser);
 }
Exemplo n.º 15
0
        public bool EditContact(PPPSecret pppSecret)
        {
            if (!ValidateContact(pppSecret, false))
                return false;

            try
            {
                UserService.EditUser(BuildUser(pppSecret));

                var _client = BuildClient(pppSecret);
                if (_client.UserId.Equals(Guid.Empty))
                    ClientService.CreateClient(_client);
                else
                    ClientService.EditClient(_client);

                var _secret = BuildSecret(pppSecret);
                if (_secret.UserId.Equals(Guid.Empty))
                    SecretService.CreatePPPSecret(_secret);
                else
                    SecretService.EditPPPSecret(_secret);
            }
            catch (Exception ex)
            {
                _validationDictionary.AddError("_FORM", "Contact is not saved. " + ex.Message);
                return false;
            }
            return true;
        }
Exemplo n.º 16
0
        public bool CreateContact(PPPSecret pppSecret)
        {
            // Validation logic
            if (!ValidateContact(pppSecret, true))
                return false;

            // Database logic
            try
            {
                pppSecret.UserId = UserService.CreateUser(BuildUser(pppSecret)).UserId;
                ClientService.CreateClient(BuildClient(pppSecret));
                pppSecret.Client = ClientService.GetClient(pppSecret.UserId);
                pppSecret.Profile = SecretService.ProfileService.GetProfile(pppSecret.ProfileName);
                SecretService.CreatePPPSecret(pppSecret);
            }
            catch (Exception ex)
            {
                _validationDictionary.AddError("_FORM", "Contact is not saved. " + ex.Message);
                return false;
            }
            return true;
        }
Exemplo n.º 17
0
 private User BuildUser(PPPSecret secret)
 {
     var user = UserService.GetUser(secret.Name) ?? new User();
     //user.UserId = secret.UserId;
     user.UserName = secret.Name;
     user.Password = secret.Password;
     user.Role = ROLES.client.ToString();
     return user;
 }
        public bool UpdateServices(PPPSecret secret)
        {
            var _secret = _pppSecretService.GetPPPSecret(secret.UserId);
            if(secret.SystemRealIP)
            {
                _repository.ppp_secret_set(_secret);

                //_repository.ip_firewall_nat_add(_secret);
                //_repository.queue_simple_add(_secret);
            }else
            {
                _repository.ppp_secret_set(_secret);
                //_repository.ip_firewall_nat_remove(_secret);
                //_repository.queue_simple_remove(_secret);
            }
            return true;
        }
 private void UpdateSystemService(PPPSecret secret, string serviceType, bool mode)
 {
     var _service = _repository.BuildService(serviceType);
     _service.UserId = _userHelper.GetCurrentUserId;
     _service.ClientId = secret.UserId;
     if (mode)
     {
         if (!_repository.ClientRegistered(_service))
             _repository.RegisterClient(_service);
     }
     else
     {
         if (_repository.ClientRegistered(_service))
             _repository.UnRegisterClient(_service);
     }
 }
 public bool UpdatePPPSecretAddresses(PPPSecret secret)
 {
     var _secret = GetPPPSecret(secret.UserId);
     _secret.LocalAddress = secret.LocalAddress;
     _secret.MACAddress = secret.MACAddress;
     _secret.RemoteAddress = secret.RemoteAddress;
     _secret.DHCPAddress = secret.DHCPAddress;
     try
     {
         _secretRepository.EditPPPSecret(_secret);
         return true;
     }
     catch (Exception ex)
     {
         _validationDictionary.AddError("_FORM", "PPP Secret is not saved. " + ex.Message);
         return false;
     }
 }