Beispiel #1
0
/**
 * validateSession()
 *
 * Returns true if a session has already been created in an
 * attempt to prevent abuse of the listener.
 */
function validateSession()
{
    global $A;
    // Activity object
    global $name;
    $name = getName();
    if (cookieVar(LACE_SESSION_COOKIE) === false && !$A->keyExists($name)) {
        joinMessage($name);
    }
    $A->update($name);
    setcookie(LACE_SESSION_COOKIE, getCookieString(), time() + 600, LACE_URL_REL);
    setcookie(LACE_NAME_COOKIE, $name, time() + 2592000, LACE_URL_REL);
    return true;
}
Beispiel #2
0
/**
 * laceListener()
 *
 * Checks POST variables for incoming messages or
 * update requests.
 */
function laceListener($fromListener = true)
{
    $cookie_name = cookieVar(LACE_NAME_COOKIE, false);
    $post_name = postVar('name', false);
    // name
    $post_text = postVar('text', false);
    // text
    if ($post_name !== false && $post_text !== false) {
        if (validateSession() === false) {
            return '"chat":{"nodata":"1"}';
        }
        if (isFlooding() === true) {
            return '"chat":{"nodata":"1"}';
        }
        $message = prepareMessage($post_name, $post_text);
        if ($message !== false) {
            if ($cookie_name && $cookie_name != $post_name) {
                addNameChange($cookie_name, $post_name);
            } else {
                global $A;
                // Activity object
                joinMessage($post_name);
                $A->update($post_name);
            }
            // Reset $name just in case it has been changed
            global $name;
            $name = $post_name;
            setcookie(LACE_NAME_COOKIE, $post_name, time() + 259200, LACE_URL_REL);
            addMessage($message);
        }
    }
    if ($fromListener) {
        $chatHash = postVar('chatHash', false);
        if ($chatHash) {
            $hash = getMessageHash();
            if (validateSession() === false || $chatHash == $hash) {
                return '"chat":{"nodata":""}';
            }
            $json = '"chat":{"hash":"' . $hash . '","data":"';
            $json .= addslashes(str_replace("\n", "", printFileContentsHTML())) . '"}';
            return $json;
        }
        return '"chat":{"nodata":""}';
    }
    return '"chat":{"nodata":""}';
}