-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new implementation of the module
- Loading branch information
1 parent
f875a5e
commit bde802a
Showing
32 changed files
with
18,285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
date_default_timezone_set("UTC"); | ||
|
||
$rootdir = dirname(dirname(dirname(dirname(dirname(__FILE__))))); | ||
require_once $rootdir.'/init.php'; | ||
|
||
use WHMCS\Database\Capsule; | ||
use WHMCS\Module\Server\upCloudVps\upCloudVps; | ||
|
||
$services = Capsule::table('tblhosting') | ||
->join('tblproducts', 'tblproducts.id', '=', 'tblhosting.packageid') | ||
->where('tblhosting.domainstatus', 'Active') | ||
->where('tblproducts.servertype', 'upCloudVps')->get(['tblhosting.id','tblhosting.packageid']); | ||
|
||
|
||
foreach ($services as $service) { | ||
$serviceId = $service->id; | ||
$packageId = $service->packageid; | ||
|
||
$tblcustomfields = Capsule::table('tblcustomfields') | ||
->where('tblcustomfields.relid', $packageId) | ||
->where('tblcustomfields.fieldname', 'instanceId|instance Id')->value('id'); | ||
|
||
$instanceId = Capsule::table('tblcustomfieldsvalues') | ||
->where('tblcustomfieldsvalues.relid', $serviceId) | ||
->where('tblcustomfieldsvalues.fieldid', $tblcustomfields)->value('value'); | ||
|
||
$product = Capsule::table('tblproducts')->where('id', $packageId)->first(); | ||
$server = Capsule::table('tblservers') | ||
->join('tblservergroupsrel', 'tblservergroupsrel.serverid', '=', 'tblservers.id') | ||
->where('tblservergroupsrel.groupid', $product->servergroup) | ||
->first(); | ||
|
||
$params = [ | ||
'serverusername' => $server->username, | ||
'serverpassword' => decrypt($server->password), | ||
]; | ||
|
||
try { | ||
$manager = new upCloudVps($params); | ||
$details = $manager->GetServer($instanceId)['response']['server']; | ||
$Ipv4 = $manager->formatSizeBytestoMB($details['plan_ipv4_bytes']); | ||
$Ipv6 = $manager->formatSizeBytestoMB($details['plan_ipv6_bytes']); | ||
|
||
if ($Ipv4 != '' && $Ipv6 != '') { | ||
Capsule::table('mod_upCloudVps_bandwidth')->insert([ 'serviceId' => $serviceId,'IPv4' => $Ipv4, | ||
'IPv6' => $Ipv6]); | ||
} | ||
} catch (\Exception $e) { | ||
echo $e->getMessage() . ' ['.$service->id.']' . PHP_EOL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
$_LANG["core"] = "Core"; | ||
$_LANG["memory"] = "Memory"; | ||
$_LANG["MB"] = "MB"; | ||
$_LANG["GB"] = "GB"; | ||
$_LANG["Disk"] = "Disk"; | ||
$_LANG["cpu"] = "CPU"; | ||
$_LANG["OS"] = "Operating System"; | ||
$_LANG["location"] = "Location"; | ||
$_LANG["sshRsa"] = "Provide SSH public key in OpenSSH format"; | ||
$_LANG["userData"] = "Cloud-init script for early initialization of cloud instances"; | ||
$_LANG["Hostname"] = "Hostname"; | ||
$_LANG["VMId"] = "VM Id"; | ||
$_LANG["Template"] = "Template"; | ||
$_LANG["Plan"] = "Plan"; | ||
$_LANG["Status"] = "Status"; | ||
$_LANG["Location"] = "Location"; | ||
$_LANG["IPAddress"] = "IP Address"; | ||
$_LANG["Access"] = "Access"; | ||
$_LANG["Family"] = "Family"; | ||
$_LANG["Interface"] = "Interface"; | ||
$_LANG["VmInfo"] = "VM Informations"; | ||
$_LANG["vncEnabled"] = "vnc Enabled"; | ||
$_LANG["vncPassword"] = "vnc Password"; | ||
$_LANG["vncPort"] = "vnc Port"; | ||
$_LANG["vncHost"] = "vnc Host"; | ||
$_LANG["reversePTR"] = "Reverse PTR"; | ||
$_LANG["TotalTraffic"] = "Total Traffic"; | ||
$_LANG["used"] = "Used"; | ||
$_LANG["Bandwidth"] = "Bandwidth"; | ||
$_LANG["selIPAddress"] = "Select IP Address"; | ||
$_LANG["rdnsval"] = "Enter RDNS Value"; | ||
$_LANG["Backup"] = "Backup"; | ||
$_LANG['overviewdetails'] = "Server Details"; | ||
$_LANG['status']['started'] = 'Started'; | ||
$_LANG['status']['stopped'] = 'Stopped'; | ||
$_LANG['status']['maintenance'] = 'Maintenance'; | ||
$_LANG['status']['error'] = 'Error'; | ||
$_LANG['ajax']['action']['not_valid'] = 'Action not valid'; | ||
$_LANG['ajax']['action']['success'] = 'Action completed successfully'; | ||
$_LANG['ajax']['unknown'] = 'Unknown error'; | ||
$_LANG['ajax']['StartServer'] = 'The container has been booted successfully'; | ||
$_LANG['ajax']['RestartServer'] = 'Reboot signal has been sent successfully'; | ||
$_LANG['ajax']['StopServer'] = 'Stop signal has been sent successfully'; | ||
$_LANG['ajax']['refreshServer'] = 'Refresh signal has been sent successfully'; | ||
$_LANG['vps']['control_panel'] = 'Control Panel'; | ||
$_LANG['vps']['shutdown'] = 'Shutdown'; | ||
$_LANG['vps']['stop'] = 'Power Off'; | ||
$_LANG['vps']['reboot'] = 'Reboot'; | ||
$_LANG['vps']['console'] = 'VNC Console'; | ||
$_LANG['vps']['boot'] = 'Power On'; | ||
$_LANG['notFound'] = 'Not Found'; | ||
$_LANG["password"] = "Password"; | ||
$_LANG["username"] = "Username"; | ||
$_LANG["IPAddresses"] = "IP Addresses"; | ||
$_LANG["Action"] = "Action"; | ||
$_LANG["basicdetails"] = "VPS Basic Required Information"; | ||
$_LANG["basicdescription"] = "Here are the essential day-to-day details you should keep readily accessible for connecting to your VPS whenever the need arises."; | ||
|
||
|
||
///vnc | ||
$_LANG['vnc']['title'] = 'VNC Configuration'; | ||
$_LANG['vnc']['description'] = 'The console provides server management as if your screen and keyboard would be plugged into the server. The console connection is particularly useful when logging into the server is not possible using normal remote connection methods due to an OS error state or faulty firewall rules, etc. Please use VNC viewer to access the VNC console.'; | ||
$_LANG['vnc']['settings'] = 'VNC Configuration'; | ||
$_LANG['vnc']['status'] = 'Status'; | ||
$_LANG['vnc']['password'] = 'Password'; | ||
$_LANG['vnc']['address'] = 'Address'; | ||
$_LANG['vnc']['port'] = 'Port'; | ||
$_LANG['vnc']['disable'] = 'Disable VNC'; | ||
$_LANG['vnc']['enable'] = 'Enable VNC'; | ||
$_LANG['vnc']['save'] = 'Save Settings'; | ||
$_LANG['vnc']['on'] = 'On'; | ||
$_LANG['vnc']['off'] = 'Off'; | ||
$_LANG['ajax']['saveVNCConfiguration'] = "VNC Configuration has been saved successfully"; | ||
$_LANG['ajax']['changeVNCStatus'] = "VNC Status has been changed successfully"; | ||
|
||
//network | ||
$_LANG['network']['title'] = 'Network Management'; | ||
$_LANG['network']['description'] = 'You have the capability to handle your IP addresses, including configuring reverse PTR records for both IPv4 and IPv6 addresses.'; | ||
$_LANG['ip']['rdn'] = 'Reverse DNS Name'; | ||
$_LANG['ip']['editRdn'] = 'Edit Reverse Dns Name for: '; | ||
$_LANG['ip']['close'] = 'Close'; | ||
$_LANG['ip']['save'] = 'Save Changes'; | ||
|
||
|
||
//server | ||
$_LANG['server']['title'] = 'Server Configuration'; | ||
$_LANG['server']['description'] = 'Your Server configuration can be updated here. By adjusting default configurations, you\'re making changes that could potentially disrupt the typical behavior of your VPS.'; | ||
$_LANG['server']['edit'] = 'Edit Server Configuration'; | ||
$_LANG['server']['hostname'] = 'Hostname'; | ||
$_LANG['server']['display'] = 'Display Adapter'; | ||
$_LANG['server']['network'] = 'Network Adapter'; | ||
$_LANG['server']['timezone'] = 'Timezone'; | ||
$_LANG['server']['boot'] = 'Boot Order'; | ||
$_LANG['server']['save'] = 'Save Configuration'; | ||
$_LANG['ajax']['saveServerConfiguration'] = "Server Configuration has been saved successfully"; | ||
|
||
|
||
$_LANG["custom"] = "Custom"; | ||
$_LANG["custDesc"] = "user Supplied Plans"; | ||
$_LANG['bandwidth']['title'] = 'Bandwidth Graphs'; | ||
$_LANG['bandwidth']['description'] = 'Your Server usage over time can be viewed here.'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
namespace WHMCS\Module\Server\upCloudVps; | ||
if (!defined("WHMCS")) {die("This file cannot be accessed directly");} | ||
|
||
use WHMCS\View\Menu\Item as MenuItem; | ||
use WHMCS\Module\Server\upCloudVps\upCloudVps; | ||
use WHMCS\Module\Server\upCloudVps\ajaxAction; | ||
|
||
class Helper | ||
{ | ||
public static function getLang() | ||
{ | ||
$languageDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR; | ||
$config = isset($GLOBALS['CONFIG']) ? $GLOBALS['CONFIG'] : []; // Check if CONFIG is set | ||
$language = isset($_SESSION['Language']) ? $_SESSION['Language'] : (isset($config['Language']) ? $config['Language'] : 'english'); // Set default language to 'english' if not found | ||
$languageFile = file_exists($languageDir . $language . '.php') ? $language : 'english'; // Check if language file exists, otherwise default to English | ||
|
||
// Include English language file if it exists | ||
if (file_exists($languageDir . 'english.php')) { | ||
include $languageDir . 'english.php'; | ||
} | ||
|
||
// Require the selected language file | ||
require $languageDir . $languageFile . '.php'; | ||
|
||
return isset($_LANG) ? $_LANG : []; // Return the language array | ||
} | ||
|
||
public static function ajaxAction(array $params, string $action) | ||
{ | ||
ob_clean(); | ||
try { | ||
$manager = new ajaxAction($params); | ||
$_LANG = self::getLang(); | ||
|
||
if (method_exists($manager, $action)) { | ||
$details = $manager->$action(); | ||
if ($details['response']['error']['error_message']) { | ||
$results['result'] = 'failure'; | ||
$results['message'] = $details['response']['error']['error_message']; | ||
} else { | ||
$results['message'] = (!empty($_LANG['ajax'][$action])) ? $_LANG['ajax'][$action] : $_LANG['ajax']['action']['success']; | ||
|
||
switch ($action) { | ||
case "refreshServer": | ||
$results['data']['details']['status'] = $details['response']['server']['state']; | ||
$results['data']['details']['statusLang'] = $_LANG['status'][$details['response']['server']['state']]; | ||
break; | ||
case "vncDetails": | ||
$results['vnchost'] = $details['vnchost']; | ||
$results['vncport'] = $details['vncport']; | ||
break; | ||
case "getIpAddresses": | ||
$results = $details; | ||
break; | ||
case "getBandwidth": | ||
$results = $details; | ||
break; | ||
} | ||
} | ||
|
||
} else { | ||
$results['result'] = 'failure'; | ||
$results['message'] = $_LANG['ajax']['action']['not_valid']; | ||
} | ||
|
||
echo json_encode($results); | ||
die; | ||
} catch (\Exception $e) { | ||
echo json_encode(['result' => 'failure', 'message' => $e->getMessage()]); | ||
die; | ||
} | ||
} | ||
|
||
public static function clientAreaPrimarySidebarHook(array $params) | ||
{ | ||
add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) use ($params) { | ||
$_LANG = Helper::getLang(); | ||
$panel = $primarySidebar->getChild('Service Details Overview'); | ||
if (is_a($panel, 'WHMCS\View\Menu\Item')) { | ||
$panel = $panel->getChild('Information'); | ||
if (is_a($panel, 'WHMCS\View\Menu\Item')) { | ||
$panel->setUri("clientarea.php?action=productdetails&id={$params['serviceid']}"); | ||
$panel->setAttributes([]); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.