forked from xchem/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rowbasedauth.py
executable file
·87 lines (64 loc) · 2.06 KB
/
rowbasedauth.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
"""
rowbasedauth.py
"""
# lives at: /var/www/cgi-bin/proasisapi/v1.4
import csv
import os
import re
import sys
# from p3SConstants import dssPyPath
# if dssPyPath not in sys.path:
# sys.path.insert(1, dssPyPath)
BLACKLISTDIR = "/usr/local/Proasis2/Data/BLACKLIST"
def readblcsv(curf):
retdict = {}
try:
with open(curf, 'rb') as csvfile:
blreader = csv.reader(csvfile, delimiter=',')
for row in blreader:
for entry in row:
if len(entry) > 2:
retdict.update({str(entry): 1})
except:
# with open('/dls/science/groups/proasis/test.txt','w') as f:
# f.write(str(sys.exc_info()))
print sys.exc_info()
return retdict
def GetUsername(inpStr):
"""
Get username from cookie Proasis3User (or Proasis2User)
"""
# with open('/dls/science/groups/proasis/test.txt', 'w') as f:
# f.write(str(inpStr))
inpStr = str(inpStr)
c = dict(re.findall(r'\[(.+?)]=\[(.+?)]', inpStr))
# with open('/dls/science/groups/proasis/test.txt', 'a') as f:
# f.write(str(c))
if "Proasis3User" in c.keys():
return c["Proasis3User"]
elif "Proasis2User" in c.keys():
return c["Proasis2User"]
else:
return ""
def GetBlacklist(inpStr):
"""
for row based authentication
"""
retDict = {}
# with open('/dls/science/groups/proasis/test.txt','w') as f:
# f.write(inpStr)
# get curUser u from inpStr
u = GetUsername(inpStr)
u = str(inpStr)
username = u.replace('username=', '')
# blacklist file has filename BLACKLISTDIR/curUser.dat
# - it is a python dictionary of type {regnoA:1, regnoB:1, ...}
# - where hits with regnoA,regnoB cannot be viewed by curUser
# these files created by separate cron job
curf = "%s/%s%s" % (BLACKLISTDIR, u, ".dat")
curf = curf.replace('username=', '')
if not os.path.isfile(curf):
curf = "%s/%s%s" % (BLACKLISTDIR, 'other_user', '.dat')
# get blacklist as python dictionary
retDict = readblcsv(curf)
return retDict