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("stringer", $f['args'])); print("$n: {$f['file']}({$f['line']}): {$c}{$t}{$f['function']}({$a})\n"); } print("Message: $message\n"); if (isset($e->query)) { print("Query: {$e->query}\n"); } print("Version: $version (on $phpver)\n"); } else { $q = (!isset($e->query) || is_null($e->query)) ? "" : "
Query: " . html_escape($e->query); header("HTTP/1.0 500 Internal Error"); echo '
Message: '.html_escape($message).' '.$q.'
Version: '.$version.' (on '.$phpver.') '; } } function _get_user(): User { global $config, $page; $my_user = null; if ($page->get_cookie("user") && $page->get_cookie("session")) { $tmp_user = User::by_session($page->get_cookie("user"), $page->get_cookie("session")); if (!is_null($tmp_user)) { $my_user = $tmp_user; } } 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 { return (@$_POST["q"]?:@$_GET["q"])?:"/"; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Things used in the installer + unit tests * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function create_dirs() { $data_exists = file_exists("data") || mkdir("data"); $data_writable = is_writable("data") || chmod("data", 0755); if (!$data_exists || !$data_writable) { throw new InstallerException( "Directory Permissions Error:", "
Shimmie needs to have a 'data' folder in its directory, writable by the PHP user.
If you see this error, if probably means the folder is owned by you, and it needs to be writable by the web server.
PHP reports that it is currently running as user: ".$_ENV["USER"]." (". $_SERVER["USER"] .")
Once you have created this folder and / or changed the ownership of the shimmie folder, hit 'refresh' to continue.
", 7 ); } } function create_tables(Database $db) { try { if ($db->count_tables() > 0) { throw new InstallerException( "Warning: The Database schema is not empty!", "Please ensure that the database you are installing Shimmie with is empty before continuing.
Once you have emptied the database of any tables, please hit 'refresh' to continue.
", 2 ); } $db->create_table("aliases", " oldtag VARCHAR(128) NOT NULL, newtag VARCHAR(128) NOT NULL, PRIMARY KEY (oldtag) "); $db->execute("CREATE INDEX aliases_newtag_idx ON aliases(newtag)", []); $db->create_table("config", " name VARCHAR(128) NOT NULL, value TEXT, PRIMARY KEY (name) "); $db->create_table("users", " id SCORE_AIPK, name VARCHAR(32) UNIQUE NOT NULL, pass VARCHAR(250), joindate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, class VARCHAR(32) NOT NULL DEFAULT 'user', email VARCHAR(128) "); $db->execute("CREATE INDEX users_name_idx ON users(name)", []); $db->execute("INSERT INTO users(name, pass, joindate, class) VALUES(:name, :pass, now(), :class)", ["name" => 'Anonymous', "pass" => null, "class" => 'anonymous']); $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", ["name" => 'anon_id', "value" => $db->get_last_insert_id('users_id_seq')]); if (check_im_version() > 0) { $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", ["name" => 'thumb_engine', "value" => 'convert']); } $db->create_table("images", " id SCORE_AIPK, owner_id INTEGER NOT NULL, owner_ip SCORE_INET NOT NULL, filename VARCHAR(64) NOT NULL, filesize INTEGER NOT NULL, hash CHAR(32) UNIQUE NOT NULL, ext CHAR(4) NOT NULL, source VARCHAR(255), width INTEGER NOT NULL, height INTEGER NOT NULL, posted TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT "); $db->execute("CREATE INDEX images_owner_id_idx ON images(owner_id)", []); $db->execute("CREATE INDEX images_width_idx ON images(width)", []); $db->execute("CREATE INDEX images_height_idx ON images(height)", []); $db->execute("CREATE INDEX images_hash_idx ON images(hash)", []); $db->create_table("tags", " id SCORE_AIPK, tag VARCHAR(64) UNIQUE NOT NULL, count INTEGER NOT NULL DEFAULT 0 "); $db->execute("CREATE INDEX tags_tag_idx ON tags(tag)", []); $db->create_table("image_tags", " image_id INTEGER NOT NULL, tag_id INTEGER NOT NULL, UNIQUE(image_id, tag_id), FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE "); $db->execute("CREATE INDEX images_tags_image_id_idx ON image_tags(image_id)", []); $db->execute("CREATE INDEX images_tags_tag_id_idx ON image_tags(tag_id)", []); $db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)"); $db->commit(); } catch (PDOException $e) { throw new InstallerException( "PDO Error:", "An error occurred while trying to create the database tables necessary for Shimmie.
Please check and ensure that the database configuration options are all correct.
{$e->getMessage()}
", 3 ); } } function write_config() { $file_content = "<" . "?php\ndefine('DATABASE_DSN', '".DATABASE_DSN."');\n"; if (!file_exists("data/config")) { mkdir("data/config", 0755, true); } if (file_put_contents("data/config/shimmie.conf.php", $file_content, LOCK_EX)) { header("Location: index.php"); print <<If you aren't redirected, click here to Continue.
Once done, click here to Continue.", 0 ); } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Code coverage * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function _start_coverage(): void { if (function_exists("xdebug_start_code_coverage")) { #xdebug_start_code_coverage(XDEBUG_CC_UNUSED|XDEBUG_CC_DEAD_CODE); xdebug_start_code_coverage(XDEBUG_CC_UNUSED); } } function _end_coverage(): void { if (function_exists("xdebug_get_code_coverage")) { // Absolute path is necessary because working directory // inside register_shutdown_function is unpredictable. $absolute_path = dirname(dirname(__FILE__)) . "/data/coverage"; if (!file_exists($absolute_path)) { mkdir($absolute_path); } $n = 0; $t = time(); while (file_exists("$absolute_path/$t.$n.log")) { $n++; } file_put_contents("$absolute_path/$t.$n.log", gzdeflate(serialize(xdebug_get_code_coverage()))); } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * 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 '