connect_error ) { die_500( "Connection failed: " . $mysql -> connect_error ); } function print_important_trace_components($call) { return substr($call['file'], strlen(BASE)+1) . '(' . $call['line'] . ')'; } function mysql_log_duration_and_trace($start) { $start = round((microtime(true) - $start) * 1000000); $trace = debug_backtrace(); array_shift($trace); // silently fail if logfile is unavailable /* if (($fp = fopen(BASE . '/log', 'a')) !== false) { flock($fp, LOCK_EX); fwrite($fp, date('Y-m-d H:i:s') . " " . $start . " " . implode(' ', array_map('print_important_trace_components', $trace)) . " - " . $trace[0]['args'][0] . "\n" ); flock($fp, LOCK_UN); fclose($fp); } */ } function mysql_run_query($query) { global $mysql; $start = microtime(true); if ( ! $result = $mysql -> query($query) ) die_500( "Query failed: " . $mysql -> error ); mysql_log_duration_and_trace($start); return $result; } function mysql_prepare_query($query) { global $mysql; $start = microtime(true); if ( ! $result = $mysql -> prepare($query) ) die_500( "Prepare failed: " . $mysql -> error ); mysql_log_duration_and_trace($start); return $result; } function show_warning_on_offline_slave() { if (gethostname() != 'buildmaster.archlinux32.org') { $result = mysql_run_query("SHOW STATUS LIKE \"Slave_running\""); if (($result -> num_rows == 0) || ($result -> fetch_assoc() ["Value"] != "ON")) { print "
The replication slave is currently not running. The database might be outdated.
\n"; } } } function mysql_url_encode($input) { return "REPLACE(" . $input . ",\"+\",\"%2B\")"; } function mysql_query_package_version($table) { return "CONCAT(" . "IF(" . "`" .$table . "`.`epoch`=\"0\"," . "\"\"," . "CONCAT(" . "`" . $table . "`.`epoch`," . "\":\"" . ")" . ")," . "`" . $table . "`.`pkgver`,\"-\"," . "`" . $table . "`.`pkgrel`," . "IF(`" . $table . "`.`sub_pkgrel_omitted`," . "\"\"," . "CONCAT(" . "\".\"," . "`" . $table . "`.`sub_pkgrel`" . ")" . ")" . ")"; } function arch_filter_query($table) { $arch_filter="`" . $table . "`.`name` IN (\"\""; foreach (explode("&", $_SERVER["QUERY_STRING"]) as $param) { if (strpos($param, "arch=")!==0) continue; $arch_filter .= ",from_base64(\"" . base64_encode(substr($param,5)) . "\")"; } $arch_filter .= ")"; return $arch_filter; } function abort_iff_webspider() { $is_a_bot = in_array( $_SERVER['HTTP_USER_AGENT'], array( '', 'Googlebot-Image/1.0', 'Linguee Bot (http://www.linguee.com/bot; bot@linguee.com)', 'Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)', 'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)', 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)', "'Mozilla/5.0 (compatible; DuckDuckBot-Https/1.1; https://duckduckgo.com/duckduckbot)'", 'Mozilla/5.0 (compatible; FemtosearchBot/1.0; http://femtosearch.com)', 'Mozilla/5.0 (compatible; Qwantify/2.4w; +https://www.qwant.com/)/2.4w', 'Mozilla/5.0 (compatible; SeznamBot/3.2; +http://napoveda.seznam.cz/en/seznambot-intro/)', 'Mozilla/5.0 (Compatible; Supybot 2019.02.23)', 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)', 'Mozilla/5.0 (compatible; Yeti/1.1; +http://naver.me/spd)', 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', 'ZoominfoBot (zoominfobot at zoominfo dot com)' ) ); if (($fp = fopen(BASE . '/user-agent-log', 'a')) !== false) { flock($fp, LOCK_EX); fwrite($fp, date('Y-m-d H:i:s') . " " . ($is_a_bot ? 'bot' : 'human') . " " . $_SERVER['HTTP_USER_AGENT'] . "\n" ); flock($fp, LOCK_UN); fclose($fp); } if ($is_a_bot) { include_once BASE . "/lib/http.php"; throw_http_error(403, 'Forbidden', 'Access forbidden for bots'); } }