Add detection and error handling for extensions like pdo_mysql

This commit is contained in:
ruan 2018-07-29 08:48:13 +02:00
parent c4afc1399f
commit 120bfd1a07
No known key found for this signature in database
GPG Key ID: 0D2EC1C52E469C0B
5 changed files with 67 additions and 15 deletions

View File

@ -28,7 +28,7 @@ class Check {
if (!isset($uuid)) {
if (filter_var($name, FILTER_VALIDATE_FLOAT)) {
echo "<br>";
$page->settings->redirect("info.php?id=$name&type=$type", false);
redirect("info.php?id=$name&type=$type", false);
return;
}
$name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
@ -42,7 +42,7 @@ class Check {
}
echo "<br>";
$page->settings->redirect($href, false);
redirect($href, false);
/*
$table = $page->settings->table['bans'];

View File

@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<title>litebans-php - Missing Extensions</title>
<link href="../inc/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="jumbotron">
<h2>Missing Extensions</h2><br>
<div class="text-warning">
The following PHP extensions are required by litebans-php but were not found:
<br>
<?php if (!extension_loaded("pdo_mysql")) {
echo "- <a class=\"text-danger\">pdo_mysql</a>";
} ?>
<?php
ob_start();
phpinfo();
$phpinfo = array('phpinfo' => array());
if (preg_match_all('#(?:<h2>(?:<a name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?: class=".*?")?><t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>)?)?</tr>)#s', ob_get_clean(), $matches, PREG_SET_ORDER))
foreach ($matches as $match)
if (strlen($match[1]))
$phpinfo[$match[1]] = array();
elseif (isset($match[3]))
$phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3];
else
$phpinfo[end(array_keys($phpinfo))][] = $match[2];
echo "These extensions can be enabled in php.ini.<br>";
echo "php.ini location: <a class=\"text-info\">" . $phpinfo['phpinfo']["Loaded Configuration File"] . "</a>";
?>
</div>
<br>
<a href="../" class="btn btn-default">Try Again</a>
</div>
</div>
</body>
</html>

12
inc/init.php Normal file
View File

@ -0,0 +1,12 @@
<?php
function redirect($url, $showtext = true) {
if ($showtext === true) {
echo "<a href=\"$url\">Redirecting...</a>";
}
die("<script data-cfasync=\"false\" type=\"text/javascript\">document.location=\"$url\";</script>");
}
if (!extension_loaded("pdo_mysql")) {
redirect("error/missing-extensions.php");
}

View File

@ -1,4 +1,5 @@
<?php
require_once './inc/init.php';
class Page {
public function __construct($name, $header = true) {

View File

@ -165,7 +165,7 @@ final class Settings {
$this->driver = $driver;
if ($connect) {
if ($username === "" && $password === "") {
$this->redirect("error/unconfigured.php");
redirect("error/unconfigured.php");
}
$host = $this->host;
$port = $this->port;
@ -212,9 +212,9 @@ final class Settings {
if ($settings->error_pages) {
if (strstr($message, "Access denied for user")) {
if ($settings->error_reporting) {
$settings->redirect("error/access-denied.php?error=" . base64_encode($message));
redirect("error/access-denied.php?error=" . base64_encode($message));
} else {
$settings->redirect("error/access-denied.php");
redirect("error/access-denied.php");
}
}
if (strstr($message, "Base table or view not found:")) {
@ -223,12 +223,12 @@ final class Settings {
$st->fetch();
$st->closeCursor();
} catch (PDOException $e) {
$settings->redirect("error/tables-not-found.php");
redirect("error/tables-not-found.php");
}
$settings->redirect("error/outdated-plugin.php");
redirect("error/outdated-plugin.php");
}
if (strstr($message, "Unknown column")) {
$settings->redirect("error/outdated-plugin.php");
redirect("error/outdated-plugin.php");
}
}
if ($settings->error_reporting === false) {
@ -238,13 +238,6 @@ final class Settings {
}
function redirect($url, $showtext = true) {
if ($showtext === true) {
echo "<a href=\"$url\">Redirecting...</a>";
}
echo "<script data-cfasync=\"false\" type=\"text/javascript\">document.location=\"$url\";</script>";
die;
}
private function test_strftime() {
// If you modify this function, you may get an "Assertion failed" error.