Exemplo n.º 1
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()))
Exemplo n.º 2
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
Exemplo n.º 3
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")
Exemplo n.º 4
0
def recall(username, c):
    share.log("[RECALL] Finding messages for " + username + "...")

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

        cur = con.cursor()
        cur.execute("SELECT * FROM messages WHERE account=? AND delivered=? ",
                    (username, "False"))

        rows = cur.fetchall()

        for row in rows:
            share.log("[MESSAGE] Found:" + str(row[5]))
            msg = "RMSG " + row[1] + " " + row[2] + " " + row[3]
            share.send(c, msg)
            cur.execute("UPDATE messages SET delivered=? WHERE id=?",
                        ("True", row[5]))
            con.commit()
        share.send(c, "RMSG over")
Exemplo n.º 5
0
def changePassword(ids, username, c, line):
    share.log("[pass change] trying for: " + ids)
    try:
        pa = line.split("_", 1)
    except:
        #wrong already.
        share.send(c, ids, "PASS fail")
        return

    con = lite.connect('system.db')
    with con:
        print "Passwords: ", pa

        cur = con.cursor()
        cur.execute("SELECT * FROM accounts WHERE username=? AND password=?",
                    (username[:4], pa[0]))

        rows = cur.fetchall()
        if (not rows):
            share.send(c, ids, "PASS fail")
        else:
            cur.execute("UPDATE accounts SET password=? WHERE  username=?",
                        (username[:4], pa[1]))
            share.send(c, ids, "PASS success")
            cur.execute("DELETE FROM token WHERE account=? ", (username, ))
            share.clear(username, c, ids)
            share.MdelC(ids)
Exemplo n.º 6
0
def send(c, ids, msg, username):
    share.log("[send] from:" + ids + " with: " + msg)
    msg = msg.split("_", 2)
    print "msg values: ", msg

    allow = share.checkAllow(msg[0], username)
    #allow = True
    if (allow):
        print "allowed"
        f = False
        for c2 in share.findEach(msg[0]):
            print "find each.."
            f = True
            share.send(c2, ids, "MSGS " + username + "_" + msg[2])
        if (f):
            share.send(c, ids, "SEND success " + msg[1])
        else:
            share.send(c, ids, "SEND fail " + msg[1])

    if (allow == "NO"):
        #share.send(c,ids,"SEND "+msg[0]+" doesn't exist")
        print "{doesn't exist}"
    if (not allow):
        share.send(c, ids, "SEND rejected " + msg[1])
Exemplo n.º 7
0
def sendTo(sender, c, line):
    sendTo = line[:4].upper()
    message = line[5:len(line)]
    share.log("[CHECK] user exist: " + sendTo)
    #check the user exists.
    exist = False
    con = lite.connect('system.db')
    with con:

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

        rows = cur.fetchall()

        for row in rows:
            exist = True

    if (exist):
        share.log("[SENDTO] User did exist, trying to send..")
        try:
            connection = share.userlist[sendTo]
            m = "MSG! " + sender + " " + message
            share.send(connection, m)
        except:
            share.log("[SENDTO] FAILED, user wasn't online - " +
                      str((sys.exc_info())))
            #as the user wasnt there, we'll add it to the database for them to collect later.
            con = lite.connect('messenger.db')

            with con:

                cur = con.cursor()
                t = time.strftime("%d/%m %H:%M:%S")
                cur.execute(
                    "INSERT INTO messages(account,sender,time,message,delivered) VALUES(?,?,?,?,?)",
                    (sendTo, sender, t, message, "False"))
                share.log("[DELAY] Message added to database for " + sendTo +
                          " Sent by " + sender)
                share.send(
                    c,
                    "MSG! JUGGERNAUT user isn't online, message will be held for "
                    + sendTo)
    else:
        share.send(c, "MSG! JUGGERNAUT The user " + sendTo + " doesn't exist")
Exemplo n.º 8
0
def connection(c, addr):
    ##vars
    auth = False
    username = ""
    extra = False
    lis = False

    for line in readlines(c):

        ##DELETE WHEN NOT REQUIRED.
        share.log("[MSG] " + line)

        if (not auth):
            ##required login details otherwise it will ignore what ever it is
            code = line[:4]
            line = line[5:len(line)]
            if (code == "AUTH"):
                username = authenticate(c, line)
                if (username != ""):
                    share.send(c, "AUTH GOOD")
                    if ("-" in username):
                        username = username + "-lis"
                        lis = True

                    if (username in share.userlist):
                        share.userlist[username].shutdown(1)
                        share.userlist[username].close()

                    share.userlist[username] = c
                    auth = True

                    continue

                else:
                    share.send(c, "AUTH wrong")

            elif (code == "LOG1"):
                username = authenticate2(c, line)
                if (username != ""):
                    share.send(c, "AUTH GOOD")
                    if (username in share.userlist):
                        share.userlist[username].shutdown(1)
                        share.userlist[username].close()

                    share.userlist[username] = c
                    auth = True
                    extra = True
                    continue

                else:
                    share.send(c, "AUTH wrong")

            else:
                share.send(c, "AUTH try")

        if (extra and auth and not lis):
            ##the non upper level user access
            code = line[:4]
            line = line[5:len(line)]
            if (code == "SEND"):
                name = username.split("-")
                sender(line, name[0], name[1])

            elif (code == "LOGO"):
                share.clear(c, username)
                c.shutdown(1)
                c.close()

            else:
                share.send(c, "NFND")

        if (auth and not extra and lis):
            ##user has logged in, access has been granted.
            code = line[:4]
            line = line[5:len(line)]

            if (code == "LOGO"):
                share.clear(c, username)
                c.shutdown(1)
                c.close()

            elif (code == "SEND"):
                sendlocal(c, username, line)

            else:
                share.send(c, "NFND")

        if (auth and not extra and not lis):
            ##user has logged in, access has been granted.
            ##this is the messenger access, the others are "extra"
            code = line[:4]
            line = line[5:len(line)]

            if (code == "LOGO"):
                share.clear(c, username)
                c.shutdown(1)
                c.close()

            elif (code == "SEND"):
                sendTo(username, c, line)

            elif (code == "RMSG"):
                recall(username, c)

            else:
                share.send(c, "NFND")

    share.log("[connection] end " + str(c))
    share.clear(c, username)
Exemplo n.º 9
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)