Beispiel #1
0
function create_session($u)
{
    // Create and set up a session
    $s = $GLOBALS['db']->prepare('INSERT INTO login_cookie_token
		(token, user_id, request_time, expiry_time)
		VALUES(?, ?, ?, ?);');
    $token = \bmtmgr\utils\gen_token();
    $request_time = time();
    $session_length = \bmtmgr\config\get('session_token_timeout', 10 * 360 * 24 * 60 * 60);
    $expiry_time = $request_time + $session_length;
    $s->execute(array($token, $u->id, $request_time, $expiry_time));
    setcookie('login_token', $token, $expiry_time, '/', false, \bmtmgr\config\get('force_https', false), true);
}
Beispiel #2
0
function create_keypair()
{
    $passphrase = \bmtmgr\utils\gen_token();
    $tmpname = \tempnam(\sys_get_temp_dir(), 'bmtmgr_sftp_key');
    \unlink($tmpname);
    \exec('ssh-keygen -q -t rsa -N ' . \escapeshellarg($passphrase) . ' -f ' . \escapeshellarg($tmpname), $output, $return_val);
    if ($return_val != 0) {
        throw new \Exception('SSH key creation failed: ' . \implode("\n", $output));
    }
    $priv_key = \file_get_contents($tmpname);
    \unlink($tmpname);
    $pub_key = \file_get_contents($tmpname . '.pub');
    \unlink($tmpname . '.pub');
    return [$priv_key, $pub_key, $passphrase];
}