Beispiel #1
0
        /*public bool Connect(String str_dbType, InfoConnection Info)
         * {
         * Array arr = Enum.GetNames(typeof(enmConnection));
         * int idx_dbtype = -1;
         * for (int i = 0; i < arr.Length; i++)
         * {
         * if (str_dbType == arr.GetValue(i).ToString())
         * { idx_dbtype = i; }
         * }
         *
         * this.dbType = ((enmConnection)idx_dbtype);
         * this.Info = Info;
         * return this.cnn.Connect(dbType, Info);
         * }*/
        #endregion

        #region public bool Connect(enmConnection dbType, InfoConnection Info)
        public bool Connect(enmConnection dbType, InfoConnection Info)
        {
            this.ForeignKeys = null;
            this.dbType      = dbType;
            this.Info        = Info;
            return(this.cnn.Connect(dbType, Info));
        }
Beispiel #2
0
        static void WriteServerInfo(String address)
        {
            InfoConnection infoConnection = new InfoConnection(address, logger);
            ServerInfo     info           = infoConnection.DownloadInfo();

            WriteServerInfo(info);
        }
Beispiel #3
0
        public bool Connect(string ConnectionString)
        {
            string[]       Fields  = ConnectionString.Split(new char[] { ';' });
            Conversion     cnv     = new Conversion();
            enmConnection  _dbType = GetDbType(GetValue("DbType", Fields));
            InfoConnection _info   = new InfoConnection(cnv.ToBool(GetValue("UseWindowsAuthentication", Fields)), GetValue("Server", Fields), GetValue("Database", Fields), GetValue("User", Fields), GetValue("Password", Fields));

            return(Connect(_dbType, _info));
        }
Beispiel #4
0
 public override void WriteBinary(ESPWriter writer)
 {
     if (InfoConnection != null)
     {
         InfoConnection.WriteBinary(writer);
     }
     if (InfoIndex != null)
     {
         InfoIndex.WriteBinary(writer);
     }
 }
Beispiel #5
0
        public override void WriteXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            if (InfoConnection != null)
            {
                ele.TryPathTo("InfoConnection", true, out subEle);
                InfoConnection.WriteXML(subEle, master);
            }
            if (InfoIndex != null)
            {
                ele.TryPathTo("InfoIndex", true, out subEle);
                InfoIndex.WriteXML(subEle, master);
            }
        }
Beispiel #6
0
        public override void ReadBinary(ESPReader reader)
        {
            List <string> readTags = new List <string>();

            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                string subTag = reader.PeekTag();

                switch (subTag)
                {
                case "INFC":
                    if (readTags.Contains("INFC"))
                    {
                        return;
                    }
                    if (InfoConnection == null)
                    {
                        InfoConnection = new RecordReference();
                    }

                    InfoConnection.ReadBinary(reader);
                    break;

                case "INFX":
                    if (readTags.Contains("INFX"))
                    {
                        return;
                    }
                    if (InfoIndex == null)
                    {
                        InfoIndex = new SimpleSubrecord <Int32>();
                    }

                    InfoIndex.ReadBinary(reader);
                    break;

                default:
                    return;
                }

                readTags.Add(subTag);
            }
        }
Beispiel #7
0
        public async void AfterServerSelected(X509Certificate2 clientCert, String address, String password, String userName)
        {
            MainPage = new Loading("Server informations are downloading...");
            try
            {
                InfoConnection infoConnection = new InfoConnection(address, logger);
                ServerInfo     info           = null;

                await Task.Run(() =>
                {
                    info = infoConnection.DownloadInfo();
                });

                MainPage = new ServerVerification(this, info, clientCert, address, password, userName);
            }
            catch (Exception ex)
            {
                MainPage = new ServerSelection(this, clientCert, address, password, userName, ex.Message);
            }
        }
Beispiel #8
0
        public override void ReadXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            if (ele.TryPathTo("InfoConnection", false, out subEle))
            {
                if (InfoConnection == null)
                {
                    InfoConnection = new RecordReference();
                }

                InfoConnection.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("InfoIndex", false, out subEle))
            {
                if (InfoIndex == null)
                {
                    InfoIndex = new SimpleSubrecord <Int32>();
                }

                InfoIndex.ReadXML(subEle, master);
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
main:
            logger = new Logger(new ConsoleLoggerOutput());
            WriteLine("Chatovatko client at your service!");
            try {
                config        = new ConsoleClientDatabaseConfig();
                initializator = new DBInitializator(config, logger);
                initializator.DBEnsureCreated();

                settingsLoader = new SettingsLoader(config, logger);

                if (settingsLoader.Exists())
                {
                    Log("Settings exists and will be loaded.");
                    settings = settingsLoader.GetSettingsCapsula();
                }
                else
                {
                    Log("Settings doesn't exist.");
                }

                bool running = true;
                while (running)
                {
                    try
                    {
                        String   command      = ReadLine().Trim();
                        String[] commandParts = command.Split(' ');

                        switch (commandParts[0])
                        {
                        case "init":
                            if (commandParts.Length < 3)
                            {
                                WriteNotEnoughParameters();
                                break;
                            }

                            if (settings != null)
                            {
                                WriteLine("Chatovatko is initialized already.");
                                break;
                            }

                            bool?  newUser       = null;
                            string userName      = null;
                            string serverAddress = commandParts[2];
                            switch (commandParts[1])
                            {
                            case "new":
                                newUser = true;
                                break;

                            case "login":
                                newUser = false;
                                break;

                            default:
                                WriteSyntaxError(commandParts[1]);
                                break;
                            }
                            if (newUser != null)
                            {
                                X509Certificate2 clientCert;
                                if (newUser == true)
                                {
                                    WriteLine("Your certificate is being created. Please, be patient.");
                                    clientCert = X509Certificate2Generator.GenerateCACertificate(logger);

                                    WriteLine("Your certificate has been generated. Enter path to save it: [default: ~/.chatovatko/mykey.p12]");
                                    string path = ReadLine();
                                    if (path.Equals(""))
                                    {
                                        path = $"{Utils.GetConfigDirectory()}/mykey.p12";
                                    }
                                    X509Certificate2Utils.ExportToPkcs12File(clientCert, path);
                                    WriteLine("----------------------------------------------------------------");

                                    WriteLine("Enter your new unique username:"******"Enter path to your certificate please: [default: ~/.chatovatko/mykey.p12]");
                                    string path = ReadLine();
                                    if (path.Equals(""))
                                    {
                                        path = $"{Utils.GetConfigDirectory()}/mykey.p12";
                                    }

                                    WriteLine("If you are logining to this server first time, it is nessary to enter you new unique username:"******"Do you trust this server (y/n):");

                                string pushed = ReadLine();
                                if (!pushed.Equals("y"))
                                {
                                    break;
                                }

                                IConnectionVerificator verificator = new ConnectionVerificator(logger, info.PublicKey);
                                connection = new Connection(logger, verificator, serverAddress, clientCert, config, userName);
                                connection.Connect();

                                Log("Saving settings.");
                                settingsLoader.Create(clientCert, connection.UserId, connection.UserName, info.Name, serverAddress, info.PublicKey, (int)connection.ClientId);
                                settings = settingsLoader.GetSettingsCapsula();

                                Log("Self-trustification begin.");
                                connection.TrustContact(connection.UserId);
                                Log("Self-trustification done.");

                                Log("Updating.");
                                connection.Pull();
                                connection.Push();
                                Log("Updating done.");
                            }
                            break;

                        case "connect":
                            CreateOpenedConnection(true);
                            break;

                        case "disconnect":
                            if (!VerifyConnectionOpened(true))
                            {
                                break;
                            }
                            connection.Disconnect();
                            break;

                        case "push":
                            if (!VerifyConnectionOpened(true))
                            {
                                break;
                            }
                            connection.Push();
                            break;

                        case "pull":
                            if (!VerifyConnectionOpened(true))
                            {
                                break;
                            }
                            connection.Pull();
                            break;

                        case "delete":
                            if (commandParts.Length < 2)
                            {
                                WriteNotEnoughParameters();
                                break;
                            }
                            switch (commandParts[1])
                            {
                            case "database":
                                initializator.DBDelete();
                                WriteLine();

                                running        = false;
                                config         = null;
                                initializator  = null;
                                settingsLoader = null;
                                settings       = null;
                                connection     = null;
                                goto main;

                            case "message":
                                if (commandParts.Length < 3)
                                {
                                    WriteNotEnoughParameters();
                                    break;
                                }
                                DeleteMessage(Int32.Parse(commandParts[2]));
                                break;

                            case "thread":
                                if (commandParts.Length < 3)
                                {
                                    WriteNotEnoughParameters();
                                    break;
                                }
                                DeleteThread(Int32.Parse(commandParts[2]));
                                break;

                            default:
                                WriteSyntaxError(commandParts[1]);
                                break;
                            }
                            break;

                        case "download":
                            if (commandParts.Length < 3)
                            {
                                WriteNotEnoughParameters();
                                break;
                            }
                            switch (commandParts[1])
                            {
                            case "info":
                                WriteServerInfo(commandParts[2]);
                                break;

                            default:
                                WriteSyntaxError(commandParts[1]);
                                break;
                            }
                            break;

                        case "ls":
                            if (commandParts.Length < 2)
                            {
                                WriteNotEnoughParameters();
                                break;
                            }
                            switch (commandParts[1])
                            {
                            case "users":
                                WriteUsers();
                                break;

                            case "threads":
                                WriteThreads();
                                break;

                            case "messages":
                                if (commandParts.Length < 3)
                                {
                                    WriteNotEnoughParameters();
                                    break;
                                }
                                WriteMessages(Int32.Parse(commandParts[2]));
                                break;

                            default:
                                WriteSyntaxError(commandParts[1]);
                                break;
                            }
                            break;

                        case "post":
                            if (commandParts.Length < 4)
                            {
                                WriteNotEnoughParameters();
                                break;
                            }
                            switch (commandParts[1])
                            {
                            case "thread":
                                PostThread(Int32.Parse(commandParts[2]), BuildFromRest(commandParts, 3));
                                break;

                            case "message":
                                PostMessage(Int32.Parse(commandParts[2]), commandParts[3]);
                                break;

                            default:
                                WriteSyntaxError(commandParts[1]);
                                break;
                            }
                            break;

                        case "rename":
                            if (commandParts.Length < 4)
                            {
                                WriteNotEnoughParameters();
                                break;
                            }
                            switch (commandParts[1])
                            {
                            case "thread":
                                RenameThread(Int32.Parse(commandParts[2]), BuildFromRest(commandParts, 3));
                                break;

                            default:
                                WriteSyntaxError(commandParts[1]);
                                break;
                            }
                            break;

                        case "trust":
                            if (commandParts.Length < 2)
                            {
                                WriteNotEnoughParameters();
                                break;
                            }
                            VerifyConnectionOpened(true);
                            connection.TrustContact(Int32.Parse(commandParts[1]));
                            break;

                        case "untrust":
                            if (commandParts.Length < 2)
                            {
                                WriteNotEnoughParameters();
                                break;
                            }
                            VerifyConnectionOpened(true);
                            connection.UntrustContact(Int32.Parse(commandParts[1]));
                            break;

                        case "generate":
                            if (commandParts.Length < 2)
                            {
                                WriteNotEnoughParameters();
                                break;
                            }
                            switch (commandParts[1])
                            {
                            case "X509Certificate2":
                                X509Certificate2 cert = X509Certificate2Generator.GenerateCACertificate(logger);
                                WriteLine(X509Certificate2Utils.ExportToBase64(cert));

                                break;

                            default:
                                WriteSyntaxError(commandParts[1]);
                                break;
                            }
                            break;

                        case "aesTrial":
                            if (!VerifyConnectionOpened(true))
                            {
                                break;
                            }
                            AesTrial();
                            break;

                        case "exit":
                        case "quit":
                            running = false;
                            break;

                        case "--":
                        case "":
                        case "#":
                            break;

                        case "status":
                            WriteStatus(settings.Settings, config);
                            break;

                        default:
                            WriteSyntaxError(commandParts[0]);
                            break;
                        }
                    }
                    catch (ChatovatkoException ex)
                    {
                        logger.Log("Program", "Core", "The command has failed.", true);
                        logger.LogException(ex);
                    }
                    catch (Exception ex)
                    {
                        logger.LogException(ex, "Program", "Core", "The command has failed.");
                    }
                }

                //Config config;

                //Connection.Connect();
            }
            catch (Exception ex)
            {
                logger.Log("Program", "Core", String.Format("The client has crashed. Exception:\n{0}\n{1}", ex.Message, ex.StackTrace), true);
            }
            finally
            {
                logger.Close();
                logger = null;
            }
        }
Beispiel #10
0
 public void Reconfigure(enmConnection DbType, InfoConnection InfoConnection)
 {
     this.cfg.DbType = DbType;
     this.cfg.Info   = InfoConnection;
     SaveDbParam();
 }