16 include_once (
"WHAT/Lib.Common.php");
23 include_once (
'Class.Action.php');
24 include_once (
'Class.Application.php');
25 include_once (
'Class.Session.php');
26 include_once (
'Lib.Http.php');
27 include_once (
'Lib.Phpini.php');
28 include_once (
'Class.Log.php');
29 include_once (
'Class.DbObj.php');
37 $_GET[
"app"] =
"CORE";
38 if (!empty(
$_SERVER[
"FREEDOM_ACCESS"])) {
39 $_GET[
"app"] =
$_SERVER[
"FREEDOM_ACCESS"];
43 $_GET[
"action"] =
"INVALID";
47 if (isset(
$auth->auth_session)) {
48 $session =
$auth->auth_session;
52 else $sess_num = GetHttpVars(Session::PARAMNAME);
53 if (!$session->Set($sess_num)) {
54 print "<strong>:~((</strong>";
64 $core->SetSession($session);
66 if ($defaultapp &&
$core->GetParam(
"CORE_START_APP")) {
67 $_GET[
"app"] =
$core->GetParam(
"CORE_START_APP");
86 if (substr(
$_SERVER[
'REQUEST_URI'], 0, 6) ==
"http:/") {
87 $aquest = parse_url(
$_SERVER[
'REQUEST_URI']);
88 $aquest[
'host'] =
$appl->machine;
91 $puburl =
"http://" .
$appl->machine .
$_SERVER[
'REQUEST_URI'];
94 Header(
"Location: $puburl");
100 if (
$appl->ssl ==
"Y") {
104 Header(
"Location: $sslurl");
108 $core->SetVolatileParam(
"CORE_BGCOLOR",
$core->GetParam(
"CORE_SSLBGCOLOR"));
116 $core_lang =
$auth->getSessionVar(
'CORE_LANG');
117 if ($core_lang !=
'') {
118 $action->setParamU(
'CORE_LANG', $core_lang);
119 $auth->setSessionVar(
'CORE_LANG',
'');
122 $core->SetVolatileParam(
"CORE_BASICAUTH",
'&authtype=basic');
123 }
else $core->SetVolatileParam(
"CORE_BASICAUTH",
'');
134 $pos = mb_strpos($url,
'://');
135 return mb_substr($url, 0, $pos + 3) . preg_replace(
'/\/+/u',
'/', mb_substr($url, $pos + 3));
145 foreach ($explorerP as $ep) {
146 $app->SetVolatileParam($ep, $defaultValue);
148 if (!empty(
$_SERVER[
"HTTP_HOST"])) {
173 $nav = isset(
$_SERVER[
'HTTP_USER_AGENT']) ?
$_SERVER[
'HTTP_USER_AGENT'] :
'';
174 $pos = strpos($nav,
"MSIE");
175 if ($app->session->Read(
"navigator",
"") ==
"") {
176 if ($pos !==
false) {
177 $app->session->Register(
"navigator",
"EXPLORER");
178 if (preg_match(
"/MSIE ([0-9.]+).*/", $nav, $reg)) {
179 $app->session->Register(
"navversion", $reg[1]);
182 $app->session->Register(
"navigator",
"NETSCAPE");
183 if (preg_match(
"|([a-zA-Z]+)/([0-9.]+).*|", $nav, $reg)) {
184 $app->session->Register(
"navversion", $reg[2]);
194 $ISAPPLEWEBKIT =
false;
197 if (preg_match(
'/MSIE ([0-9]+).*/', $nav, $match)) {
219 } elseif (preg_match(
'|\bAppleWebKit/(.*?)\b|', $nav, $match)) {
220 $ISAPPLEWEBKIT =
true;
221 if (preg_match(
'|\bChrome/(.*?)\b|', $nav, $match)) {
223 } elseif (preg_match(
'|\bSafari/(.*?)\b|', $nav, $match)) {
228 $app->SetVolatileParam(
"ISIE", ($app->session->read(
"navigator") ==
"EXPLORER"));
229 $app->SetVolatileParam(
"ISIE6", ($ISIE6 ===
true));
230 $app->SetVolatileParam(
"ISIE7", ($ISIE7 ===
true));
231 $app->SetVolatileParam(
"ISIE8", ($ISIE8 ===
true));
232 $app->SetVolatileParam(
"ISIE9", ($ISIE9 ===
true));
233 $app->SetVolatileParam(
"ISIE10", ($ISIE10 ===
true));
234 $app->SetVolatileParam(
"ISAPPLEWEBKIT", ($ISAPPLEWEBKIT ===
true));
235 $app->SetVolatileParam(
"ISSAFARI", ($ISSAFARI ===
true));
236 $app->SetVolatileParam(
"ISCHROME", ($ISCHROME ===
true));
246 if (php_sapi_name() ==
'cli') {
256 $puburl = $core->GetParam(
"CORE_PUBURL",
"http://" . $hostname .
"/freedom");
258 $absindex = $core->GetParam(
"CORE_URLINDEX");
259 if ($absindex ==
'') {
260 $absindex =
"$puburl/";
264 $core_mailaction = $core->
getParam(
"CORE_MAILACTION");
265 $core_mailactionurl = ($core_mailaction !=
'') ? ($core_mailaction) : ($core_externurl .
"?app=FDL&action=OPENDOC&mode=view");
267 $core->SetVolatileParam(
"CORE_EXTERNURL", $core_externurl);
268 $core->SetVolatileParam(
"CORE_PUBURL",
".");
269 $core->SetVolatileParam(
"CORE_ABSURL", $puburl .
"/");
270 $core->SetVolatileParam(
"CORE_JSURL",
"WHAT/Layout");
271 $core->SetVolatileParam(
"CORE_ROOTURL",
"$absindex?sole=R&");
272 $core->SetVolatileParam(
"CORE_BASEURL",
"$absindex?sole=A&");
273 $core->SetVolatileParam(
"CORE_SBASEURL",
"$absindex?sole=A&");
274 $core->SetVolatileParam(
"CORE_STANDURL",
"$absindex?sole=Y&");
275 $core->SetVolatileParam(
"CORE_SSTANDURL",
"$absindex?sole=Y&");
276 $core->SetVolatileParam(
"CORE_ASTANDURL",
"$absindex?sole=Y&");
277 $core->SetVolatileParam(
"CORE_MAILACTIONURL", $core_mailactionurl);
282 $indexphp = basename(
$_SERVER[
"SCRIPT_NAME"]);
283 $pattern = preg_quote($indexphp,
"|");
284 if (preg_match(
"|(.*)/$pattern|",
$_SERVER[
'SCRIPT_NAME'], $reg)) {
287 if (
$_SERVER[
'HTTPS'] !=
'on') $puburl =
"http://" .
$_SERVER[
'SERVER_NAME'] .
":" .
$_SERVER[
'SERVER_PORT'] . $reg[1];
288 else $puburl =
"https://" .
$_SERVER[
'SERVER_NAME'] .
":" .
$_SERVER[
'SERVER_PORT'] . $reg[1];
291 print "<strong>:~(</strong>";
295 if (array_key_exists(
'authtype',
$_GET)) {
296 $add_args.=
"&authtype=" .
$_GET[
'authtype'];
299 $urlindex = $core->
getParam(
"CORE_URLINDEX");
301 $core_mailaction = $core->
getParam(
"CORE_MAILACTION");
302 $core_mailactionurl = ($core_mailaction !=
'') ? ($core_mailaction) : ($core_externurl .
"?app=FDL&action=OPENDOC&mode=view");
304 $sessKey = isset($session->id) ? $session->getUKey(
getParam(
"WVERSION")) : uniqid(
getParam(
"WVERSION"));
305 $core->SetVolatileParam(
"CORE_EXTERNURL", $core_externurl);
306 $core->SetVolatileParam(
"CORE_PUBURL",
".");
307 $core->SetVolatileParam(
"CORE_ABSURL",
stripUrlSlahes($puburl .
"/"));
308 $core->SetVolatileParam(
"CORE_JSURL",
"WHAT/Layout");
309 $core->SetVolatileParam(
"CORE_ROOTURL",
"?sole=R$add_args&");
310 $core->SetVolatileParam(
"CORE_BASEURL",
"?sole=A$add_args&");
311 $core->SetVolatileParam(
"CORE_SBASEURL",
"?sole=A&_uKey_=$sessKey$add_args&");
312 $core->SetVolatileParam(
"CORE_STANDURL",
"?sole=Y$add_args&");
313 $core->SetVolatileParam(
"CORE_SSTANDURL",
"?sole=Y&_uKey_=$sessKey$add_args&");
314 $core->SetVolatileParam(
"CORE_ASTANDURL",
"$puburl/$indexphp?sole=Y$add_args&");
315 $core->SetVolatileParam(
"CORE_MAILACTIONURL", $core_mailactionurl);
325 $standalone = GetHttpVars(
"sole",
"Y");
326 if ($standalone !=
"A") {
328 else echo (
$action->execute());
330 if ((isset(
$action->parent)) && (
$action->parent->with_frame !=
"Y")) {
340 $head->
set(
"TITLE", _(
$action->parent->short_name));
357 else echo (
$action->execute());
364 $uid = posix_getuid();
366 throw new \Dcp\Exception(sprintf(
"Error: this script must NOT be run as root (uid 0).\n"));
368 if (($owner = fileowner(
$file)) ===
false) {
369 throw new \Dcp\Exception(sprintf(
"Error: could not get owner of file '%s'.\n",
$file));
371 if ($owner !== $uid) {
373 Error: current uid %d does not match owner %d of file
'%s'.
375 You might need to either:
376 - run the script under the webserver
's user;
377 - or set proper ownership of context's files to that of the webserver
's user.
380 throw new \Dcp\Exception(sprintf($msg, $uid, $owner, $file));
387 function handleActionException($e)
391 if (php_sapi_name() !== "cli") {
392 if (method_exists($e, "addHttpHeader")) {
396 if ($e->getHttpHeader()) {
397 header($e->getHttpHeader());
399 header("HTTP/1.1 500 Dynacase Uncaught Exception");
402 header("HTTP/1.1 500 Dynacase Uncaught Exception");
406 $displayMsg = \Dcp\Core\LogException::logMessage($e, $errId);
407 if (isset($action) && is_a($action, '
Action') && isset($action->parent)) {
409 if ($action->parent->name === ApplicationParameterManager::getParameterValue("CORE", "CORE_START_APP")) {
410 $action->parent->session->Close();
411 $action->exitError(_("You don't have access to any content. Please contact your administrator.
"));
414 if (php_sapi_name() === 'cli') {
415 fwrite(STDERR, sprintf("[%s]: %
s\n", $errId, $displayMsg));
417 $action->exitError($displayMsg, true, $errId);
421 if (php_sapi_name() === 'cli') {
422 fwrite(STDERR, sprintf("[%s]: %
s\n", $errId, $displayMsg));
424 print htmlspecialchars(sprintf("[%s]: %
s\n", $errId, $displayMsg));
430 function isInteractiveCLI()
432 if (php_sapi_name() !== 'cli') {
435 if (function_exists('posix_isatty')) {
436 return (posix_isatty(STDIN) || posix_isatty(STDOUT) || posix_isatty(STDERR));
441 function _wsh_send_error($errMsg, $expand = array())
444 $wshError = new Dcp\WSHMailError($action, $errMsg);
445 $wshError->prefix = sprintf('%s %s ', date('c') , php_uname('n'));
446 $wshError->addExpand($expand);
447 $wshError->autosend();
457 function _wsh_exception_handler($e, $callStack = true)
459 if ($callStack === true) {
460 $errMsg = \Dcp\Core\LogException::formatErrorLogException($e);
463 $errMsg = $e->getMessage();
466 if (!isInteractiveCLI()) {
468 'm' => preg_replace('/^([^\n]*).*/s', '\1', $e->getMessage())
470 _wsh_send_error($errMsg, $expand);
476 function _wsh_shutdown_handler()
480 $error = error_get_last();
481 if ($error === null) {
486 switch ($error["
type"]) {
488 $title = "Runtime Error
";
492 $title = "Startup Error
";
496 $title = "Parse Error
";
499 case E_COMPILE_ERROR:
500 $title = "Compile Error
";
503 case E_RECOVERABLE_ERROR:
504 $title = "Recoverable Error
";
513 $pid> Dynacase $title
516 if (php_sapi_name() == 'cli' && is_array($argv)) {
517 $errMsg.= sprintf("\n%s> Command line arguments: %s
", $pid, join(' ', array_map("escapeshellarg
", $argv)));
518 $errMsg.= sprintf("\n%s> error_log: %s
", $pid, ini_get('error_log'));
523 $pid> Type: ${error['type']}
524 $pid> Message: ${error['message']}
525 $pid> File: ${error['file']}
526 $pid> Line: ${error['line']}
530 if (!isInteractiveCLI()) {
532 'm' => preg_replace('/^([^\n]*).*/s', '\1', $error['message'])
534 _wsh_send_error($errMsg, $expand);
538 function enable_wsh_safetybelts()
548 function formatErrorLogException($e)
550 return \Dcp\Core\LogException::formatErrorLogException($e);
555 function errorLogException($e)
557 \Dcp\Core\LogException::writeLog($e);
560 function handleFatalShutdown()
564 $error = error_get_last();
566 if ($error !== NULL && $action) {
568 if (in_array($error["
type"], array(
577 if (!headers_sent()) {
578 header("HTTP/1.1 500 Dynacase Fatal Error
");
581 $displayMsg = \Dcp\Core\LogException::logMessage($error, $errId);
583 $action->exitError($displayMsg, false, $errId);
587 // Fatal error are already logged by PHP
593 set_exception_handler('handleActionException');
Layout is a template generator.
getParam($key, $default="")
if(ActionRouter::inMaintenance()) $auth
static setCoreApplication(\Application $coreApplication)
_wsh_exception_handler($e, $callStack=true)
initMainVolatileParam(Application &$core, Session &$session=null)
initExplorerParam(Application &$app, $defaultValue=false)
_initMainVolatileParamCli(Application &$core)
executeAction(&$action, &$out=null)
_initMainVolatileParamWeb(Application &$core, Session &$session=null)
getParam($name, $def="")
must be in core or global type
getMainAction($auth, &$action)
getHttpVars($name, $def="", $scope="all")
initExplorerWebParam(Application &$app)
getExplorerParamtersName()
if($file) if($subject==""&&$file) if($subject=="") $err