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);
 }
 function logoutCallback($actionName, $httpVars, $fileVars)
 {
     $safeCredentials = AJXP_Safe::loadCredentials();
     $crtUser = $safeCredentials["user"];
     if (isset($_SESSION["AJXP_DYNAMIC_FTP_DATA"])) {
         unset($_SESSION["AJXP_DYNAMIC_FTP_DATA"]);
     }
     AJXP_Safe::clearCredentials();
     $adminUser = $this->options["ADMIN_USER"];
     $subUsers = array();
     if ($crtUser != $adminUser && $crtUser != "") {
         AJXP_User::deleteUser($crtUser, $subUsers);
     }
     AuthService::disconnect();
     session_destroy();
     session_write_close();
     AJXP_XMLWriter::header();
     AJXP_XMLWriter::loggingResult(2);
     AJXP_XMLWriter::close();
 }
 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 #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);
 }
 protected function apiCall($method, $endpoint, $data = null)
 {
     //I think this is prettier.
     $method = strtoupper($method);
     //Get our token. If we have one.
     $token = AJXP_Safe::loadCredentials();
     $query = '';
     if ($token) {
         $query = '?private_token=' . $token['password'];
     }
     //Prepare the CURL call.
     $handle = curl_init();
     $options = array(CURLOPT_TIMEOUT => 2, CURLOPT_CONNECTTIMEOUT => 1, CURLOPT_FOLLOWLOCATION => false, CURLOPT_MAXREDIRS => 0, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => 'Pydio GitLab Auth Driver v1', CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS, CURLOPT_URL => $this->url . $this->path . $endpoint . $query);
     switch ($method) {
         case 'GET':
             break;
         case 'POST':
             $options[CURLOPT_CUSTOMREQUEST] = $method;
             $dataString = json_encode($data);
             $options[CURLOPT_POSTFIELDS] = $dataString;
             $options[CURLOPT_HTTPHEADER] = array('Content-Type: application/json; charset=UTF-8', 'Content-Length: ' . strlen($dataString));
             break;
         default:
             throw new Exception("Unknown API method '" . $method . "'.");
     }
     curl_setopt_array($handle, $options);
     //Perform the post.
     $user_data = curl_exec($handle);
     $error = curl_error($handle);
     $status = curl_getinfo($handle, CURLINFO_HTTP_CODE);
     //Done with CURL now.
     curl_close($handle);
     return (object) array('body' => json_decode($user_data), 'status' => $status, 'error' => $error);
 }
 /**
  * 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);
 }