function process_login($method_name, $params, $userID)
{
    $config =& get_config();
    $userService = $config['user_service'];
    log_message('debug', "Processing new login request");
    $req = $params[0];
    $fullname = $req["first"] . ' ' . $req["last"];
    // Sanity check the request, make sure it's somewhat valid
    if (empty($userID)) {
        if (!isset($req["first"], $req["last"], $req["passwd"]) || empty($req["first"]) || empty($req["last"]) || empty($req["passwd"])) {
            return array('reason' => 'key', 'login' => 'false', 'message' => "Login request must contain a first name, last name, and password and they cannot be blank");
        }
        // Authorize the first/last/password and resolve it to a user account UUID
        log_message('debug', "Doing password-based authorization for user {$fullname}");
        $userID = authorize_identity($fullname, $req['passwd']);
        if (empty($userID)) {
            return array('reason' => 'key', 'login' => 'false', 'message' => "Sorry! We couldn't log you in.\nPlease check to make sure you entered the right\n    * Account name\n    * Password\nAlso, please make sure your Caps Lock key is off.");
        }
        log_message('debug', sprintf("Authorization success for %s", $userID));
    } else {
        log_message('debug', sprintf("Using pre-authenticated capability for %s", $userID));
    }
    // Get information about the user account
    $user = get_user_by_id($userID);
    if (empty($user)) {
        return array('reason' => 'key', 'login' => 'false', 'message' => "Sorry! We couldn't log you in. User account information could not be retrieved. If this problem persists, please contact the grid operator.");
    }
    $login_success = true;
    //ensure username has the same case as in the database
    $fullname = $user['Name'];
    if (!empty($user['UserFlags'])) {
        // get_user_by_id() fully decodes the structure, this is not needed
        //$userflags = json_decode($user['UserFlags'], TRUE);
        $userflags = $user['UserFlags'];
        if (!empty($userflags['Suspended']) && (bool) $userflags['Suspended'] === true) {
            $login_success = false;
            log_message('debug', "User " . $user['Name'] . " is banned.");
        } else {
            if ($user['AccessLevel'] < $config['access_level_minimum']) {
                if ($config['validation_required']) {
                    if (!empty($userflags['Validated'])) {
                        $login_success = $userflags['Validated'];
                    } else {
                        $login_success = false;
                    }
                    if (!$login_success) {
                        log_message('debug', "User " . $user['Name'] . " has not validated their email.");
                    }
                }
            }
        }
    } else {
        if ($user['AccessLevel'] < $config['access_level_minimum'] && $config['validation_required']) {
            $login_success = false;
            log_message('debug', "User " . $user['Name'] . " has not validated their email.");
        }
    }
    if (!$login_success) {
        return array('reason' => 'key', 'login' => 'false', 'message' => "Sorry!  We couldn't log you in.  User account has been suspended or is not yet activated.  If this problem persists, please contact the grid operator.");
    }
    $lastLocation = null;
    if (isset($user['LastLocation'])) {
        $lastLocation = SceneLocation::fromOSD($user['LastLocation']);
    }
    $homeLocation = null;
    if (isset($user['HomeLocation'])) {
        $homeLocation = SceneLocation::fromOSD($user['HomeLocation']);
    }
    log_message('debug', sprintf("User retrieval success for %s", $fullname));
    // Check for an existing session
    $existingSession = get_session($userID);
    if (!empty($existingSession)) {
        log_message('debug', sprintf("Existing session %s found for %s in scene %s", $existingSession["SessionID"], $fullname, $existingSession["SceneID"]));
        $sceneID = null;
        if (UUID::TryParse($existingSession["SceneID"], $sceneID)) {
            inform_scene_of_logout($sceneID, $userID);
        }
        if (remove_session($userID)) {
            log_message('debug', "Removed existing session for {$fullname} ({$userID})");
        } else {
            log_message('warn', "Failed to remove session for {$fullname} ({$userID})");
            return array('reason' => 'presence', 'login' => 'false', 'message' => "You are already logged in from another location. Please try again later.");
        }
    } else {
        log_message('debug', "No existing session found for {$fullname} ({$userID})");
    }
    // Create a login session
    $sessionID = null;
    $secureSessionID = null;
    $extradata = array('ClientIP' => $_SERVER['REMOTE_ADDR']);
    if (!add_session($userID, $sessionID, $secureSessionID, $extradata)) {
        return array('reason' => 'presence', 'login' => 'false', 'message' => "Failed to create a login session. Please try again later.");
    }
    log_message('debug', sprintf("Session creation success for %s (%s)", $fullname, $userID));
    // Find the starting scene for this user
    $scene = null;
    $startPosition = null;
    $startLookAt = null;
    if (!find_start_location($req['start'], $lastLocation, $homeLocation, $scene, $startPosition, $startLookAt) || !isset($scene->ExtraData['ExternalAddress'], $scene->ExtraData['ExternalPort'])) {
        return array('reason' => 'presence', 'login' => 'false', 'message' => "Error connecting to the grid. No suitable region to connect to.");
    }
    $lludpAddress = $scene->ExtraData['ExternalAddress'];
    $lludpPort = $scene->ExtraData['ExternalPort'];
    // Generate a circuit code
    srand(make_seed());
    $circuitCode = rand();
    // Prepare a login to the destination scene
    $seedCapability = NULL;
    $appearance = $user['LLPackedAppearance'];
    if (!create_opensim_presence($scene, $userID, $circuitCode, $fullname, $appearance, $sessionID, $secureSessionID, $startPosition, $seedCapability)) {
        return array('reason' => 'presence', 'login' => 'false', 'message' => "Failed to establish a presence in the destination region. Please try again later.");
    }
    log_message('debug', sprintf("Presence creation success for %s (%s) in %s with seedcap %s", $fullname, $userID, $scene->Name, $seedCapability));
    // Build the response
    $response = array();
    $response['seconds_since_epoch'] = time();
    $response['login'] = '******';
    $response['agent_id'] = (string) $userID;
    list($response['first_name'], $response['last_name']) = explode(' ', $fullname);
    $response['message'] = $config['message_of_the_day'];
    $response['udp_blacklist'] = $config['udp_blacklist'];
    $response['circuit_code'] = $circuitCode;
    $response['sim_ip'] = $lludpAddress;
    $response['sim_port'] = (int) $lludpPort;
    $response['seed_capability'] = $seedCapability;
    $response['region_x'] = (string) $scene->MinPosition->X;
    $response['region_y'] = (string) $scene->MinPosition->Y;
    $response['region_size_x'] = (string) ($scene->MaxPosition->X - $scene->MinPosition->X);
    $response['region_size_y'] = (string) ($scene->MaxPosition->Y - $scene->MinPosition->Y);
    $response['look_at'] = sprintf("[r%s, r%s, r%s]", $startLookAt->X, $startLookAt->Y, $startLookAt->Z);
    // TODO: If a valid $homeLocation is set, we should be pulling region_handle / position / lookat out of it
    $response['home'] = sprintf("{'region_handle':[r%s, r%s], 'position':[r%s, r%s, r%s], 'look_at':[r%s, r%s, r%s]}", $scene->MinPosition->X, $scene->MinPosition->Y, $startPosition->X, $startPosition->Y, $startPosition->Z, $startLookAt->X, $startLookAt->Y, $startLookAt->Z);
    $response['session_id'] = (string) $sessionID;
    $response['secure_session_id'] = (string) $secureSessionID;
    $req['options'][] = 'initial-outfit';
    for ($i = 0; $i < count($req['options']); $i++) {
        $option = str_replace('-', '_', $req['options'][$i]);
        if (file_exists(BASEPATH . "options/Class.{$option}.php")) {
            if (include_once BASEPATH . "options/Class.{$option}.php") {
                $instance = new $option($user);
                $response[$req["options"][$i]] = $instance->GetResults();
            } else {
                log_message('warn', "Unable to process login option: " . $option);
            }
        } else {
            log_message('debug', "Option " . $option . " not implemented.");
        }
    }
    $response["start_location"] = $req["start"];
    $response["agent_access"] = 'A';
    $response["agent_region_access"] = 'A';
    $response["agent_access_max"] = 'A';
    $response["agent_flags"] = 0;
    $response["ao_transition"] = 0;
    $response["inventory_host"] = "127.0.0.1";
    log_message('info', sprintf("Login User=%s %s Channel=%s Start=%s Viewer=%s id0=%s Mac=%s", $req["first"], $req["last"], $req["channel"], $req["start"], $req["version"], $req["id0"], $req["mac"]));
    return $response;
}
Esempio n. 2
0
<?php

switch ($_GET['action']) {
    case 'add_session':
        add_session();
        break;
    case 'get_session':
        get_session();
        break;
    case 'remove_session':
        remove_session();
        break;
}
function add_session()
{
    session_start();
    $data = json_decode(file_get_contents("php://input"));
    $_SESSION["feedbackTool"] = json_encode($data);
    echo $_SESSION["feedbackTool"];
}
function get_session()
{
    session_start();
    if (isset($_SESSION["feedbackTool"])) {
        if ($_SESSION["feedbackTool"] != null) {
            echo $_SESSION["feedbackTool"];
        } else {
            echo json_encode(array('SESSION' => 'NOSESSION'));
        }
    } else {
        echo json_encode(array('SESSION' => 'NOSESSION'));
Esempio n. 3
0
function save_session()
{
    $username = get_session_value(SESSION_USER_KEY);
    add_session($username, serialize($_SESSION));
}
Esempio n. 4
0
        $session->SessionID = $_POST["SessionID"];
        $session->SessionName = $_POST["SessionName"];
        $session->TrackID = $_POST["TrackID"];
        if (array_key_exists("SessionTrackID", $_POST)) {
            $session->SessionTrackID = $_POST["SessionTrackID"];
        }
        $session->PresentationTypeID = $_POST["PresentationTypeID"];
        $session->StartTime = sprintf("%s %02d:%02d:00", $_POST["StartDate"], $_POST["StartHour"] % 12 + ($_POST["StartMeridiem"] == "pm" ? 12 : 0), $_POST["StartMinute"]);
        $session->EndTime = sprintf("%s %02d:%02d:00", $_POST["EndDate"], $_POST["EndHour"] % 12 + ($_POST["EndMeridiem"] == "pm" ? 12 : 0), $_POST["EndMinute"]);
        $session->RoomID = $_POST["RoomID"];
        $session->ChairID = $_POST["ChairID"];
        if ($_POST["SessionID"] && !$_GET["duplicate"]) {
            $result = update_session($session);
        } else {
            $session->SessionID = 0;
            $result = add_session($session);
        }
        $url = "Location: sessions.php";
        header($url);
    }
}
$vars = array();
if ($sessionID) {
    $session = get_session_info($sessionID);
    $vars["SessionID"] = $session->SessionID;
    $vars["SessionName"] = $session->SessionName;
    $vars["TrackID"] = $session->TrackID;
    $vars["SessionTrackID"] = $session->SessionTrackID;
    $vars["PresentationTypeID"] = $session->PresentationTypeID;
    $startTime = get_date_obj($session->StartTime);
    $vars["StartDate"] = $startTime->Date;