check for pterodactyl

This commit is contained in:
1Day 2022-01-11 16:12:48 +01:00
parent 94513db2c9
commit f589f26e23
3 changed files with 156 additions and 0 deletions

48
public/install/dotenv.php Normal file
View file

@ -0,0 +1,48 @@
<?php
namespace DevCoder;
class DotEnv
{
/**
* The directory where the .env file can be located.
*
* @var string
*/
protected $path;
public function __construct(string $path)
{
if(!file_exists($path)) {
throw new \InvalidArgumentException(sprintf('%s does not exist', $path));
}
$this->path = $path;
}
public function load() :void
{
if (!is_readable($this->path)) {
throw new \RuntimeException(sprintf('%s file is not readable', $this->path));
}
$lines = file($this->path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) {
continue;
}
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value);
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
putenv(sprintf('%s=%s', $name, $value));
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
}
}

View file

@ -2,10 +2,16 @@
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
use DevCoder\DotEnv;
require 'dotenv.php';
require 'phpmailer/Exception.php';
require 'phpmailer/PHPMailer.php';
require 'phpmailer/SMTP.php';
(new DotEnv(dirname(__FILE__,3)."/.env"))->load();
include("functions.php");
if(isset($_POST['checkDB'])){
@ -104,6 +110,52 @@ if(isset($_POST['checkSMTP'])){
}
if(isset($_POST['checkPtero'])){
$url = $_POST['url'];
$key = $_POST['key'];
if(substr($url, -1)==="/"){
$url = substr_replace($url ,"", -1);
}
$pteroURL = $url."/api/application/users";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pteroURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Content-Type: application/json",
"Authorization: Bearer " . $key
));
$response = curl_exec($ch);
$result = json_decode($response, true);
curl_close($ch); // Close the connection
if(!is_array($result) or in_array($result["errors"][0]["code"],$result)){
header("LOCATION: index.php?step=5&message=Couldnt connect to Pterodactyl. Make sure your API key has all read and write permissions!");
die();
}else{
$query1= "UPDATE `dashboard`.`settings` SET `value` = '$url' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:URL')";
$query2= "UPDATE `dashboard`.`settings` SET `value` = '$key' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN')";
$db = new mysqli(getenv("DB_HOST"), getenv("DB_USERNAME"), getenv("DB_PASSWORD"), getenv("DB_DATABASE"), getenv("DB_PORT"));
if ($db->connect_error) {
header("LOCATION: index.php?step=5&message=Could not connect to the Database");
die();
}
if($db->query($query1) && $db->query($query2)){
header("LOCATION: index.php?step=6");
}else{
header("LOCATION: index.php?step=5&message=Something went wrong when communicating with the Database!");
}
}
}
?>

View file

@ -282,6 +282,62 @@ if (isset($_GET['step']) && $_GET['step']==4){
</div>
</div>
</div>
<?php
}
if (isset($_GET['step']) && $_GET['step']==5){
if (isset($_GET['exec'])){
shell_exec('php artisan migrate --seed --force');
}
?>
<div class="card card-outline card-primary">
<div class="card-header text-center">
<b class="mr-1">Controlpanel.GG</b>
</div>
<div class="card-body">
<p class="login-box-msg">Almost done! </p>
<p class="login-box-msg">Lets get some info about your Pterodactyl Installation!</p>
<p class="login-box-msg">Before this Step make sure you ran <b>php artisan migrate --seed --force</b> in your Linux Terminal!</p>
<a href="?step=5&exec"><button class="btn btn-success">You can also try to click here</button></a>
<?php if(isset($_GET['message'])){
echo "<p class='notok'>".$_GET['message']."</p>";
}
?>
<form method="POST" enctype="multipart/form-data" class="mb-3"
action="/install/forms.php" name="checkPtero">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div class="custom-control mb-3">
<label for="url">Pterodactyl URL</label>
<input id="url" name="url"
type="text" required
value="" class="form-control">
</div>
</div>
<div class="form-group">
<div class="custom-control mb-3">
<label for="key">Pterodactyl API-Key</label>
<input id="key" name="key" type="text"
required
value="" class="form-control" placeholder="The Key needs ALL read&write Permissions!">
</div>
</div>
</div>
<button class="btn btn-primary" name="checkPtero">Submit</button>
</div>
</div>
</div>
</div>
<?php