X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/9680dd584c26031ebe3c4e70b1e9440e9e79755b..6745a128c318e72b520545f54de46ec6e43f6a82:/api/installation.php diff --git a/api/installation.php b/api/installation.php index ccc25b9..45b3919 100644 --- a/api/installation.php +++ b/api/installation.php @@ -1,50 +1,34 @@ "Configuration file exists."])); -$method; -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 == "rpc") -{ - if (isset($tls_verify)) - { - if ($tls_verify == "false") - $tls_verify = false; - elseif ($tls_verify == "true") - $tls_verify = true; - } - try { - $rpc = new UnrealIRCd\Connection - ( - "wss://$host:$port", - "$user:$password", - ["tls_verify" => $tls_verify] - ); - } - catch (Exception $e) - { - die(json_encode(["error" => "Unable to connect to UnrealIRCd: ".$e->getMessage()])); - } - die(json_encode(["success" => "Successfully connected"])); -} -elseif ($method == "sql") +if ($_POST['method'] == "sql") { - $conn = mysqli_connect($host, $user, $password, $database); + 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()])); - // 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"])); + // close connection + mysqli_close($conn); + die(json_encode(["success" => "SQL Connection successful"])); -} \ No newline at end of file +}