function automacuser($json = false)
{
    global $Settings;
    // TODO MAC is passed in via uam
    $mac = DatabaseFunctions::getInstance()->latestMacFromIP(remoteip());
    $autoUsername = mactoautousername($mac);
    // Attempt to create user
    //
    $autoCreateGroup = $Settings->getSetting('autocreategroup');
    $autoCreatePassword = $Settings->getSetting('autocreatepassword');
    $groupSettings = $Settings->getGroup($autoCreateGroup);
    /* TODO Set at the group level and not in the radcheck table,
     * requires changes to how DB class works
     */
    if ($autoCreateGroup && strlen($autoUsername) > 0) {
        // Create user
        DatabaseFunctions::getInstance()->createUser($autoUsername, $autoCreatePassword, false, false, '--', $groupSettings[$autoCreateGroup]['ExpireAfter'], $autoCreateGroup, "Auto created account for {$mac} at " . date('Ymd H:i:s'));
        // Users password may not match the autocreatepassword if it's changed.
        // Should we update the users password or get the users password?
        DatabaseFunctions::getInstance()->setUserPassword($autoUsername, $autoCreatePassword);
        // Create CHAP Challenge/Response token
        $challenge = $_GET['challenge'];
        $response = chapchallengeresponse($challenge, $autoCreatePassword);
        $loginURL = uamloginurl($autoUsername, $response);
        if ($json) {
            return json_encode(array('username' => $autoUsername, 'challenge' => $challenge, 'response' => $response));
        } else {
            header("Location: {$loginURL}");
            return false;
        }
    }
    return false;
}
Esempio n. 2
0
            $reply = array($_GET['reply']);
        }
        $smarty->assign("error", $reply);
        //break; // Fall through?
    //break; // Fall through?
    case 'notyet':
    case 'logoff':
        // Display login
        setup_login_form();
        break;
    case 'success':
        //Logged in. Try popup and redirect to userurl
        // If this is an automac login (check UID vs MAC) then we skip the
        // normal success and go back to portal which should work better as
        // it's not a nojs login
        if ($_GET['uid'] == mactoautousername($_GET['mac'])) {
            break;
        }
        //
        load_templates(array('loggedinnojshtml'));
        $smarty->display('loggedin.tpl');
        exit;
        break;
}
function setup_login_form()
{
    global $smarty;
    $smarty->display('portal.tpl');
    exit;
}
$smarty->display('portal.tpl');