Exemplo n.º 1
0
    // check this user has joined the channel
    if (!Container_channels::checkChannelUser($cid, $online_uid)) {
        $res->status(403);
        // You have to join channel
        return;
    }
    // check this user is an operator on this channel
    if (!Container_channels_op::isOp($cid, $online_uid)) {
        $res->status(403);
        // You have to be an operator to unban a user
        return;
    }
    // removes name64 from the ban list
    $banlist = Container_channels_ban::getBanList($cid);
    $ok = Container_channels_ban::rmBan($cid, $name64);
    if ($ok) {
        // check if the user is in the ban list
        $name = base64_decode($name64);
        if (!isset($banlist[$name])) {
            $res->status(404);
            return;
        }
        // notification to other connected user of this removed ban
        $unban_body = $banlist[$name];
        $unban_body = array_merge($unban_body, array('name' => $name));
        Container_messages::postMsgToChannel($cid, $online_uid, $unban_body, 'unban');
        $res->status(200);
    } else {
        $res->status(500);
    }
});
Exemplo n.º 2
0
        // Need to authenticate
        return;
    }
    $uid = $_SESSION['userdata']['id'];
    // check this user is online
    if (!Container_users::checkUserExists($uid)) {
        $res->status(400);
        // User is not connected
        return;
    }
    // check this user has joined the channel
    if (!Container_channels::checkChannelUser($cid, $uid)) {
        $res->status(403);
        // You have to join channel before post a message
        return;
    }
    // check that request content contains a message
    $data = json_decode($req->getBody());
    if (!isset($data->body) or $data->body === '') {
        $res->status(400);
        // Missing parameter [body]
        $res['Content-Type'] = 'application/json; charset=utf-8';
        $res->body('{ "error": "Missing parameter [body]" }');
        return;
    }
    // post message
    $msg = Container_messages::postMsgToChannel($cid, $uid, $data->body);
    $res->status(201);
    $res['Content-Type'] = 'application/json; charset=utf-8';
    $res->body($msg);
});
Exemplo n.º 3
0
        return;
    }
    $uid = $_SESSION['userdata']['id'];
    // check this user is online
    if (!Container_users::checkUserExists($uid)) {
        $res->status(400);
        // User is not connected
        return;
    }
    // check this user has joined the channel
    if (!Container_channels::checkChannelUser($cid, $uid)) {
        $res->status(403);
        // You have to join channel before post a message
        return;
    }
    // check that request content contains a message
    $data = json_decode($req->getBody());
    if (!$data or !is_string($data)) {
        $res->status(400);
        // Wrong message format
        $res['Content-Type'] = 'application/json; charset=utf-8';
        $res->body('{ "error": "Wrong message format (must be a JSON string)" }');
        return;
    }
    // post the message
    $http_result = Container_messages::postMsgToChannel($cid, $uid, $data);
    $http_status = 201;
    $res->status($http_status);
    $res['Content-Type'] = 'application/json; charset=utf-8';
    $res->body($http_result);
});
Exemplo n.º 4
0
 /**
  * Run the garbage collector (disconnect timeouted users)
  * Has to be called by each users when they check pending messages
  */
 public static function runGC()
 {
     // get the GC time
     $gc = dirname(__FILE__) . '/../data/gc';
     if (file_exists($gc)) {
         $gctime = (int) file_get_contents($gc);
     } else {
         $gctime = time();
     }
     if (time() >= $gctime) {
         // write next gc check time
         file_put_contents($gc, time() + $GLOBALS['pfc_timeout']);
         // run the GC
         foreach (self::getUsers() as $uid) {
             $timestamp_file = self::getDir() . '/' . $uid . '/timestamp';
             if (file_exists($timestamp_file)) {
                 $timestamp = file_get_contents($timestamp_file);
                 $timeouted = $timestamp <= time() - $GLOBALS['pfc_timeout'];
                 if ($timeouted) {
                     // check the leave reason
                     $close_file = self::getDir() . '/' . $uid . '/closed';
                     $reason = file_exists($close_file) ? 'quit' : 'timeout';
                     // disconnect the user (send leave messages on his channels)
                     foreach (self::getUserChannels($uid) as $cid) {
                         self::leaveChannel($uid, $cid);
                         // post a leave message related to timeout
                         $msg = Container_messages::postMsgToChannel($cid, $uid, $reason, 'leave');
                     }
                     // clear user data
                     self::rmUser($uid);
                 }
             } else {
                 self::rmUser($uid);
                 // no timeout file, just delete the user
             }
         }
     }
 }
Exemplo n.º 5
0
    if (!Container_users::checkUserExists($online_uid)) {
        $res->status(400);
        // User is not connected
        return;
    }
    // check this user is an operator on this channel
    if (!Container_channels_op::isOp($cid, $online_uid)) {
        $res->status(403);
        // You have to be an operator to give op to other user
        return;
    }
    // check the destination user is an operator on this channel
    if (!Container_channels_op::isOp($cid, $uid)) {
        $res->status(400);
        $res['Content-Type'] = 'application/json; charset=utf-8';
        $res->body(GetPfcError(40002));
        // This user is not an operator on the channel
        return;
    }
    // removes $uid user as a $cid channel operator
    $ok = Container_channels_op::rmOp($cid, $uid);
    if ($ok) {
        $res->status(200);
        // notification to other connected user of this removed operator
        Container_messages::postMsgToChannel($cid, $online_uid, $uid, 'deop');
    } else {
        $res->status(500);
    }
    $res['Content-Type'] = 'application/json; charset=utf-8';
    $res->body(json_encode($ok));
});