diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/.htaccess | 1 | ||||
-rw-r--r-- | lib/http.php | 18 | ||||
-rw-r--r-- | lib/mysql.php | 26 |
3 files changed, 45 insertions, 0 deletions
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>"; + } +} |