Example #1
0
    def __init__(self,
                 jid,
                 accountJid,
                 sourcePath,
                 uploadUrl,
                 resumeOffset=0,
                 successClbk=None,
                 errorClbk=None,
                 progressCallback=None,
                 asynchronous=True):
        WARequest.__init__(self)

        self.asynchronous = asynchronous
        self.jid = jid
        self.accountJid = accountJid
        self.sourcePath = sourcePath
        self.uploadUrl = uploadUrl
        self.resumeOffset = resumeOffset

        self.successCallback = successClbk
        self.errorCallback = errorClbk
        self.progressCallback = progressCallback

        self.pvars = [
            "name", "type", "size", "url", "error", "mimetype", "filehash",
            "width", "height"
        ]

        self.setParser(JSONResponseParser())

        self.sock = socket.socket()
Example #2
0
    def __init__(self, cc, p_in, idx):
        super(WAExistsRequest, self).__init__()

        self.addParam("cc", cc)
        self.addParam("in", p_in)
        self.addParam("id", idx)
        self.addParam("lg", "en")
        self.addParam("lc", "GB")
        self.addParam("token", YowsupEnv.getCurrent().getToken(p_in))
        self.addParam("mistyped", '6')
        self.addParam('network_radio_type', '1')
        self.addParam('simnum', '1')
        self.addParam('s', '')
        self.addParam('copiedrc', '1')
        self.addParam('hasinrc', '1')
        self.addParam('rcmatch', '1')
        self.addParam('pid', os.getpid())
        self.addParam('extexist', '1')
        self.addParam('extstate', '1')

        self.url = "v.whatsapp.net/v2/exist"

        self.pvars = [
            "status", "reason", "sms_length", "voice_length", "result",
            "param", "pw", "login", "type", "expiration", "kind", "price",
            "cost", "currency", "price_expiration"
        ]

        self.setParser(JSONResponseParser())
Example #3
0
    def __init__(self,
                 cc,
                 p_in,
                 mcc="000",
                 mnc="000",
                 sim_mcc="000",
                 sim_mnc="000",
                 method="sms"):
        super(WACodeRequest, self).__init__()
        idx = StorageTools.getIdentity(cc + p_in)

        self.p_in = p_in
        self.__id = idx
        self.cc = cc

        self.addParam("cc", cc)
        self.addParam("in", p_in)
        self.addParam("lc", "GB")
        self.addParam("lg", "en")
        self.addParam("sim_mcc", sim_mcc.zfill(3))
        self.addParam("sim_mnc", sim_mnc.zfill(3))
        self.addParam("method", method)

        self.addParam("token", CURRENT_ENV.getToken(p_in))

        self.url = "v.whatsapp.net/v2/code"

        self.pvars = ["status","reason","length", "method", "retry_after", "code", "param"] +\
                    ["login", "pw", "type", "expiration", "kind", "price", "cost", "currency", "price_expiration"]

        self.setParser(JSONResponseParser())
Example #4
0
    def __init__(self,cc, p_in, code):
        super(WARegRequest,self).__init__()
        idx = StorageTools.getIdentity(cc + p_in)

        if idx is None:
            logger.error("You have to request code first")

        self.addParam("cc", cc)
        self.addParam("in", p_in)

        self.addParam("id", idx)
        self.addParam("code", code)

        self.addParam("lc", "GB")
        self.addParam("lg", "en")

        self.addParam("mistyped", '6')
        # self.addParam('network_radio_type', '1')
        self.addParam('simnum', '1')
        self.addParam('s', '')
        self.addParam('copiedrc', '1')
        self.addParam('hasinrc', '1')
        self.addParam('rcmatch', '1')
        self.addParam('pid', os.getpid())
        self.addParam('rchash', hashlib.sha256(os.urandom(20)).hexdigest())
        self.addParam('anhash', hashlib.md5(os.urandom(20)).hexdigest())
        self.addParam('extexist', '1')
        self.addParam('extstate', '1')

        self.url = "v.whatsapp.net/v2/register"

        self.pvars = ["status", "login", "pw", "type", "expiration", "kind", "price", "cost", "currency", "price_expiration",
                      "reason","retry_after"]

        self.setParser(JSONResponseParser())
Example #5
0
    def __init__(self,cc, p_in, idx):
        super(WAExistsRequest,self).__init__();

        self.addParam("cc", cc);
        self.addParam("in", p_in);
        self.addParam("id", idx);

        self.url = "v.whatsapp.net/v2/exist"

        self.pvars = ["status", "reason", "sms_length", "voice_length", "result","param", "pw", "login", "type", "expiration", "kind",
                    "price", "cost", "currency", "price_expiration"
                    ]

        self.setParser(JSONResponseParser())
Example #6
0
    def __init__(self,cc, p_in, code, idx):
        super(WARegRequest,self).__init__();

        self.addParam("cc", cc);
        self.addParam("in", p_in);
        self.addParam("id", idx)
        self.addParam("code", code)

        self.url = "v.whatsapp.net/v2/register"

        self.pvars = ["status", "login", "pw", "type", "expiration", "kind", "price", "cost", "currency", "price_expiration",
                      "reason","retry_after"]

        self.setParser(JSONResponseParser())
Example #7
0
    def __init__(self,
                 cc,
                 p_in,
                 mcc="000",
                 mnc="000",
                 sim_mcc="000",
                 sim_mnc="000",
                 method="sms"):
        super(WACodeRequest, self).__init__()
        idx = StorageTools.getIdentity(cc + p_in)

        self.p_in = p_in
        self.__id = idx
        self.cc = cc

        self.addParam("cc", cc)
        self.addParam("in", p_in)
        self.addParam("lc", "GB")
        self.addParam("lg", "en")
        self.addParam("sim_mcc", sim_mcc.zfill(3))
        self.addParam("sim_mnc", sim_mnc.zfill(3))
        self.addParam("mcc", sim_mcc.zfill(3))
        self.addParam("mnc", sim_mnc.zfill(3))
        self.addParam("method", method)

        self.addParam("mistyped", "6")
        self.addParam("network_radio_type", "1")
        self.addParam("simnum", "1")
        self.addParam("s", "")
        self.addParam("copiedrc", "1")
        self.addParam("hasinrc", "1")
        self.addParam("rcmatch", "1")
        self.addParam("pid", int(random.uniform(100, 9999)))
        self.addParam("rchash", hashlib.sha256(os.urandom(20)).hexdigest())
        self.addParam("anhash", os.urandom(20))
        self.addParam("extexist", "1")
        self.addParam("extstate", "1")

        self.addParam("token", YowsupEnv.getCurrent().getToken(p_in))

        self.url = "v.whatsapp.net/v2/code"

        self.pvars = ["status","reason","length", "method", "retry_after", "code", "param"] +\
                    ["login", "pw", "type", "expiration", "kind", "price", "cost", "currency", "price_expiration"]

        self.setParser(JSONResponseParser())
Example #8
0
    def __init__(self, config):
        """
        :param config:
        :type config: yowsup.config.v1.config.Config
        """
        super(WAExistsRequest, self).__init__(config)
        if config.id is None:
            raise ValueError("Config does not contain id")

        self.url = "v.whatsapp.net/v2/exist"

        self.pvars = [
            "status", "reason", "sms_length", "voice_length", "result",
            "param", "login", "type", "chat_dns_domain", "edge_routing_info"
        ]

        self.setParser(JSONResponseParser())
        self.addParam("token", YowsupEnv.getCurrent().getToken(self._p_in))
Example #9
0
    def __init__(self, config, code):
        """
        :param config:
        :type config: yowsup.config.vx.config.Config
        :param code:
        :type code: str
        """
        super(WARegRequest, self).__init__(config)

        self.addParam("code", code)

        self.url = "v.whatsapp.net/v2/register"

        self.pvars = [
            "status", "login", "type", "edge_routing_info", "chat_dns_domain"
            "reason", "retry_after"
        ]

        self.setParser(JSONResponseParser())
Example #10
0
    def __init__(self,
                 cc,
                 p_in,
                 idx,
                 mcc="000",
                 mnc="000",
                 sim_mcc="000",
                 sim_mnc="000",
                 method="sms"):
        super(WACodeRequest, self).__init__()

        self.p_in = p_in

        self.addParam("cc", cc)
        self.addParam("in", p_in)
        self.addParam("lc", "US")
        self.addParam("lg", "en")
        self.addParam("mcc", "000")
        self.addParam("mnc", "000")
        self.addParam("sim_mcc", sim_mcc.zfill(3))
        self.addParam("sim_mnc", sim_mnc.zfill(3))
        self.addParam("method", method)
        self.addParam("id", idx)
        self.addParam("network_radio_type", "1")
        self.addParam("reason", "self-send-jailbroken")

        self.currentToken = None  #Utilities.readToken()

        if self.currentToken:
            print("Read token from %s " %
                  os.path.expanduser(Constants.tokenStorage))
        else:
            self.currentToken = Constants.DATA_CLIENT

        self.addParam("token", self.getToken(p_in, self.currentToken["t"]))

        self.url = "v.whatsapp.net/v2/code"

        self.pvars = ["status","reason","length", "method", "retry_after", "code", "param"] +\
                    ["login", "pw", "type", "expiration", "kind", "price", "cost", "currency", "price_expiration"]

        self.setParser(JSONResponseParser())
Example #11
0
    def __init__(self, cc, p_in, code):
        super(WARegRequest, self).__init__()
        idx = StorageTools.getIdentity(cc + p_in)

        if idx is None:
            raise ValueError("You have to request code first")

        self.addParam("cc", cc)
        self.addParam("in", p_in)

        self.addParam("id", idx)
        self.addParam("code", code)

        self.url = "v.whatsapp.net/v2/register"

        self.pvars = [
            "status", "login", "pw", "type", "expiration", "kind", "price",
            "cost", "currency", "price_expiration", "reason", "retry_after"
        ]

        self.setParser(JSONResponseParser())
Example #12
0
    def __init__(self, method, config):
        """
        :type method: str
        :param config:
        :type config: yowsup.config.v1.config.Config
        """
        super(WACodeRequest,self).__init__(config)

        self.addParam("mcc", config.mcc.zfill(3))
        self.addParam("mnc", config.mnc.zfill(3))
        self.addParam("sim_mcc", config.sim_mcc.zfill(3))
        self.addParam("sim_mnc", config.sim_mnc.zfill(3))
        self.addParam("method", method)
        self.addParam("reason", "")
        self.addParam("token", YowsupEnv.getCurrent().getToken(self._p_in))
        self.addParam("hasav", "1")

        self.url = "v.whatsapp.net/v2/code"

        self.pvars = ["status","reason","length", "method", "retry_after", "code", "param"] +\
                    ["login", "type", "sms_wait", "voice_wait"]
        self.setParser(JSONResponseParser())
        self.jid = jid
        self.accountJid = accountJid
        self.sourcePath = sourcePath
        self.uploadUrl = uploadUrl
        self.resumeOffset = resumeOffset

        self.successCallback = successClbk
        self.errorCallback = errorClbk
        self.progressCallback = progressCallback

        self.pvars = [
            "name", "type", "size", "url", "error", "mimetype", "filehash",
            "width", "height"
        ]

        self.setParser(JSONResponseParser())

        self.sock = socket.socket()

    def start(self):
        if self. async:
            threading.Thread.__init__(self)
            super(MediaUploader, self).start()
        else:
            self.run()

    def pad(self, s):
        # return s + (16 - len(s) % 16) * chr(16 - len(s) % 16)
        y = (16 - len(s) % 16) * chr(16 - len(s) % 16)
        a = s + y.encode()
        return a
Example #14
0
    def MediaUpload(cls, fromjid, tojid, filename, filedata, uploadUrl, userAgent):
        sock = socket.socket()
        _host = uploadUrl.replace("https://","")

        url = _host[:_host.index('/')]
        port = 443

        filetype = mimetypes.guess_type(filename)[0]
        filesize = len(filedata)

        sock.connect((url, port))
        ssl_sock = ssl.wrap_socket(sock)

        m = hashlib.md5()
        m.update(filename.encode())
        crypto = m.hexdigest() + os.path.splitext(filename)[1]

        boundary = "zzXXzzYYzzXXzzQQ"#"-------" + m.hexdigest() #"zzXXzzYYzzXXzzQQ"
        contentLength = 0

        hBAOS = "--" + boundary + "\r\n"
        hBAOS += "Content-Disposition: form-data; name=\"to\"\r\n\r\n"
        hBAOS += tojid.replace("@whatsapp.net","").replace("@g.us","") + "\r\n"
        hBAOS += "--" + boundary + "\r\n"
        hBAOS += "Content-Disposition: form-data; name=\"from\"\r\n\r\n"
        hBAOS += fromjid.replace("@whatsapp.net","") + "\r\n"

        hBAOS += "--" + boundary + "\r\n"
        hBAOS += "Content-Disposition: form-data; name=\"file\"; filename=\"" + crypto + "\"\r\n"
        hBAOS  += "Content-Type: " + filetype + "\r\n\r\n"

        fBAOS = "\r\n--" + boundary + "--\r\n"

        contentLength += len(hBAOS)
        contentLength += len(fBAOS)
        contentLength += filesize

        POST = "POST %s\r\n" % uploadUrl
        POST += "Content-Type: multipart/form-data; boundary=" + boundary + "\r\n"
        POST += "Host: %s\r\n" % url
        POST += "User-Agent: %s\r\n" % userAgent
        POST += "Content-Length: " + str(contentLength) + "\r\n\r\n"

        ssl_sock.send(bytearray(POST.encode()))
        ssl_sock.send(bytearray(hBAOS.encode()))

        totalsent = 0
        buf = 1024
        stream = filedata

        logcount = 0
        while totalsent < int(filesize):
            if logcount > 10:
                logcount = 0
                print('{}/{}'.format(totalsent, int(filesize)))
            logcount += 1
            ssl_sock.send(stream[:buf])
            stream = stream[buf:]
            totalsent = totalsent + buf

        ssl_sock.send(bytearray(fBAOS.encode()))

        data = ssl_sock.recv(8192)
        data += ssl_sock.recv(8192)
        data += ssl_sock.recv(8192)
        data += ssl_sock.recv(8192)
        data += ssl_sock.recv(8192)
        data += ssl_sock.recv(8192)
        data += ssl_sock.recv(8192)
        lines = data.decode().splitlines()


        result = None

        pvars = ["name", "type", "size", "url", "error", "mimetype", "filehash", "width", "height"]
        parser = JSONResponseParser()
        
        for l in lines:
            if l.startswith("{"):
                result = parser.parse(l, pvars)
                break

        if not result:
            raise Exception("json data not found")

        return result["url"]