Exemplo n.º 1
0
        private void SaveUserCert(string certName, byte[] certCa, byte[] certCrt,
                                  byte[] certKey, bool expired)
        {
            using (var db = Setup.DbFactory)
            {
                db.Open();
                // TODO: how does this work, id is user id not UserOpenVpnCerts id
                var certData = db.Query <LibPoco.UserOpenVpnCerts>("SELECT * FROM UserOpenVpnCerts WHERE UserId=@UserId",
                                                                   new { UserId = userData.Id });

                if (!certData.Any())
                {
                    var certDataNew = new LibPoco.UserOpenVpnCerts(userData.Id, certName, certCa, certCrt, certKey, expired, DateTime.UtcNow, vpnData.Id);
                    db.Insert(certDataNew);
                }
                else
                {
                    certData.First().CertCa       = certCa;
                    certData.First().CertCrt      = certCrt;
                    certData.First().CertKey      = certKey;
                    certData.First().CertName     = certName;
                    certData.First().Expired      = expired;
                    certData.First().CreateTime   = DateTime.UtcNow;
                    certData.First().VpnServersId = vpnData.Id;
                    db.Update(certData.First());
                }
            }
        }
Exemplo n.º 2
0
        public InlineOvpnProfile(int userId)
        {
            using (var db = Setup.DbFactory)
            {
                db.Open();
                var data = db.Query <LibPoco.UserOpenVpnCerts>("SELECT * FROM UserOpenVpnCerts WHERE UserId=@UserId",
                                                               new { UserId = userId });

                if (data.Count() == 1)
                {
                    userCertData = data.First();
                    serverData   = db.Get <LibPoco.VpnServers>(userCertData.VpnServersId);
                }
                else if (data.Count() > 1)
                {
                    throw new Exceptions.InvalidDataException("InlineOvpnProfile, to many values found.");
                }
            }
        }