示例#1
0
        private void OnEnableCopy(AutoExecItem item)
        {
            //disable this device for the cloned entry
            KeeAutoExecExt.SetDeviceEnabled(item, KeeAutoExecExt.ThisDeviceId, false);
            //remember the original device settings
            ProtectedString ifDeviceOrig = item.Entry.Strings.GetSafe(KeeAutoExecExt._ifDevice);

            //reset device settings so only the current device is enabled
            item.Entry.Strings.Set(KeeAutoExecExt._ifDevice, new ProtectedString(false, ""));
            KeeAutoExecExt.SetDeviceEnabled(item, KeeAutoExecExt.ThisDeviceId, true);
            //now clone
            var newEntry = item.Entry.CloneDeep();

            //reset device settings
            item.Entry.Strings.Set(KeeAutoExecExt._ifDevice, ifDeviceOrig);
            newEntry.SetUuid(new PwUuid(true), true); // Create new UUID
            string strTitle = newEntry.Strings.ReadSafe(PwDefs.TitleField);

            newEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, strTitle + " (" + Android.OS.Build.Model + ")"));
            var addTask = new AddEntry(this, App.Kp2a, newEntry, item.Entry.ParentGroup, new ActionOnFinish(this, (success, message, activity) => ((ConfigureChildDatabasesActivity)activity).Update()));

            ProgressTask pt = new ProgressTask(App.Kp2a, this, addTask);

            pt.Run();
        }
示例#2
0
        public override void PrepareForSaving(PwEntry entry)
        {
            entry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, entry.Strings.ReadSafe(strUiDatabaseFile)));
            entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, entry.Strings.ReadSafe(strUiKeyFile)));
            entry.Strings.Remove(strUiDatabaseFile);
            entry.Strings.Remove(strUiKeyFile);

            Dictionary <string, bool> devices = new Dictionary <string, bool>();

            foreach (string key in entry.Strings.GetKeys())
            {
                if (key.StartsWith(strUiIfDevice))
                {
                    string device = key.Substring(strUiIfDevice.Length);
                    devices[device] = entry.Strings.ReadSafe(key).Equals("true", StringComparison.OrdinalIgnoreCase);
                }
            }
            entry.Strings.Set(KeeAutoExecExt._ifDevice, new ProtectedString(false, KeeAutoExecExt.BuildIfDevice(devices)));
            foreach (string device in devices.Keys)
            {
                entry.Strings.Remove(strUiIfDevice + device);
            }

            base.PrepareForSaving(entry);
        }
示例#3
0
        private bool OpenAutoExecEntries(Database db)
        {
            string thisDevice = KeeAutoExecExt.ThisDeviceId;

            foreach (var autoOpenItem in KeeAutoExecExt.GetAutoExecItems(db.KpDatabase))
            {
                if (!autoOpenItem.Enabled)
                {
                    continue;
                }
                if (!KeeAutoExecExt.IsDeviceEnabled(autoOpenItem, thisDevice, out _))
                {
                    continue;
                }
                IOConnectionInfo dbIoc;
                if (KeeAutoExecExt.TryGetDatabaseIoc(autoOpenItem, out dbIoc) &&
                    App.Kp2a.TryGetDatabase(dbIoc) == null &&
                    App.Kp2a.AttemptedToOpenBefore(dbIoc) == false
                    )
                {
                    if (KeeAutoExecExt.AutoOpenEntry(this, autoOpenItem, false))
                    {
                        LaunchingOther = true;
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#4
0
 public void Update()
 {
     _displayedChildDatabases = KeeAutoExecExt.GetAutoExecItems(App.Kp2a.CurrentDb.KpDatabase)
                                .Where(e => App.Kp2a.TryFindDatabaseForElement(e.Entry) != null) //Update() can be called while we're adding entries to the database. They may be part of the group but without saving complete
                                .OrderBy(e => SprEngine.Compile(e.Entry.Strings.ReadSafe(PwDefs.TitleField), new SprContext(e.Entry, App.Kp2a.FindDatabaseForElement(e.Entry).KpDatabase, SprCompileFlags.All)))
                                .ThenByDescending(e => e.Entry.LastModificationTime)
                                .ToList();
 }
示例#5
0
        public override void InitializeEntry(PwEntry entry)
        {
            base.InitializeEntry(entry);
            if (!entry.Strings.Exists(strVisible))
            {
                entry.Strings.Set(strVisible, new ProtectedString(false, "true"));
            }
            if (!entry.Strings.Exists(strEnabled))
            {
                entry.Strings.Set(strEnabled, new ProtectedString(false, "true"));
            }
            var autoExecItem = KeeAutoExecExt.MakeAutoExecItem(App.Kp2a.CurrentDb.KpDatabase, entry, 0);
            IOConnectionInfo ioc;

            if (!KeeAutoExecExt.TryGetDatabaseIoc(autoExecItem, out ioc))
            {
                ioc = IOConnectionInfo.FromPath(entry.Strings.ReadSafe(PwDefs.UrlField));
            }
            string path = ioc.Path;

            try
            {
                var filestorage = App.Kp2a.GetFileStorage(ioc);
                if (filestorage != null)
                {
                    path = filestorage.IocToPath(ioc);
                }
            }
            catch (NoFileStorageFoundException)
            {
            }


            entry.Strings.Set(strUiDatabaseFile, new ProtectedString(false, path));
            entry.Strings.Set(strUiKeyFile, new ProtectedString(false, entry.Strings.ReadSafe(PwDefs.UserNameField)));

            var devices =
                KeeAutoExecExt.GetIfDevice(KeeAutoExecExt.MakeAutoExecItem(App.Kp2a.CurrentDb.KpDatabase, entry, 0));

            //make sure user can enable/disable on this device explicitly:
            if (!devices.ContainsKey(KeeAutoExecExt.ThisDeviceId))
            {
                devices[KeeAutoExecExt.ThisDeviceId] = false;
            }
            foreach (var ifDevice in devices)
            {
                entry.Strings.Set(strUiIfDevice + ifDevice.Key, new ProtectedString(false, ifDevice.Value.ToString()));
            }
        }
示例#6
0
        private void AddAutoOpenEntryForDatabase(Database db)
        {
            PwGroup autoOpenGroup = null;
            var     rootGroup     = App.Kp2a.CurrentDb.KpDatabase.RootGroup;

            foreach (PwGroup pgSub in rootGroup.Groups)
            {
                if (pgSub.Name == "AutoOpen")
                {
                    autoOpenGroup = pgSub;
                    break;
                }
            }
            if (autoOpenGroup == null)
            {
                AddGroup addGroupTask = AddGroup.GetInstance(this, App.Kp2a, "AutoOpen", 1, null, rootGroup, null, true);
                addGroupTask.Run();
                autoOpenGroup = addGroupTask.Group;
            }

            PwEntry newEntry = new PwEntry(true, true);

            newEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, App.Kp2a.GetFileStorage(db.Ioc).GetDisplayName(db.Ioc)));
            newEntry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, TryMakeRelativePath(App.Kp2a.CurrentDb, db.Ioc)));
            var password = db.KpDatabase.MasterKey.GetUserKey <KcpPassword>();

            newEntry.Strings.Set(PwDefs.PasswordField, password == null ? new ProtectedString(true, "") : password.Password);

            var keyfile = db.KpDatabase.MasterKey.GetUserKey <KcpKeyFile>();

            if ((keyfile != null) && (keyfile.Ioc != null))
            {
                newEntry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, TryMakeRelativePath(App.Kp2a.CurrentDb, keyfile.Ioc)));
            }

            newEntry.Strings.Set(KeeAutoExecExt._ifDevice,
                                 new ProtectedString(false,
                                                     KeeAutoExecExt.BuildIfDevice(new Dictionary <string, bool>()
            {
                { KeeAutoExecExt.ThisDeviceId, true }
            })));

            var addTask = new AddEntry(this, App.Kp2a, newEntry, autoOpenGroup, new ActionOnFinish(this, (success, message, activity) => (activity as ConfigureChildDatabasesActivity)?.Update()));

            ProgressTask pt = new ProgressTask(App.Kp2a, this, addTask);

            pt.Run();
        }
        private static bool IsValidIoc(AutoExecItem item)
        {
            IOConnectionInfo itemIoc;

            if (!KeeAutoExecExt.TryGetDatabaseIoc(item, out itemIoc))
            {
                return(false);
            }
            try
            {
                //see if we have a file storage for the given protocol
                App.Kp2a.GetFileStorage(itemIoc);
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
示例#8
0
            public void Update()
            {
                string thisDevice = KeeAutoExecExt.ThisDeviceId;

                _displayedDatabases = App.Kp2a.OpenDatabases.ToList();
                _autoExecItems      = App.Kp2a.OpenDatabases
                                      .SelectMany(db => KeeAutoExecExt.GetAutoExecItems(db.KpDatabase))
                                      .Where(item =>
                                             item.Visible
                                             &&
                                             KeeAutoExecExt.IsDeviceEnabled(item, thisDevice, out _)
                                             &&
                                             !_displayedDatabases.Any(displayedDb =>
                {
                    IOConnectionInfo itemIoc;
                    return(KeeAutoExecExt.TryGetDatabaseIoc(item, out itemIoc) &&
                           displayedDb.Ioc.IsSameFileAs(itemIoc));
                }))
                                      .ToList();
            }
        private bool OpenAutoExecEntries(Database db)
        {
            try
            {
                string thisDevice = KeeAutoExecExt.ThisDeviceId;
                foreach (var autoOpenItem in KeeAutoExecExt.GetAutoExecItems(db.KpDatabase))
                {
                    if (!autoOpenItem.Enabled)
                    {
                        continue;
                    }
                    if (!KeeAutoExecExt.IsDeviceEnabled(autoOpenItem, thisDevice, out _))
                    {
                        continue;
                    }
                    if (!IsValidIoc(autoOpenItem))
                    {
                        continue;
                    }

                    IOConnectionInfo dbIoc;
                    if (KeeAutoExecExt.TryGetDatabaseIoc(autoOpenItem, out dbIoc) &&
                        App.Kp2a.TryGetDatabase(dbIoc) == null &&
                        App.Kp2a.AttemptedToOpenBefore(dbIoc) == false
                        )
                    {
                        if (KeeAutoExecExt.AutoOpenEntry(this, autoOpenItem, false, new ActivityLaunchModeRequestCode(ReqCodeOpenNewDb)))
                        {
                            LaunchingOther = true;
                            return(true);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Kp2aLog.LogUnexpectedError(e);
            }

            return(false);
        }
示例#10
0
 private void OnAutoExecItemSelected(AutoExecItem autoExecItem)
 {
     KeeAutoExecExt.AutoOpenEntry(this, autoExecItem, true);
 }
示例#11
0
 private void OnAutoExecItemSelected(AutoExecItem autoExecItem)
 {
     KeeAutoExecExt.AutoOpenEntry(this, autoExecItem, true, new ActivityLaunchModeSimple());
 }
示例#12
0
            public override View GetView(int position, View convertView, ViewGroup parent)
            {
                if (cursorInflater == null)
                {
                    cursorInflater = (LayoutInflater)_context.GetSystemService(Context.LayoutInflaterService);
                }

                View view;

                if (convertView == null)
                {
                    // if it's not recycled, initialize some attributes

                    view = cursorInflater.Inflate(Resource.Layout.child_db_config_row, parent, false);


                    view.FindViewById <Button>(Resource.Id.child_db_enable_on_this_device).Click += (sender, args) =>
                    {
                        View sending_view = (View)sender;
                        _context.OnEnable(_displayedChildDatabases[GetClickedPos(sending_view)]);
                    };

                    view.FindViewById <Button>(Resource.Id.child_db_disable_on_this_device).Click += (sender, args) =>
                    {
                        View sending_view = (View)sender;
                        _context.OnDisable(_displayedChildDatabases[GetClickedPos(sending_view)]);
                    };


                    view.FindViewById <Button>(Resource.Id.child_db_edit).Click += (sender, args) =>
                    {
                        View sending_view = (View)sender;
                        _context.OnEdit(_displayedChildDatabases[GetClickedPos(sending_view)]);
                    };


                    view.FindViewById <Button>(Resource.Id.child_db_open).Click += (sender, args) =>
                    {
                        View sending_view = (View)sender;
                        _context.OnOpen(_displayedChildDatabases[GetClickedPos(sending_view)]);
                    };


                    view.FindViewById <Button>(Resource.Id.child_db_enable_a_copy_for_this_device).Click += (sender, args) =>
                    {
                        View sending_view = (View)sender;
                        _context.OnEnableCopy(_displayedChildDatabases[GetClickedPos(sending_view)]);
                    };
                }
                else
                {
                    view = convertView;
                }


                var iv           = view.FindViewById <ImageView>(Resource.Id.child_db_icon);
                var autoExecItem = _displayedChildDatabases[position];
                var pw           = autoExecItem.Entry;

                SprContext ctx = new SprContext(pw, App.Kp2a.FindDatabaseForElement(pw).KpDatabase, SprCompileFlags.All);

                string deviceId = KeeAutoExecExt.ThisDeviceId;

                view.FindViewById <TextView>(Resource.Id.child_db_title).Text =
                    SprEngine.Compile(pw.Strings.GetSafe(PwDefs.TitleField).ReadString(), ctx);

                view.FindViewById <TextView>(Resource.Id.child_db_url).Text =
                    _context.GetString(Resource.String.entry_url) + ": " + SprEngine.Compile(pw.Strings.GetSafe(PwDefs.UrlField).ReadString(), ctx);

                bool deviceEnabledExplict;
                bool deviceEnabled = KeeAutoExecExt.IsDeviceEnabled(autoExecItem, deviceId, out deviceEnabledExplict);

                deviceEnabled &= deviceEnabledExplict;


                if (!autoExecItem.Enabled)
                {
                    view.FindViewById <TextView>(Resource.Id.child_db_enabled_here).Text =
                        _context.GetString(Resource.String.plugin_disabled);
                }
                else
                {
                    view.FindViewById <TextView>(Resource.Id.child_db_enabled_here).Text =
                        _context.GetString(Resource.String.child_db_enabled_on_this_device) + ": " +
                        (!deviceEnabledExplict ?
                         _context.GetString(Resource.String.unspecified)
                            :
                         ((autoExecItem.Enabled && deviceEnabled)
                                ? _context.GetString(Resource.String.yes)
                                : _context.GetString(Resource.String.no)));
                }

                view.FindViewById(Resource.Id.child_db_enable_on_this_device).Visibility  = !deviceEnabled && autoExecItem.Enabled ? ViewStates.Visible : ViewStates.Gone;
                view.FindViewById(Resource.Id.child_db_disable_on_this_device).Visibility = (deviceEnabled || !deviceEnabledExplict) && autoExecItem.Enabled ? ViewStates.Visible : ViewStates.Gone;
                view.FindViewById(Resource.Id.child_db_enable_a_copy_for_this_device_container).Visibility = !deviceEnabled && autoExecItem.Enabled ? ViewStates.Visible : ViewStates.Gone;
                view.FindViewById(Resource.Id.child_db_edit).Visibility = deviceEnabledExplict || !autoExecItem.Enabled  ? ViewStates.Visible : ViewStates.Gone;
                IOConnectionInfo ioc;

                if ((KeeAutoExecExt.TryGetDatabaseIoc(autoExecItem, out ioc)) && App.Kp2a.TryGetDatabase(ioc) == null)
                {
                    view.FindViewById(Resource.Id.child_db_open).Visibility = ViewStates.Visible;
                }
                else
                {
                    view.FindViewById(Resource.Id.child_db_open).Visibility = ViewStates.Gone;
                }


                Database db = App.Kp2a.FindDatabaseForElement(pw);

                bool isExpired = pw.Expires && pw.ExpiryTime < DateTime.Now;

                if (isExpired)
                {
                    db.DrawableFactory.AssignDrawableTo(iv, _context, db.KpDatabase, PwIcon.Expired, PwUuid.Zero, false);
                }
                else
                {
                    db.DrawableFactory.AssignDrawableTo(iv, _context, db.KpDatabase, pw.IconId, pw.CustomIconUuid, false);
                }



                view.Tag = position.ToString();

                return(view);
            }
示例#13
0
 private void OnEnable(AutoExecItem item)
 {
     KeeAutoExecExt.SetDeviceEnabled(item, KeeAutoExecExt.ThisDeviceId, true);
     Save(item);
 }
示例#14
0
 private void OnOpen(AutoExecItem item)
 {
     KeeAutoExecExt.AutoOpenEntry(this, item, true);
 }
 private void OnOpen(AutoExecItem item)
 {
     KeeAutoExecExt.AutoOpenEntry(this, item, true, new ActivityLaunchModeSimple());
 }