Skip to content

Commit bde802a

Browse files
adityawbwcescop
authored andcommitted
feat: new implementation of the module
1 parent f875a5e commit bde802a

32 files changed

+18285
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
date_default_timezone_set("UTC");
3+
4+
$rootdir = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
5+
require_once $rootdir.'/init.php';
6+
7+
use WHMCS\Database\Capsule;
8+
use WHMCS\Module\Server\upCloudVps\upCloudVps;
9+
10+
$services = Capsule::table('tblhosting')
11+
->join('tblproducts', 'tblproducts.id', '=', 'tblhosting.packageid')
12+
->where('tblhosting.domainstatus', 'Active')
13+
->where('tblproducts.servertype', 'upCloudVps')->get(['tblhosting.id','tblhosting.packageid']);
14+
15+
16+
foreach ($services as $service) {
17+
$serviceId = $service->id;
18+
$packageId = $service->packageid;
19+
20+
$tblcustomfields = Capsule::table('tblcustomfields')
21+
->where('tblcustomfields.relid', $packageId)
22+
->where('tblcustomfields.fieldname', 'instanceId|instance Id')->value('id');
23+
24+
$instanceId = Capsule::table('tblcustomfieldsvalues')
25+
->where('tblcustomfieldsvalues.relid', $serviceId)
26+
->where('tblcustomfieldsvalues.fieldid', $tblcustomfields)->value('value');
27+
28+
$product = Capsule::table('tblproducts')->where('id', $packageId)->first();
29+
$server = Capsule::table('tblservers')
30+
->join('tblservergroupsrel', 'tblservergroupsrel.serverid', '=', 'tblservers.id')
31+
->where('tblservergroupsrel.groupid', $product->servergroup)
32+
->first();
33+
34+
$params = [
35+
'serverusername' => $server->username,
36+
'serverpassword' => decrypt($server->password),
37+
];
38+
39+
try {
40+
$manager = new upCloudVps($params);
41+
$details = $manager->GetServer($instanceId)['response']['server'];
42+
$Ipv4 = $manager->formatSizeBytestoMB($details['plan_ipv4_bytes']);
43+
$Ipv6 = $manager->formatSizeBytestoMB($details['plan_ipv6_bytes']);
44+
45+
if ($Ipv4 != '' && $Ipv6 != '') {
46+
Capsule::table('mod_upCloudVps_bandwidth')->insert([ 'serviceId' => $serviceId,'IPv4' => $Ipv4,
47+
'IPv6' => $Ipv6]);
48+
}
49+
} catch (\Exception $e) {
50+
echo $e->getMessage() . ' ['.$service->id.']' . PHP_EOL;
51+
}
52+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
$_LANG["core"] = "Core";
3+
$_LANG["memory"] = "Memory";
4+
$_LANG["MB"] = "MB";
5+
$_LANG["GB"] = "GB";
6+
$_LANG["Disk"] = "Disk";
7+
$_LANG["cpu"] = "CPU";
8+
$_LANG["OS"] = "Operating System";
9+
$_LANG["location"] = "Location";
10+
$_LANG["sshRsa"] = "Provide SSH public key in OpenSSH format";
11+
$_LANG["userData"] = "Cloud-init script for early initialization of cloud instances";
12+
$_LANG["Hostname"] = "Hostname";
13+
$_LANG["VMId"] = "VM Id";
14+
$_LANG["Template"] = "Template";
15+
$_LANG["Plan"] = "Plan";
16+
$_LANG["Status"] = "Status";
17+
$_LANG["Location"] = "Location";
18+
$_LANG["IPAddress"] = "IP Address";
19+
$_LANG["Access"] = "Access";
20+
$_LANG["Family"] = "Family";
21+
$_LANG["Interface"] = "Interface";
22+
$_LANG["VmInfo"] = "VM Informations";
23+
$_LANG["vncEnabled"] = "vnc Enabled";
24+
$_LANG["vncPassword"] = "vnc Password";
25+
$_LANG["vncPort"] = "vnc Port";
26+
$_LANG["vncHost"] = "vnc Host";
27+
$_LANG["reversePTR"] = "Reverse PTR";
28+
$_LANG["TotalTraffic"] = "Total Traffic";
29+
$_LANG["used"] = "Used";
30+
$_LANG["Bandwidth"] = "Bandwidth";
31+
$_LANG["selIPAddress"] = "Select IP Address";
32+
$_LANG["rdnsval"] = "Enter RDNS Value";
33+
$_LANG["Backup"] = "Backup";
34+
$_LANG['overviewdetails'] = "Server Details";
35+
$_LANG['status']['started'] = 'Started';
36+
$_LANG['status']['stopped'] = 'Stopped';
37+
$_LANG['status']['maintenance'] = 'Maintenance';
38+
$_LANG['status']['error'] = 'Error';
39+
$_LANG['ajax']['action']['not_valid'] = 'Action not valid';
40+
$_LANG['ajax']['action']['success'] = 'Action completed successfully';
41+
$_LANG['ajax']['unknown'] = 'Unknown error';
42+
$_LANG['ajax']['StartServer'] = 'The container has been booted successfully';
43+
$_LANG['ajax']['RestartServer'] = 'Reboot signal has been sent successfully';
44+
$_LANG['ajax']['StopServer'] = 'Stop signal has been sent successfully';
45+
$_LANG['ajax']['refreshServer'] = 'Refresh signal has been sent successfully';
46+
$_LANG['vps']['control_panel'] = 'Control Panel';
47+
$_LANG['vps']['shutdown'] = 'Shutdown';
48+
$_LANG['vps']['stop'] = 'Power Off';
49+
$_LANG['vps']['reboot'] = 'Reboot';
50+
$_LANG['vps']['console'] = 'VNC Console';
51+
$_LANG['vps']['boot'] = 'Power On';
52+
$_LANG['notFound'] = 'Not Found';
53+
$_LANG["password"] = "Password";
54+
$_LANG["username"] = "Username";
55+
$_LANG["IPAddresses"] = "IP Addresses";
56+
$_LANG["Action"] = "Action";
57+
$_LANG["basicdetails"] = "VPS Basic Required Information";
58+
$_LANG["basicdescription"] = "Here are the essential day-to-day details you should keep readily accessible for connecting to your VPS whenever the need arises.";
59+
60+
61+
///vnc
62+
$_LANG['vnc']['title'] = 'VNC Configuration';
63+
$_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.';
64+
$_LANG['vnc']['settings'] = 'VNC Configuration';
65+
$_LANG['vnc']['status'] = 'Status';
66+
$_LANG['vnc']['password'] = 'Password';
67+
$_LANG['vnc']['address'] = 'Address';
68+
$_LANG['vnc']['port'] = 'Port';
69+
$_LANG['vnc']['disable'] = 'Disable VNC';
70+
$_LANG['vnc']['enable'] = 'Enable VNC';
71+
$_LANG['vnc']['save'] = 'Save Settings';
72+
$_LANG['vnc']['on'] = 'On';
73+
$_LANG['vnc']['off'] = 'Off';
74+
$_LANG['ajax']['saveVNCConfiguration'] = "VNC Configuration has been saved successfully";
75+
$_LANG['ajax']['changeVNCStatus'] = "VNC Status has been changed successfully";
76+
77+
//network
78+
$_LANG['network']['title'] = 'Network Management';
79+
$_LANG['network']['description'] = 'You have the capability to handle your IP addresses, including configuring reverse PTR records for both IPv4 and IPv6 addresses.';
80+
$_LANG['ip']['rdn'] = 'Reverse DNS Name';
81+
$_LANG['ip']['editRdn'] = 'Edit Reverse Dns Name for: ';
82+
$_LANG['ip']['close'] = 'Close';
83+
$_LANG['ip']['save'] = 'Save Changes';
84+
85+
86+
//server
87+
$_LANG['server']['title'] = 'Server Configuration';
88+
$_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.';
89+
$_LANG['server']['edit'] = 'Edit Server Configuration';
90+
$_LANG['server']['hostname'] = 'Hostname';
91+
$_LANG['server']['display'] = 'Display Adapter';
92+
$_LANG['server']['network'] = 'Network Adapter';
93+
$_LANG['server']['timezone'] = 'Timezone';
94+
$_LANG['server']['boot'] = 'Boot Order';
95+
$_LANG['server']['save'] = 'Save Configuration';
96+
$_LANG['ajax']['saveServerConfiguration'] = "Server Configuration has been saved successfully";
97+
98+
99+
$_LANG["custom"] = "Custom";
100+
$_LANG["custDesc"] = "user Supplied Plans";
101+
$_LANG['bandwidth']['title'] = 'Bandwidth Graphs';
102+
$_LANG['bandwidth']['description'] = 'Your Server usage over time can be viewed here.';
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
namespace WHMCS\Module\Server\upCloudVps;
3+
if (!defined("WHMCS")) {die("This file cannot be accessed directly");}
4+
5+
use WHMCS\View\Menu\Item as MenuItem;
6+
use WHMCS\Module\Server\upCloudVps\upCloudVps;
7+
use WHMCS\Module\Server\upCloudVps\ajaxAction;
8+
9+
class Helper
10+
{
11+
public static function getLang()
12+
{
13+
$languageDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR;
14+
$config = isset($GLOBALS['CONFIG']) ? $GLOBALS['CONFIG'] : []; // Check if CONFIG is set
15+
$language = isset($_SESSION['Language']) ? $_SESSION['Language'] : (isset($config['Language']) ? $config['Language'] : 'english'); // Set default language to 'english' if not found
16+
$languageFile = file_exists($languageDir . $language . '.php') ? $language : 'english'; // Check if language file exists, otherwise default to English
17+
18+
// Include English language file if it exists
19+
if (file_exists($languageDir . 'english.php')) {
20+
include $languageDir . 'english.php';
21+
}
22+
23+
// Require the selected language file
24+
require $languageDir . $languageFile . '.php';
25+
26+
return isset($_LANG) ? $_LANG : []; // Return the language array
27+
}
28+
29+
public static function ajaxAction(array $params, string $action)
30+
{
31+
ob_clean();
32+
try {
33+
$manager = new ajaxAction($params);
34+
$_LANG = self::getLang();
35+
36+
if (method_exists($manager, $action)) {
37+
$details = $manager->$action();
38+
if ($details['response']['error']['error_message']) {
39+
$results['result'] = 'failure';
40+
$results['message'] = $details['response']['error']['error_message'];
41+
} else {
42+
$results['message'] = (!empty($_LANG['ajax'][$action])) ? $_LANG['ajax'][$action] : $_LANG['ajax']['action']['success'];
43+
44+
switch ($action) {
45+
case "refreshServer":
46+
$results['data']['details']['status'] = $details['response']['server']['state'];
47+
$results['data']['details']['statusLang'] = $_LANG['status'][$details['response']['server']['state']];
48+
break;
49+
case "vncDetails":
50+
$results['vnchost'] = $details['vnchost'];
51+
$results['vncport'] = $details['vncport'];
52+
break;
53+
case "getIpAddresses":
54+
$results = $details;
55+
break;
56+
case "getBandwidth":
57+
$results = $details;
58+
break;
59+
}
60+
}
61+
62+
} else {
63+
$results['result'] = 'failure';
64+
$results['message'] = $_LANG['ajax']['action']['not_valid'];
65+
}
66+
67+
echo json_encode($results);
68+
die;
69+
} catch (\Exception $e) {
70+
echo json_encode(['result' => 'failure', 'message' => $e->getMessage()]);
71+
die;
72+
}
73+
}
74+
75+
public static function clientAreaPrimarySidebarHook(array $params)
76+
{
77+
add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) use ($params) {
78+
$_LANG = Helper::getLang();
79+
$panel = $primarySidebar->getChild('Service Details Overview');
80+
if (is_a($panel, 'WHMCS\View\Menu\Item')) {
81+
$panel = $panel->getChild('Information');
82+
if (is_a($panel, 'WHMCS\View\Menu\Item')) {
83+
$panel->setUri("clientarea.php?action=productdetails&id={$params['serviceid']}");
84+
$panel->setAttributes([]);
85+
}
86+
}
87+
});
88+
}
89+
90+
}

0 commit comments

Comments
 (0)