Hash: $hash" : ""; //'.$h_hash.' if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { print("Trace: "); $t = array_reverse($e->getTrace()); foreach ($t as $n => $f) { $c = $f['class'] ?? ''; $t = $f['type'] ?? ''; $a = implode(", ", array_map("Shimmie2\stringer", $f['args'] ?? [])); print("$n: {$f['file']}({$f['line']}): {$c}{$t}{$f['function']}({$a})\n"); } print("Message: $message\n"); if (is_a($e, DatabaseException::class)) { print("Query: {$e->query}\n"); print("Args: ".var_export($e->args, true)."\n"); } print("Version: $version (on $phpver)\n"); } else { $query = is_a($e, DatabaseException::class) ? $e->query : null; $code = is_a($e, SCoreException::class) ? $e->http_code : 500; $q = ""; if(is_a($e, DatabaseException::class)) { $q .= "
Query: " . html_escape($query); $q .= "
Args: " . html_escape(var_export($e->args, true)); } if ($code >= 500) { error_log("Shimmie Error: $message (Query: $query)\n{$e->getTraceAsString()}"); } header("HTTP/1.0 $code Error"); echo '
Message: '.html_escape($message).' '.$q.'
Version: '.$version.' (on '.$phpver.')
Stack Trace:
'.$e->getTraceAsString().''; } } function _get_user(): User { global $config, $page; $my_user = null; if (isset($_SERVER['HTTP_AUTHORIZATION'])) { $parts = explode(" ", $_SERVER['HTTP_AUTHORIZATION'], 2); if (count($parts) == 2 && $parts[0] == "Bearer") { $parts = explode(":", $parts[1], 2); if (count($parts) == 2) { $my_user = User::by_session($parts[0], $parts[1]); } } } if (is_null($my_user) && $page->get_cookie("user") && $page->get_cookie("session")) { $my_user = User::by_session($page->get_cookie("user"), $page->get_cookie("session")); } if (is_null($my_user)) { $my_user = User::by_id($config->get_int("anon_id", 0)); } assert(!is_null($my_user)); return $my_user; } function _get_query(): string { // if query is explicitly set, use it $q = @$_POST["q"] ?: @$_GET["q"]; if(!empty($q)) { return $q; } // if we're just looking at index.php, use the default query elseif (str_contains($_SERVER['REQUEST_URI'], "index.php")) { return "/"; } // otherwise, use the request URI else { return explode("?", $_SERVER['REQUEST_URI'])[0]; } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * HTML Generation * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /** * Give a HTML string which shows an IP (if the user is allowed to see IPs), * and a link to ban that IP (if the user is allowed to ban IPs) * * FIXME: also check that IP ban ext is installed */ function show_ip(string $ip, string $ban_reason): string { global $user; $u_reason = url_escape($ban_reason); $u_end = url_escape("+1 week"); $ban = $user->can(Permissions::BAN_IP) ? ", Ban" : ""; $ip = $user->can(Permissions::VIEW_IP) ? $ip.$ban : ""; return $ip; } /** * Make a form tag with relevant auth token and stuff */ function make_form(string $target, string $method = "POST", bool $multipart = false, string $form_id = "", string $onsubmit = ""): string { global $user; if ($method == "GET") { $link = html_escape($target); $target = make_link($target); $extra_inputs = ""; } else { $extra_inputs = $user->get_auth_html(); } $extra = empty($form_id) ? '' : 'id="'. $form_id .'"'; if ($multipart) { $extra .= " enctype='multipart/form-data'"; } if ($onsubmit) { $extra .= ' onsubmit="'.$onsubmit.'"'; } return '