Exemplo n.º 1
0
        //Listen for ClientConnection on port
        public void Listen(ushort port)
        {
            _localSecurity = new Security.Security();
            _localSecurity.GenerateSecurity(true, true, true);

            _localRecvBuffer = new TransferBuffer(8192, 0, 0);
            _localListener   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _localSocket     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            //Thread Management
            _thPacketProcessor = new Thread(ThreadedPacketProcessing)
            {
                Name         = "Proxy.Network.Client.PacketProcessor",
                IsBackground = true
            };
            _thPacketProcessor.Start();

            try
            {
                if (_localListener.IsBound == false)
                {
                    _localListener.Bind(new IPEndPoint(IPAddress.Loopback, port));
                    _localListener.Listen(1);
                }
                _localListener.BeginAccept(OnClientConnect, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 2
0
        public Dictionary <Guid, int> SaveMany([FromUri] int appId, [FromBody] List <BundleWithHeader <EntityWithLanguages> > items, [FromUri] bool partOfPage = false)
        {
            // log and do security check
            Log.Add($"save many started with a#{appId}, i⋮{items.Count}, partOfPage:{partOfPage}");

            var appReadForSecurityCheckOnly = new AppRuntime(appId, true, Log);

            #region check if it's an update, and do more security checks - shared with UiController.Save
            // basic permission checks
            var permCheck = new Security.Security(BlockBuilder, Log)
                            .DoPreSaveSecurityCheck(appId, items);

            var foundItems = items.Where(i => i.EntityId != 0 && i.EntityGuid != Guid.Empty)
                             .Select(i => i.EntityGuid != Guid.Empty
                    ? appReadForSecurityCheckOnly.Entities.Get(i.EntityGuid) // prefer guid access if available
                    : appReadForSecurityCheckOnly.Entities.Get(i.EntityId)   // otherwise id
                                     );
            if (foundItems.Any(i => i != null) && !permCheck.EnsureAll(GrantSets.UpdateSomething, out var exception))
            {
                throw exception;
            }
            #endregion

            return(new DnnPublishing(BlockBuilder, Log)
                   .SaveWithinDnnPagePublishingAndUpdateParent(appId, items, partOfPage,
                                                               forceSaveAsDraft => SaveOldFormatKeepTillReplaced(appId, items, partOfPage, forceSaveAsDraft),
                                                               permCheck));
        }
        public void Update(Security.Security aggRoot)
        {
            var existingInstrument = Security.FirstOrDefault(i => i.IsSameAs(aggRoot));

            if (existingInstrument != null)
            {
                Security[Security.IndexOf(existingInstrument)] = aggRoot;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Execute a stored procedure that does not return any data
        /// </summary>
        /// <param name="storedProcedureName">The name of the stored porocedure to execute</param>
        /// <param name="parameters">The list of parameters to pass to the stored procedure</param>
        /// <param name="cfConStr">Configuration file element name for the connection string</param>
        /// <param name="cfServer">Configuration file element name for the database server name</param>
        /// <param name="cfDatabase">Configuration file element name for the database name</param>
        /// <param name="cfUser">Configuration file element name for the database user name</param>
        /// <param name="cfPassword">Configuration file element name for the database user's password</param>
        public void ExecuteNonQuery(string storedProcedureName, List <ParameterSQL> parameters, string cfConStr, string cfServer, string cfDatabase, string cfUser, string cfPassword)
        {
            string connectionString = ConfigurationManager.ConnectionStrings[cfConStr].ToString();

            if (connectionString.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"DatabaseConnectionString\" in the config file");
            }
            if (storedProcedureName.IsNullOrEmpty())
            {
                throw new Exception("Invalid stored procedure name");
            }
            string server = ConfigurationManager.AppSettings[cfServer];

            if (server.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"" + cfServer + "\" in the config file");
            }
            string database = ConfigurationManager.AppSettings[cfDatabase];

            if (database.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"" + cfDatabase + "\" in the config file");
            }
            string user = ConfigurationManager.AppSettings[cfUser];

            if (user.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"" + cfUser + "\" in the config file");
            }
            string password = ConfigurationManager.AppSettings[cfPassword];

            if (password.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"" + cfPassword + "\" in the config file");
            }

            Security.Security security = new Security.Security();

            password = DecryptPassword(password);

            connectionString = connectionString.FormatString(server, database, user, password);

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(storedProcedureName, connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    parameters          = this.LoadParameters(command, storedProcedureName, parameters);

                    command.ExecuteNonQuery();
                    this.ReadOutputParameters(command, parameters);
                }
            }
        }
Exemplo n.º 5
0
 public void Setup()
 {
     unitOfWork        = new UnitOfWork();
     appViewModel      = new ApplicationViewModel <Model.Donor>();
     appViewModel.User = new Model.Donor {
         PersonID = 0
     };
     dispatcherWrapper = new Core.UnitTests.Dependencies.DispatcherWrapper();
     parentPage        = new ParentPage();
     security          = new Security.Security();
     viewModel         = new ProfileViewModel(unitOfWork, appViewModel, dispatcherWrapper, security)
     {
         ParentPage = parentPage
     };
 }
Exemplo n.º 6
0
        public void Connect(string ip, ushort port)
        {
            if (_remoteSocket != null)
            {
                Disconnect();
            }

            //Create objects
            _remoteRecvBuffer = new TransferBuffer(8192, 0, 0);
            _remoteSocket     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            //Thread Management
            if (_thPacketProcessor == null)
            {
                _thPacketProcessor = new Thread(ThreadedPacketProcessing)
                {
                    Name         = "Proxy.Network.Server.PacketProcessor",
                    IsBackground = true
                };
                _thPacketProcessor.Start();
            }

            try
            {
                //Recreate the Security
                _remoteSecurity = new Security.Security();

                //Connect
                _remoteSocket.Connect(ip, port);

                if (!_remoteSocket.Connected)
                {
                    return;
                }
                Connected?.Invoke(ip, port);
                _doPacketProcess = true;
                _remoteSocket.BeginReceive(_remoteRecvBuffer.Buffer, 0, 8192, SocketFlags.None, WaitForServerData,
                                           _remoteSocket);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 7
0
        private void OnClientConnect(IAsyncResult ar)
        {
            if (_isClosing)
            {
                return;
            }
            try
            {
                _doPacketProcess = true;
                _localSocket     = _localListener.EndAccept(ar);
                _localSocket.BeginReceive(_localRecvBuffer.Buffer, 0, 8192, SocketFlags.None, WaitForData, _localSocket);

                _localSecurity = new Security.Security();
                _localSecurity.GenerateSecurity(false, false, false);

                Connected?.Invoke();
            }
            catch (Exception ex)
            {
                throw new Exception("Network.Client.OnClientConnect: " + ex.Message, ex);
            }
        }
Exemplo n.º 8
0
        private string DecryptPassword(string password)
        {
            string returnValue = null;

            Security.Security security = new Security.Security();

            if (password.Length < 800)
            {
                returnValue = Encryptor.Decrypt(password);
            }
            else
            {
                returnValue = security.Decrypt(password);
            }

            if (returnValue.IsNullOrEmpty())
            {
                throw new Exception("Invalid password encryption");
            }

            return(returnValue);
        }
Exemplo n.º 9
0
        public Dictionary <Guid, int> Save([FromBody] AllInOne package, int appId, bool partOfPage)
        {
            Log.Add($"save started with a#{appId}, i⋮{package.Items.Count}, partOfPage:{partOfPage}");

            var validator = new SaveDataValidator(package, Log);

            // perform some basic validation checks
            if (!validator.ContainsOnlyExpectedNodes(out var exp))
            {
                throw exp;
            }

            // todo: unsure about this - thought I should check contentblockappid in group-header, because this is where it should be saved!
            //var contextAppId = appId;
            //var targetAppId = package.Items.First().Header.Group.ContentBlockAppId;
            //if (targetAppId != 0)
            //{
            //    Log.Add($"detected content-block app to use: {targetAppId}; in context of app {contextAppId}");
            //    appId = targetAppId;
            //}

            var appMan  = new AppManager(appId, Log);
            var appRead = appMan.Read;
            var ser     = new JsonSerializer(appRead.AppState, Log)
            {
                // Since we're importing directly into this app, we would prefer local content-types
                PreferLocalAppTypes = true
            };

            validator.PrepareForEntityChecks(appRead);

            #region check if it's an update, and do more security checks then - shared with EntitiesController.Save
            // basic permission checks
            var permCheck = new Security.Security(BlockBuilder, Log)
                            .DoPreSaveSecurityCheck(appId, package.Items);

            var foundItems = package.Items.Where(i => i.EntityId != 0 && i.EntityGuid != Guid.Empty)
                             .Select(i => i.EntityGuid != Guid.Empty
                        ? appRead.Entities.Get(i.EntityGuid) // prefer guid access if available
                        : appRead.Entities.Get(i.EntityId)   // otherwise id
                                     );
            if (foundItems.Any(i => i != null) && !permCheck.EnsureAll(GrantSets.UpdateSomething, out var exception))
            {
                throw exception;
            }
            #endregion


            var items = package.Items.Select(i =>
            {
                var ent = ser.Deserialize(i.Entity, false, false) as Entity;

                var index = package.Items.IndexOf(i); // index is helpful in case of errors
                if (!validator.EntityIsOk(index, ent, out exp))
                {
                    throw exp;
                }

                if (!validator.IfUpdateValidateAndCorrectIds(index, ent, out exp))
                {
                    throw exp;
                }

                ent.IsPublished        = package.IsPublished;
                ent.PlaceDraftInBranch = package.DraftShouldBranch;

                // new in 11.01
                if (i.Header.ListHas())
                {
                    // Check if Add was true, and fix if it had already been saved (EntityId != 0)
                    // the entityId is reset by the validator if it turns out to be an update
                    // todo: verify use - maybe it's to set before we save, as maybe afterwards it's always != 0?
                    var add      = i.Header.ListAdd();
                    i.Header.Add = add;
                    if (ent.EntityId > 0 && add)
                    {
                        i.Header.Add = false;
                    }
                    //i.Header.ReallyAddBecauseAlreadyVerified = i.Header.Add;
                }

                return(new BundleWithHeader <IEntity>
                {
                    Header = i.Header,
                    Entity = ent
                });
            })
                        .ToList();

            Log.Add("items to save generated, all data tests passed");

            return(new DnnPublishing(BlockBuilder, Log)
                   .SaveWithinDnnPagePublishingAndUpdateParent(appId, items, partOfPage,
                                                               forceSaveAsDraft => DoSave(appMan, items, forceSaveAsDraft),
                                                               permCheck));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Execute a stored procedure and returns all data returned by the procedure in a Dataset
        /// </summary>
        /// <param name="storedProcedureName">The name of the stored porocedure to execute</param>
        /// <param name="parameters">The list of parameters to pass to the stored procedure</param>
        /// <returns></returns>
        public DataSet ExecuteQuery(string storedProcedureName, List <ParameterSQL> parameters)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ToString();

            if (connectionString.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"DatabaseConnectionString\" in the config file");
            }
            if (storedProcedureName.IsNullOrEmpty())
            {
                throw new Exception("Invalid stored procedure name");
            }
            string server = ConfigurationManager.AppSettings["SQL_SERVER_NAME"];

            if (server.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"SQL_SERVER_NAME\" in the config file");
            }
            string database = ConfigurationManager.AppSettings["SQL_DATABASE_NAME"];

            if (database.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"SQL_DATABASE_NAME\" in the config file");
            }
            string user = ConfigurationManager.AppSettings["SQL_USER_ID"];

            if (user.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"SQL_USER_ID\" in the config file");
            }
            string password = ConfigurationManager.AppSettings["SQL_PASSWORD"];

            if (password.IsNullOrEmpty())
            {
                throw new Exception("Could not find \"SQL_PASSWORD\" in the config file");
            }

            Security.Security security = new Security.Security();

            password = DecryptPassword(password);

            connectionString = connectionString.FormatString(server, database, user, password);

            using (DataSet returnValue = new DataSet())
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand(storedProcedureName, connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        parameters          = this.LoadParameters(command, storedProcedureName, parameters);

                        using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                        {
                            adapter.Fill(returnValue);
                        }
                        this.ReadOutputParameters(command, parameters);
                    }
                }

                return(returnValue);
            }
        }
 public void Add(Security.Security aggRoot)
 {
     Security.Add(aggRoot);
 }