/** * Logout the user form the current symfony application and from the * CAS server * @param boolean $onlyLocal Set it to true, to logout from the application, but stay login in the CAS */ public function logout($url = null, $onlyLocal = false) { parent::signOut(); $this->username = null; if (!$onlyLocal) { sfCAS::initPhpCAS(); if (!empty($url)) { phpCAS::logoutWithUrl($url); } else { phpCas::logout(); } } }
/** * Class EcasPhpCASParser * @param \DOMElement $root XML element coming from phpCAS * @return array Attributes * @see \phpCAS */ public function parse(\DOMElement $root) { phpCAS::trace('Found attribute ' . $root->nodeName); $result = array(); if ($root->hasAttributes()) { $attrs = $root->attributes; foreach ($attrs as $attr) { if ($attr->name == 'number') { continue; } phpCAS::trace('Additional attribute ' . $attr->name . ' : ' . $attr->value); $result['@attributes'][$attr->name] = $attr->value; } } if ($root->hasChildNodes()) { $children = $root->childNodes; if ($children->length == 1) { $child = $children->item(0); if ($child->nodeType == XML_TEXT_NODE) { $result['_value'] = $child->nodeValue; return count($result) == 1 ? $result['_value'] : $result; } } $groups = array(); foreach ($children as $child) { $nodeName = str_replace('cas:', '', $child->nodeName); phpCAS::traceBegin(); if ($nodeName == 'groups') { $result['groups'] = array(); phpCas::traceBegin(); foreach ($child->childNodes as $groupChild) { $result['groups'][] = $this->parse($groupChild); } phpCAS::traceEnd('Parsed groups'); } elseif (!isset($result[$nodeName])) { $result[$nodeName] = $this->parse($child); } else { if (!isset($groups[$nodeName])) { $result[$nodeName] = array($result[$nodeName]); $groups[$nodeName] = 1; } $result[$nodeName][] = $this->parse($child); } phpCAS::traceEnd(); } } return $result; }
<?php require_once "./cas/phpCAS-master/CAS.php"; require_once "config.example.php"; phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_context); phpCAS::setNoCasServerValidation(); if (isset($_REQUEST['logout'])) { $_SESSION['cas'] = "yes"; phpCAS::logoutWithRedirectService("https://osr-etudiant.unistra.fr/~r.henry/aCalendar/"); } if (phpCAS::checkAuthentication()) { $_SESSION['user'] = phpCas::getUser(); $_SESSION['cas'] = "yes"; header('Location: ../index.php'); } else { phpCAS::forceAuthentication(); } //echo phpCAS::logoutWithRedirectService('inscription.php'); // ?> <!--<!<?php //if (isset($erreur)) echo '<br /><br />',$erreur; //if(isset($_POST['connexion']) && $_POST['connexion'] == 'Connexion'){ //if((isset($_POST['login']) && isset($_POST['pass'])) && (!empty($_POST['login']) && !empty($_POST['pass']))) //{ //$base = new PDO('mysql:host=localhost;dbname=test', 'root', '') ; //or die("Erreur".mysql_error($base)); //mysqli_select_db ('test', $base); //$sql = 'select count(*) from membre where login="******" and //pass_md5="'. $base->quote($_POST['pass']).'"'; //$requete= $base->query($sql) or die('Erreur sql !'.$sql.mysql_error());
/** * This method will parse the DOM and pull out the attributes from the XML * payload and put them into an array, then put the array into the session. * * @param string $success_elements payload of the response * * @return bool true when successfull, halt otherwise by calling * CAS_Client::_authError(). */ private function _readExtraAttributesCas20($success_elements) { phpCAS::traceBegin(); $extra_attributes = array(); // "Jasig Style" Attributes: // // <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> // <cas:authenticationSuccess> // <cas:user>jsmith</cas:user> // <cas:attributes> // <cas:attraStyle>RubyCAS</cas:attraStyle> // <cas:surname>Smith</cas:surname> // <cas:givenName>John</cas:givenName> // <cas:memberOf>CN=Staff,OU=Groups,DC=example,DC=edu</cas:memberOf> // <cas:memberOf>CN=Spanish Department,OU=Departments,OU=Groups,DC=example,DC=edu</cas:memberOf> // </cas:attributes> // <cas:proxyGrantingTicket>PGTIOU-84678-8a9d2sfa23casd</cas:proxyGrantingTicket> // </cas:authenticationSuccess> // </cas:serviceResponse> // if ($success_elements->item(0)->getElementsByTagName("attributes")->length != 0) { $attr_nodes = $success_elements->item(0)->getElementsByTagName("attributes"); phpCas::trace("Found nested jasig style attributes"); if ($attr_nodes->item(0)->hasChildNodes()) { // Nested Attributes foreach ($attr_nodes->item(0)->childNodes as $attr_child) { phpCas::trace("Attribute [" . $attr_child->localName . "] = " . $attr_child->nodeValue); $this->_addAttributeToArray($extra_attributes, $attr_child->localName, $attr_child->nodeValue); } } } else { // "RubyCAS Style" attributes // // <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> // <cas:authenticationSuccess> // <cas:user>jsmith</cas:user> // // <cas:attraStyle>RubyCAS</cas:attraStyle> // <cas:surname>Smith</cas:surname> // <cas:givenName>John</cas:givenName> // <cas:memberOf>CN=Staff,OU=Groups,DC=example,DC=edu</cas:memberOf> // <cas:memberOf>CN=Spanish Department,OU=Departments,OU=Groups,DC=example,DC=edu</cas:memberOf> // // <cas:proxyGrantingTicket>PGTIOU-84678-8a9d2sfa23casd</cas:proxyGrantingTicket> // </cas:authenticationSuccess> // </cas:serviceResponse> // phpCas::trace("Testing for rubycas style attributes"); $childnodes = $success_elements->item(0)->childNodes; foreach ($childnodes as $attr_node) { switch ($attr_node->localName) { case 'user': case 'proxies': case 'proxyGrantingTicket': continue; default: if (strlen(trim($attr_node->nodeValue))) { phpCas::trace("Attribute [" . $attr_node->localName . "] = " . $attr_node->nodeValue); $this->_addAttributeToArray($extra_attributes, $attr_node->localName, $attr_node->nodeValue); } } } } // "Name-Value" attributes. // // Attribute format from these mailing list thread: // http://jasig.275507.n4.nabble.com/CAS-attributes-and-how-they-appear-in-the-CAS-response-td264272.html // Note: This is a less widely used format, but in use by at least two institutions. // // <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> // <cas:authenticationSuccess> // <cas:user>jsmith</cas:user> // // <cas:attribute name='attraStyle' value='Name-Value' /> // <cas:attribute name='surname' value='Smith' /> // <cas:attribute name='givenName' value='John' /> // <cas:attribute name='memberOf' value='CN=Staff,OU=Groups,DC=example,DC=edu' /> // <cas:attribute name='memberOf' value='CN=Spanish Department,OU=Departments,OU=Groups,DC=example,DC=edu' /> // // <cas:proxyGrantingTicket>PGTIOU-84678-8a9d2sfa23casd</cas:proxyGrantingTicket> // </cas:authenticationSuccess> // </cas:serviceResponse> // if (!count($extra_attributes) && $success_elements->item(0)->getElementsByTagName("attribute")->length != 0) { $attr_nodes = $success_elements->item(0)->getElementsByTagName("attribute"); $firstAttr = $attr_nodes->item(0); if (!$firstAttr->hasChildNodes() && $firstAttr->hasAttribute('name') && $firstAttr->hasAttribute('value')) { phpCas::trace("Found Name-Value style attributes"); // Nested Attributes foreach ($attr_nodes as $attr_node) { if ($attr_node->hasAttribute('name') && $attr_node->hasAttribute('value')) { phpCas::trace("Attribute [" . $attr_node->getAttribute('name') . "] = " . $attr_node->getAttribute('value')); $this->_addAttributeToArray($extra_attributes, $attr_node->getAttribute('name'), $attr_node->getAttribute('value')); } } } } $this->setAttributes($extra_attributes); phpCAS::traceEnd(); return true; }
*****************************************************************************/ /* Set error handler to own one, initialize time calculation and start session. */ session::start(); if (isset($_REQUEST['signout']) && $_REQUEST['signout']) { if (session::global_is_set('connected')) { $config = session::global_get('config'); if ($config->get_cfg_value('casActivated') == 'TRUE') { require_once 'CAS.php'; /* Move CAS autoload before FD autoload */ spl_autoload_unregister('CAS_autoload'); spl_autoload_register('CAS_autoload', TRUE, TRUE); phpCAS::client(CAS_VERSION_2_0, $config->get_cfg_value('casHost', 'localhost'), (int) $config->get_cfg_value('casPort', 443), $config->get_cfg_value('casContext', '')); // Set the CA certificate that is the issuer of the cert phpCAS::setCasServerCACert($config->get_cfg_value('casServerCaCertPath')); phpCas::logout(); } } session::destroy(); session::start(); } /* Reset errors */ session::set('errors', ''); session::set('errorsAlreadyPosted', ''); session::set('LastError', ''); /* Check if we need to run setup */ if (!file_exists(CONFIG_DIR . '/' . CONFIG_FILE)) { header('location:setup.php'); exit; } /* Check if fusiondirectory.conf (.CONFIG_FILE) is accessible */
$arg = $version_database; $res_column = mysql2_query_secure($sql, $_SESSION['OCS']["writeServer"], $arg); $_SESSION['OCS']['SQL_BASE_VERS'] = $version_database; } else { msg_error($l->g(2114) . " " . $version_database); die; } } msg_success($l->g(1121)); echo "<br><br><br><b><a href='index.php'>" . $l->g(2051) . "</a></b>"; //Logout after update(s) //Contrib of FranciX (http://forums.ocsinventory-ng.org/viewtopic.php?pid=41923#p41923) if ($_SESSION['OCS']['cnx_origine'] == "CAS") { require_once PHPCAS; require_once BACKEND . 'require/cas.config.php'; $cas = new phpCas(); $cas->client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_uri); $cas->logout(); } //end contrib unset($_SESSION['OCS']); unset($_GET); } echo "</form>"; if (isset($_GET['debug'])) { unset($_SESSION['OCS']['DEBUG']); } require_once 'require/footer.php'; /* * function to execute sql file *
/** * This method is used to redirect the client to the CAS server. * It is used by CASClient::forceAuthentication() and CASClient::checkAuthentication(). * @param $gateway true to check authentication, false to force it * @public */ function redirectToCas($gateway = false) { $cas = new phpCas(); $cas->traceBegin(); $cas_url = $this->getServerLoginURL($gateway); header('Location: ' . $cas_url); $this->printHTMLHeader($this->getString(CAS_STR_AUTHENTICATION_WANTED)); printf('<p>' . $this->getString(CAS_STR_SHOULD_HAVE_BEEN_REDIRECTED) . '</p>', $cas_url); $this->printHTMLFooter(); $cas->traceExit(); exit; }
/** * Set phpCAS Debug */ private function setDebug() { $debug = !!$this->config['cas_debug']; if ($debug) { phpCas::setDebug(storage_path('logs/cas.log')); } }
<?php //==================================================================================== // OCS INVENTORY REPORTS // Copyleft FranciX 2010 //http://forums.ocsinventory-ng.org/viewtopic.php?pid=30974 // // This code is open source and may be copied and modified as long as the source // code is always made freely available. // Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt //==================================================================================== require_once PHPCAS; require_once BACKEND . 'require/cas.config.php'; $cas = new phpCas(); $cas->client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_uri); $cas->forceAuthentication(); $login = $cas->getUser(); $mdp = ""; if ($login) { $login_successful = "OK"; $cnx_origine = "CAS"; $user_group = "CAS"; }