-
Notifications
You must be signed in to change notification settings - Fork 0
/
apientry.py
89 lines (66 loc) · 2.31 KB
/
apientry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
# coding: utf-8
#
# Authorization module software developed for the staircase door access control at Hackerspace Kraków.
# Copyright (C) 2016 Tadeusz Magura-Witkowski
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from auth_plugin import EnterpriseAuthPlugin, main
import sys
import syslog
sys.path.append("/opt/skladki")
import skladki_lib
syslog.openlog("zamek_auth_plugin", 0, 128)
def log(txt):
syslog.syslog(txt.encode("utf-8"))
print(txt.encode("utf-8"))
def check_card_api(card_number):
api = skladki_lib.SkladkiAPI()
api.connect()
user = api.getUserByCard(card_number)
if user is None:
log('No card in database')
return False
if user.active:
log(u"User {0} auth succeed".format(user.getLongName()))
return True
else:
log(u"User {0} card is not active".format(user.getLongName()))
return False
def check_card(card_number):
if check_card_api(card_number):
return True
with file('karty.txt', 'r') as f:
for line in f:
number = line.strip()
if len(number) == 0:
continue
if number[0] == ';':
continue
number, comment = map(lambda x: x.strip(), number.split(':'))
if card_number == number:
return True
return False
class SkladkiAPIAuthPlugin(EnterpriseAuthPlugin):
def __init__(self):
super(SkladkiAPIAuthPlugin, self).__init__()
self.name = 'Connector for old system'
def on_cardread(self, zoneid, cardcode):
retval = check_card(cardcode)
if retval:
self.accept(zoneid)
else:
self.reject(zoneid)
if __name__ == '__main__':
main(SkladkiAPIAuthPlugin)