def User_DeleteDev_Req(username,devname,usql): #delete added dev sqler2=sqlt("user_of_dev",usql) sqler3=sqlt("registed_user",usql) dres=sqler2.Table_Select("devname",condition="devname='%s'"%devname) if len(dres)>0: did=dres[0][0] else: did="none" ures=sqler3.Table_Select("nid",condition="name='%s'"%username) if len(ures)>0: uid=ures[0][0] else: uid="none" sres=sqler2.Table_Select("uid,devname") if (uid,did) in sres: sqler2.Table_Delete(condition="uid=%s and devname='%s'"%(str(uid),did)) return 0 return 1
def User_Added_Dev(cls,username,usql): sqler1=sqlt("iot_dev",usql) sqler2=sqlt("user_of_dev",usql) sqler3=sqlt("registed_user",usql) ures=sqler3.Table_Select("nid",condition="name='%s'"%username) uid=ures[0][0] dres=sqler2.Table_Select("dev_sign",condition="uid=%s"%str(uid)) if len(dres)>0: devinfo=[] for i in range(len(dres)): did=dres[i][0] #dev_sign ires=sqler1.Table_Select("dev_name","dev_owner",condition="dev_sign='%s'"%did) #shared dev if len(ires)>0: devinfo.append(ires[0]) dres=cls.Dev_Info_Pair(devinfo) else: dres="none%none%" return dres
def Granted_Dev_Of_User(devname,devowner,usql): sqler1=sqlt("iot_dev",usql) sqler2=sqlt("user_of_dev",usql) dev_sign=devname+'_'+devowner dres=sqler1.Table_Select("dev_sign",condition="dev_sign='%s'"%dev_sign) if len(dres)>0: if len(dres[0])==1: dres=dres[0][0] ures=sqler2.Table_Select("uid",condition="dev_sign='%s'"%dres) if len(ures)>0: print("%s granted to:"%devname,ures) return ures #((1,),(2,),) else: return 1 # this dev have not shared else: return 0 # not found the dev which called devname else: return 1
def View_User_Of_Dev(username,usql): sqler1=sqlt("user_of_dev",usql) sqler2=sqlt("registed_user",usql) ures=sqler2.Table_Select("nid",condition="name='%s'"%username) uid=ures[0][0] dres=sqler1.Table_Select("dev_sign",condition="uid=%s"%str(uid)) dev_info=[] if len(dres)>0: for i in range(len(dres)): did=dres[i][0] did=did.split('_') print("did",did) dev_info.append(did[0]) dev_info.append(did[1]) else: dev_info.append("none") dev_info.append("none") print("user_dev_name",dev_info) return dev_info
def User_Add_Req(username,devname,ownername,usql): sqler1=sqlt("iot_dev",usql) sqler2=sqlt("user_of_dev",usql) sqler3=sqlt("registed_user",usql) devsign=devname+'_'+ownername dres=sqler1.Table_Select("dev_sign",condition="dev_sign='%s'"%devsign) if len(dres)>0: did=dres[0][0] else: did="none" ures=sqler3.Table_Select("nid",condition="name='%s'"%username) if len(ures)>0: uid=ures[0][0] else: uid="none" sres=sqler2.Table_Select("uid,dev_sign") if (uid,did) in sres: return 1 elif did=="none": return 2 sqler2.Table_Insert("devname","dev_sign","uid",value1="'%s','%s',%s"%(devname,devname+'_'+ownername,str(uid))) return 0
def View_IoT_Dev(username,usql): sqler=sqlt("iot_dev",usql) dres=sqler.Table_Select("dev_name",condition="dev_owner='%s'"%username) dev_info=[] if len(dres)>0: for i in range(len(dres)): dev_info.append(dres[i][0]) dev_info.append(username) else: dev_info.append("none") dev_info.append("none") print("iot_dev_name",dev_info) return dev_info
def Identify_User(cls,username,userpwd,userip,userport,usql): sqler=sqlt("registed_user",usql) userinfo=(username,userpwd) ures=sqler.Table_Select("name","pwd") qres=userinfo in ures if qres==True: lres=cls.Login_Successe(username,userip,userport,usql) if lres==0: return 0 elif lres==1: return 1 else: return 2 else: lres=cls.Login_Failed() return lres
def Current_Logged(usql): sqler=sqlt("logged_user",usql) ures=sqler.Table_Select("uid,ip,port") return ures
def Send_Msg_Board(recver,sender,msg,usql): sqler=sqlt("msg_board",usql) sqler.Table_Insert("sender","recver","msg",values="'%s','%s','%s'"%(sender,recver,msg))
def Delete_Msg_Board(recver,sender,usql): sqler=sqlt("msg_board",usql) sqler.Table_Delete(condition="sender='%s'and recver='%s'"%(sender,recver)) return sqler