This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New parameters LOCAL_PREFIX and ROLE_MAP for auth.remote plugin : map…
… CMS roles to ajaxplorer Roles. Remote plugin must pass the "role" key in the user array. Implement pagination, as the plugin is finally serial based.
- Loading branch information
Showing
5 changed files
with
250 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,154 +1,154 @@ | ||
<?php | ||
/* | ||
* Copyright 2007-2011 Charles du Jeu <contact (at) cdujeu.me> | ||
* This file is part of AjaXplorer. | ||
* | ||
* AjaXplorer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* AjaXplorer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with AjaXplorer. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* The latest code can be found at <http://www.ajaxplorer.info/>. | ||
* | ||
* This functions are necessary to implement the bridge between Ajaxplorer | ||
* and other CMS's. | ||
*/ | ||
|
||
/** | ||
* @package AjaXplorer_Plugins | ||
* @subpackage Auth | ||
* | ||
* @param HttpClient $client | ||
* @return array | ||
*/ | ||
function extractResponseCookies($client){ | ||
//AJXP_Logger::debug(print_r($client, true)); | ||
$cooks = $client->getHeader("set-cookie"); | ||
if(empty($cooks)) return array(); | ||
if(is_string($cooks)){ | ||
$cooks = array($cooks); | ||
} | ||
$cookies = array(); | ||
foreach ($cooks as $cookieString){ | ||
list($name,$value) = explode("=", $cookieString); | ||
$ar = explode(";", $value); | ||
$value = array_shift($ar); | ||
$cookies[$name] = $value; | ||
} | ||
return $cookies; | ||
} | ||
|
||
function wordpress_remote_auth($host, $uri, $login, $pass, $formId = ""){ | ||
$client = new HttpClient($host); | ||
$client->setHandleRedirects(false); | ||
$client->setHeadersOnly(true); | ||
$res = $client->post($uri."/wp-login.php", array( | ||
"log" => $login, | ||
"pwd" => $pass, | ||
"wp-submit" => "Log In", | ||
"testcookie" => 1) | ||
); | ||
$newCookies = extractResponseCookies($client); | ||
if(isSet($newCookies["AjaXplorer"])){ | ||
return $newCookies["AjaXplorer"]; | ||
} | ||
return ""; | ||
} | ||
|
||
function joomla_remote_auth($host, $uri, $login, $pass, $formId = ""){ | ||
|
||
$client = new HttpClient($host); | ||
$client->setHandleRedirects(false); | ||
$res = $client->get($uri); | ||
$content = $client->getContent(); | ||
$postData = array( | ||
"username" => $login, | ||
"password" => $pass, | ||
"Submit" => "Log in", | ||
"remember" => "yes" | ||
); | ||
$xmlDoc = @DOMDocument::loadHTML($content); | ||
if($xmlDoc === false){ | ||
$pos1 = strpos($content, "<form "); | ||
$pos2 = strpos($content, "</form>", $pos1); | ||
$content = substr($content, $pos1, $pos2 + "7" - $pos1); | ||
$xmlDoc = @DOMDocument::loadHTML($content); | ||
} | ||
if($xmlDoc !== false){ | ||
$xPath = new DOMXPath($xmlDoc); | ||
if($formId == "") $formId = "login-form"; | ||
$nodes = $xPath->query('//form[@id="'.$formId.'"]'); | ||
if(!$nodes->length) { | ||
return ""; | ||
} | ||
$form = $nodes->item(0); | ||
$postUri = $form->getAttribute("action"); | ||
$hiddens = $xPath->query('//input[@type="hidden"]', $form); | ||
foreach($hiddens as $hiddenNode){ | ||
$postData[$hiddenNode->getAttribute("name")] = $hiddenNode->getAttribute("value"); | ||
} | ||
}else{ | ||
// Grab all inputs and hardcode $postUri. | ||
if(preg_match_all("<input type=\"hidden\" name=\"(.*)\" value=\"(.*)\">", $content, $matches)){ | ||
foreach($matches[0] as $key => $match){ | ||
$postData[$matches[1][$key]] = $matches[2][$key]; | ||
} | ||
$postUri = "/login-form"; | ||
} | ||
} | ||
//AJXP_Logger::debug("Carry on ". $hiddens->length); | ||
$client->setHandleRedirects(false); | ||
$client->setHeadersOnly(true); | ||
$client->setCookies(extractResponseCookies($client)); | ||
$res2 = $client->post($postUri, $postData); | ||
$newCookies = extractResponseCookies($client); | ||
if(isSet($newCookies["AjaXplorer"])){ | ||
return $newCookies["AjaXplorer"]; | ||
} | ||
return ""; | ||
} | ||
|
||
function drupal_remote_auth($host, $uri, $login, $pass, $formId = ""){ | ||
|
||
$client = new HttpClient($host); | ||
$client->setHandleRedirects(false); | ||
$res = $client->get($uri); | ||
$content = $client->getContent(); | ||
$xmlDoc = DOMDocument::loadHTML($content); | ||
$xPath = new DOMXPath($xmlDoc); | ||
if($formId == "") $formId = "user-login-form"; | ||
$nodes = $xPath->query('//form[@id="'.$formId.'"]'); | ||
if(!$nodes->length) { | ||
return ""; | ||
} | ||
$form = $nodes->item(0); | ||
$postUri = $form->getAttribute("action"); | ||
$hiddens = $xPath->query('//input[@type="hidden"]', $form); | ||
AJXP_Logger::debug("Carry on Drupal hiddens ". $hiddens->length); | ||
$postData = array( | ||
"name" => $login, | ||
"pass" => $pass, | ||
"Submit" => "Log in" | ||
); | ||
foreach($hiddens as $hiddenNode){ | ||
$postData[$hiddenNode->getAttribute("name")] = $hiddenNode->getAttribute("value"); | ||
} | ||
$client->setHandleRedirects(false); | ||
$client->setHeadersOnly(true); | ||
$client->setCookies(extractResponseCookies($client)); | ||
$res2 = $client->post($postUri, $postData); | ||
$newCookies = extractResponseCookies($client); | ||
if(isSet($newCookies["AjaXplorer"])){ | ||
return $newCookies["AjaXplorer"]; | ||
} | ||
return ""; | ||
} | ||
<?php | ||
/* | ||
* Copyright 2007-2011 Charles du Jeu <contact (at) cdujeu.me> | ||
* This file is part of AjaXplorer. | ||
* | ||
* AjaXplorer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* AjaXplorer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with AjaXplorer. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* The latest code can be found at <http://www.ajaxplorer.info/>. | ||
* | ||
* This functions are necessary to implement the bridge between Ajaxplorer | ||
* and other CMS's. | ||
*/ | ||
|
||
/** | ||
* @package AjaXplorer_Plugins | ||
* @subpackage Auth | ||
* | ||
* @param HttpClient $client | ||
* @return array | ||
*/ | ||
function extractResponseCookies($client){ | ||
//AJXP_Logger::debug(print_r($client, true)); | ||
$cooks = $client->getHeader("set-cookie"); | ||
if(empty($cooks)) return array(); | ||
if(is_string($cooks)){ | ||
$cooks = array($cooks); | ||
} | ||
$cookies = array(); | ||
foreach ($cooks as $cookieString){ | ||
list($name,$value) = explode("=", $cookieString); | ||
$ar = explode(";", $value); | ||
$value = array_shift($ar); | ||
$cookies[$name] = $value; | ||
} | ||
return $cookies; | ||
} | ||
|
||
function wordpress_remote_auth($host, $uri, $login, $pass, $formId = ""){ | ||
$client = new HttpClient($host); | ||
$client->setHandleRedirects(false); | ||
$client->setHeadersOnly(true); | ||
$res = $client->post($uri."/wp-login.php", array( | ||
"log" => $login, | ||
"pwd" => $pass, | ||
"wp-submit" => "Log In", | ||
"testcookie" => 1) | ||
); | ||
$newCookies = extractResponseCookies($client); | ||
if(isSet($newCookies["AjaXplorer"])){ | ||
return $newCookies; | ||
} | ||
return ""; | ||
} | ||
|
||
function joomla_remote_auth($host, $uri, $login, $pass, $formId = ""){ | ||
|
||
$client = new HttpClient($host); | ||
$client->setHandleRedirects(false); | ||
$res = $client->get($uri); | ||
$content = $client->getContent(); | ||
$postData = array( | ||
"username" => $login, | ||
"password" => $pass, | ||
"Submit" => "Log in", | ||
"remember" => "yes" | ||
); | ||
$xmlDoc = @DOMDocument::loadHTML($content); | ||
if($xmlDoc === false){ | ||
$pos1 = strpos($content, "<form "); | ||
$pos2 = strpos($content, "</form>", $pos1); | ||
$content = substr($content, $pos1, $pos2 + "7" - $pos1); | ||
$xmlDoc = @DOMDocument::loadHTML($content); | ||
} | ||
if($xmlDoc !== false){ | ||
$xPath = new DOMXPath($xmlDoc); | ||
if($formId == "") $formId = "login-form"; | ||
$nodes = $xPath->query('//form[@id="'.$formId.'"]'); | ||
if(!$nodes->length) { | ||
return ""; | ||
} | ||
$form = $nodes->item(0); | ||
$postUri = $form->getAttribute("action"); | ||
$hiddens = $xPath->query('//input[@type="hidden"]', $form); | ||
foreach($hiddens as $hiddenNode){ | ||
$postData[$hiddenNode->getAttribute("name")] = $hiddenNode->getAttribute("value"); | ||
} | ||
}else{ | ||
// Grab all inputs and hardcode $postUri. | ||
if(preg_match_all("<input type=\"hidden\" name=\"(.*)\" value=\"(.*)\">", $content, $matches)){ | ||
foreach($matches[0] as $key => $match){ | ||
$postData[$matches[1][$key]] = $matches[2][$key]; | ||
} | ||
$postUri = "/login-form"; | ||
} | ||
} | ||
//AJXP_Logger::debug("Carry on ". $hiddens->length); | ||
$client->setHandleRedirects(false); | ||
$client->setHeadersOnly(true); | ||
$client->setCookies(extractResponseCookies($client)); | ||
$res2 = $client->post($postUri, $postData); | ||
$newCookies = extractResponseCookies($client); | ||
if(isSet($newCookies["AjaXplorer"])){ | ||
return $newCookies; | ||
} | ||
return ""; | ||
} | ||
|
||
function drupal_remote_auth($host, $uri, $login, $pass, $formId = ""){ | ||
|
||
$client = new HttpClient($host); | ||
$client->setHandleRedirects(false); | ||
$res = $client->get($uri); | ||
$content = $client->getContent(); | ||
$xmlDoc = DOMDocument::loadHTML($content); | ||
$xPath = new DOMXPath($xmlDoc); | ||
if($formId == "") $formId = "user-login-form"; | ||
$nodes = $xPath->query('//form[@id="'.$formId.'"]'); | ||
if(!$nodes->length) { | ||
return ""; | ||
} | ||
$form = $nodes->item(0); | ||
$postUri = $form->getAttribute("action"); | ||
$hiddens = $xPath->query('//input[@type="hidden"]', $form); | ||
AJXP_Logger::debug("Carry on Drupal hiddens ". $hiddens->length); | ||
$postData = array( | ||
"name" => $login, | ||
"pass" => $pass, | ||
"Submit" => "Log in" | ||
); | ||
foreach($hiddens as $hiddenNode){ | ||
$postData[$hiddenNode->getAttribute("name")] = $hiddenNode->getAttribute("value"); | ||
} | ||
$client->setHandleRedirects(false); | ||
$client->setHeadersOnly(true); | ||
$client->setCookies(extractResponseCookies($client)); | ||
$res2 = $client->post($postUri, $postData); | ||
$newCookies = extractResponseCookies($client); | ||
if(isSet($newCookies["AjaXplorer"])){ | ||
return $newCookies; | ||
} | ||
return ""; | ||
} | ||
?> |
Oops, something went wrong.