protected function getCredentials()
 {
     // 1. Try from plugin config
     $user = $this->options["USER"];
     $password = $this->options["PASS"];
     // 1BIS : encoded?
     if ($user == "" && isset($this->options["ENCODED_CREDENTIALS"])) {
         list($user, $password) = AJXP_Safe::getCredentialsFromEncodedString($this->options["ENCODED_CREDENTIALS"]);
     }
     // 2. Try from session
     if ($user == "" && isset($this->options["USE_SESSION_CREDENTIALS"])) {
         $safeCred = AJXP_Safe::loadCredentials();
         if ($safeCred !== false) {
             $user = $safeCred["user"];
             $password = $safeCred["password"];
         }
     }
     return array($user, $password);
 }
 protected function getCredentials()
 {
     // 1. Try from plugin config
     $user = $this->options["USER"];
     $password = $this->options["PASS"];
     // 1BIS : encoded?
     if ($user == "" && isset($this->options["ENCODED_CREDENTIALS"])) {
         list($user, $password) = AJXP_Safe::getCredentialsFromEncodedString($this->options["ENCODED_CREDENTIALS"]);
     }
     // 2. Try from session
     if ($user == "" && isset($this->options["USE_SESSION_CREDENTIALS"])) {
         $safeCred = AJXP_Safe::loadCredentials();
         if ($safeCred !== false) {
             $user = $safeCred["user"];
             $password = $safeCred["password"];
         } else {
             throw new Exception("Session credential are empty! Did you forget to check the Set Session Credential in the Authentication configuration panel?");
         }
     }
     return array($user, $password);
 }
Exemple #3
0
}
$optUser = $options["u"];
if (!empty($optUser)) {
    if (isset($options["p"])) {
        $optPass = $options["p"];
    } else {
        // Consider "u" is a crypted version of u:p
        $optToken = $options["t"];
        $cKey = ConfService::getCoreConf("AJXP_CLI_SECRET_KEY", "conf");
        if (empty($cKey)) {
            $cKey = "CDAFx¨op#";
        }
        $optUser = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($optToken . $cKey), base64_decode($optUser), MCRYPT_MODE_ECB), "");
        $env = getenv("AJXP_SAFE_CREDENTIALS");
        if (!empty($env)) {
            $array = AJXP_Safe::getCredentialsFromEncodedString($env);
            if (isset($array["user"]) && $array["user"] == $optUser) {
                unset($optToken);
                $optPass = $array["password"];
            }
        }
    }
    if (strpos($optUser, ",") !== false) {
        $originalOptUser = $optUser;
        $nextUsers = explode(",", $optUser);
        $optUser = array_shift($nextUsers);
        $nextUsers = implode(",", $nextUsers);
    } else {
        if (strpos($optUser, "queue:") === 0) {
            $optUserQueue = substr($optUser, strlen("queue:"));
            $optUser = false;
Exemple #4
0
 /**
  * Will try to get the credentials for a given repository as follow :
  * + Try to get the credentials from the url parsing
  * + Try to get them from the user "Wallet" (personal data)
  * + Try to get them from the repository configuration
  * + Try to get them from the AJXP_Safe.
  *
  * @param array $parsedUrl
  * @param Repository $repository
  * @return array
  */
 public static function tryLoadingCredentialsFromSources($parsedUrl, $repository)
 {
     $user = $password = "";
     $optionsPrefix = "";
     if ($repository->getAccessType() == "ftp") {
         $optionsPrefix = "FTP_";
     }
     // Get USER/PASS
     // 1. Try from URL
     if (isset($parsedUrl["user"]) && isset($parsedUrl["pass"])) {
         $user = rawurldecode($parsedUrl["user"]);
         $password = rawurldecode($parsedUrl["pass"]);
     }
     // 2. Try from user wallet
     if ($user == "") {
         $loggedUser = AuthService::getLoggedUser();
         if ($loggedUser != null) {
             $wallet = $loggedUser->getPref("AJXP_WALLET");
             if (is_array($wallet) && isset($wallet[$repository->getId()][$optionsPrefix . "USER"])) {
                 $user = $wallet[$repository->getId()][$optionsPrefix . "USER"];
                 $password = $loggedUser->decodeUserPassword($wallet[$repository->getId()][$optionsPrefix . "PASS"]);
             }
         }
     }
     // 2bis. Wallet is now a custom parameter
     if ($user == "") {
         $loggedUser = AuthService::getLoggedUser();
         if ($loggedUser != null) {
             $u = $loggedUser->mergedRole->filterParameterValue("access." . $repository->getAccessType(), $optionsPrefix . "USER", $repository->getId(), "");
             $p = $loggedUser->mergedRole->filterParameterValue("access." . $repository->getAccessType(), $optionsPrefix . "PASS", $repository->getId(), "");
             if (!empty($u) && !empty($p)) {
                 $user = $u;
                 $password = $loggedUser->decodeUserPassword($p);
             }
         }
     }
     // 3. Try from repository config
     if ($user == "") {
         $user = $repository->getOption($optionsPrefix . "USER");
         $password = $repository->getOption($optionsPrefix . "PASS");
     }
     // 4. Test if there are encoded credentials available
     if ($user == "" && $repository->getOption("ENCODED_CREDENTIALS") != "") {
         list($user, $password) = AJXP_Safe::getCredentialsFromEncodedString($repository->getOption("ENCODED_CREDENTIALS"));
     }
     // 5. Try from session
     $storeCreds = false;
     if ($repository->getOption("META_SOURCES")) {
         $options["META_SOURCES"] = $repository->getOption("META_SOURCES");
         foreach ($options["META_SOURCES"] as $metaSource) {
             if (isset($metaSource["USE_SESSION_CREDENTIALS"]) && $metaSource["USE_SESSION_CREDENTIALS"] === true) {
                 $storeCreds = true;
                 break;
             }
         }
     }
     if ($user == "" && ($repository->getOption("USE_SESSION_CREDENTIALS") || $storeCreds || self::getInstance()->forceSessionCredentials)) {
         $safeCred = AJXP_Safe::loadCredentials();
         if ($safeCred !== false) {
             $user = $safeCred["user"];
             $password = $safeCred["password"];
         }
     }
     return array("user" => $user, "password" => $password);
 }
 /**
  * Will try to get the credentials for a given repository as follow :
  * + Try to get the credentials from the url parsing
  * + Try to get them from the user "Wallet" (personal data)
  * + Try to get them from the repository configuration
  * + Try to get them from the AJXP_Safe.
  * 
  * @param array $parsedUrl
  * @param Repository $repository
  * @return array
  */
 public static function tryLoadingCredentialsFromSources($parsedUrl, $repository)
 {
     $user = $password = "";
     $optionsPrefix = "";
     if ($repository->getAccessType() == "ftp") {
         $optionsPrefix = "FTP_";
     }
     // Get USER/PASS
     // 1. Try from URL
     if (isset($parsedUrl["user"]) && isset($parsedUrl["pass"])) {
         $user = rawurldecode($parsedUrl["user"]);
         $password = rawurldecode($parsedUrl["pass"]);
     }
     // 2. Try from user wallet
     if ($user == "") {
         $loggedUser = AuthService::getLoggedUser();
         if ($loggedUser != null) {
             $wallet = $loggedUser->getPref("AJXP_WALLET");
             if (is_array($wallet) && isset($wallet[$repository->getId()][$optionsPrefix . "USER"])) {
                 $user = $wallet[$repository->getId()][$optionsPrefix . "USER"];
                 $password = $loggedUser->decodeUserPassword($wallet[$repository->getId()][$optionsPrefix . "PASS"]);
             }
         }
     }
     // 3. Try from repository config
     if ($user == "") {
         $user = $repository->getOption($optionsPrefix . "USER");
         $password = $repository->getOption($optionsPrefix . "PASS");
     }
     // 4. Test if there are encoded credentials available
     if ($user == "" && $repository->getOption("ENCODED_CREDENTIALS") != "") {
         list($user, $password) = AJXP_Safe::getCredentialsFromEncodedString($repository->getOption("ENCODED_CREDENTIALS"));
     }
     // 5. Try from session
     if ($user == "" && ($repository->getOption("USE_SESSION_CREDENTIALS") || self::getInstance()->forceSessionCredentials)) {
         $safeCred = AJXP_Safe::loadCredentials();
         if ($safeCred !== false) {
             $user = $safeCred["user"];
             $password = $safeCred["password"];
         }
     }
     return array("user" => $user, "password" => $password);
 }