venomous0x / WhatsAPI

Interface to WhatsApp Messenger
2.59k stars 2.13k forks source link

pollMessages with ajaxDemo #492

Closed mgp25 closed 11 years ago

mgp25 commented 11 years ago

Hi, im trying ajaxDemo, and it sends perfectly messages to the target, but i cant figure out why the incoming messages are not being displayed. The target's profile picture too.

Any idea?

shirioko commented 11 years ago

Uncomment line 38 to 42 in index.php and check the output you get after a while https://github.com/venomous0x/WhatsAPI/blob/master/src/php/ajaxDemo/index.php#L38

mgp25 commented 11 years ago

@shirioko ty!, now its returning this error. Related with:

session_start();
 <b>Warning</b>: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /whatsprot.class.php:1404) in <b>ajaxDemo/socket.php</b> on line <b>37</b><br /> <br /> 
<b>Warning</b>: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at whatsprot.class.php:1404) in <b>ajaxDemo/socket.php</b> on line <b>37</b><br />
shirioko commented 11 years ago

Add

ob_start();

at the beginning and

ob_flush();

at the end of socket.php

Hmm, just realized that socket.php has no PHP closing tag... late night coding struggles :/

mgp25 commented 11 years ago

No errors now, although incoming messages are not being displayed yet.

with

$debug = true;
 rx <message from="34***@s.whatsapp.net" id="message-1381618532-1" type="chat" t="1381618532"> rx <notify xmlns="urn:xmpp:whatsapp" name="Test :D"></notify> rx <request xmlns="urn:xmpp:receipts"></request> rx <body>hola</body> rx </message>

Not displayed but received.

shirioko commented 11 years ago

Something messed up your PHP sessions. Do you have cookies enabled? What is your server setup?

mgp25 commented 11 years ago

Yup, i have cookies enabled.

PHP version => PHP Version 5.3.27

session.use_cookies On  On
session.use_only_cookies    On  On
shirioko commented 11 years ago

oh ffs I see the problem Let me push a fix

shirioko commented 11 years ago

@mgp25 can you confirm this fix? :)

mgp25 commented 11 years ago

@shirioko :D

Fully working! Profile picture is not displayed but i think i can figure it out.

Thx ;)

shirioko commented 11 years ago

Fixed profile picture as well.

mgp25 commented 11 years ago

@shirioko i tried the latest fix, profile picture is not displayed. We may have overlooked something.

shirioko commented 11 years ago

Do you have the ../pictures folder and write permissions for it?

mgp25 commented 11 years ago

Yup. 777

    $filename = "../".WhatsProt::PICTURES_FOLDER."/" . $filename;

I have another script and its working. I dont know what could be happening with ajaxDemo :/

function onGetProfilePicture($from, $target, $type, $data)
{
    if ($type == "preview") {
        $filename = "preview_" . $target . ".jpg";
    } else {
        $filename = $target . ".jpg";
    }
    $filename = WhatsProt::PICTURES_FOLDER."/" . $filename;

    $fp = @fopen($filename, "w");
    if ($fp) {
        fwrite($fp, $data);
        fclose($fp);

    }

    echo '<a href="'.$filename.'"><center><img src="'.$filename.'" height="250" width="250"></center></a><br><br>';    

}
$w->eventManager()->bind("onGetProfilePicture", "onGetProfilePicture");
$w->sendGetProfilePicture($target, true);
mgp25 commented 11 years ago

@shirioko did you found what happened? Also there is a vuln using ajaxDemo… PoC on image:

This is easily fixed, so we dont have to be worried at all :p

shirioko commented 11 years ago

Profile picture works for me though. What's the debug output you get in your script? Change lines 38-42 to

if(data)
            {
                var foo = $("#debug").html();
                $("#debug").html(foo + data);
            }

to fix formatting

mgp25 commented 11 years ago

@shirioko omg… my fault, never mind. Its working 100%

mgp25 commented 11 years ago

@shirioko just one more thing.

$w->SendPresenceSubscription($target);

It suppossed to print if target is online, offline or either typing right? because it doesnt, i need to code something?

            <span id="contactname"></span>
            <br />
            <span id="contactstatus"></span>

If i want for example to print last seen time using ajax:

socket.php

function onGetRequestLastSeen($username, $msgid, $seconds)
{
// function
// ...

    session_start();
    $_SESSION["lastseen"] = $lastseen;
    session_write_close();
}
$w->eventManager()->bind('onGetRequestLastSeen', 'onGetRequestLastSeen');
$w->sendGetRequestLastSeen($target);

on index.php should i only do this?

   <span id="contactstatus"></span>

I know... i have to get in touch with this languages