def advanceApply(self,clientId,msgDict,sessionkey): masterDb = DatabaseAgent(conf.mdbName,conf.muserName,conf.host,conf.mdbPassword,conf.port) masterDb.initConnection() cond = {"clientid":clientId} dbData = masterDb.fetchData("regusers",["password"],cond) password = dbData[0][0] adminDb = DatabaseAgent(clientId, clientId, conf.host,password, 5432) adminDb.initConnection() # try: if adminDb.fetchData("labourer",["labourerid"],{"siteid":msgDict["siteId"],"labourerid":msgDict["labourerId"]}): timestamp = datetime.datetime.now() if adminDb.pushData("accountinfo",["labourerid","timestamp","phonenumber","siteid","recoveryperiod","reson"],[msgDict["labourerId"],timestamp,msgDict["phoneNumber"],msgDict["siteId"],msgDict["recoveryPeriod"],msgDict["reasonForRequest"]]): sitedbData = adminDb.fetchData("sites",[ "projectid","siteid ","creditaccountid","debitaccountid"],{"siteid":msgDict["siteId"]}) print("............ls",sitedbData) adminDb.pushData("account",["timestamp","projectid","siteid ","creditaccountid","debitaccountid"],[timestamp,sitedbData[0][0],sitedbData[0][1],sitedbData[0][2],sitedbData[0][3]]) adminDb.pushData("payment",["timestamp","projectid","siteid ","creditaccountid","debitaccountid","amount","resontype"],[timestamp,sitedbData[0][0],sitedbData[0][1],sitedbData[0][2],sitedbData[0][3],msgDict["fundAuthorized"],msgDict["reasonType"]]) response = {"Header":{"status":"success","module":"labourerManage"},"Body":{"message":"labbouerAdavnce request placed sucessfully","data":""},"Signature":{"signature":"","Key":""}} return response else: self.log.logEvent("laboureradvance",2,"advanceapply canot apply",clientId,sessionMange.session[sessionkey]["userid"]) response = {"Header":{"status":"fail","module":"labourerManage"},"Body":{"message":"labbouerAdavnce request can't be placed","data":""},"Signature":{"signature":"","Key":""}} return response else: response = {"Header":{"status":"fail","module":"labourerManage"},"Body":{"message":"labbouer can't exist this site","data":""},"Signature":{"signature":"","Key":""}} return response
def shiftCreation(self,clientId,msgDict,sessionkey): masterDb = DatabaseAgent(conf.mdbName,conf.muserName,conf.host,conf.mdbPassword,conf.port) masterDb.initConnection() cond = {"clientid":clientId} dbData = masterDb.fetchData("regusers",["password"],cond) password = dbData[0][0] adminDb = DatabaseAgent(clientId, clientId, conf.host,password, 5432) adminDb.initConnection() nameLs = [] valueLs = [] for key in msgDict: nameLs.append(key) valueLs.append(msgDict[key]) curTime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") nameLs.append("shiftcreatedon") valueLs.append(curTime) reval = False try: reval = adminDb.pushData("shift",nameLs,valueLs) if reval: self.log.logEvent("shiftManage",2,"labourer shift created successfully",clientId,sessionMange.session[sessionkey]["userid"]) response = {"Header":{"status":"success","module":"ShiftManage"},"Body":{"message":"shift Added successfully","data":""},"Signature":{"signature":"","Key":""}} return response else: self.log.logEvent("shiftManage",2,"labourer shift creation error",clientId,sessionMange.session[sessionkey]["userid"]) response = {"Header":{"status":"fail","module":"ShiftManage"},"Body":{"message":"shift can't created","data":""},"Signature":{"signature":"","Key":""}} return response except Exception as expc: print("oocured exception is",expc) self.log.logEvent("shiftmanage",2,str(expc),clientId,sessionMange.session[sessionkey]["userid"])
def labourerReg(self,clientId,msgDict,sessionkey): masterDb = DatabaseAgent(conf.mdbName,conf.muserName,conf.host,conf.mdbPassword,conf.port) masterDb.initConnection() cond = {"clientid":clientId} dbData = masterDb.fetchData("regusers",["password"],cond) password = dbData[0][0] adminDb = DatabaseAgent(clientId, clientId, conf.host,password, 5432) adminDb.initConnection() nameLs = [] valueLs = [] for key,val in msgDict.items(): nameLs.append(key.lower()) valueLs.append(val) try: siteid = adminDb.fetchData("sites",["siteid"],{"sitenames":msgDict["siteOfJoining"]}) nameLs.append("siteid") valueLs.append(siteid[0]) if adminDb.pushData("labourer",nameLs,valueLs): self.log.logEvent("labourerManage",2,"labourer added successfully",clientId,sessionMange.session[sessionkey]["userid"]) response = {"Header":{"status":"success","module":"labourerManage"},"Body":{"message":"labourer added successfully","data":""},"Signature":{"signature":"","Key":""}} return response else: self.log.logEvent("labourerManage",2,"labourer can't added",clientId,sessionMange.session[sessionkey]["userid"]) response = {"Header":{"status":"fail","module":"labourerManage"},"Body":{"message":"labourer can't added","data":""},"Signature":{"signature":"","Key":""}} return response except Exception as expc: # self.syslog.eventHandle("labourerManage","exception","exception on labourerManage module",str(expc)) self.log.logEvent("labourerManage",2,"occured expection is"+str(expc),clientId,sessionMange.session[sessionkey]["userid"])
def addSites(self, clientId, msgDict, sessionkey): masterDb = DatabaseAgent(conf.mdbName, conf.muserName, conf.host, conf.mdbPassword, conf.port) masterDb.initConnection() cond = {"clientid": clientId} dbData = masterDb.fetchData("regusers", ["password"], cond) password = dbData[0][0] adminDb = DatabaseAgent(clientId, clientId, conf.host, password, 5432) adminDb.initConnection() nameLs = [] valuels = [] try: for key in msgDict: nameLs.append(key.lower()) valuels.append(msgDict[key]) if adminDb.pushData("sites", nameLs, valuels): self.log.logEvent("projectManage", 2, "project added successfully", clientId, sessionMange.session[sessionkey]["userid"]) response = { "Header": { "status": "success", "module": "projectManage" }, "Body": { "message": "site added sucessfully", "data": "" }, "Signature": { "signature": "", "Key": "" } } return response else: self.log.logEvent("projectManage", 2, "project can't added", clientId, sessionMange.session[sessionkey]["userid"]) response = { "Header": { "status": "success", "module": "projectManage" }, "Body": { "message": "site can't added", "data": "" }, "Signature": { "signature": "", "Key": "" } } return response except Exception as expc: # self.syslog.eventHandle("projectmanagement","exception","exception on projectManage module",str(expc)) self.log.logEvent( "projectManage", 3, " all role permission listed occured " + str(expc), clientId, sessionMange.session[sessionkey]["userid"])
class Logger: def __init__(self): self.curTime = datetime.datetime.now() self.db = DatabaseAgent(conf.mdbName, conf.muserName, conf.host, conf.mdbPassword, conf.port) self.db.initConnection() def finalizeLogger(self): self.db.dbFinalize() def logEvent(self, moduleName, severityLevel, message, clientId="", userId=""): if severityLevel not in range(Constants.LOG_SEVERITY_LOW, Constants.LOG_SEVERITY_CRITICAL): return False logSeverity = [ "LOG_SEVERITY_LOW", "LOG_SEVERITY_MEDIUM", "LOG_SEVERITY_HIGH", "LOG_SEVERITY_CRITICAL" ] logData = "<" + moduleName + " : " + str( self.curTime) + "> " + message logYear = self.curTime.year logDay = self.curTime.day logMonth = self.curTime.month print("data::::", logData) fields = [ "module_name", "day", "month", "year", "log_severity", "message", "clientid", "userid" ] values = [ moduleName, logDay, logMonth, logYear, logSeverity[severityLevel], logData, clientId, userId ] self.db.pushData("applogs", fields, values) # log = Logger() # log.logEvent("admin",1,"master login")
def generateKeys(self): Priva_key = PrivateKey.generate() authDictkey = ["UserId", "privateKey", "publicKey"] authDictvalue = [] tablename = "userkeys" userid = 1557 print("actual key=", Priva_key) encoPrivateKey = Priva_key.encode(Base64Encoder).decode('utf8') print("publickey", Priva_key.public_key) encopubk_key = Priva_key.public_key.encode(Base64Encoder).decode( 'utf8') authDictvalue.append(userid) authDictvalue.append(encoPrivateKey) authDictvalue.append(encopubk_key) dbagent = DatabaseAgent(conf.mdbName, conf.muserName, conf.host, conf.mdbPassword, conf.port) dbagent.pushData(tablename, authDictkey, authDictvalue)
def signUp(self, password): salt = base64.urlsafe_b64encode(uuid.uuid4().bytes) hashPassword = hashlib.sha512(password.encode() + salt).hexdigest() signobj = {} signobj["hashPassword"] = hashPassword print("salt type...................", type(salt)) signobj["salt"] = salt print("hashedpassword", hashPassword) print("salt---", salt) dbagent = DatabaseAgent("kunnel", "kunnel", "127.0.0.1", "kunnel123", "5432") dbagent.initConnection() fileds = ["username", "password", "salt"] datas = ["karthiban", hashPassword, salt] dbagent.pushData("users", fileds, datas) return signobj
def fincheck(self): recdict = bytes(self.storage[0]).decode("utf-8") print("nomore clients here/////////", recdict) dataDict = json.loads(recdict) bigstr = "" nameLs = [] valueLs = [] for key in dataDict: if key == "FinSig": nameLs.append(key) valueLs.append(dataDict[key]) continue else: bigstr += dataDict[key] nameLs.append(key) valueLs.append(dataDict[key]) print("nomore clients here/////////", bigstr) sign = hashlib.md5(bigstr.encode("utf-8")).hexdigest() print("sign value is", sign) if dataDict["FinSig"] == sign: masterDb = DatabaseAgent(conf.mdbName, conf.muserName, conf.host, conf.mdbPassword, conf.port) masterDb.initConnection() if not masterDb.fetchSyslogg(): entry = sign + "GEN000000X" else: dbEntryId = masterDb.fetchSyslogg() # decoEntryId = bytes(dbEntryId[0][0]).decode("utf-8") # print("entryid",str(decoEntryId)) entry = sign + dbEntryId[0][0] hash = hashlib.md5(entry.encode()).hexdigest() firstChar = hash[0] while firstChar != "0": hash = hashlib.md5(hash.encode()).hexdigest() print("Entry ID hash: Current hash = ", hash) firstChar = hash[0] print("true") nameLs.append("entryid") valueLs.append(hash[:10]) masterDb.pushData("syslogg", nameLs, valueLs) else: print("fing signature is wrong")
def classAdding(self,clientId,msgDict,sessionkey): masterDb = DatabaseAgent(conf.mdbName,conf.muserName,conf.host,conf.mdbPassword,conf.port) masterDb.initConnection() cond = {"clientid":clientId} dbData = masterDb.fetchData("regusers",["password"],cond) password = dbData[0][0] adminDb = DatabaseAgent(clientId, clientId, conf.host,password, 5432) adminDb.initConnection() keyList =[] valList = [] for key in msgDict: keyList.append(key.lower()) valList.append(msgDict[key]) try: if adminDb.pushData("labourerclass",keyList,valList): self.log.logEvent("Admin",2,msgDict["labourerClass"]+" class added successfully",clientId,sessionMange.session[sessionkey]["userid"]) response = {"Header":{"status":"success","module":"labourerClass"},"Body":{"message":"class added successfully","data":""},"Signature":{"signature":"","Key":""}} return response else: response = {"Header":{"status":"fail","module":"labourerClass"},"Body":{"message":"class can't added","data":""},"Signature":{"signature":"","Key":""}} return response except Exception as expc: # self.syslog.eventHandle("labourerclassManage","exception","exception on labourerclassManage module",str(expc)) self.log.logEvent("labourerclassManage",2,"occured expection is"+str(expc),clientId,sessionMange.session[sessionkey]["userid"])
def projectsAdding(self, clientId, msgDict, sessionkey): masterDb = DatabaseAgent(conf.mdbName, conf.muserName, conf.host, conf.mdbPassword, conf.port) masterDb.initConnection() cond = {"clientid": clientId} dbData = masterDb.fetchData("regusers", ["password"], cond) password = dbData[0][0] adminDb = DatabaseAgent(clientId, clientId, conf.host, password, 5432) adminDb.initConnection() # nameLs = [] # valueLs = [] # sites = "" # labourercnt = "" # for key in msgDict: # if key == "locations": # continue # else: # nameLs.append(key.lower()) # valueLs.append(msgDict[key]) # print("namels............",nameLs) # print("valuels...............",valueLs) try: if adminDb.pushData("projects", ["projectname"], [msgDict["projectName"]]): projectid = adminDb.fetchData( "projects", ["projectid"], {"projectname": msgDict["projectName"]}) # for key in msgDict: # if key == "locations": # for cnt in range(len(msgDict["locations"])): adminDb.pushData("sites", [ "sitenames", "numoflabourer", "projectid", "compensationamount", "compensationdays", "concreteamount", "debitaccountid", "creditaccountid" ], [ msgDict["siteNames"], msgDict["numOfLabourer"], projectid[0], msgDict["compensationAmount"], msgDict["compensationDays"], msgDict["concreteAmount"], msgDict["debitAccountId"], msgDict["creditAccountId"] ]) self.log.logEvent( "projectManage", 2, msgDict["projectName"] + " project added successfully", clientId, sessionMange.session[sessionkey]["userid"]) response = { "Header": { "status": "success", "module": "projectManage" }, "Body": { "message": "project added successfully", "data": "" }, "Signature": { "signature": "", "Key": "" } } return response else: self.log.logEvent( "Admin", 2, msgDict["projectName"] + " project canot added", clientId, sessionMange.session[sessionkey]["userid"]) response = { "Header": { "status": "fail", "module": "projectManage" }, "Body": { "message": "project can't added", "data": "" }, "Signature": { "signature": "", "Key": "" } } return response except Exception as expc: # self.syslog.eventHandle("projectmanagement","exception","exception on projectManage module",str(expc)) self.log.logEvent( "projectManage", 3, " all role permission listed occured " + str(expc), clientId, sessionMange.session[sessionkey]["userid"])
def createRoles(self, clientId, msgDict, sessionkey): masterDb = DatabaseAgent(conf.mdbName, conf.muserName, conf.host, conf.mdbPassword, conf.port) masterDb.initConnection() cond = {"clientid": clientId} dbData = masterDb.fetchData("regusers", ["password"], cond) password = dbData[0][0] adminDb = DatabaseAgent(clientId, clientId, conf.host, password, 5432) adminDb.initConnection() valuelist = [] templist = [] valuelist.append(msgDict["roleName"]) for key in msgDict: if key == "roleName": continue else: templist.append(msgDict[key]) bigstr = "" for val in templist: bigstr += val + "&&" valuelist.append(bigstr) try: if adminDb.pushData("permission", ["rolename", "permissions"], valuelist): self.log.logEvent("roleManage", 2, "Client role created successfully", clientId, sessionMange.session[sessionkey]["userid"]) response = { "Header": { "status": "success", "module": "roleMange" }, "Body": { "message": "role created successfully", "data": "" }, "Signature": { "signature": "", "Key": "" } } return response else: self.log.logEvent("roleManage", 2, "Client role creation db error occured", clientId, sessionMange.session[sessionkey]["userid"]) response = { "Header": { "status": "success", "module": "roleManage" }, "Body": { "message": "role can't created", "data": "" }, "Signature": { "signature": "", "Key": "" } } return response except Exception as expc: # self.syslog.eventHandle("rolemanagement","exception","exception on rolemanage module",str(expc)) self.log.logEvent("labourerManage", 2, "occured expection is" + str(expc), clientId, sessionMange.session[sessionkey]["userid"])
def labourRegistration(self,msgobj): dbobj = DatabaseAgent("kunnel", "kunnel", "127.0.0.1", "kunnel123", "5432") keys = [] labregkey = True labregval = True values = [] keylist = ["labourName","callByName","gender","dateOfBirth","fatherName","bloodGroup","nextOfKin", "contactNumberOFNextOfKin","motherTounge","addressLine1","addressLine2","addressLine3","village", "state","country","pincode","mobileNumber","residancePhoneNumber","emergencyPhoneNumber","dateOfJoining", "migrantWorker","siteId","siteOfJoining","designation","labourerClass","wageClass","documentType", "documentNumber","nameAsPerDoc","bankName","IFSCcode","backAccountNumber","brancName","nameInBank"] for key,value in msgobj.items(): keys.append(key) values.append(value) for check in keylist: if check in keys: print("success",check) else: print("error") break labregkey = False if "" in values: print("error througing") labregval = False else: print("sucess througing") #print("values",values) personalDataKey = [] personalDataVal = [] for num in range(0,19): personalDataKey.append(keys[num]) personalDataVal.append(values[num]) #print("personkey",personalDataKey) # print("persondata",personalDataVal) dbobj.pushData("labourerdata",personalDataKey,personalDataVal) empDatakey = [] empDataVal = [] for num in range(19,26): empDatakey.append(keys[num]) empDataVal.append(values[num]) # print("empkey",empDatakey) # print("empvalue",empDataVal) dbobj.pushData("empdata",empDatakey,empDataVal) identyKey = [] identyVal = [] for num in range(26,29): identyKey.append(keys[num]) identyVal.append(values[num]) # print("identykey",identyKey) # print("identydetails",identyVal) dbobj.pushData("laboureridenty",identyKey,identyVal) bankDetailsKey = [] bankDetailsVal = [] for num in range(29,34): bankDetailsKey.append(keys[num]) bankDetailsVal.append(values[num]) # print("bankkey",bankDetailsKey) # print("bankdetails=",bankDetailsVal) dbobj.pushData("labourerbank",bankDetailsKey,bankDetailsVal) return labregkey and labregval
def addUser(self, clientId, msgDict, sessionkey): masterDb = DatabaseAgent(conf.mdbName, conf.muserName, conf.host, conf.mdbPassword, conf.port) masterDb.initConnection() cond = {"clientid": clientId} dbData = masterDb.fetchData("regusers", ["password"], cond) password = dbData[0][0] adminDb = DatabaseAgent(clientId, clientId, conf.host, password, 5432) adminDb.initConnection() digest = self.authen.signUp(msgDict["password"]) msgDict["password"] = digest["hashPassword"] msgDict["salt"] = digest["salt"] print("message", msgDict) # admin = Admin() nameLs = [] valueLs = [] for key, val in msgDict.items(): nameLs.append(key.lower()) valueLs.append(val) print(nameLs) print(valueLs) reval = False try: if not adminDb.fetchData("clientusers", ["username"], {"username": msgDict["userName"]}): if adminDb.pushData("clientusers", nameLs, valueLs): self.log.logEvent( "Admin", 1, msgDict["userName"] + " Client user registerd successfully", clientId, msgDict["userName"]) response = { "Header": { "status": "success", "module": "admin" }, "Body": { "message": "user added successfully", "data": "" }, "Signature": { "signature": "", "Key": "" } } return response else: self.log.logEvent( "Admin", 1, msgDict["userName"] + "Client user registerd failed and eception is occured") response = { "Header": { "status": "success", "module": "admin" }, "Body": { "message": "user can't added ", "data": "" }, "Signature": { "signature": "", "Key": "" } } return response else: self.log.logEvent( "Admin", 1, msgDict["userName"] + "Client user name alraedy exist", clientId, msgDict["userName"]) response = { "Header": { "status": "success", "module": "admin" }, "Body": { "message": "user name already exixt ", "data": "" }, "Signature": { "signature": "", "Key": "" } } return response except Exception as expc: self.log.logEvent("Admin", 0, "occured exception is " + str(expc))