コード例 #1
0
        public static void VerifyPassword(Packet packet)
        {
            using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
            {
                Packet sendPacket;
                dbCon.Username = "******";
                dbCon.Password = "******";
                dbCon.Connect();
                string command  = string.Format("SELECT `username`, `password` FROM `adminDB` WHERE `username`='{0}'", packet.Username);
                string passInDB = dbCon.SearchForString(command, "password");

                bool foo = CryptSharp.Crypter.CheckPassword(packet.Argument, passInDB);

                if (foo)
                {
                    ConsoleUtils.Print(string.Format("[{0}]'s Allowed: Logging in with valid credential [{1}]", packet.ClientIP, packet.Username));
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                }
                else
                {
                    ConsoleUtils.Print(string.Format("[{0}]'s Denied: Logging in with wrong password [{1}]", packet.ClientIP, packet.Username));
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                }
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                command = string.Empty;
            }
        }
コード例 #2
0
        public static int CheckForAvailabilityGID()
        {
            int retint = 0;

            using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
            {
                dbCon.Username = "******";
                dbCon.Password = "******";
                dbCon.Connect();

                string   command = "SELECT `groupid` FROM `groupDB`";
                string[] gather  = dbCon.GetListCollumnValue(command, "groupid");

                if (gather.Length != 0)
                {
                    List <string> check = new List <string>(gather);
                    for (int i = 0; i < gather.Length; i++)
                    {
                        if (!check.Contains(retint.ToString()))
                        {
                            break;
                        }
                        else
                        {
                            retint++;
                        }
                    }
                }
                command = string.Empty;
                dbCon.Close();
            }
            return(retint);
        }
コード例 #3
0
        public static void VerifyUser(Packet packet)
        {
            using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
            {
                Packet sendPacket;
                dbCon.Username = "******";
                dbCon.Password = "******";
                dbCon.Connect();
                string command = string.Format("SELECT `username` FROM `adminDB` WHERE `username`='{0}'", packet.Username);
                bool   ver     = dbCon.SearchForBoolean(command, null);

                if (ver)
                {
                    ConsoleUtils.Print(string.Format("[{0}]'s Request: Logging in to the server [{1}]", packet.ClientIP, packet.Username));
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Confirm, packet.Token);
                }
                else
                {
                    ConsoleUtils.Print(string.Format("[{0}]'s Denied: Logging in with wrong username [{1}]", packet.ClientIP, packet.Username));
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                }
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                command = string.Empty;
            }
        }
コード例 #4
0
        /*
         * In this class, there were many derived method that should be simpler, but no
         * as this is open the freedom to process more command if any appended change is
         * bound to set, and we will group it within this container, so a memory leak won't be a problem
         */

        public static void GenerateToken(Packet packet)
        {
            Packet sendPacket;

            try
            {
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Requesting token exchange from server [{1}]", packet.ClientIP, packet.Username));
                Token newToken = PacketParser.GenerateToken();
                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();
                    string brt     = dbCon.GetSqlDateTimeNow(2);
                    string command = string.Format("UPDATE `adminDB` SET `token`='{0}', `tokenExpired`='{1}' WHERE `username`='{2}'", newToken.GetString(),
                                                   brt, packet.Username);
                    dbCon.ExecuteCommand(command);
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.ReceiveOK, newToken);
                    command    = string.Empty;
                    dbCon.Close();
                }
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Generate Token Failure: {0}:{1}", e.Source, e.Message));
                sendPacket = PacketParser.CreatePacket(ResponseEnum.Failure);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }
コード例 #5
0
        public static void DeleteProject(Packet packet)
        {
            Packet sendPacket;

            try
            {
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Delete project to the server [{1}]", packet.ClientIP, packet.Username));
                Project           project = null;
                ProjectCollection projCol = ProjectBrowserStore.GetListProject();
                foreach (Project proj in projCol)
                {
                    if (proj.ProjectName == packet.Argument)
                    {
                        project = proj;
                        break;
                    }
                }

                ProjectBrowserStore.DeactivateProject(project);
                ProjectBrowserStore.DeleteProject(project);

                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();

                    string command = string.Format("DELETE FROM `projectDB` WHERE (`projectname`= '{0}')", project.ProjectName);
                    dbCon.ExecuteCommand(command);
                    command = string.Empty;
                    dbCon.Close();
                }

                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Successfully deleting project: {1} [{2}]", packet.ClientIP, project.ProjectName, packet.Username));
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Delete Project Error: [{0}] {1}", e.GetType().ToString(), e.Message));
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }
コード例 #6
0
        public static int CheckForGroupGID(string group)
        {
            int retint = -1;

            using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
            {
                dbCon.Username = "******";
                dbCon.Password = "******";
                dbCon.Connect();

                string command = string.Format("SELECT `groupid` FROM `groupDB` WHERE `groupname`='{0}'", group);
                retint = dbCon.SearchForInt(command, "groupid");

                command = string.Empty;
                dbCon.Close();
            }
            return(retint);
        }
コード例 #7
0
        public static void DeleteUser(Packet packet)
        {
            Packet sendPacket;

            try
            {
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Delete user to the server [{1}]", packet.ClientIP, packet.Username));
                string username = packet.Argument;
                if (username == "root" || username == Environment.UserName)
                {
                    ConsoleUtils.Print(string.Format("[{0}]'s Denied: User requesting to remove unallowed name: {1} [{2}]", packet.ClientIP, username, packet.Username));
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                    packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                    return;
                }

                UserInfoInserter.DeleteUser(username);
                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();

                    string command = string.Format("DELETE FROM `userDB` WHERE (`username`= '{0}')", username);
                    dbCon.ExecuteCommand(command);
                    command = string.Empty;
                    dbCon.Close();
                }
                UserCleaner.RemoveUserInEveryGroup(username);
                UserCleaner.RemoveUserInEveryProject(username);

                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Successfully deleting user {1} [{2}]", packet.ClientIP, username, packet.Username));
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Delete User Error: {0}", e.Message));
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }
コード例 #8
0
        public static void CreateUser(Packet packet)
        {
            Packet sendPacket;

            try
            {
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Create new user to the server [{1}]", packet.ClientIP, packet.Username));
                string[] store    = packet.Argument.Split(char.Parse("|"));
                string   name     = store[0];
                string   username = store[1];
                if (username.ToLower().Contains("root") || username == Environment.UserName)
                {
                    ConsoleUtils.Print(string.Format("Adding User Error: User requesting to create unallowed name [{0}]", username));
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                    packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                    return;
                }
                string password = store[2];
                UserInfoInserter.AddUser(username, password);
                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();

                    string command = string.Format("INSERT INTO `exceeddb`.`userDB` (`name`, `username`, `password`, `dateCreated`," +
                                                   " `token`, `tokenExpired`) VALUES ('{0}', '{1}', '{2}', '{3}', '', '')", name, username, CryptSharp.Crypter.Sha512.Crypt(password), DateTime.Now.ToString());
                    dbCon.ExecuteCommand(command);
                    command = string.Empty;
                    dbCon.Close();
                }
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                ConsoleUtils.Print(string.Format("[{0}]'s Success: Successfully creating user {1} [{2}]", packet.ClientIP, username, packet.Username));
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Adding User Error: {0}", e.Message));
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }
コード例 #9
0
        public static void ChangePassword(Packet packet)
        {
            Packet sendPacket;

            try
            {
                string[] store    = packet.Argument.Split(char.Parse("|"));
                string   username = store[0];
                string   password = store[1];
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Changing password of user [{1}] in the server [{2}]", packet.ClientIP, username, packet.Username));
                if (username == "root" || username == Environment.UserName)
                {
                    ConsoleUtils.Print(string.Format("Change Password Error: User requesting to change password of unallowed name [{0}]", username));
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                    packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                    return;
                }
                UserInfoInserter.ChangeUserPassword(username, password);
                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();

                    string command = string.Format("UPDATE `userDB` SET `password`='{0}' WHERE `username`='{1}'", CryptSharp.Crypter.Sha512.Crypt(password), username);
                    dbCon.ExecuteCommand(command);
                    command = string.Empty;
                    dbCon.Close();
                }
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Change Password Error: {0}", e.Message));
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }
コード例 #10
0
        public static void RemoveUserInEveryGroup(string username)
        {
            string[] groupstack = new string[0];
            using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
            {
                dbCon.Username = "******";
                dbCon.Password = "******";
                dbCon.Connect();

                string command = "SELECT `groupname` FROM `groupDB`";
                groupstack = dbCon.GetListCollumnValue(command, "groupname");

                command = string.Empty;
                dbCon.Close();
            }

            if (groupstack.Length == 0)
            {
                return;
            }

            foreach (string group in groupstack)
            {
                try
                {
                    MySQLAccountParsing.RemoveUserFromGroup(username, group);
                }
                catch (Exception ex)
                {
                    if (!(ex is MissingMemberException))
                    {
                        throw;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
コード例 #11
0
        public bool HasValidToken()
        {
            try
            {
                string convertedToken;
                string result;
                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();

                    string command  = string.Format("SELECT * FROM `adminDB` WHERE `username`='{0}'", Username);
                    string expToken = dbCon.SearchForString(command, "tokenExpired");
                    if (string.IsNullOrEmpty(expToken))
                    {
                        return(false);
                    }

                    DateTime validate = DateTime.Parse(expToken);
                    if (DateTime.Now > validate)
                    {
                        return(false);
                    }

                    result         = dbCon.SearchForString(command, "token");
                    convertedToken = Token.GetString();
                    command        = string.Empty;

                    dbCon.Close();
                }
                return(convertedToken == result);
            }
            catch (Exception e)
            {
                ConsoleUtils.Print("HasValidToken(): " + e.Message);
                return(false);
            }
        }
コード例 #12
0
        public static void RemoveGroup(Packet packet)
        {
            Packet sendPacket;

            try
            {
                string group = packet.Argument;
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Remove group from the server [{2}]", packet.ClientIP, group, packet.Username));

                UserInfoInserter.RemoveGroup(group);

                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();

                    string command = string.Format("DELETE FROM `groupDB` WHERE (`groupname`= '{0}')", group);
                    dbCon.ExecuteCommand(command);
                    command = string.Empty;
                    dbCon.Close();
                }

                GroupCleaner.RemoveGroupFromEveryProject(group);

                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Removing group success: {1} [{2}]", packet.ClientIP, group, packet.Username));
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Remove Group Error: [{0}] {1}", e.GetType().ToString(), e.Message));
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }
コード例 #13
0
        public static void CreateProject(Packet packet)
        {
            Packet sendPacket;

            try
            {
                string[] split       = packet.Argument.Split(char.Parse("|"));
                string   projectName = split[0];
                string   activate    = split[1];
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Create new project to the server [{1}]", packet.ClientIP, packet.Username));
                Project newProj = ProjectBrowserStore.CreateProject(projectName);
                ProjectBrowserStore.ActivateProject(newProj);

                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();

                    string command = string.Format("INSERT INTO `exceeddb`.`projectDB` (`projectname`, `group`, `user`)" +
                                                   " VALUES ('{0}', '', '')", newProj.ProjectName);
                    dbCon.ExecuteCommand(command);
                    command = string.Empty;
                    dbCon.Close();
                }

                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Create Project Error: [{0}] {1}", e.GetType().ToString(), e.Message));
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }
コード例 #14
0
        public static void CreateGroup(Packet packet)
        {
            Packet sendPacket;

            try
            {
                string group = packet.Argument;
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Add group to the server [{2}]", packet.ClientIP, group, packet.Username));

                int gid = UserInfoInserter.AddGroup(group);

                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();

                    string command = string.Format("INSERT INTO `exceeddb`.`groupDB` (`groupid`, `groupname`, `dateCreated`, `member`)" +
                                                   " VALUES ('{0}', '{1}', '{2}', '')", gid, group, DateTime.Now.ToString());
                    dbCon.ExecuteCommand(command);
                    command = string.Empty;
                    dbCon.Close();
                }

                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Adding group success: {1} [{2}]", packet.ClientIP, group, packet.Username));
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Adding Group Error: [{0}] {1}", e.GetType().ToString(), e.Message));
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }
コード例 #15
0
        internal static void RequestGroupList(Packet packet)
        {
            string filepath = string.Format("/tmp/exceedop/grouplist_{0}",
                                            DateTime.Now.ToString().Split(char.Parse(" "))[0].Replace(char.Parse("/"), char.Parse("_")));

            FileMode option = !File.Exists(filepath) ? FileMode.OpenOrCreate : FileMode.Truncate;

            lock (stateGroup)
            {
                using (var fsl = new FileStream(filepath, option, FileAccess.Write))
                {
                    List <string[]> resDb;
                    using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                    {
                        dbCon.Username = "******";
                        dbCon.Password = "******";
                        dbCon.Connect();

                        string command = "SELECT * FROM `groupDB`";
                        resDb   = dbCon.GetAllCollumnValue(command);
                        command = string.Empty;
                        dbCon.Close();
                    }

                    if (resDb.Count == 0)
                    {
                        Packet sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                        packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                        return;
                    }

                    StreamWriter writer = new StreamWriter(fsl);
                    writer.WriteLine("=== Group List ===");
                    writer.WriteLine("  ");
                    foreach (string[] list in resDb)
                    {
                        writer.WriteLine(string.Format("[{0}]", list[1]));
                        writer.WriteLine(string.Format("   dateCreated: {0}", list[2]));
                        writer.WriteLine(string.Format("   users: {0}", list[3]));
                        writer.WriteLine("  ");
                    }
                    writer.Close();
                }
            }

            using (var file = new FileStream(filepath, FileMode.Open, FileAccess.Read))
            {
                Packet sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Confirm, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);

                int curReadBytes = 0;

                do
                {
                    byte[] sendByte = new byte[10000];
                    curReadBytes = file.Read(sendByte, 0, sendByte.Length);
                    if (curReadBytes != 0)
                    {
                        packet.Stream.Write(sendByte, 0, curReadBytes);
                        byte[] recByte = new byte[2];
                        packet.Stream.Read(recByte, 0, 2);
                        if (Utilities.ByteConverter.ToResponse(recByte, 0) != ResponseEnum.Confirm)
                        {
                            packet.Stream.Write(ByteReader.ReadBytes(ResponseEnum.Failure), 0, 2);
                            throw new InvalidAsynchronousStateException("User did not responded properly");
                        }
                    }
                    else
                    {
                        packet.Stream.Write(ByteReader.ReadBytes(ResponseEnum.Success), 0, 2);
                    }
                }while (curReadBytes != 0);
            }
        }