Пример #1
0
    def __send_email(self):
        while True:
            self.mutex.acquire()

            peer_itr = self.mspider.get_mail_peers()
            social_distances = socialdistance.calculate_social_distance(peer_itr, email=True)

            for user in social_distances:

                if social_distances[user] < float(data["social"]["social_distace_allowed"]):
                    fpeer = self.session.query(SocialPeer).filter_by(id_peer=user).all()
                    if len(fpeer) == 0:
                        us = SocialPeer()
                        us.id_peer = user
                        us.social_distance = social_distances[user]
                        us.ip = ""
                        us.source = "email"
                        self.session.merge(us)
                        self.session.flush()
                    else:
                        fpeer[0].us.social_distance = social_distances[user]
                        self.session.merge(fpeer[0])
                        self.session.flush()

                    if social_distances[user] != -1:
                        try:
                            self.mspider.send_email(user, get_message(user))
                        except Exception, e:
                            print e

            self.mutex.release()
            time.sleep(float(data["social"]["time_send_dm"]))
Пример #2
0
    def __share_ip(self):

        while True:
            self.share_public_key()
            self.mutex.acquire()
            self.fbspider.refresh_api()
            self.jsn = json.load(open(data["db"]["filename_facebook"], "r"))
            social_distance = socialdistance.calculate_social_distance(
                self.fbspider.spider_facebook_peers(), facebook=True
            )
            # peers = [{ 'id' : 711736710, 'key' : '-----BEGIN RSA PUBLIC KEY-----\nMEgCQQCGLar9k9EN6W0x86ccXrr491f3v7G2pEzI7AQWg649Cv1SxYuts36Aresf\nBEM+yL75n74Z7dkeqBJwo4IRwoQ7AgMBAAE=\n-----END RSA PUBLIC KEY-----\n'}]
            peers = {}

            if "key_peers" in self.jsn[self.user]:
                peers = self.jsn[self.user]["key_peers"]

            for peer in peers:
                if peer["id"] in social_distance and social_distance[peer["id"]] < float(
                    data["social"]["social_distace_allowed"]
                ):
                    fpeer = self.session.query(SocialPeer).filter_by(id_peer=peer["id"]).all()
                    if len(fpeer) == 0:
                        us = SocialPeer()
                        us.id_peer = peer["id"]
                        us.social_distance = social_distance[peer["id"]]
                        us.ip = ""
                        us.source = "facebook"
                        self.session.merge(us)
                        self.session.flush()
                    else:
                        fpeer[0].us.social_distance = social_distance[peer["id"]]
                        self.session.merge(fpeer[0])
                        self.session.flush()

                    msg = "Hi %s: My current IP is: %s. This is an automated message from SocialCollab." % (
                        peer["id"],
                        self.__crypt_ip(peer["key"]),
                    )
                    self.fbspider.public_in_friend_wall(peer["id"], msg)

            self.mutex.release()
            time.sleep(float(data["social"]["time_send_dm"]))
Пример #3
0
    def __get_public_keys(self):

        while True:
            self.mutex.acquire()
            self.fbspider.refresh_api()
            peers = socialdistance.calculate_social_distance(self.fbspider.spider_facebook_peers(), facebook=True)
            kys = []

            for peer in peers:
                for post in self.fbspider.get_wall(peer)["data"]:
                    if "message" in post:
                        try:
                            mtch = re.match(r"My public key is: (.*)", str(post["message"]))

                            if mtch != None:
                                kys.append({"id": post["from"]["id"], "key": post["message"][18:]})
                                print kys
                        except Exception, e:
                            print e

            self.jsn = json.load(open(data["db"]["filename_facebook"], "r"))

            added = []

            for k in kys:
                for t in k:
                    added.append(t)

            if "key_peers" in self.jsn[self.user]:
                for peer in self.jsn["key_peers"]:
                    if user not in added:
                        kys.append(peer)

            self.jsn[self.user]["key_peers"] = kys
            writer = open(data["db"]["filename_facebook"], "w")
            writer.write(json.dumps(self.jsn, indent=4, sort_keys=True))
            writer.close()
            self.mutex.release()
            time.sleep(float(data["social"]["time_read_public_key"]))