def mac_search(*args):
db = MySQLdb.connect(host="localhost",user="test",passwd="test",db="test")
cursor = db.cursor()
cursor.execute('SELECT * FROM ip_groups WHERE mac="%s" AND is_deleted=0;' %args[0].split()[0])
for j in cursor.fetchall():
cursor.execute("SELECT * FROM iptraffic_service_links WHERE ip_group_id=%s and is_deleted=0;" %j[1])
for j1 in cursor.fetchall():
cursor.execute("SELECT * FROM service_links WHERE id=%s AND is_deleted=0;" %j1[0])
for j2 in cursor.fetchall():
cursor.execute("SELECT * FROM accounts WHERE is_deleted=0 AND id=%s AND is_blocked=0;" %j2[2])
for j3 in cursor.fetchall():
cursor.execute("SELECT * FROM service_links WHERE account_id=%s AND is_deleted=0;" %j2[2])
for j4 in cursor.fetchall():
if j4[3]==465 or j4[3]==641:
cursor.execute("SELECT * FROM s_multicast WHERE service_id=%s AND %s>=ip_start AND %s<=ip_end;" %(j4[3],args[0].split()[1],args[0].split()[1]))
for j5 in cursor.fetchall():
return j5
db.close()
def authorize(p):
print "*** authorize ***"
radiusd.radlog(radiusd.L_INFO, '*** radlog call in authorize ***')
mac = "{0}:{1}:{2}:{3}:{4}:{5}".format(p[0][1][1:-1][:2],p[0][1][1:-1][2:4],p[0][1][1:-1][4:6],p[0][1][1:-1][6:8],p[0][1][1:-1][8:10],p[0][1][1:-1][10:12]).lower()
ipm = "{0}".format(struct.unpack("!I", socket.inet_aton(p[8][1]))[0])
data = "{0} {1}".format(mac,ipm)
g = mac_search(data)
if g:
print g
return radiusd.RLM_MODULE_OK
else:
return radiusd.RLM_MODULE_REJECT
real 0m0.096s
user 0m0.064s
sys 0m0.032s