X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/c06c1713af2db485d55a91073bbc5b63b6aa8c0b..67bff06aa6fd4d7d3a9aefc2919307326fa6d755:/api/installation.php diff --git a/api/installation.php b/api/installation.php index 76711f3..45b3919 100644 --- a/api/installation.php +++ b/api/installation.php @@ -8,21 +8,27 @@ require_once "../inc/common.php"; if (file_exists("../config/config.php")) die(json_encode(["error" => "Configuration file exists."])); -if (!isset($_GET) || empty($_GET)) +if (!isset($_POST) || empty($_POST)) die(json_encode(["error" => "Incorrect parameters"])); -foreach($_GET as $key => $str) - ${$key} = $str; -if ($method == "sql") +if ($_POST['method'] == "sql") { - $conn = mysqli_connect($host, $user, $password, $database); - - // check connection - if (mysqli_connect_errno()) - die(json_encode(["error" => "Failed to connect to MySQL: " . mysqli_connect_error()])); - - // close connection - mysqli_close($conn); - die(json_encode(["success" => "SQL Connection successful"])); + try { + $conn = mysqli_connect($_POST['host'], $_POST['user'], $_POST['password'], $_POST['database']); + } catch(Exception $e) + { + } + // check connection + if (mysqli_connect_errno()) + die(json_encode(["error" => "Failed to connect to MySQL: " . mysqli_connect_error()])); + + $sql = "SHOW TABLES LIKE '".$conn->real_escape_string($_POST['table_prefix'])."%'"; // SQL query to check if table exists + $result = $conn->query($sql); + if ($result->num_rows > 0) + die(json_encode(["warn" => "Database already has data"])); + + // close connection + mysqli_close($conn); + die(json_encode(["success" => "SQL Connection successful"])); }