Exemplo n.º 1
0
        public bool UpdateUser(User user)
        {
            bool b = false;

            try
            {
                var dataContext = GetDataContext();
                var oldUser     = GetUserById(user.UserId);
                if (oldUser != null)
                {
                    oldUser.AccessLevel    = user.AccessLevel;
                    oldUser.ComputerType   = user.ComputerType;
                    oldUser.Email          = user.Email;
                    oldUser.HashedPassword = user.HashedPassword;
                    oldUser.RealName       = user.RealName;
                    oldUser.Username       = user.Username;
                    dataContext.SubmitChanges();
                    b = true;
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", user, e);
            }
            return(b);
        }
Exemplo n.º 2
0
        public bool UpdateAccessGroup(AccessGroup accessGroup)
        {
            bool b = false;

            try
            {
                var dataContext    = GetDataContext();
                var oldAccessGroup = dataContext.AccessGroups.FirstOrDefault(p => p.AccessGroupId == accessGroup.AccessGroupId);
                if (oldAccessGroup != null)
                {
                    oldAccessGroup.AccessGroupNumber       = accessGroup.AccessGroupNumber;
                    oldAccessGroup.CallsPerDay             = accessGroup.CallsPerDay;
                    oldAccessGroup.Description             = accessGroup.Description;
                    oldAccessGroup.Flag_Remote_Maintenance = accessGroup.Flag_Remote_Maintenance;
                    oldAccessGroup.Is_SysOp       = accessGroup.Is_SysOp;
                    oldAccessGroup.MinutesPerCall = accessGroup.MinutesPerCall;
                    oldAccessGroup.Title          = accessGroup.Title;
                    dataContext.SubmitChanges();
                    b = true;
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", accessGroup, e);
            }
            return(b);
        }
Exemplo n.º 3
0
        public List <Tuple <string, string> > GetLastTenCalls()
        {
            var glist = new List <Tuple <string, string> >();

            try
            {
                var callList = _bbsDataContext.CallLogs.OrderByDescending(p => p.Connected).Take(10).ToList();
                foreach (var call in callList)
                {
                    var connected = call.Connected.ToString("yyyy-MM-dd hh:mm");
                    var username  = "";
                    if (call.User == null)
                    {
                        var user = GetUserById(call.UserId);
                        username = user.Username;
                    }
                    else
                    {
                        username = call.User.Username;
                    }
                    glist.Add(new Tuple <string, string>(connected, username));
                    // = callList.Select(p => new Tuple<string, string>(p.Connected.ToString("yyyy-MM-dd hh:mm"), p.User.Username)).ToList();
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
            }
            return(glist);
        }
Exemplo n.º 4
0
        public bool UpdateAccessGroup(AccessGroup accessGroup)
        {
            bool b = false;

            try
            {
                var oldAccessGroup = GetAccessGroupById(accessGroup.Id);
                if (oldAccessGroup != null)
                {
                    //oldAccessGroup.AccessGroupNumber = accessGroup.AccessGroupNumber;
                    oldAccessGroup.CallsPerDay            = accessGroup.CallsPerDay;
                    oldAccessGroup.Description            = accessGroup.Description;
                    oldAccessGroup.AllowRemoteMaintenance = accessGroup.AllowRemoteMaintenance;
                    oldAccessGroup.AllowSysOp             = accessGroup.AllowSysOp;
                    oldAccessGroup.MinutesPerCall         = accessGroup.MinutesPerCall;
                    oldAccessGroup.Title       = accessGroup.Title;
                    oldAccessGroup.Description = accessGroup.Description;
                    _bbsDataContext.SaveChanges();
                    b = true;
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", accessGroup, e);
            }
            return(b);
        }
Exemplo n.º 5
0
        ///
        /// Decription: Open a listener socket and wait for a connection.
        ///
        private void StartListening()
        {
            // Establish the local endpoint for the socket.
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, _portNumber);
            // Create a TCP/IP socket.
            Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // Bind the socket to the local endpoint and listen for incoming connections.
            try
            {
                listener.Bind(localEndPoint);
                listener.Listen(1000);
                while (!ShuttingDown)
                {
                    // Set the event to nonsignaled state.
                    allDone.Reset();
                    // Start an asynchronous socket to listen for connections.

                    listener.BeginAccept(new AsyncCallback(this.AcceptCallback), listener);

                    // Wait until a connection is made before continuing.
                    allDone.WaitOne();
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
                threadEnd[0].Set();
            }
        }
Exemplo n.º 6
0
        //public int PFile_ParentArea(int? area)
        //{
        //    int i = -1;
        //    try
        //    {

        //        PFileArea gfa = _bbsDataContext.PFileAreas.FirstOrDefault(p => p.ParentAreaId.Equals(area));
        //        if (gfa != null)
        //        {
        //            i = gfa.ParentAreaId;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        LoggingAPI.LogEntry("Exception in DataInterface.PFile_ParentArea: " + e.Message);
        //    }
        //    return i;
        //}
        public List <AreaListRow> PFileListArea(int?area, int userid)
        {
            //List all files and areas in the current area
            var response = new List <AreaListRow>();

            try
            {
                //User u = GetUserById(userid);
                //User must have at least one access group that matches the gfile area
                List <PFileArea>   pfileAreas   = _bbsDataContext.PFileAreas.Where(p => p.ParentAreaId == area).ToList();
                List <PFileDetail> pfileDetails = _bbsDataContext.PFileDetails.Where(p => p.PFileAreaId == area).ToList();
                int listId = 1;
                foreach (PFileArea pfileArea in pfileAreas)
                {
                    listId++;
                    response.Add(new AreaListRow(pfileArea, listId, AreaListRowType.Area));
                }
                foreach (PFileDetail pfileDetail in pfileDetails)
                {
                    listId++;
                    response.Add(new AreaListRow(pfileDetail, listId, AreaListRowType.Entry));
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
            }
            return(response);
        }
Exemplo n.º 7
0
        public User SaveNewUser(string userName, string password, string realName, string email, string computerType, string ip, string webPage)
        {
            User newUser = null;

            try
            {
                var u = new User()
                {
                    Username          = userName,
                    HashedPassword    = password,
                    RealName          = realName,
                    Email             = email,
                    ComputerType      = computerType,
                    WebPage           = webPage,
                    LastConnection    = DateTime.Now,
                    LastDisconnection = DateTime.Now,
                    LastConnectionIP  = ip
                };
                _bbsDataContext.Users.Add(u);
                _bbsDataContext.SaveChanges();
                newUser = GetUserByName(userName);
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
                newUser = null;
            }
            return(newUser);
        }
Exemplo n.º 8
0
        ///
        /// Decription: Call back method to handle incoming data.
        ///
        /// <param name="ar">Status of an asynchronous operation.</param>
        protected void ReadCallback(IAsyncResult ar)
        {
            //String content = String.Empty;
            // Retrieve the state object and the handler socket
            // from the async state object.
            StateObject state   = (StateObject)ar.AsyncState;
            Socket      handler = state.workSocket;

            try
            {
                // Read data from the client socket.
                int bytesRead = handler.EndReceive(ar);

                if (bytesRead > 0)
                {
                    Monitor.Enter(state);
                    for (int i = 0; i < bytesRead; i++)
                    {
                        state.Received(state.buffer[i]);
                    }
                    Monitor.Exit(state);
                    //content = state.sb.ToString();
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(this.ReadCallback), state);
                }
                else
                { //Disconnected
                    RemoveSocket(state);
                }
            }
            catch (System.Net.Sockets.SocketException es)
            {
                RemoveSocket(state);
                OnDisconnect(state);
                if (es.ErrorCode == 10057 || es.NativeErrorCode == 10054)
                {
                    LoggingAPI.SysLogEntry(state.RemoteAddress + ": Socket Disconnected");
                }
                else
                {
                    if (es.ErrorCode != 64)
                    {
                        LoggingAPI.Error(es);
                    }
                }
            }
            catch (Exception e)
            {
                RemoveSocket(state);
                OnDisconnect(state);
                if (e.GetType() != typeof(System.ObjectDisposedException))
                {
                    LoggingAPI.Error(e);
                }
            }
        }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            Console.Clear();
            Console.WriteLine("SixNet BBS, Starting up...");
            _bbsDatabaseConfiguration = BBSDatabaseConfiguration.LoadConfig("./");
            if (_bbsDatabaseConfiguration == null)
            {
                Console.WriteLine("Run setup utility first.");
                return;
            }
            _connectionString = BBSDatabaseConfiguration.BuildConnectionString(_bbsDatabaseConfiguration);
            LoggingAPI.Init("./Logs/");
            if (BBSDatabaseConfiguration.IsDatabaseSetup(_connectionString))
            {
                Console.WriteLine("Database configured.");
                _core = new BBSDataCore(_connectionString);
            }
            else
            {
                Console.WriteLine("Database not configured - run setup utility.");
                return;
            }
            var config = _core.GetBBSConfig();

            LoggingAPI.LogEntry("Software started.");
            try
            {
                quitFlag = false;
                BBSServer bbsServer = new BBSServer(_connectionString, config.BBSPort, "BBS Server");
                bbsServer.Start();
                while (!quitFlag)
                {
                    Thread.Sleep(100);
                    if (Console.KeyAvailable)
                    {
                        if (Console.ReadKey().Key == ConsoleKey.Q)
                        {
                            quitFlag = true;
                            bbsServer.Stop();
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
            }
            finally
            {
                LoggingAPI.LogEntry("Software shutdown.");
                LoggingAPI.FlushQueue();
            }
        }
Exemplo n.º 10
0
 public User GetUserById(int id)
 {
     try
     {
         return(_bbsDataContext.Users.FirstOrDefault(p => p.Id.Equals(id)));
     }
     catch (Exception e)
     {
         LoggingAPI.Error("(" + id + ")", e);
         return(null);
     }
 }
Exemplo n.º 11
0
 public MessageBase GetMessageBaseById(int id)
 {
     try
     {
         return(GetDataContext().MessageBases.FirstOrDefault(p => p.MessageBaseId.Equals(id)));
     }
     catch (Exception e)
     {
         LoggingAPI.Error("(" + id + ")", e);
         return(null);
     }
 }
Exemplo n.º 12
0
 public User GetUserByName(string username)
 {
     try
     {
         return(_bbsDataContext.Users.FirstOrDefault(p => p.Username.ToUpper().Equals(username.ToUpper())));
     }
     catch (Exception e)
     {
         LoggingAPI.Error("(" + username + ")", e);
         return(null);
     }
 }
Exemplo n.º 13
0
 public AccessGroup GetAccessGroup(int level)
 {
     try
     {
         return(GetDataContext().AccessGroups.FirstOrDefault(p => p.AccessGroupNumber.Equals(level)));
     }
     catch (Exception e)
     {
         LoggingAPI.Error("(" + level + "): " + e);
         return(null);
     }
 }
Exemplo n.º 14
0
 public string MessageBaseAreaName(int id)
 {
     try
     {
         return(GetMessageBaseAreaById(id).Title);
     }
     catch (Exception e)
     {
         LoggingAPI.Error("(" + id + ")", e);
         return("Invalid");
     }
 }
Exemplo n.º 15
0
 public MessageBaseArea GetMessageBaseAreaById(int id)
 {
     try
     {
         return(_bbsDataContext.MessageBaseAreas.FirstOrDefault(p => p.Id.Equals(id)));
     }
     catch (Exception e)
     {
         LoggingAPI.Error("(" + id + ")", e);
         return(null);
     }
 }
Exemplo n.º 16
0
        //public AccessGroup GetAccessGroup(int level)
        //{
        //    try
        //    {
        //        return _bbsDataContext.AccessGroups.FirstOrDefault(p => p.AccessGroupNumber.Equals(level));
        //    }
        //    catch (Exception e)
        //    {
        //        LoggingAPI.Error("(" + level + "): " + e);
        //        return null;
        //    }
        //}

        public List <AccessGroup> ListAccessGroups()
        {
            try
            {
                return(_bbsDataContext.AccessGroups.ToList());
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
                return(null);
            }
        }
Exemplo n.º 17
0
 public AccessGroup GetAccessGroupById(int id)
 {
     try
     {
         return(_bbsDataContext.AccessGroups.FirstOrDefault(p => p.Id.Equals(id)));
     }
     catch (Exception e)
     {
         LoggingAPI.Error("(" + id + ")", e);
         return(null);
     }
 }
Exemplo n.º 18
0
 public void Disconnect(StateObject so)
 {
     try
     {
         so.Disconnect();
         so.workSocket = null;
         OnDisconnect(so);
     }
     catch (Exception e)
     {
         LoggingAPI.Error(e);
     }
 }
Exemplo n.º 19
0
        ///
        /// Decription: Call back method to handle outgoing data.
        ///
        /// <param name="ar">Status of an asynchronous operation.</param>
        protected void SendCallback(IAsyncResult ar)
        {
            // Retrieve the socket from the async state object.
            Socket handler = (Socket)ar.AsyncState;

            try
            {
                // Complete sending the data to the remote device.
                int bytesSent = handler.EndSend(ar);
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
            }
        }
Exemplo n.º 20
0
        public Field GetField(int?userId, string fieldName)
        {
            Field result = null;

            try
            {
                result = _bbsDataContext.Fields.FirstOrDefault(p => p.UserId == userId && p.FieldName.ToUpper() == fieldName.ToUpper());
            }
            catch (Exception ex)
            {
                LoggingAPI.Error("Exception: ", ex);
                result = null;
            }
            return(result);
        }
Exemplo n.º 21
0
        public GFileArea GetGFileArea(int id)
        {
            GFileArea result = null;

            try
            {
                result = _bbsDataContext.GFileAreas.FirstOrDefault(p => p.Id == id);
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
                result = null;
            }
            return(result);
        }
Exemplo n.º 22
0
        public bool CreateAccessGroup(AccessGroup accessGroup)
        {
            bool b = false;

            try
            {
                _bbsDataContext.AccessGroups.Add(accessGroup);
                _bbsDataContext.SaveChanges();
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", accessGroup, e);
            }
            return(b);
        }
Exemplo n.º 23
0
        public bool CreateMessageBase(MessageBase messageBase)
        {
            bool b = false;

            try
            {
                _bbsDataContext.MessageBases.Add(messageBase);
                _bbsDataContext.SaveChanges();
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", messageBase, e);
            }
            return(b);
        }
Exemplo n.º 24
0
        public bool CreateUser(User user)
        {
            bool b = false;

            try
            {
                _bbsDataContext.Users.Add(user);
                _bbsDataContext.SaveChanges();
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", user, e);
            }
            return(b);
        }
Exemplo n.º 25
0
        public BBSConfig GetBBSConfig()
        {
            BBSConfig result = null;

            try
            {
                result = _bbsDataContext.BBSConfigs.FirstOrDefault(p => true);
            }
            catch (Exception ex)
            {
                LoggingAPI.Error("Exception: ", ex);
                result = null;
            }
            return(result);
        }
Exemplo n.º 26
0
        public bool CreateAccessGroup(AccessGroup accessGroup)
        {
            bool b = false;

            try
            {
                var dataContext = GetDataContext();
                dataContext.AccessGroups.InsertOnSubmit(accessGroup);
                dataContext.SubmitChanges();
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", accessGroup, e);
            }
            return(b);
        }
Exemplo n.º 27
0
        public PFileDetail GetPFileDetailByAreaAndNumber(int?area, int number)
        {
            PFileDetail pf = null;

            try
            {
                pf = _bbsDataContext.PFileDetails.FirstOrDefault(p => p.PFileAreaId.Equals(area) //& p.PFileNumber.Equals(number)
                                                                 );
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
                pf = null;
            }
            return(pf);
        }
Exemplo n.º 28
0
 public void NewFeedback(string subject, string body, int fromUser)
 {
     try
     {
         Feedback f = new Feedback()
         {
             Subject = subject, Body = body, UserId = fromUser, Sent = DateTime.Now, Read = false
         };
         _bbsDataContext.Feedbacks.Add(f);
         _bbsDataContext.SaveChanges();
     }
     catch (Exception e)
     {
         LoggingAPI.Error("Exception", e);
     }
 }
Exemplo n.º 29
0
        public bool CreateMessageBase(MessageBase messageBase)
        {
            bool b = false;

            try
            {
                var dataContext = GetDataContext();
                dataContext.MessageBases.InsertOnSubmit(messageBase);
                dataContext.SubmitChanges();
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", messageBase, e);
            }
            return(b);
        }
Exemplo n.º 30
0
        public bool CreateUser(User user)
        {
            bool b = false;

            try
            {
                var dataContext = GetDataContext();
                dataContext.Users.InsertOnSubmit(user);
                dataContext.SubmitChanges();
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", user, e);
            }
            return(b);
        }