You are not logged in! Failed to run command.
"; return simplexml_load_string('' . $tmp . ''; ob_flush(); flush(); } } } } // Look for serverdone response $fullpattern = '/
xCAT submit request socket error: $errno - $errstr
"; } // Flush (send) the output buffer and turn off output buffering ob_end_flush(); // Close syslog closelog(); if (!$cleanexit) { if (preg_match('/^\s*(Error) xCAT response ended prematurely: ", htmlentities($response), "
"; $rsp = FALSE; } } return $rsp; } /** * Enable password storage to split between cookie and session variable */ function xorcrypt($data, $key) { $datalen = strlen($data); $keylen = strlen($key); for ($i=0;$i<$datalen;$i++) { $data[$i] = chr(ord($data[$i])^ord($key[$i])); } return $data; } /** * Get password */ function getpassword() { if (isset($GLOBALS['xcatauthsecret'])) { $cryptext = $GLOBALS['xcatauthsecret']; } else if (isset($_COOKIE["xcatauthsecret"])) { $cryptext = $_COOKIE["xcatauthsecret"]; } else { return false; } return xorcrypt($_SESSION["secretkey"], base64_decode($cryptext)); } /** * Get the password splitting knowledge between server and client side persistant storage. * Caller should regenerate session ID when contemplating a new user/password, * to preclude session fixation, though fixation is limited without the secret. * * @param $password Password */ function setpassword($password) { $randlen = strlen($password); $key = getrandchars($randlen); $cryptext = xorcrypt($password,$key); // Non-ascii characters, encode it in base64 $cryptext = base64_encode($cryptext); setcookie("xcatauthsecret",$cryptext,0,'/'); $GLOBALS["xcatauthsecret"] = $cryptext; $_SESSION["secretkey"] = $key; } /** * Get RAND characters * * @param $length Length of characters * @return RAND characters */ function getrandchars($length) { $charset = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*'; $charsize = strlen($charset); srand(); $chars = ''; for ($i=0;$i<$length;$i++) { $num=rand()%$charsize; $chars=$chars.substr($charset,$num,1); } return $chars; } /** * Determine if a user/password session exists * * @return True if user has a session, false otherwise */ function is_logged() { if (isset($_SESSION["username"]) and !is_bool(getpassword())) { return true; } else { return false; } } /** * Determine if a user is currently logged in successfully * * @return True if the user is currently logged in successfully, false otherwise */ function isAuthenticated() { if (is_logged()) { if ($_SESSION["xcatpassvalid"] != 1) { $testcred = docmd("authcheck", "", NULL, NULL); if (isset($testcred->{'xcatresponse'}->{'data'})) { $result = "".$testcred->{'xcatresponse'}->{'data'}; if (is_numeric(strpos("Authenticated",$result))) { // Logged in successfully $_SESSION["xcatpassvalid"] = 1; } else { // Not logged in $_SESSION["xcatpassvalid"] = 0; } } } } if (isset($_SESSION["xcatpassvalid"]) and $_SESSION["xcatpassvalid"]==1) { return true; } else { return false; } } /** * Determine if a user has root access * * @return True if the user has root access, false otherwise */ function isRootAcess() { if (is_logged() && $_SESSION["xcatpassvalid"]) { $testacc = docmd('tabdump', '', array('policy', '-w', "name==" . $_SESSION["username"]), array()); if (isset($testacc->{'xcatresponse'}->{'data'}->{1})) { $result = $testacc->{'xcatresponse'}->{'data'}->{1}; $result = str_replace('"', '', $result); $args = array(); $args = explode(",", $result); // Get the comments which contains the privilege $comments = $args[8]; $args = explode(";", $comments); // Default privilege is guest $privilege = 'guest'; $_SESSION["xcatpassvalid"] = 0; foreach ($args as $arg) { // Get user privilege if ($arg && is_numeric(strpos($arg, "privilege"))) { if (is_numeric(strpos($arg, "root"))) { // Set privilege to root $privilege = 'root'; $_SESSION["xcatpassvalid"] = 1; } break; } } } } if (strcmp($_SESSION["username"], 'root') == 0) { $_SESSION["xcatpassvalid"] = 1; } if (isset($_SESSION["xcatpassvalid"]) and $_SESSION["xcatpassvalid"]==1) { return true; } else { return false; } } /** * Log out of current user session */ function logout() { // Clear the secret cookie from browser if (isset($_COOKIE["xcatauthsecret"])) { setcookie("xcatauthsecret",'',time()-86400*7,'/'); } // Expire session cookie if (isset($_COOKIE[session_name()])) { setcookie(session_name(),"",time()-86400*7,"/"); } // Clear server store of data $_SESSION=array(); } /** * Format a given string and echo it back to the browser */ function format_TBD($str) { // Format a given string however you want it echo $tmp . '