2022-01-11 18:54:32 +00:00
< ? php
2022-01-11 14:09:00 +00:00
2022-01-11 18:54:32 +00:00
use DevCoder\DotEnv ;
use PHPMailer\PHPMailer\Exception ;
use PHPMailer\PHPMailer\PHPMailer ;
2022-01-11 15:12:48 +00:00
2022-01-11 18:54:32 +00:00
require 'dotenv.php' ;
require 'phpmailer/Exception.php' ;
require 'phpmailer/PHPMailer.php' ;
require 'phpmailer/SMTP.php' ;
2022-01-11 15:12:48 +00:00
2022-01-11 18:54:32 +00:00
( new DotEnv ( dirname ( __FILE__ , 3 ) . " /.env " )) -> load ();
2022-01-11 15:12:48 +00:00
2022-01-11 13:09:20 +00:00
include ( " functions.php " );
2022-01-11 18:54:32 +00:00
if ( isset ( $_POST [ 'checkDB' ])) {
$values = [
//SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)
" DB_HOST " => " databasehost " ,
" DB_DATABASE " => " database " ,
" DB_USERNAME " => " databaseuser " ,
" DB_PASSWORD " => " databaseuserpass " ,
" DB_PORT " => " databaseport " ,
" DB_CONNECTION " => " databasedriver "
];
2022-01-11 13:09:20 +00:00
2022-01-11 18:54:32 +00:00
$db = new mysqli ( $_POST [ " databasehost " ], $_POST [ " databaseuser " ], $_POST [ " databaseuserpass " ], $_POST [ " database " ], $_POST [ " databaseport " ]);
if ( $db -> connect_error ) {
2022-02-08 07:13:13 +00:00
wh_log ( $db -> connect_error );
2022-01-11 18:54:32 +00:00
header ( " LOCATION: index.php?step=2&message=Could not connect to the Database " );
die ();
}
2022-01-11 13:09:20 +00:00
2022-01-11 18:54:32 +00:00
foreach ( $values as $key => $value ) {
$param = $_POST [ $value ];
2022-01-24 11:12:50 +00:00
# if ($key == "DB_PASSWORD") {
# $param = '"' . $_POST[$value] . '"';
# }
2022-01-11 18:54:32 +00:00
setEnvironmentValue ( $key , $param );
}
2022-01-20 08:26:46 +00:00
header ( " LOCATION: index.php?step=2.5 " );
2022-01-11 13:09:20 +00:00
2022-01-11 18:54:32 +00:00
}
2022-01-11 13:09:20 +00:00
2022-01-11 13:15:09 +00:00
2022-01-11 18:54:32 +00:00
if ( isset ( $_POST [ 'checkGeneral' ])) {
2022-01-11 14:09:00 +00:00
2022-01-11 18:54:32 +00:00
$appname = '"' . $_POST [ 'name' ] . '"' ;
$appurl = $_POST [ 'url' ];
2022-01-11 14:09:00 +00:00
2022-01-11 18:54:32 +00:00
if ( substr ( $appurl , - 1 ) === " / " ) {
$appurl = substr_replace ( $appurl , " " , - 1 );
}
2022-01-11 14:09:00 +00:00
2022-01-11 18:54:32 +00:00
setEnvironmentValue ( " APP_NAME " , $appname );
setEnvironmentValue ( " APP_URL " , $url );
2022-01-11 14:09:00 +00:00
2022-01-11 18:54:32 +00:00
header ( " LOCATION: index.php?step=4 " );
}
2022-01-24 11:25:30 +00:00
if ( isset ( $_POST [ 'feedDB' ])) {
2022-01-20 08:26:46 +00:00
$logs = " " ;
2022-01-24 11:12:50 +00:00
#$logs .= run_console(putenv('COMPOSER_HOME=' . dirname(__FILE__, 3) . '/vendor/bin/composer'));
#$logs .= run_console('composer install --no-dev --optimize-autoloader');
$logs .= run_console ( 'php artisan migrate --seed --force' );
$logs .= run_console ( 'php artisan db:seed --class=ExampleItemsSeeder --force' );
2022-02-07 14:44:59 +00:00
if ( strpos ( getEnvironmentValue ( " APP_KEY " ), 'base64' ) === false ) {
$logs .= run_console ( 'php artisan key:generate --force' );
} else {
$logs .= " Key already exists. Skipping \n " ;
}
2022-01-24 11:12:50 +00:00
$logs .= run_console ( 'php artisan storage:link' );
2022-02-08 07:13:13 +00:00
wh_log ( $logs );
2022-01-24 11:12:50 +00:00
2022-01-26 12:04:12 +00:00
if ( strpos ( getEnvironmentValue ( " APP_KEY " ), 'base64' ) !== false ) {
2022-01-24 11:12:50 +00:00
header ( " LOCATION: index.php?step=3 " );
} else {
2022-02-15 15:05:46 +00:00
header ( " LOCATION: index.php?step=2.5&message=There was an error. Please check the .txt file in /var/www/controlpanel/public/install/logs ! " );
2022-01-24 11:12:50 +00:00
}
2022-01-20 08:26:46 +00:00
}
2022-01-11 18:54:32 +00:00
if ( isset ( $_POST [ 'checkSMTP' ])) {
2022-01-24 11:12:50 +00:00
2022-01-11 18:54:32 +00:00
try {
2022-01-11 14:09:00 +00:00
$mail = new PHPMailer ( true );
//Server settings
$mail -> isSMTP (); // Send using SMTP
2022-01-11 18:54:32 +00:00
$mail -> Host = $_POST [ 'host' ]; // Set the SMTP server to send through
$mail -> SMTPAuth = true ; // Enable SMTP authentication
$mail -> Username = $_POST [ 'user' ]; // SMTP username
$mail -> Password = $_POST [ 'pass' ]; // SMTP password
2022-01-11 14:09:00 +00:00
$mail -> SMTPSecure = PHPMailer :: ENCRYPTION_STARTTLS ; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
2022-01-11 18:54:32 +00:00
$mail -> Port = $_POST [ 'port' ]; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS`
2022-01-11 14:09:00 +00:00
//Recipients
$mail -> setFrom ( $_POST [ 'user' ], $_POST [ 'user' ]);
2022-01-11 18:54:32 +00:00
$mail -> addAddress ( $_POST [ 'user' ], $_POST [ 'user' ]); // Add a recipient
2022-01-11 14:09:00 +00:00
// Content
$mail -> isHTML ( true ); // Set email format to HTML
$mail -> Subject = 'It Worked!' ;
2022-01-11 18:54:32 +00:00
$mail -> Body = " Your E-Mail Settings are correct! " ;
2022-01-11 14:09:00 +00:00
$mail -> send ();
2022-01-11 18:54:32 +00:00
} catch ( Exception $e ) {
header ( " LOCATION: index.php?step=4&message=Something wasnt right when sending the E-Mail! " );
die ();
2022-01-11 14:09:00 +00:00
}
2022-01-24 11:12:50 +00:00
$db = new mysqli ( getEnvironmentValue ( " DB_HOST " ), getEnvironmentValue ( " DB_USERNAME " ), getEnvironmentValue ( " DB_PASSWORD " ), getEnvironmentValue ( " DB_DATABASE " ), getEnvironmentValue ( " DB_PORT " ));
if ( $db -> connect_error ) {
2022-02-08 07:13:13 +00:00
wh_log ( $db -> connect_error );
header ( " LOCATION: index.php?step=4&message=Could not connect to the Database: " );
2022-01-24 11:12:50 +00:00
die ();
}
2022-01-11 18:54:32 +00:00
$values = [
2022-01-24 11:12:50 +00:00
" SETTINGS::MAIL:MAILER " => $_POST [ " method " ],
" SETTINGS::MAIL:HOST " => $_POST [ " host " ],
" SETTINGS::MAIL:PORT " => $_POST [ " port " ],
" SETTINGS::MAIL:USERNAME " => $_POST [ " user " ],
" SETTINGS::MAIL:PASSWORD " => $_POST [ " pass " ],
" SETTINGS::MAIL:ENCRYPTION " => $_POST [ " encryption " ],
" SETTINGS::MAIL:FROM_ADDRESS " => $_POST [ " user " ]
2022-01-11 18:54:32 +00:00
];
foreach ( $values as $key => $value ) {
2022-01-24 11:12:50 +00:00
$query = " UPDATE ` " . getEnvironmentValue ( " DB_DATABASE " ) . " `.`settings` SET `value` = ' $value ' WHERE (`key` = ' $key ') " ;
$db -> query ( $query );
2022-01-11 18:54:32 +00:00
}
2022-01-24 11:12:50 +00:00
2022-01-11 18:54:32 +00:00
header ( " LOCATION: index.php?step=5 " );
}
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 {
2022-01-24 11:12:50 +00:00
$query1 = " UPDATE ` " . getEnvironmentValue ( " DB_DATABASE " ) . " `.`settings` SET `value` = ' $url ' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:URL') " ;
$query2 = " UPDATE ` " . getEnvironmentValue ( " DB_DATABASE " ) . " `.`settings` SET `value` = ' $key ' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN') " ;
2022-01-11 18:54:32 +00:00
2022-01-20 08:26:46 +00:00
$db = new mysqli ( getEnvironmentValue ( " DB_HOST " ), getEnvironmentValue ( " DB_USERNAME " ), getEnvironmentValue ( " DB_PASSWORD " ), getEnvironmentValue ( " DB_DATABASE " ), getEnvironmentValue ( " DB_PORT " ));
2022-01-11 18:54:32 +00:00
if ( $db -> connect_error ) {
2022-02-08 07:13:13 +00:00
wh_log ( $db -> connect_error );
2022-01-11 18:54:32 +00:00
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 {
2022-02-08 07:13:13 +00:00
wh_log ( $db -> error );
2022-01-11 18:54:32 +00:00
header ( " LOCATION: index.php?step=5&message=Something went wrong when communicating with the Database! " );
}
}
}
if ( isset ( $_POST [ 'createUser' ])) {
2022-01-20 08:26:46 +00:00
$db = new mysqli ( getEnvironmentValue ( " DB_HOST " ), getEnvironmentValue ( " DB_USERNAME " ), getEnvironmentValue ( " DB_PASSWORD " ), getEnvironmentValue ( " DB_DATABASE " ), getEnvironmentValue ( " DB_PORT " ));
2022-01-11 18:54:32 +00:00
if ( $db -> connect_error ) {
2022-02-08 07:13:13 +00:00
wh_log ( $db -> connect_error );
2022-01-11 18:54:32 +00:00
header ( " LOCATION: index.php?step=6&message=Could not connect to the Database " );
die ();
}
$pteroID = $_POST [ 'pteroID' ];
$pass = $_POST [ 'pass' ];
$repass = $_POST [ 'repass' ];
2022-01-24 11:12:50 +00:00
$key = $db -> query ( " SELECT `value` FROM ` " . getEnvironmentValue ( " DB_DATABASE " ) . " `.`settings` WHERE `key` = 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN' " ) -> fetch_assoc ();
$pterobaseurl = $db -> query ( " SELECT `value` FROM ` " . getEnvironmentValue ( " DB_DATABASE " ) . " `.`settings` WHERE `key` = 'SETTINGS::SYSTEM:PTERODACTYL:URL' " ) -> fetch_assoc ();
2022-01-11 18:54:32 +00:00
$pteroURL = $pterobaseurl [ " value " ] . " /api/application/users/ " . $pteroID ;
$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 [ " value " ]
));
$response = curl_exec ( $ch );
$result = json_decode ( $response , true );
curl_close ( $ch ); // Close the connection
2022-02-09 06:54:03 +00:00
if ( ! $result [ " attributes " ][ " email " ]) {
header ( " LOCATION: index.php?step=6&message=Could not find the user with pterodactyl ID " . $pteroID );
2022-01-11 18:54:32 +00:00
die ();
}
if ( $pass !== $repass ) {
header ( " LOCATION: index.php?step=6&message=The Passwords did not match! " );
die ();
}
2022-02-09 06:54:03 +00:00
$mail = $result [ " attributes " ][ " email " ];
$name = $result [ " attributes " ][ " username " ];
2022-01-11 18:54:32 +00:00
$pass = password_hash ( $pass , PASSWORD_DEFAULT );
$pteroURL = $pterobaseurl [ " value " ] . " /api/application/users/ " . $pteroID ;
$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 [ " value " ]
));
curl_setopt ( $ch , CURLOPT_POSTFIELDS , array (
" email " => $mail ,
" username " => $name ,
" first_name " => $name ,
" last_name " => $name ,
" password " => $pass
));
$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 ();
}
2022-02-09 06:54:03 +00:00
2022-01-24 11:12:50 +00:00
$query1 = " INSERT INTO ` " . getEnvironmentValue ( " DB_DATABASE " ) . " `.`users` (`name`, `role`, `credits`, `server_limit`, `pterodactyl_id`, `email`, `password`, `created_at`) VALUES (' $name ', 'admin', '250', '1', ' $pteroID ', ' $mail ', ' $pass ', CURRENT_TIMESTAMP) " ;
2022-01-11 18:54:32 +00:00
if ( $db -> query ( $query1 )) {
2022-02-09 06:54:03 +00:00
wh_log ( " [USER MAKER] Created user with Email " . $mail . " and pterodactyl ID " . $pteroID );
2022-01-11 18:54:32 +00:00
header ( " LOCATION: index.php?step=7 " );
} else {
2022-02-08 07:13:13 +00:00
wh_log ( $db -> error );
header ( " LOCATION: index.php?step=6&message=Something went wrong when communicating with the Database " );
2022-01-24 11:12:50 +00:00
2022-01-11 18:54:32 +00:00
}
}
?>