コード例 #1
0
/**
 * Sets character's OpenFire permissions
 */
function eveapi_setOpenFireAccess($userId, $jabber = array(), $extraJabber = array(), $characterName = "---", $password = null)
{
    global $db, $config, $phpbb_root_path, $phpEx;
    // Merge both jabber group arrays
    $merge = array_merge($jabber, $extraJabber);
    // Create the OpenFireUserService object.
    $pofus = new OpenFireUserService();
    // Set the required config parameters
    $pofus->secret = $config['eveapi_openfire_code'];
    $pofus->host = $config['eveapi_openfire_host'];
    $pofus->port = isset($config['eveapi_openfire_port']) && $config['eveapi_openfire_port'] > 0 ? (int) $config['eveapi_openfire_port'] : 9090;
    $pofus->useSSL = $pofus->port == 9091 ? true : false;
    // Get characters (forum username)
    $sql = "SELECT username, user_email, user_lang, user_jabber\n\t\t\tFROM " . USERS_TABLE . "\n\t\t\tWHERE user_id = " . (int) $userId;
    $result = $db->sql_query($sql);
    $data = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    // Clean username for support with Jabber
    // Changing ' to |
    // and <space> to _
    $clean_username = str_replace(array(" ", "'"), array("_", "_"), $data['username']);
    // Check if we have any groups or not, determines whether or not we should disable the jabber account
    if (!empty($merge)) {
        // Remove duplicates
        $merge = array_unique($merge);
        $jabberGroups = array();
        // Loop to remove empty strings
        foreach ($merge as $currentMerge) {
            if (!empty($currentMerge)) {
                $jabberGroups[] = $currentMerge;
            }
        }
        $jabber_name = $clean_username . '@almostawesome.org';
        if ($data['user_jabber'] != $jabber_name) {
            $data_jabber = array('user_jabber' => $clean_username . '@almostawesome.org');
            // And doing an update query: (Using the same data as for SELECT)
            $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $data_jabber) . ' WHERE user_id = ' . (int) $userId;
            $db->sql_query($sql);
        }
        // Check to see if the user exists.
        $result = $pofus->getUser($clean_username);
        // If the user exists, update them, otherwise, create them.
        if ($result) {
            $updated = $pofus->updateUser($clean_username, $password, $data['username'], $data['user_email']);
            if ($updated) {
                $result = $pofus->getGroup($clean_username);
                $xml = @new SimpleXMLElement($result);
                $jabberGroupsDelete = array();
                foreach ($xml->groupname as $row) {
                    if (in_array((string) $row, $jabberGroups)) {
                        if (($key = array_search((string) $row, $jabberGroups)) !== false) {
                            unset($jabberGroups[$key]);
                        }
                    } else {
                        $jabberGroupsDelete[] = (string) $row;
                    }
                }
                if (!empty($jabberGroups)) {
                    $pofus->addGroup($clean_username, $jabberGroups);
                }
                if (!empty($jabberGroupsDelete)) {
                    $pofus->deleteGroup($clean_username, $jabberGroupsDelete);
                }
                // Cronlog it
                cronlog("Updating OpenFire groups => " . implode(", ", $jabberGroups), $characterName);
                // Command was a success, no further action required
                return true;
            }
        } else {
            if (!isset($password)) {
                // User doesn't exist yet, time to create the user
                // Create a random password
                $password = eveapi_randomString(8);
            }
            // Create the actual user
            $added = $pofus->addUser($clean_username, $password, $data['username'], $data['user_email']);
            if ($added) {
                if (!empty($jabberGroups)) {
                    // Add the user to Openfire Groups
                    $pofus->addGroup($clean_username, $jabberGroups);
                }
                $data_jabber = array('user_jabber_password' => $password);
                // And doing an update query: (Using the same data as for SELECT)
                $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $data_jabber) . ' WHERE user_id = ' . (int) $userId;
                $db->sql_query($sql);
                // Cronlog it
                cronlog("Adding OpenFire account with groups => " . implode(", ", $jabberGroups), $characterName);
                // And we are done
                return true;
            }
        }
    } else {
        // Check to see if the user exists.
        $result = $pofus->getUser($clean_username);
        // If the user exists, delete them, otherwise, do nothing
        if ($result) {
            $data_jabber = array('user_jabber' => '', 'user_jabber_password' => '');
            // And doing an update query: (Using the same data as for SELECT)
            $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $data_jabber) . ' WHERE user_id = ' . (int) $userId;
            $db->sql_query($sql);
            $pofus->deleteUser($clean_username);
            cronlog("Removing OpenFire account", $characterName);
        }
    }
    return false;
}
コード例 #2
0
/**
* Sets character's OpenFire permissions
*/
function eveapi_setOpenFireAccess($userId, $jabber = array(), $extraJabber = array(), $characterName = "---")
{
    global $db, $config, $phpbb_root_path, $phpEx;
    // Merge both jabber group arrays
    $merge = array_merge($jabber, $extraJabber);
    // Create the OpenFireUserService object.
    $pofus = new OpenFireUserService();
    // Set the required config parameters
    $pofus->secret = $config['eveapi_openfire_code'];
    $pofus->host = $config['eveapi_openfire_host'];
    $pofus->port = isset($config['eveapi_openfire_port']) && $config['eveapi_openfire_port'] > 0 ? (string) $config['eveapi_openfire_port'] : "9090";
    // Get characters (forum username)
    $sql = "SELECT username, user_email, user_lang\n\t\t\tFROM " . USERS_TABLE . "\n\t\t\tWHERE user_id = " . $userId;
    $result = $db->sql_query($sql);
    $data = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    // Clean username for support with Jabber
    // Changing ' to |
    // and <space> to _
    $clean_username = str_replace(" ", "_", str_replace("'", "|", $data['username']));
    // Check if we have any groups or not, determines whether or not we should disable the jabber account
    if (!empty($merge)) {
        // Remove duplicates
        $merge = array_unique($merge);
        $jabberGroups = array();
        // Loop to remove empty strings
        foreach ($merge as $currentMerge) {
            if (!empty($currentMerge)) {
                $jabberGroups[] = $currentMerge;
            }
        }
        // Now that we have the information we need, let's try to update the jabber groups of the selected user
        $result = $pofus->updateUser($clean_username, false, false, false, $jabberGroups);
        // Check if we have an initial result
        if ($result) {
            // We have a result, but check what the actual result type is
            if ($result['result']) {
                // Cronlog it
                cronlog("Updating OpenFire groups => " . implode(", ", $jabberGroups), $characterName);
                // Command was a success, no further action required
                return true;
            } else {
                if ($result['message'] == 'UserNotFoundException') {
                    // User doesn't exist yet, time to create the user
                    // Create a random password
                    $password = eveapi_randomString(8);
                    // Create the actual user
                    $pofus->addUser($clean_username, $password, $data['username'], $data['user_email'], $jabberGroups);
                    // Cronlog it
                    cronlog("Adding OpenFire account with groups => " . implode(", ", $jabberGroups), $characterName);
                    // Email the newly created password to the user
                    // Load phpBB's Messenger class
                    include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                    $messenger = new messenger();
                    // Load email text from template
                    $messenger->template('openfire_added', $data['user_lang']);
                    // Add recipient
                    $messenger->to($data['user_email'], $data['username']);
                    // Assign variables using in template
                    $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($clean_username), 'PASSWORD' => htmlspecialchars_decode($password), 'HOST' => htmlspecialchars_decode($config['eveapi_openfire_host'])));
                    // Send the actual email
                    $messenger->send();
                    $messenger->save_queue();
                    // And we are done
                    return true;
                }
            }
        }
    } else {
        // No groups found, remove the user from jabber
        $result = $pofus->deleteUser($clean_username);
        if ($result && $result['result']) {
            cronlog("Removing OpenFire account", $characterName);
        }
    }
    return false;
}