/**
  * @preserveGlobalState disabled
  */
 public function testLogin()
 {
     try {
         if (!isset($_SESSION)) {
             $_SESSION = array();
         }
         OC_RoundCube_App::login('127.0.0.1', '49080', 'roundcube', '*****@*****.**', '42');
     } catch (Exception $e) {
         echo OC_RoundCube_App::showMailFrame('127.0.0.1', '49080', 'roundcube')->getHtmlOutput();
     }
 }
 /**
  * Login into roundcube server
  * @param $params userdata
  * @return true if login was succesfull otherwise false
  */
 public static function login($params)
 {
     try {
         $username = $params['uid'];
         $password = $params['password'];
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->login(): Preparing login of user "' . $username . '" into roundcube', OCP\Util::DEBUG);
         $maildir = OCP\Config::getAppValue('roundcube', 'maildir', '');
         $rc_host = OCP\Config::getAppValue('roundcube', 'rcHost', '');
         if ($rc_host == '') {
             $rc_host = OC_Request::serverHost();
         }
         $rc_port = OCP\Config::getAppValue('roundcube', 'rcPort', '');
         $enable_auto_login = OCP\Config::getAppValue('roundcube', 'autoLogin', false);
         if ($enable_auto_login) {
             // SSO attempt
             $mail_username = $username;
             $mail_password = $password;
         } else {
             // Fetch credentials from data-base
             $mail_userdata_entries = OC_RoundCube_App::checkLoginData($username);
             // TODO create dropdown list
             $mail_userdata = $mail_userdata_entries[0];
             $privKey = OC_RoundCube_App::getPrivateKey($username, $password);
             $mail_username = OC_RoundCube_App::decryptMyEntry($mail_userdata['mail_user'], $privKey);
             $mail_password = OC_RoundCube_App::decryptMyEntry($mail_userdata['mail_password'], $privKey);
         }
         // save login data encrypted for later usage
         $pubKey = OC_RoundCube_App::getPublicKey($username);
         $emailUserCrypted = OC_RoundCube_App::cryptMyEntry($mail_username, $pubKey);
         $emailPasswordCrypted = OC_RoundCube_App::cryptMyEntry($mail_password, $pubKey);
         $_SESSION[OC_RoundCube_App::SESSION_ATTR_RCLOGIN] = $emailUserCrypted;
         $_SESSION[OC_RoundCube_App::SESSION_ATTR_RCPASSWORD] = $emailPasswordCrypted;
         // login
         OC_RoundCube_App::login($rc_host, $rc_port, $maildir, $mail_username, $mail_password);
         return true;
     } catch (Exception $e) {
         // We got an exception == table not found
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->login(): Login error. ' . $e, OCP\Util::DEBUG);
         return false;
     }
 }
 /**
  * Login into roundcube server
  *
  * @param $params userdata            
  * @return true if login was succesfull otherwise false
  */
 public static function login($params)
 {
     OCP\App::checkAppEnabled('roundcube');
     try {
         $username = $params['uid'];
         $password = $params['password'];
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->login(): Preparing login of roundcube user "' . $username . '"', OCP\Util::DEBUG);
         $maildir = OCP\Config::getAppValue('roundcube', 'maildir', '');
         $rc_host = self::getServerHost();
         $rc_port = OCP\Config::getAppValue('roundcube', 'rcPort', '');
         $enable_auto_login = OCP\Config::getAppValue('roundcube', 'autoLogin', false);
         if ($enable_auto_login) {
             OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->login(): Starting auto login', OCP\Util::DEBUG);
             // SSO attempt
             $mail_username = $username;
             $mail_password = $password;
         } else {
             OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->login(): Starting manual login', OCP\Util::DEBUG);
             $privKey = OC_RoundCube_App::getPrivateKey($username, $password);
             // Fetch credentials from data-base
             $mail_userdata_entries = OC_RoundCube_App::checkLoginData($username);
             // TODO create dropdown list
             $mail_userdata = $mail_userdata_entries[0];
             $mail_username = OC_RoundCube_App::decryptMyEntry($mail_userdata['mail_user'], $privKey);
             OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->login(): Used roundcube user: '******'mail_password'], $privKey);
         }
         // save username for displaying in later usage
         OC_RoundCube_App::setSessionVariable(OC_RoundCube_App::SESSION_ATTR_RCUSER, $mail_username);
         // login
         return OC_RoundCube_App::login($rc_host, $rc_port, $maildir, $mail_username, $mail_password);
     } catch (Exception $e) {
         // We got an exception == table not found
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_AuthHelper.class.php->login(): Login error. ' . $e, OCP\Util::ERROR);
         return false;
     }
 }
Exemplo n.º 4
0
<?php

// Init owncloud
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('roundcube');
// CSRF checks
OCP\JSON::callCheck();
$l = new OC_L10N('roundcube');
if (isset($_POST['appname']) && $_POST['appname'] == "roundcube") {
    $ocUser = OCP\User::getUser();
    $result = OC_RoundCube_App::cryptEmailIdentity($ocUser, $_POST['rc_mail_username'], $_POST['rc_mail_password']);
    if ($result) {
        // update login credentials
        $maildir = OCP\Config::getAppValue('roundcube', 'maildir', '');
        $rc_host = OCP\Config::getAppValue('roundcube', 'rcHost', '');
        if ($rc_host == '') {
            $rc_host = OC_Request::serverHost();
        }
        $rc_port = OCP\Config::getAppValue('roundcube', 'rcPort', null);
        OC_RoundCube_App::login($rc_host, $rc_port, $maildir, $_POST['rc_mail_username'], $_POST['rc_mail_password']);
    } else {
        OC_JSON::error(array("data" => array("message" => $l->t("Unable to store email credentials in the data-base."))));
        return false;
    }
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Not submitted for us."))));
    return false;
}
OCP\JSON::success(array('data' => array('message' => $l->t('Email-user credentials successfully stored.'))));
return true;