Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-04-17 09:36:08 +0200
committerErich Eckner <git@eckner.net>2018-04-17 09:36:08 +0200
commit8af016645fee5c0b22e69d46de9b3401c1bc82d3 (patch)
tree992acf6649f005c3d6891d767a5509fdbb91024b
parent951d045cb95cc8e0d07c97104a2b9a5e9ea5ffc8 (diff)
lib/ new
-rw-r--r--buildmaster/build-list.php39
-rw-r--r--lib/.htaccess1
-rw-r--r--lib/http.php18
-rw-r--r--lib/mysql.php26
-rw-r--r--packages/pkginfo.php12
5 files changed, 68 insertions, 28 deletions
diff --git a/buildmaster/build-list.php b/buildmaster/build-list.php
index d576019..966c5b5 100644
--- a/buildmaster/build-list.php
+++ b/buildmaster/build-list.php
@@ -1,7 +1,7 @@
-<html>
-<head>
<?php
+include "lib/mysql.php";
+
if (isset($_GET["show"]))
$to_show=$_GET["show"];
else
@@ -14,21 +14,9 @@ elseif ($to_show == "broken")
elseif ($to_show == "next")
$match = "";
else
- die();
-
-print "<title>List of " . $to_show . " package builds</title>\n";
-print "<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/style.css\">\n";
-print "</head>\n";
-print "<body>\n";
-print "<a href=\"https://buildmaster.archlinux32.org/\">Start page</a>\n";
-print "<a href=\"https://buildmaster.archlinux32.org/build-logs/\">build logs</a><br>\n";
+ die_500("Unknown parameter for \"show\".");
-$mysql = new mysqli("localhost", "webserver", "empty", "buildmaster");
-if ($mysql->connect_error) {
- die("Connection failed: " . $mysql->connect_error);
-}
-
-$result = $mysql -> query(
+$result = mysql_run_query(
"SELECT DISTINCT " .
"`build_assignments`.`id`," .
"`build_assignments`.`is_blocked`," .
@@ -65,6 +53,7 @@ $result = $mysql -> query(
"LEFT JOIN `build_slaves` ON `build_slaves`.`currently_building`=`build_assignments`.`id` " .
"WHERE `repositories`.`name`=\"build-list\"" . $match
);
+
if ($result -> num_rows > 0) {
$count = 0;
@@ -76,7 +65,7 @@ if ($result -> num_rows > 0) {
($row["dependencies_pending"]==1))
continue;
- $fail_result = $mysql -> query(
+ $fail_result = mysql_run_query(
"SELECT " .
"`fail_reasons`.`name`, " .
"`failed_builds`.`log_file` " .
@@ -167,6 +156,22 @@ if ($result -> num_rows > 0) {
$count++;
}
+}
+
+?>
+<html>
+<head>
+<?php
+
+print "<title>List of " . $to_show . " package builds</title>\n";
+print "<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/style.css\">\n";
+print "</head>\n";
+print "<body>\n";
+print "<a href=\"https://buildmaster.archlinux32.org/\">Start page</a>\n";
+print "<a href=\"https://buildmaster.archlinux32.org/build-logs/\">build logs</a><br>\n";
+
+if ($count > 0) {
+
usort(
$rows,
function (array $a, array $b) {
diff --git a/lib/.htaccess b/lib/.htaccess
new file mode 100644
index 0000000..3a42882
--- /dev/null
+++ b/lib/.htaccess
@@ -0,0 +1 @@
+Deny from all
diff --git a/lib/http.php b/lib/http.php
new file mode 100644
index 0000000..5fe87dc
--- /dev/null
+++ b/lib/http.php
@@ -0,0 +1,18 @@
+<?php
+
+
+# do not include twice
+if (function_exists("throw_http_error"))
+ return;
+
+function throw_http_error($error_number, $error_message, $extra_message = "") {
+ header("Status: " . $error_number . " " . $error_message);
+ print "Error " . $error_number . ": " . $error_message . "\n";
+ if ($extra_message != "")
+ print "<br>\n" . $extra_message;
+ die();
+};
+
+function die_500($message) {
+ throw_http_error(500, "Internal Server Error", $message);
+};
diff --git a/lib/mysql.php b/lib/mysql.php
new file mode 100644
index 0000000..a5edbd5
--- /dev/null
+++ b/lib/mysql.php
@@ -0,0 +1,26 @@
+<?php
+
+# do not include twice
+if (isset($mysql))
+ return;
+
+include "lib/http.php";
+
+$mysql = new mysqli("localhost", "webserver", "empty", "buildmaster");
+if ( $mysql -> connect_error ) {
+ die_500( "Connection failed: " . $mysql -> connect_error );
+}
+
+function mysql_run_query($query) {
+ global $mysql;
+ if ( ! $result = $mysql -> query($query) )
+ die_500( "Query failed: " . $mysql -> error );
+ return $result;
+}
+function show_warning_on_offline_slave() {
+ $result = mysql_run_query("SHOW STATUS LIKE \"Slave_running\"");
+ if (($result -> num_rows == 0) ||
+ ($result -> fetch_assoc() ["Value"] != "ON")) {
+ print "<div><font color=\"fff0000\">The replication slave is currently not running. The database might be outdated.</font></div>";
+ }
+}
diff --git a/packages/pkginfo.php b/packages/pkginfo.php
index 3b31a71..366d0eb 100644
--- a/packages/pkginfo.php
+++ b/packages/pkginfo.php
@@ -1,16 +1,6 @@
<?php
- function throw_http_error($error_number, $error_message, $extra_message = "") {
- header("Status: " . $error_number . " " . $error_message);
- print "Error " . $error_number . ": " . $error_message . "\n";
- if ($extra_message != "")
- print "<br>\n" . $extra_message;
- die();
- };
-
- function die_500($message) {
- throw_http_error(500, "Internal Server Error", $message);
- };
+ include "lib/mysql.php";
$json_content = json_decode(
file_get_contents(