public AccessControlLogEntry(DateTime timestamp, string description, AccessControlCard accessctlcard, string expander, string panel)
 {
     this.timestamp     = timestamp;
     this.description   = description;
     this.accessctlcard = new AccessControlCard(accessctlcard);
     this.expander      = expander;
     this.panel         = panel;
 }
        public PanelState(AccessControlCard card, UInt64 uptime, DateTime timestamp)
        {
            if (card != null)
            {
                this.card = new AccessControlCard(card);
            }


            this.uptime    = uptime;
            this.timestamp = timestamp;
        }
Example #3
0
 public AccessControlCard(AccessControlCard card) : this(card.UID, card.Type, card.Timestamp)
 {
 }
Example #4
0
        private void NewCardPresented(PanelMonitor pnlmon, PanelEventArgs pnlevargs)
        {
            try
            {
                using (MySqlConnection sqlconn = new MySqlConnection(dbconnprop.ConnectionString))
                {
                    sqlconn.Open();

                    //lookup
                    using (MySqlCommand cmdName = new MySqlCommand("select data from `" + table_name + "` where uid=" + pnlevargs.PanelState.Card.UID, sqlconn))
                        using (MySqlDataReader reader = cmdName.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                if (reader[0] != DBNull.Value)
                                {
                                    byte[] bytes = (byte[])reader["data"];

                                    AccessProperties accessprop;
                                    using (MemoryStream ms = new MemoryStream())
                                    {
                                        ms.Write(bytes, 0, bytes.Length);
                                        ms.Position = 0;
                                        accessprop  = (AccessProperties)bf.Deserialize(ms);
                                    }

                                    //add to processing queue
                                    if (!accessprop.ForceDisable)
                                    {
                                        if (accessprop.EnabledFrom <= DateTime.Now || accessprop.ForceEnable)
                                        {
                                            if (accessprop.EnabledTo >= DateTime.Now || accessprop.ForceEnable)
                                            {
                                                //card is active; continue verifying

                                                List <ExpanderModificationProperties> temp = accessprop.ProcessActivations();
                                                int associated_car = pnlmon.AssociatedCar;

                                                if (temp.Count > 0)
                                                {
                                                    pnlmon.AnimateLED(PanelCommand.ANIMATION_APPROVAL);

                                                    PanelMonitor      monitor = pnlmon;
                                                    AccessControlCard card    = pnlevargs.PanelState.Card;

                                                    Task.Run(delegate()
                                                    {
                                                        AccessControlLogManager.AddAccessControlLogEntry(card.UID, new AccessControlLogEntry(DateTime.Now, "User Approved Entry", card,
                                                                                                                                             expmon.ToString(), monitor.ToString()));
                                                    });
                                                }
                                                else
                                                {
                                                    pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);

                                                    PanelMonitor      monitor = pnlmon;
                                                    AccessControlCard card    = pnlevargs.PanelState.Card;

                                                    Task.Run(delegate()
                                                    {
                                                        AccessControlLogManager.AddAccessControlLogEntry(card.UID, new AccessControlLogEntry(DateTime.Now, "User Declined Entry", card,
                                                                                                                                             expmon.ToString(), monitor.ToString()));
                                                    });
                                                }

                                                foreach (ExpanderModificationProperties expmodprop in temp)
                                                {
                                                    expmodprop.AssociatedCar = associated_car;
                                                    expmodprops.Add(expmodprop);
                                                }
                                            }
                                            else
                                            {
                                                pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                                            }
                                        }
                                        else
                                        {
                                            pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                                        }
                                    }
                                    else
                                    {
                                        pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                                    }
                                }
                            }
                            else
                            {
                                pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                            }
                        }
                }
            }
            catch (MySqlException mysqlex)
            {
                ErrorLogManager.AppendLog("AltMonitor - MySqlException Occured During Card Lookup", true);
            }
            catch (Exception ex)
            {
                ErrorLogManager.AppendLog("AltMonitor - General Error Occured During Card Lookup", true);
            }
        }
Example #5
0
        private Task Refresh()
        {
            return(Task.Run(delegate()
            {
                UInt64 uid, uptime;
                DateTime uid_read_timestamp;

                PanelCommandHandle pch = connection.EnqueueCommand(new PanelCommand(PanelCommand.POLL_CARD_PRESENCE));
                pch.Handle.WaitOne(); //uid will be waiting
                uid_read_timestamp = DateTime.Now;

                byte[] conversion_buffer = new byte[8];
                Array.Copy(pch.Command.RxPacket, 1, conversion_buffer, 1, 7);
                Array.Reverse(conversion_buffer);

                uid = BitConverter.ToUInt64(conversion_buffer, 0);

                if (uid != 0)
                {
                    connection.EnqueueCommand(new PanelCommand(PanelCommand.CLEAR_CARD)).Handle.WaitOne();
                }

                pch = connection.EnqueueCommand(new PanelCommand(PanelCommand.GET_UPTIME));
                pch.Handle.WaitOne(); //uid will be waiting
                uptime = BitConverter.ToUInt64(pch.Command.RxPacket, 1);

                PanelState stcpy = null;
                lock (state_lock)
                    if (state != null)
                    {
                        stcpy = new PanelState(state);
                    }
                    else
                    {
                        state = new PanelState(new AccessControlCard(uid, AccessControlCard.MIFARE_CLASSIC, uid_read_timestamp), uptime, uid_read_timestamp);
                    }

                if (stcpy != null)
                {
                    AccessControlCard accessctlcd = stcpy.Card;

                    //if this is a different card then continue
                    if (accessctlcd.UID != uid)
                    {
                        accessctlcd = new AccessControlCard(uid, AccessControlCard.MIFARE_CLASSIC, uid_read_timestamp);

                        if (uid != 0)
                        {
                            if (presented != null)
                            {
                                presented(this, new PanelEventArgs(new PanelState(accessctlcd, uptime, uid_read_timestamp)));
                            }
                        }
                    }

                    lock (state_lock)
                        state = new PanelState(accessctlcd, uptime, uid_read_timestamp);

                    if (newstate != null)
                    {
                        newstate(this, new PanelEventArgs(new PanelState(accessctlcd, uptime, uid_read_timestamp)));
                    }
                }
            }));
        }