Skip to content

Commit

Permalink
Added option for FTP details.
Browse files Browse the repository at this point in the history
  • Loading branch information
wohahobg committed Jan 9, 2024
1 parent 8511274 commit bac8ae1
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 172 deletions.
180 changes: 98 additions & 82 deletions clientarea.tpl
Original file line number Diff line number Diff line change
@@ -1,86 +1,102 @@
<div class="text-center">
<p style="padding: 0 0 2em;">
<a href="{$serviceurl}" target="_blank" class="btn btn-default">{$LANG.GOTO_PANEL}</a>
</p>
<h5 class="text-center" style="padding: 0 0 1em;">{$serverIp}</h5>
<h4 class="text-center" style="padding: 0 0 1em;">{$LANG.QUICK_ACTIONS_PANEL}</h4>
<!-- Your HTML Buttons using Smarty variables -->
<button id="startButton"
onclick="if (confirm('Are you sure you want to start this server?')) sendRequest('{$starturl}')"
class="btn btn-success" style="margin-bottom: 0.3em;" {if $current_state === 'online'} disabled{/if}><i
class="fas fa-play"></i> {$LANG.SERVER_START_PANEL}</button>
<button id="rebootButton"
onclick="if (confirm('Are you sure you want to reboot this server?')) sendRequest('{$rebooturl}')"
class="btn btn-warning" style="margin-bottom: 0.3em;" {if $current_state === 'offline'} disabled{/if}><i
class="fas fa-sync"></i> {$LANG.SERVER_RESTART_PANEL}</button>
<button id="stopButton"
onclick="if (confirm('Are you sure you want to stop this server?')) sendRequest('{$stopurl}')"
class="btn btn-danger" style="margin-bottom: 0.3em;" {if $current_state === 'offline'} disabled{/if}><i
class="fas fa-stop"></i> {$LANG.SERVER_STOP_PANEL}</button>

{if $serverFound == false}
<p class="alert alert-warning">{$LANG.SERVER_NOT_FOUND}</p>
{else}
<p class="margin-top-bottom">
<a href="{$serviceUrl}" target="_blank" class="btn btn-default">{$LANG.GOTO_PANEL}</a>
</p>
<div class="row mb-3 mb-5">
<div class="col-md-6">
<label>Server ID</label>
<input
class="form-control text-center copy-text"
aria-label="serverId"
type="text"
id="change-text-id"
data-id="change-text-id"
data-new-text="{$LANG.ID_COPIED}"
data-clipboard-text="{$serverId}"
value="{$serverId}"
readonly>
</div>
<div class="col-md-6">
<label>Server IP</label>
<input
class="form-control text-center copy-text"
id="change-text-ip"
data-id="change-text-ip"
data-new-text="{$LANG.IP_COPIED}"
data-clipboard-text="{$serverIp}"
value="{$serverIp}" readonly>
</div>
</div>
<h2 class="mb-3">{$LANG.QUICK_ACTIONS_PANEL}</h2>
<!-- Your HTML Buttons using Smarty variables -->
<button id="startButton"
onclick="if (confirm('Are you sure you want to start this server?')) sendRequest('{$startUrl}')"
class="btn btn-success" {if $current_state === 'online'} disabled{/if}><i
class="fas fa-play"></i> {$LANG.SERVER_START_PANEL}</button>
<button id="rebootButton"
onclick="if (confirm('Are you sure you want to reboot this server?')) sendRequest('{$rebootUrl}')"
class="btn btn-warning" {if $current_state === 'offline'} disabled{/if}><i
class="fas fa-sync"></i> {$LANG.SERVER_RESTART_PANEL}</button>
<button id="stopButton"
onclick="if (confirm('Are you sure you want to stop this server?')) sendRequest('{$stopUrl}')"
class="btn btn-danger" {if $current_state === 'offline'} disabled{/if}><i
class="fas fa-stop"></i> {$LANG.SERVER_STOP_PANEL}</button>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#ftpDetails">
FTP Details
</button>
<!-- The modal -->
<div class="modal fade" id="ftpDetails" tabindex="-1" role="dialog" aria-labelledby="modalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="modalLabel">
{$LANG.SERVER_FTP_INFORMATION}
</h4>
</div>
<div class="modal-body">
<div class="alert alert-warning" role="alert">
{$LANG.SERVER_FTP_PASSWORD_INFORMATION}
</div>
<!-- FTP Host + Port -->
<div class="mb-3">
<label for="ftpHost" class="form-label">
{$LANG.SERVER_FTP_HOST_AND_PORT}
</label>
<input type="text" class="form-control copy-text"
data-id="ftpHost"
data-new-text="{$LANG.SERVER_FTP_HOST_COPIED}"
data-clipboard-text="{$ftpDetails['username']}"
id="ftpHost"
value="{$ftpDetails['host']}" readonly>
</div>
<!-- FTP Username -->
<div class="mb-3">
<label for="ftpUsername" class="form-label">
{$LANG.SERVER_FTP_USERNAME}
</label>
<input type="text" class="form-control copy-text"
data-id="ftpUsername"
data-new-text="{$LANG.SERVER_FTP_USERNAME_COPIED}"
data-clipboard-text="{$ftpDetails['username']}"
id="ftpUsername"
value="{$ftpDetails['username']}" readonly>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">
{$LANG.close}
</button>
</div>
</div>
</div>
</div>
{/if}
</div>

<script>
let currentState = "{$current_state}";
const serverStateUrl = "{$getstateurl}"
let currentState = "{$currentState}";
const serverStateUrl = "{$getStateUrl}"
</script>
{literal}
<script>
function disableButtons(state) {
var startButton = $('#startButton');
var rebootButton = $('#rebootButton');
var stopButton = $('#stopButton');
currentState = state;
switch (state) {
case "running":
startButton.prop('disabled', true);
rebootButton.prop('disabled', false);
stopButton.prop('disabled', false);
break;
case "offline":
startButton.prop('disabled', false);
rebootButton.prop('disabled', true);
stopButton.prop('disabled', true);
break;
case "starting":
case "stopping":
startButton.prop('disabled', true);
rebootButton.prop('disabled', true);
stopButton.prop('disabled', true);
break;
default:
startButton.prop('disabled', true);
rebootButton.prop('disabled', true);
stopButton.prop('disabled', true);
break;
}
}


function sendRequest(url) {
disableButtons('request')
var $button = $(event.currentTarget);
var originalHtml = $button.html();
$button.html('<i class="fas fa-spinner fa-spin"></i> ' + originalHtml);
$.post(url, function (data, status) {
disableButtons(data.state)
const interval = setInterval(function () {
$.post(serverStateUrl, function (data, status) {
if (data.state === 'running') {
$button.html(originalHtml); // Restore original content after completion
clearInterval(interval)
}
disableButtons(data.state)
})
}, 2000);
});
}

$(document).ready(function () {
disableButtons(currentState)
});
</script>
{/literal}
40 changes: 26 additions & 14 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ class PteroSyncSettings
public $dynamic_variables = [
'SERVER_PORT_OFFSET'
];
///$environment

public $dynamic_environment_array = [];

public $jsPath = '';
public $cssPath = '';

public function __construct()
{
$data = file_get_contents(dirname(__FILE__) . '/config.json');
Expand All @@ -29,6 +32,8 @@ public function __construct()
foreach ($data as $key => $value) {
$this->$key = $value;
}
$this->jsPath = '//' . $_SERVER['HTTP_HOST'] . '/modules/servers/pterosync/pterosync.js?v=' . time();
$this->cssPath = '//' . $_SERVER['HTTP_HOST'] . '/modules/servers/pterosync/pterosync.css?v=' . time();
}

public static function get(): ?PteroSyncSettings
Expand Down Expand Up @@ -175,10 +180,12 @@ function pteroSyncGetMemorySwapAndDisck($params)
return [$memory, $swap, $disk];
}

function pteroSyncGetServerID(array $params, $raw = false)
function pteroSyncGetServerID(array $params, $raw = false, $include = false)
{

$serverResult = pteroSyncApplicationApi($params, 'servers/external/' . $params['serviceid'], [], 'GET', true);
if ($include) {
$include = '?include=' . $include;
}
$serverResult = pteroSyncApplicationApi($params, 'servers/external/' . $params['serviceid'] . $include, [], 'GET', true);

if ($serverResult['status_code'] === 200) {
if ($raw) return $serverResult['attributes'];
Expand All @@ -189,6 +196,18 @@ function pteroSyncGetServerID(array $params, $raw = false)
return false;
}

function pteroSyncGetClientServer($params, $serverId)
{
$serverResult = pteroSyncClientApi($params, 'servers/' . $serverId . '?include=subusers', [], 'GET', true);

if ($serverResult['status_code'] === 200) {
return $serverResult['attributes'];
} else if ($serverResult['status_code'] === 500) {
throw new Exception('Failed to get server, panel errored. Check panel logs for more info.');
}
return false;
}

function pteroSyncRandom($length)
{
if (class_exists("\Illuminate\Support\Str")) {
Expand Down Expand Up @@ -363,7 +382,8 @@ function pteroSyncfindFreePortsForAllVariablesOnIP($ports, $variables, $_SERVER_
}
}

function pteroSyncSetServerPortVariables(&$variables, $serverPort, $ips, $isRange = false) {
function pteroSyncSetServerPortVariables(&$variables, $serverPort, $ips, $isRange = false)
{
$serverPortValue = $isRange ? $serverPort : $serverPort . '-' . $serverPort;
$serverPortArray = ['SERVER_PORT' => $serverPortValue];
$serverPortOffsetArray = [];
Expand Down Expand Up @@ -517,12 +537,4 @@ function pteroSyncServerState($params, $serverState, $serverId)
pteroSyncReturnJson([
'state' => $serverState
], 200);
}

function pterosyncCheckPHPSelf($action = 'configproducts.php')
{
if (!str_contains($_SERVER['PHP_SELF'], $action)) {
return true;
}
return false;
}
}
28 changes: 26 additions & 2 deletions hooks.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}

include_once dirname(__FILE__) . '/helper.php';

/**
* @class hook
Expand All @@ -12,14 +17,33 @@

add_hook('ClientAreaProductDetailsPreModuleTemplate', 1, function ($params) {
if ($params['modulename'] !== 'pterosync') return;
//$params['service']['domain'] = '';
$params['domain'] = '';
return $params;
});
add_hook('ClientAreaProductDetails', 1, function ($params) {
if ($params['modulename'] !== 'pterosync') return;
$params['dedicatedip'] = $params['domain'];
//$params['service']['domain'] = '';
$params['domain'] = '';
return $params;
});

add_hook('AdminAreaHeadOutput', 1, function ($params) {
$url = PteroSyncSettings::get()->cssPath;
return '<link rel="stylesheet" href="' . $url . '">' . PHP_EOL;
});

add_hook('AdminAreaFooterOutput', 1, function ($params) {
$url = PteroSyncSettings::get()->jsPath;
$urls = '<script src="' . $url . '"></script>' . PHP_EOL;
$urls .= '<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>';
return $urls;
});

add_hook('ClientAreaHeadOutput', 1, function ($params) {
if ($params['modulename'] !== 'pterosync') return;
$cssUrl = PteroSyncSettings::get()->cssPath;
$jsUrl = PteroSyncSettings::get()->jsPath;
$urls = '<link rel="stylesheet" href="' . $cssUrl . '">' . PHP_EOL;
$urls .= '<script src="' . $jsUrl . '"></script>' . PHP_EOL;
return $urls;
});
12 changes: 11 additions & 1 deletion lang/bulgarian.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@
'SERVER_START_PANEL' => "СТАРТИРАНЕ НА СЪРВЪРА",
'SERVER_RESTART_PANEL' => "РЕСТАРТИРАНЕ НА СЪРВЪРА",
'SERVER_STOP_PANEL' => "СПИРАНЕ НА СЪРВЪРА",
'SERVER_NOT_FOUND' => "Този сървър не съществува. Моля, свържете се с нас, ако смятате, че това е грешка."
'SERVER_NOT_FOUND' => "Този сървър не съществува. Моля, свържете се с нас, ако смятате, че това е грешка.",
"IP_COPIED" => "IP на сървъра е копирано!",
"ID_COPIED" => "ID на сървъра е копирано!",
"SERVER_FTP_INFORMATION" => "Информация за FTP на сървъра",
"SERVER_FTP_PASSWORD_INFORMATION" => "Моля, имайте предвид, че паролата за FTP е същата като тази, която използвате за достъп до контролния панел!",
"SERVER_FTP_USERNAME_COPIED" => "Потребителското име е копирано!",
"SERVER_FTP_HOST_COPIED" => "FTP хостът е копиран!",
"SERVER_FTP_HOST_AND_PORT" => "FTP Хост + Порт",
"SERVER_FTP_USERNAME" => "Потребителско име",
"SERVER_IP" => "Сървър IP",
"SERVER_ID" => "Сървър ID"
];
12 changes: 11 additions & 1 deletion lang/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@
'SERVER_START_PANEL' => "START SERVER",
'SERVER_RESTART_PANEL' => "RESTART SERVER",
'SERVER_STOP_PANEL' => "STOP SERVER",
'SERVER_NOT_FOUND' => "This server does not exist. Please contact us if you believe that's a mistake."
'SERVER_NOT_FOUND' => "This server does not exist. Please contact us if you believe that's a mistake.",
"IP_COPIED" => "Server IP Copied!",
"ID_COPIED" => "Server ID Copied!",
"SERVER_FTP_INFORMATION" => "FTP Information",
"SERVER_FTP_PASSWORD_INFORMATION" => "Please note, the FTP password is the same as the password you use to access the control panel!",
"SERVER_FTP_USERNAME_COPIED" => "Username copied!",
"SERVER_FTP_HOST_COPIED" => "FTP Host copied!",
"SERVER_FTP_HOST_AND_PORT" => "FTP Host + Port",
"SERVER_FTP_USERNAME" => "Username",
"SERVER_IP" => "Server IP",
"SERVER_ID" => "Server ID",
];
10 changes: 9 additions & 1 deletion lang/german.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
'SERVER_START_PANEL' => "SERVER STARTEN",
'SERVER_RESTART_PANEL' => "SERVER NEUSTARTEN",
'SERVER_STOP_PANEL' => "SERVER STOPPEN",
'SERVER_NOT_FOUND' => "Dieser Server existiert nicht. Bitte kontaktieren Sie uns, wenn Sie glauben, dass dies ein Fehler ist."
'SERVER_NOT_FOUND' => "Dieser Server existiert nicht. Bitte kontaktieren Sie uns, wenn Sie glauben, dass dies ein Fehler ist.",
"IP_COPIED" => "Server IP Kopiert!",
"ID_COPIED" => "Server ID Kopiert!",
"SERVER_FTP_INFORMATION" => "FTP Informationen",
"SERVER_FTP_PASSWORD_INFORMATION" => "Bitte beachten Sie, dass das FTP-Passwort dasselbe ist wie das Passwort, das Sie für den Zugang zum Control Panel verwenden!",
"SERVER_FTP_USERNAME_COPIED" => "FTP Nutzernamen Kopiert!",
"SERVER_FTP_HOST_COPIED" => "FTP Adresse Kopiert!",
"SERVER_IP" => "Server-IP",
"SERVER_ID" => "Server-ID",
];
22 changes: 22 additions & 0 deletions pterosync.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#divModuleSettings .module-settings .select-inline,
#divModuleSettings .module-settings .select2-container--default
{
width: 300px;
max-width: 300px;
}
#divModuleSettings .module-settings .fieldarea{
width: 25%;
}
#divModuleSettings .module-settings textarea{
width: 327px;
height: 75px;
}


.ptero-content{
min-width: 450px;
}

.mb-3{
margin-bottom: 20px;
}
Loading

0 comments on commit bac8ae1

Please sign in to comment.