Пример #1
0
def authenticate(c, data):
    share.log("[AUTH] " + data)
    try:
        username, password = data.split("::")
    except:
        return ""
    username = username.upper()
    if ("-" in username):
        t = username.split("-")
        ty = t[1]
        username = t[0]
    else:
        ty = ""
    password = password.rstrip()
    print "using ", username
    con = lite.connect('system.db')
    with con:

        cur = con.cursor()
        cur.execute("SELECT * FROM accounts WHERE master=? AND password=?",
                    (username, password))

        rows = cur.fetchall()

        for row in rows:
            share.log("[AUTH] Found user!(" + username + ") ")
            if (ty != ""):
                return username + "-" + ty
            else:
                return username

    return ""
Пример #2
0
def sender(data, master, name):
    master = master + "-" + name + "-lis"
    share.log("[sender] master: " + master + " from: " + name + " with: " +
              data)
    msg = "SELF " + name + " " + data
    ##now we need to get the connection data of the main user
    con = None
    try:
        con = share.userlist[master]
        share.send(con, msg)
    except:
        share.log(
            "[ERROR] at sender, unable to find master in connected list - " +
            str(sys.exc_info()))
Пример #3
0
def getContacts(username, c):

    share.log("[CONTACTS] Finding for " + username + "...")

    con = lite.connect('messenger.db')
    with con:

        cur = con.cursor()
        cur.execute("SELECT * FROM contacts WHERE account=? ", (username, ))

        rows = cur.fetchall()

        for row in rows:
            share.log("[CONTACTS] Found:" + row[1])
            share.send(c, "CONT " + row[1])  #online/offline. check userlist
Пример #4
0
def sendlocal(c, username, line):
    username = username.split("-")[0]
    addressTo = line[:4]
    addressTo = addressTo.upper()
    msg = line[5:len(line)]
    addressTo = username + "-" + addressTo
    share.log("[local send] from: " + username + " to: " + addressTo +
              " Sending: " + msg)
    con = None
    try:
        con = share.userlist[addressTo]
        share.send(con, msg)
    except:
        ##local user isn't connected.
        share.send(c, "ERRO " + addressTo + " OFF")
Пример #5
0
def connection(c, addr, ids):
    try:
        #c.settimeout(600.0)
        try:
            c = ssl.wrap_socket(c,
                                server_side=True,
                                certfile="server.crt",
                                keyfile="server.key")
            share.updateSecure(ids, c, "Yes")
            share.MupdateSecure(ids, c)
        except:
            share.log("[ERROR SSL] " + str(sys.exc_info()))
            share.send(c, ids, "SSL OFF")

        auth = False
        username = None
        goes = 0
        app = "0000"
        share.connections[ids] = c

        for line in readlines(c):
            print "line: ", line
            ##encryption block here

            ##

            try:
                code = line[:4].upper()
                line = line[5:len(line)]
                line = line.rstrip()
            except:
                share.log("[Error] APPID_" + ids +
                          " not enough values (needs two)")

            if (code == "DISP"):
                print share.userlist  #working
                print share.connections  #not working..
                print share.num  # working

            if (code == "APP!"):
                print "App id"
                if (tasks.checkAppId(line, ids, c)):
                    app = line

                else:
                    share.send(c, ids, "APP! fail")
            if (code == "LOGT"):
                share.log("[LOGT] " + ids)
                break

            elif (not auth):
                #they need to login.
                if (len(line) > 5):
                    username = tasks.authenticate(c, line, app, ids)
                    if (username == "OVERMAX"):
                        #too many logins.. What do we want to do about that?
                        print "Undecided what to do, but over max."
                    if (username != ""):
                        #correct
                        share.send(c, ids, "AUTH correct")
                        share.userlist[username + ids] = c
                        share.updateUserName(ids, username)
                        auth = True
                        share.MupdateUser(ids, username)
                        if (username[:4] == "MONI"):
                            share.giveList()

                    else:
                        share.send(c, ids, "AUTH wrong")
                        goes = goes + 1
                        print "Goes: ", goes
                        if (goes > 3):

                            share.block(addr, "Wrong username/password")
                            break

            if (auth):
                #they've logged in

                if (code == "SEND"):
                    #try:
                    tasks.send(c, ids, line, username)
                    #except:
                    #	share.log("[ERROR] "+str(sys.exc_info()))
                    #	share.send(c,ids,"SEND didn't work")
                elif (code == "CODE"):
                    #generate a token code.
                    if (app == "0000"):
                        share.send(c, ids, "CODE app id needed")
                    else:
                        token = ''.join(
                            random.choice(string.ascii_uppercase +
                                          string.digits) for _ in range(300))
                        tasks.updateToken(token, username, app, ids)
                        share.send(c, ids, "CODE " + token)
                elif (code == "PASS"):
                    tasks.changePassword(ids, username, c, line)
                elif (code == "AUTH"):
                    share.send(c, ids, "AUTH DONE")

        #do the disconnect stuff...

        share.clear(username, c, ids)
        share.MdelC(ids)

    except:
        print "Major error has caused the connection is fall.. "
        share.log("[error] " + str(sys.exc_info()))
        share.clear(username, c, ids)
        share.MdelC(ids)
Пример #6
0
import socket,thread,sys,time,ssl

import main,share,random,string,time


host = "192.168.1.19"   #ip of juggernaut
port = 2030	#port to connect to




try:
	s = socket.socket()
	s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
	s.bind((host,port))
	share.log("[info] Ready for connections")
	s.listen(5)
	while(True):
		print "waiting.."
		c,addr = s.accept()
		
		
		address = addr[0]
		
		
		if(share.checkBlock(address)=="Blocked"):
			share.log("[connection] blocked for "+address)
			c.send("Blocked")
			c.shutdown(1)
			c.close()
			continue