/** * Assist your to debug vars. Accept n vars parameters * Included Debug on ARRAY an IteratorInterface Object * * @param mixed $arg1 * @param mixed $arg2 * @param mixed $arg3 */ public static function PrintValue($arg1, $arg2 = null) { if (self::$_logger == null) { self::$_logger = new LogWrapper('debug.output'); } for ($i = 0, $numArgs = func_num_args(); $i < $numArgs; $i++) { $var = func_get_arg($i); ErrorHandler::getInstance()->addExtraInfo('DEBUG_' . Debug::$count++, $var); if (array_key_exists("raw", $_REQUEST)) { continue; } if (is_array($var)) { self::writeLog(null, print_r($var, true), true); } elseif ($var instanceof SingleRow) { self::writeLog('SingleRow', print_r($var->toArray(), true), true); } elseif ($var instanceof AnyDataset) { Debug::PrintValue($var->getIterator()); } elseif ($var instanceof IteratorInterface || $var instanceof AnyIterator) { $it = $var; if (!$it->hasNext()) { self::writeLog('IteratorInterface', "Não trouxe registros.", false); } else { $result = "<style>.devdebug {border: 1px solid silver; padding: 2px;} table.devdebug {border-collapse:collapse;} th.devdebug {background-color: silver}</style>" . "<table class='devdebug'>"; $arr = null; while ($it->hasNext()) { $i++; $sr = $it->moveNext(); if ($i > 100) { break; } if (is_null($arr)) { $arr = $sr->getFieldNames(); $result .= '<tr><th class="devdebug">' . implode('</b></th><th class="devdebug">', $arr) . '</th></tr>'; } $raw = $sr->toArray(); $result .= '<tr>'; foreach ($raw as $item) { $result .= '<td class="devdebug">'; if (is_array($item)) { $result .= implode(',', $item); } else { $result .= $item; } $result .= '</td>'; } $result .= '</tr>'; } $result .= "</table>"; self::writeLog('IteratorInterface', $result, false); } } elseif ($var instanceof IteratorFilter) { $filter = $var->getSql("ANYTABLE", $param, "*"); $filter = substr($filter, strpos($filter, "where") + 6); $result = array("XPath" => $var->getXPath(), "Filter" => $filter) + $param; self::writeLog(get_class($var), print_r($result, true), true); } elseif ($var instanceof FilenameProcessor) { $result = array("PathSuggested()" => $var->PathSuggested(), "PrivatePath()" => $var->PrivatePath(), "SharedPath()" => $var->SharedPath(), "Name" => $var->ToString(), "Extension()" => $var->Extension(), "FullQualifiedName()" => $var->FullQualifiedName(), "FullQualifiedNameAndPath()" => $var->FullQualifiedNameAndPath(), "getFilenameLocation()" => $var->getFilenameLocation(), "File Exists?" => file_exists($var->FullQualifiedNameAndPath()) ? "yes" : "no"); self::writeLog(get_class($var), print_r($result, true), true); } elseif ($var instanceof LanguageCollection) { self::writeLog("", get_class($var) . ": Is Loaded? " . ($var->loadedFromFile() ? 'yes' : 'no'), false); $var->Debug(); } elseif (is_object($var)) { if ($var instanceof DOMDocument) { $var->formatOutput = true; self::writeLog(get_class($var), htmlentities($var->saveXML()), true); } elseif ($var instanceof DOMElement || $var instanceof DOMNode) { $doc = $var->ownerDocument; $doc->formatOutput = true; echo htmlentities($doc->saveXML($var)) . "</pre>"; self::writeLog(get_class($var), htmlentities('[' . $var->nodeName . "]") . "\n" . htmlentities($doc->saveXML()), true); } else { self::writeLog(get_class($var), print_r($var, true), true); } } elseif (gettype($var) == "boolean") { self::writeLog("", '(boolean) ' . ($var ? "true" : "false"), true); } else { self::writeLog("", gettype($var) . ": " . $var, true); } } }
/** * Locate and create custom module if exists. Otherwise throw exception. * * Important: * A module must reside on a folder named 'Modules'. * You can call a module by \namespace\Modules\ModuleName or just \namespace\ModuleName * * @param string $modulename * @param object $o * @return IModule */ public static function GetModule($modulename, $o = null) { $context = Context::getInstance(); $basePath = ""; $classNameAr = explode('.', $modulename); if (strpos($modulename, '.Modules.') === false) { array_splice($classNameAr, count($classNameAr) - 1, 0, array('Modules')); } $className = '\\' . implode('\\', $classNameAr); if (class_exists($className, true)) { $result = new $className(); } else { throw new ModuleNotFoundException("Module \"{$modulename}\" not found"); } if (!$result instanceof IModule) { throw new InvalidArgumentException('Class "' . $className . '" is not a IModule object'); } // ---------------------------------------------------------- // Activate the Module // ---------------------------------------------------------- $xml = new XMLFilenameProcessor($modulename); $result->Setup($xml, $o); $urlSSL = ""; $isHttps = $context->get("HTTPS") == "on" || $context->get("HTTP_X_FORWARDED_PROTO") == "https"; $requireSSL = $result->requiresSSL(); if ($requireSSL == SSLAccess::ForcePlain && $isHttps) { $urlSSL = "http://" . $context->get("HTTP_HOST") . $context->get("REQUEST_URI"); } else { if ($requireSSL == SSLAccess::ForceSSL && !$isHttps) { $urlSSL = "https://" . $context->get("HTTP_HOST") . $context->get("REQUEST_URI"); } } $output = $result->getOutputFormat(); if ($output != null) { $context->setOutputFormat($output); ErrorHandler::getInstance()->setHandler($output); } if (strlen($urlSSL) > 0) { if ($context->get("REQUEST_METHOD") == "GET") { $context->redirectUrl($urlSSL); } else { echo "<html><body>"; echo "<div style='font-family: arial; font-size: 14px; background-color: lightblue; line-height: 24px; width: 80px; text-align: center'>Switching...</div>"; echo '<form action="' . $urlSSL . '" method="post">'; foreach ($_POST as $key => $value) { echo "<input type='hidden' name='{$key}' value='{$value}' />"; } echo "<script language='JavaScript'>document.forms[0].submit()</script>"; echo "</body></html>"; die; } } if ($result->requiresAuthentication()) { if ($result->getAuthMode() == AuthMode::Form && !$context->IsAuthenticated()) { throw new NotAuthenticatedException("You need login to access this feature"); } elseif ($result->getAuthMode() == AuthMode::HttpBasic) { $realm = 'Restricted area'; if (empty($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="' . $realm . '"'); header('HTTP/1.0 401 Unauthorized'); die('You have to provide your credentials before proceed.'); } else { $usersDb = $context->getUsersDatabase(); $users = $usersDb->getUserName($_SERVER['PHP_AUTH_USER']); if ($users == null) { header('HTTP/1.1 403 Forbiden'); die('Wrong Credentials!'); } $userTable = $usersDb->getUserTable(); // Check if Username and plain password is valid. If dont try to check if the SHA1 password is ok if (!$usersDb->isValidUser($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) { $password = $users->getField($userTable->Password); if ($password != $_SERVER['PHP_AUTH_PW']) { header('HTTP/1.1 403 Forbiden'); die('Wrong Credentials!'); } } $context->MakeLogin($users->getField($userTable->Username), $users->getField($userTable->Id)); } } elseif ($result->getAuthMode() == AuthMode::HttpDigest) { $realm = 'Restricted area'; if (empty($_SERVER['PHP_AUTH_DIGEST'])) { header('HTTP/1.1 401 Unauthorized'); header('WWW-Authenticate: Digest realm="' . $realm . '",qop="auth",nonce="' . uniqid() . '",opaque="' . md5($realm) . '"'); die('You have to provide your credentials before proceed.'); } // analyze the PHP_AUTH_DIGEST variable if (!($data = self::httpDigestParse($_SERVER['PHP_AUTH_DIGEST'])) || !isset($data['username'])) { die('Wrong Credentials!'); } // Validate if the username and password are valid $usersDb = $context->getUsersDatabase(); $users = $usersDb->getUserName($data['username']); if ($users == null) { header('HTTP/1.1 403 Forbiden'); die('Wrong Credentials!'); } $userTable = $usersDb->getUserTable(); $password = $users->getField($userTable->Password); // generate the valid response $A1 = md5($data['username'] . ':' . $realm . ':' . $password); $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']); $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2); if ($data['response'] != $valid_response) { header('HTTP/1.1 403 Forbiden'); die('Wrong Credentials!'); } // ok, valid username & password $context->MakeLogin($users->getField($userTable->Username), $users->getField($userTable->Id)); } if (!$result->accessGranted()) { $result->processInsufficientPrivilege(); } } return $result; }
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: post-check=0, pre-check=0", false); session_cache_limiter("must-revalidate"); header("Content-Type: text/html; charset=utf-8"); define("SESSION_XMLNUKE_AUTHUSER", "SESSION_XMLNUKE_AUTHUSER"); define("SESSION_XMLNUKE_AUTHUSERID", "SESSION_XMLNUKE_AUTHUSERID"); define("SESSION_XMLNUKE_USERCONTEXT", "SESSION_XMLNUKE_USERCONTEXT"); /* This main of engine */ if (!class_exists('config') && !file_exists("config.inc.php")) { die("<b>Fatal error:</b> Could not find required 'config.inc.php'"); } require_once "config.inc.php"; if (!class_exists('config')) { header("Location: check_install.php"); exit; } // Composer Autoload if (file_exists(PHPXMLNUKEDIR . 'src/vendor/autoload.php')) { require PHPXMLNUKEDIR . 'src/vendor/autoload.php'; } if (file_exists(PHPXMLNUKEDIR . '../../../autoload.php')) { require PHPXMLNUKEDIR . '../../../autoload.php'; } // XMLNuke autoload if (!is_readable(PHPXMLNUKEDIR . "src/Xmlnuke/Core/Engine/AutoLoad.php")) { die("<b>Fatal error:</b> Bad Xmlnuke configuration. Check your constant 'PHPXMLNUKEDIR'"); } $autoload = AutoLoad::getInstance(); // Error Handler ErrorHandler::getInstance()->register();