def push(options):
    """
    for example:
    python pusher.py --do=remove_all --ip=10.66.10.123 --sn=123159516
    python pusher.py --do=add --rfid_id=444411 --ip=10.66.10.123 --sn=123159516
    etc...
    """
    #to test password change, if password is '0' it's disabled. password can be max 6 digits; must be an 'integer'.
    try:
        do = options.do
        rfid_id = options.rfid_id
        ip = options.ip
        controller_serial = int(options.serial_number)
        do_list = [
            'add', 'remove', 'open', 'get_all_cards', 'remove_all',
            'set_passwords'
        ]
        assert do in do_list, 'Change parameter "do"! It can be "add", "remove", "get_all_cards", "open", "remove_all" or "set_passwords"'
        client = rfid.RFIDClient(ip, controller_serial)

        if do == do_list[3]:
            #total_users, card_numbers = wd.get_all_cards('http://'+ip)
            #return total_users, card_numbers
            pass
        else:
            card = rfid.ten_digit_to_comma_format(
                rfid_id)  # rfid_id needs to be converted to "comma format"
            # print('rfid_id = ', rfid_id)
            # print('card number = ', card)
            if do == do_list[0]:
                client.add_user(card, [1])  # add privileges for door 1
                # print('added')
            elif do == do_list[1]:
                client.remove_user(card)
                # print('deleted')
            elif do == do_list[2]:
                client.open_door(1)  # Open door 1
                # print('the door is opened')
            elif do == do_list[4]:
                client.remove_all()  # remove all entries
                # print('all the entries has been removed')
            elif do == do_list[5]:
                pass_1 = options.pass_1
                pass_2 = options.pass_2
                pass_3 = options.pass_3
                pass_4 = options.pass_4
                client.set_passwords(
                    pass_1, pass_2, pass_3,
                    pass_4)  # set 1 to 4 passwords with max 6 digits
                # print('password(s) has been changed')
        print('true')
    except:
        print('false')
 def index(self, apiKey=None, action=None, badge=None):
     if (apiKey == "secret"):
         if badge:
             badge = ten_digit_to_comma_format(int(badge))
             if (action == "remove"):
                 try:
                     client.remove_user(badge)
                     return "User Removed Successfully"
                 except:
                     return "Failed To Remove User"
             elif (action == "add"):
                 try:
                     client.add_user(badge, [1, 2])
                     return "User Added Successfully"
                 except:
                     return "Failed To Add User"
             else:
                 return "must specify an action"
         else:
             return "no badge number entered"
     else:
         return ""  #return nothing when no API key is entered
	def index(self, apiKey=None, action=None, badge=None):
		if (apiKey == "secret"):
			if badge:
				badge = ten_digit_to_comma_format(int(badge)) 
				if (action == "remove"):
					try:
						client.remove_user(badge)
						return "User Removed Successfully"
					except:
						return "Failed To Remove User"
				elif (action == "add"):
					try:
						client.add_user(badge, [1,2])
						return "User Added Successfully"
					except:
						return "Failed To Add User"
				else:
					return "must specify an action"
			else:
				return "no badge number entered"
		else:
			return "" #return nothing when no API key is entered
Ejemplo n.º 4
0
from rfid import ten_digit_to_comma_format, RFIDClient

ip_address = '192.168.1.20'
controller_serial = 123106461
client = RFIDClient(ip_address, controller_serial)

badge = ten_digit_to_comma_format(
    11111111)  # badge number needs to be in "comma format"

client.add_user(badge, [1])  # add badge to door 1
client.add_user(badge, [1, 2])  # add badge to door 1 and 2
client.add_user(badge, [1, 2, 3])  # add badge to door 1, 2, and 3
client.add_user(badge, [1, 2, 3, 4])  # add badge to door 1, 2, 3, and 4
from rfid import ten_digit_to_comma_format, RFIDClient

ip_address = '192.168.1.20'
controller_serial = 123106461
client = RFIDClient(ip_address, controller_serial)

badge = ten_digit_to_comma_format(11111111) # badge number needs to be in "comma format"

client.add_user(badge, [1]) # add badge to door 1
client.add_user(badge, [1, 2]) # add badge to door 1 and 2
client.add_user(badge, [1, 2, 3]) # add badge to door 1, 2, and 3
client.add_user(badge, [1, 2, 3, 4]) # add badge to door 1, 2, 3, and 4