Ejemplo n.º 1
0
        public static void CheckingData(TAccountItem account)
        {
            Converts conv = new Converts();

            ////////////////////////////////////////////
            account.Url = (account.Url == null || account.Url == "") ? "" : HIOStaticValues.getDomainName(account.Url.ToLower());
            var urlByteArray = account.Url.GetUTF8Bytes(256);

            account.Url = UnicodeEncoding.UTF8.GetString(urlByteArray);
            //proccess unicode character and get len of string
            account.Name = (account.Name == null || account.Name == "") ? "" : (account.Name.Length < 65) ? account.Name : account.Name.Substring(0, 64);
            var titleByteArray = account.Name.GetUTF8Bytes(256);

            account.Name = UnicodeEncoding.UTF8.GetString(titleByteArray);
            //////////////////////
            account.Password = (account.Password == null || account.Password == "") ? "" : (account.Password.Length < 65) ? account.Password : account.Password.Substring(0, 64);
            var passByteArray = account.Password.GetUTF8Bytes(256);

            account.Password = UnicodeEncoding.UTF8.GetString(passByteArray);
            ////////////////////////////////////////
            account.Username = (account.Username == null || account.Username == "") ? "" : (account.Username.Length < 65) ? account.Username : account.Username.Substring(0, 64);
            if (account.Username != "")
            {
                HIOStaticValues.username = account.Username;//check username(if user want just fill password element and username element filled already by self)
            }
            var userByteArray = account.Username.GetUTF8Bytes(256);

            account.Username = UnicodeEncoding.UTF8.GetString(userByteArray);
            ////////////////////////////////////////////
        }
        private void TCheckingData(JObject data, ref string url, ref string title, ref string message, ref string username)
        {
            Converts conv = new Converts();


            ////////////////////////////////////////////
            url = (data["url"] == null) ? "" : HIOStaticValues.getDomainName(data["url"].Value <string>().ToLower());
            var urlByteArray = url.GetUTF8Bytes(256);

            url = UnicodeEncoding.UTF8.GetString(urlByteArray);

            //proccess unicode character and get len of string
            title = (data["title"] == null) ? "" : (data["title"].Value <string>().Length < 65) ? data["title"].Value <string>() : data["title"].Value <string>().Substring(0, 64);
            var titleByteArray = title.GetUTF8Bytes(64);

            title = UnicodeEncoding.UTF8.GetString(titleByteArray);
            //////////////////////
            message = (data["CMD"] == null) ? "" : data["CMD"].Value <string>();
            ////////////////////////////////////////
            username = (data["username"] == null) ? "" : (data["username"].Value <string>().Length < 65) ? data["username"].Value <string>() : data["username"].Value <string>().Substring(0, 64);
            if (username != "")
            {
                HIOStaticValues.username = username;//check username(if user want just fill password element and username element filled already by self)
            }
            var usernameByteArray = username.GetUTF8Bytes(64);

            username = UnicodeEncoding.UTF8.GetString(usernameByteArray);
            ////////////////////////////////////////////
        }
Ejemplo n.º 3
0
        //public void UpdateIconWebsite()
        //{
        //    try
        //    {

        //        string url = "";
        //        string sql = "";
        //        try
        //        {

        //            DataTable DB = new DataTable();
        //            sql = string.Format("select distinct origin_url from logins where   image_data IS  NULL or length(image_data)==0 limit 1 ");
        //            using (SQLiteConnection connect = new SQLiteConnection(ConnectionString))
        //            {
        //                connect.Open();
        //                using (SQLiteCommand command = new SQLiteCommand(sql, connect))
        //                {
        //                    SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
        //                    adapter.Fill(DB);
        //                    if (DB.Rows.Count == 0) return;
        //                    url = (DB.Rows[0][0] == DBNull.Value) ? string.Empty : DB.Rows[0][0].ToString();

        //                    adapter.Dispose();
        //                    connect.Close();
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {


        //        }



        //        byte[] imageData = GetIconFromUrl(encode.Base64Decode( url));


        //        sql = string.Format("update \"main\".\"logins\" set   image_data=@image_byte_array where origin_url='{0}'   ", url);


        //        using (SQLiteConnection connect = new SQLiteConnection(ConnectionString))
        //        {
        //            connect.Open();
        //            using (SQLiteCommand command = new SQLiteCommand(sql, connect))
        //            {
        //                command.Parameters.Add("@image_byte_array", DbType.Binary, imageData.Length);
        //                command.Parameters["@image_byte_array"].Value = imageData;
        //                command.ExecuteNonQuery();


        //            }
        //            connect.Close();
        //        }



        //    }
        //    catch (Exception ex)
        //    {

        //    }

        //}

        private byte[] GetIconFromUrl(string url)
        {
            byte[] imageData = new byte[0];


            Converts conv       = new Converts();
            Image    _imageData = null;

            try
            {
                _imageData = Favicon.GetFromUrl(url).Icon;



                if (_imageData != null)
                {
                    byte[] tmpImageData = conv.ImageToByteArray(_imageData);
                    Array.Resize(ref imageData, tmpImageData.Length);
                    Array.Copy(tmpImageData, imageData, tmpImageData.Length);
                }

                return(imageData);
            }
            catch (Exception ex)
            {
                return(imageData);
            }
        }
        /// <summary>
        /// For Extensions
        /// </summary>
        /// <param name="data">recieve data from browser</param>
        /// <param name="source">check refrence of data</param>
        /// <param name="tMain">parent handler</param>

        public void ProcessRecieveMessage(JObject data, Source source)
        {
            try
            {
                if (data == null)
                {
                    return;
                }
                Converts conv = new Converts();
                Dictionary <string, string> dicData = new Dictionary <string, string> ();
                string url = "", title = "", message = "", username = "";
                TCheckingData(data, ref url, ref title, ref message, ref username);

                DataBase db = new DataBase();
                if (HIOStaticValues.CONNECTIONBHIO == false)
                {
                    dicData.Add("CMD", "CONNCETION");
                    dicData.Add("DATA", "false");


                    HIOStaticValues.BaS.Write(dicData, source);
                    if (message != "INIT" && message != "SUBMIT")
                    {
                        HIOStaticValues.popUp("HIO is not connected!");
                    }
                    return;
                }
                if (message != "INIT" && !HIOStaticValues.TPinStatus())
                {
                    return;
                }


                if (HIOStaticValues.CheckSyncingData())
                {
                    return;
                }

                switch (message)
                {
                case "exit":
                    //Environment.Exit(0);
                    break;

                case "MENUCHROME":
                    List <LoginFieldS> listUsers = db.getInfoFromDB("*", "", "");
                    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        HIOStaticValues.AdminExtention.CloseAll();
                        HIOStaticValues.AdminExtention.ExtentionMenu.Initialize(url, title);
                        HIOStaticValues.AdminExtention.ExtentionMenu.Show();
                    }));

                    break;


                //case "DASHBOARD":
                //    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                //    {
                //        TMain.Instance.Show();
                //    }));
                //    break;
                //case "MANAGEALLUSER":
                //    List<LoginFieldS> lnFields = db.getInfoFromDB("*", "", "");
                //    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                //    {


                //        HIOStaticValues.AdminExtention.CloseAll();
                //        HIOStaticValues.AdminExtention.Extention08.Initialize(lnFields);
                //        HIOStaticValues.AdminExtention.Extention08.Show();

                //    }));

                //    break;
                //case "ADDUSER":

                //    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                //    {
                //        HIOStaticValues.AdminExtention.CloseAll();
                //        HIOStaticValues.AdminExtention.Extention02.Show(new TAccountItem { Url = url, Name = title });
                //    }));
                //    break;
                case "READYDATA":
                    //ready for fill username
                    dicData.Add("CMD", "USER");
                    dicData.Add("USER", HIOStaticValues.username);
                    HIOStaticValues.BaS.Write(dicData, source, true);
                    break;

                case "READYDATAPASS":
                    //ready for fill password
                    //  Dictionary<string, string> dicData = new Dictionary<string, string> { { "CMD", "USER" }, { "USER", HIOStaticValues.username } };
                    dicData.Add("CMD", "PASS");
                    dicData.Add("DATA", HIOStaticValues.password);
                    HIOStaticValues.BaS.Write(dicData, source, true);
                    break;

                case "INIT":
                    dicData.Add("CMD", "CONNCETION");
                    dicData.Add("DATA", HIOStaticValues.CONNECTIONBHIO.ToString().ToLower());
                    HIOStaticValues.BaS.Write(dicData, source);
                    break;

                case "MANAGEUSER":
                    break;

                case "CANNOTFIND":
                    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => {
                        HIOStaticValues.popUp("HIO could not find the login form." +
                                              "\nMove the cursor inside the Username or Password field.");
                    }));
                    break;
                //case "GENERATEPASSWORDNOFILL":


                //    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                //    {

                //        try
                //        {
                //            HIOStaticValues.AdminExtention.CloseAll();
                //            HIOStaticValues.AdminExtention.Extentiongp.Show(false,false);

                //        }
                //        catch (Exception ex)
                //        {

                //            ;
                //        }
                //    }));

                //    break;
                case "GENERATEPASSWORD":
                    TGeneratePasswordForm();

                    break;

                case "JUSTMENU":

                    url = (url.Length < 257) ? url : url.Substring(0, 256);
                    // action = data["action"].Value<string>().ToLower();
                    title = (data["title"].Value <string>().Length < 65) ? data["title"].Value <string>() : data["title"].Value <string>().Substring(0, 64);
                    List <LoginFieldS> lgnpack = db.getInfoFromDB(url, "", "");

                    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        HIOStaticValues.AdminExtention.CloseAll();
                        HIOStaticValues.AdminExtention.ExtentionManage.Initialize(lgnpack, false, source, url);
                        HIOStaticValues.AdminExtention.ExtentionManage.Show();
                    }));

                    break;

                case "SUBMIT":
                    url = (url.Length < 257) ? url : url.Substring(0, 256);
                    string passwd = (data["password"].Value <string>().Length < 64) ? data["password"].Value <string>() : data["password"].Value <string>().Substring(0, 64);

                    List <LoginFieldS> listlgnpck = db.getInfoFromDB(url, username, "");
                    if (listlgnpck.Count == 0)
                    {
                        System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            HIOStaticValues.AdminExtention.CloseAll();
                            HIOStaticValues.AdminExtention.Extention10.Initialize(new LoginFieldS {
                                url = url, title = title, userName = username, password = passwd
                            });
                            HIOStaticValues.AdminExtention.Extention10.Show();
                        }));
                    }

                    break;

                case "CHECKPASS":
                    dicData.Add("CMD", "CHECKPASS");

                    HIOStaticValues.BaS.Write(dicData, source);
                    break;

                case "GETUSER":
                    HIOStaticValues.username = "";
                    url = (url.Length < 257) ? url : url.Substring(0, 256);

                    TGetUsername(url, title, source, db);

                    break;

                case "GETPASS":

                    url = (url.Length < 257) ? url : url.Substring(0, 256);
                    TGetPassword(url, title, db, source);


                    break;
                }
            }
            catch (Exception ex)
            {
            }
        }