コード例 #1
0
ファイル: user.py プロジェクト: aeksei/project
	def setPort(self, port):
		sql = """UPDATE Users
   		SET port='%(port)s'
  		WHERE login = '******'
   		"""%{"l":self.login,"port":port}

   		d = DB('localhost','root','messenger','root')
   		d.execute(sql)
コード例 #2
0
ファイル: kuaidi_task.py プロジェクト: chenyueling/kuaidi
def active_kuaidi_tixing(cid):
    try:
        db = DB()
        sql = "update t_dd_kuaidi set active=1 where cid = '%s'" % cid
        db.update(sql)
        print "Successful to Active cid:%s from t_dd_kuaidi!" % cid
    except Exception,e:
        print "Error:Faild active cid:%s from t_dd_kuaidi!" % cid
        print "Failed info:", e
        print "sql:",sql
コード例 #3
0
ファイル: kuaidi_task.py プロジェクト: chenyueling/kuaidi
def response_ding_action(sid, cid, push_token):
    db = DB()
    sql = "select com,nu from t_dd_kuaidi where cid='%s'" % cid
    data = db.query(sql)

    com = data[0][0]
    nu = data[0][1]

    dtype = "ding"

    q.enqueue(query_kuaidi_info, sid, cid, com, nu, dtype, push_token)
コード例 #4
0
ファイル: user.py プロジェクト: aeksei/project
	def reg(self, p):
		self.password = hex(GOST(256).hash(p.encode('hex') + self.login.encode('hex')))
		self.__pswd   = hex(GOST(256).hash(self.password.encode('hex')))[:32]
		sql = """INSERT INTO Users(login, passwd)
		VALUES ('%(l)s', '%(p)s')
		"""%{"l":self.login, "p": self.password}
		d = DB('localhost','root','messenger','root')		
   		d.execute(sql)

   		self.genRSAKey()
   		self.genDSKey()

   		return self.password
コード例 #5
0
ファイル: Server.py プロジェクト: MattiKemp/Lift-Server
async def echo(websocket, path):
    async for message in websocket:
        global db
        db = DB()
        if (message == "recent"):
            await websocket.send(encodeJSONTotal(db.get_all_weekly()))
        elif ("daily" in message):
            await websocket.send(encodeJSON(daily(message[6:])))
        elif ("weekly" in message):
            await websocket.send(encodeJSON(weekly(message[7:])))
        elif ("monthly" in message):
            await websocket.send(encodeJSON(monthly(message[8:])))
        db.close()
コード例 #6
0
ファイル: user.py プロジェクト: aeksei/project
	def decriptRSAKey(self):
		sql = """SELECT priv, iv from RSA
		WHERE login='******'
		"""%{"l":self.login}

		d       = DB('localhost','root','messenger','root')
		key, iv = d.execute(sql)
		
		key    = key.decode('hex')
		iv     = iv.decode('hex')
		cipher = AES.new(self.__pswd, AES.MODE_CFB, iv)
		key    = cipher.decrypt(key)
		self.__PrivRSAKey = RSA.importKey(key)
コード例 #7
0
ファイル: kuaidi_task.py プロジェクト: chenyueling/kuaidi
def loop_kuaidi_task(sid):
    db = DB()
    sql = """
    select cid, com, nu
    from t_dd_kuaidi
    where active=1
    """

    print "Start loop kaudi task..."
    data = db.query(sql)
    dtype = 'loop'
    for record in data:
        cid, com, nu = record[0], record[1], record[2]
        q.enqueue(query_kuaidi_info, sid, cid, com, nu, dtype)
コード例 #8
0
ファイル: user.py プロジェクト: aeksei/project
	def genRSAKey(self):
		key  = RSA.generate(self.RSALenghtKey)
		pub  = key.publickey().exportKey()
		priv = key.exportKey()
		AES.block_size = 32
		iv   = os.urandom(8).encode('hex')
		# Encryption
		cipher = AES.new(self.__pswd, AES.MODE_CFB, iv)
		priv   = cipher.encrypt(priv)

		sql = """INSERT INTO RSA(login, pub, priv, iv)
  		VALUES ('%(l)s', '%(pub)s', '%(priv)s', '%(iv)s')
   		"""%{"l":self.login,"pub":pub.encode('hex'), "priv":priv.encode('hex'), "iv":iv.encode('hex')}

   		d = DB('localhost','root','messenger','root')
   		d.execute(sql)
コード例 #9
0
ファイル: user.py プロジェクト: aeksei/project
   	def checkSign(self, login):


		sql = """SELECT x, y from DS
		WHERE login='******'
		"""%{"l":login}

		d = DB('localhost','root','messenger','root')
   		E = d.execute(sql)

   		E = map(lambda h: int(h[2:-1], 16), E)
   		Q = ECPoint(E[0], E[1], a, b, p)



   		return DS.SingVer(H, sign, Q)
コード例 #10
0
ファイル: kuaidi_task.py プロジェクト: chenyueling/kuaidi
def add_kuaidi_tixing(cid, com, nu):
    db = DB()

    now = int(time.time())
    create_time = datetime.fromtimestamp(now)

    try:
        sql = "insert into t_dd_kuaidi(cid, com, nu, create_time, active)\
                values('{0}', '{1}', '{2}', '{3}', 1)".format(cid, com, nu, create_time)
        db.update(sql)
        print "Successful to add kuaidi tixing: cid=%s, com=%s,\
                nu=%s" % (cid, com, nu)
    except Exception,e:
        print "Error: Failed to add kuaidi tixing: cid=%s, com=%s,\
                nu=%s" % (cid, com, nu)
        print "Failed info:", e
        print "sql:", sql
コード例 #11
0
ファイル: user.py プロジェクト: aeksei/project
	def genDSKey(self):
		priv = self.DS.GenPrivateKey()
		pub  = self.DS.GenPublicKey(priv)
		pub  = pub.getAttr()
		
		AES.block_size = 32
		iv   = os.urandom(8).encode('hex')
		# Encryption
		cipher = AES.new(self.__pswd, AES.MODE_CFB, iv)
		priv   = cipher.encrypt(hex(priv))

		sql = """INSERT INTO DS(login, x, y, a, b, fieldchar, priv, iv)
  		VALUES ('%(l)s', '%(x)s', '%(y)s', '%(a)s', '%(b)s', '%(f)s', '%(priv)s', '%(iv)s')
   		"""%{"l":self.login,"x":hex(pub[0]), "y":hex(pub[1]), "a":hex(pub[2]), "b":hex(pub[3]), "f":hex(pub[4]), "priv":priv.encode('hex'), "iv":iv.encode('hex')}
		
		d = DB('localhost','root','messenger','root')
   		d.execute(sql)
コード例 #12
0
ファイル: user.py プロジェクト: aeksei/project
	def updateRSAKey(self):
		key  = RSA.generate(self.RSALenghtKey)
		pub  = key.publickey().exportKey()
		priv = key.exportKey()
		AES.block_size = 32
		iv   = os.urandom(8).encode('hex')
		# Encryption
		cipher = AES.new(self.__pswd, AES.MODE_CFB, iv)
		priv   = cipher.encrypt(priv)

		sql = """UPDATE RSA
   		SET pub='%(pub)s', priv='%(priv)s', iv='%(iv)s'
  		WHERE login = '******'
   		"""%{"l":self.login,"pub":pub.encode('hex'), "priv":priv.encode('hex'), "iv":iv.encode('hex')}

   		d = DB('localhost','root','messenger','root')
   		d.execute(sql)
コード例 #13
0
ファイル: user.py プロジェクト: aeksei/project
   	def updateDSKey(self):
		priv = self.DS.GenPrivateKey()
		pub  = self.DS.GenPublicKey(priv)
		pub  = pub.getAttr()
		
		AES.block_size = 32
		iv   = os.urandom(8).encode('hex')
		# Encryption
		cipher = AES.new(self.__pswd, AES.MODE_CFB, iv)
		priv   = cipher.encrypt(hex(priv))

   		sql = """UPDATE DS
   		SET x='%(x)s', y ='%(y)s', priv='%(priv)s', iv='%(iv)s'
  		WHERE login = '******'
   		"""%{"x":hex(pub[0]), "y":hex(pub[1]), "priv":priv.encode('hex'), "iv":iv.encode('hex')}

   		d = DB('localhost','root','messenger','root')
   		d.execute(sql)
コード例 #14
0
ファイル: user.py プロジェクト: aeksei/project
	def __init__(self, login, port):
		self.login    = login
		self.port     = port
		sql = """SELECT passwd from Users
		WHERE login='******'
		"""%{"l":self.login}

		d = DB('localhost','root','messenger','root')
		q = d.execute(sql)
		print q

   		if q is None:
   			self.password = q
   		else:
   			self.password = q[0]
   			self.__pswd   = hex(GOST(256).hash(self.password.encode('hex')))[:32]

   		self.signature()
コード例 #15
0
ファイル: user.py プロジェクト: aeksei/project
	def encryptMsg(self, login, msg):
		sql = """SELECT pub from RSA
		WHERE login='******'
		"""%{"l":login}

		d   = DB('localhost','root','messenger','root')
		key = d.execute(sql)[0]
		key = key.decode('hex')
		PubKey = RSA.importKey(key)		
		iv  = os.urandom(4).encode('hex')
		H  = GOST(256).hash(msg.encode('hex'))
		print self.__PrivDSKey
		self.DS.GenPublicKey(self.__PrivDSKey,self.b)
		sign = self.DS.SingGen(32, self.__PrivDSKey)

		pack = "#---#".join(msg, sign)
		print pack

		cipher_text = ''.join(PubKey.encrypt(pack, iv)).encode('hex')

		print 'messenge encrypt'

		return 
コード例 #16
0
ファイル: kuaidi_task.py プロジェクト: chenyueling/kuaidi
def push_handler(sid, cid, ck_time, last_time, context, dtype, push_token):
    db = DB()
    sql = "select state_time, check_time from t_dd_kuaidi where cid='%s'" % cid
    data = db.query(sql)

    state_time = data[0][0]
    check_time = data[0][1]

    # update check_time
    udb = DB()
    sql = "update t_dd_kuaidi set check_time='%s' where cid='%s'" % (ck_time, cid)
    print "Update check_time,sql:", sql
    udb.update(sql)

    #print "state_time:%s, last_time:%s" % (state_time, last_time)

    if state_time != last_time or dtype=='ding':
        # push new state and update push_time, state_time
        print "Start push message..."
        Push = PushService(sid, cid, push_token)
        status_code = Push.push_text('快递提醒', context)

        now = int(time.time())
        push_time = datetime.fromtimestamp(now)

        if status_code == 200:
            print "Push message Successful!"
            sdb = DB()
            sql = "update t_dd_kuaidi set state_time='%s',\
                    push_time='%s' where cid='%s'" % (last_time, push_time, cid)
            sdb.update(sql)
            print "Update state_time, push_time:%s" % sql
        else:
            print "Push message Error!"
            print "Status code: %s, Error accurs when push new state: cid=%s, ck_time=%s,\
                    last_time=%s, context=%s, push_token=%s, push_time=%s\
                    " % (status_code, cid, ck_time, last_time, context, push_token, push_time)
コード例 #17
0
from MySQL import DB
from Artista import Artista

c = DB.run("select * from Artista")

for b in c:
    unArtista = Artista
    unArtista.idArtist = b['idArtista']
    unArtista.Nombre = b['Nombre']
    unArtista.Apellido = b['Apellido']
    unArtista.Conciertos = b['Conciertos']
コード例 #18
0
ファイル: Server.py プロジェクト: MattiKemp/Lift-Server
import asyncio
import websockets
from MySQL import DB
import json
import datetime

db = DB()
#this is all terrible old code and needs to be severly rewritten for a larger scale project :/


def encodeJSONTotal(data):
    JSONData = {}
    for i in range(len(data)):
        if JSONData.get(data[i][0]) != None:
            JSONData[data[i][0]]['minutes'] += 1
        else:
            JSONData[data[i][0]] = {'minutes': 1}
    return json.dumps(JSONData)


def encodeJSON(data):
    return json.dumps(data)


def daily(name):
    info = db.get_user_daily(name)
    day = {}
    for k in info:
        if day.get(k[1].hour):
            day[k[1].hour] += 1
        else:
コード例 #19
0
def main():
    database = DB()
    repository = Repository(database)
    controller = Controller(repository)
    view = View(controller)
    view.mainMenu()
コード例 #20
0
ファイル: user.py プロジェクト: aeksei/project
		return msg

	def setPort(self, port):
		sql = """UPDATE Users
   		SET port='%(port)s'
  		WHERE login = '******'
   		"""%{"l":self.login,"port":port}

   		d = DB('localhost','root','messenger','root')
   		d.execute(sql)



if __name__ == '__main__':
	login = '******'
	password = '******'
	password = hex(GOST(256).hash(password.encode('hex') + login.encode('hex')))
	sql = """INSERT INTO Users(login, passwd)
	VALUES ('%(l)s', '%(p)s')
	"""%{"l":login, "p": password}

	d = DB('localhost','root','messenger','root')
   	d.execute(sql)
	#Q = newUser.genRSAKey()
	#newUser.genRSAKey()
	#newUser.decriptDSKey()
	#print Q
	#print Q.decode('hex')
		

コード例 #21
0
    def SetInsert(self, idArtista, Nombre, Apellido, Conciertos):

        DB.run("insert into Artista values (null,'" + self.Nombre + "','" +
               self.Apellido + "')")