Skip to content

Commit da1ea55

Browse files
authored
misc bugfixes (#3)
1 parent 06a41f5 commit da1ea55

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

modules/servers/hostinger/hostinger.php

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,32 +105,42 @@ function hostinger_AdminCustomButtonArray(): array
105105
*/
106106
function hostinger_UsageUpdate(array $params): void
107107
{
108-
try {
109-
$apiClient = new VPSVirtualMachineApi(config: getHostingerApiConfig($params));
110-
$response = $apiClient->getMetricsV1(
111-
virtualMachineId: getHostingerVirtualMachineId($params),
112-
dateFrom: new DateTime('-1 day'),
113-
dateTo: new DateTime(),
114-
);
115-
116-
$diskUsageArray = (array) $response->getDiskSpace()->getUsage();
117-
$incomingTrafficArray = (array) $response->getIncomingTraffic()->getUsage();
118-
$outgoingTrafficArray = (array) $response->getOutgoingTraffic()->getUsage();
119-
$latestDiskUsage = array_pop($diskUsageArray);
120-
$latestIncomingTraffic = array_pop($incomingTrafficArray);
121-
$latestOutgoingTraffic = array_pop($outgoingTrafficArray);
122-
123-
Capsule::table('tblhosting')
124-
->where('server', $params['serverid'])
125-
->update([
126-
'diskusage' => $latestDiskUsage / 1024 / 1024 ?? $params['diskusage'],
127-
'bwusage' => ($latestIncomingTraffic + $latestOutgoingTraffic) / 1024 / 1024 ?? $params['bwusage'],
128-
'lastupdate' => Capsule::raw('now()'),
129-
]);
130-
} catch (Throwable $e) {
131-
logModuleCall('hostinger', __FUNCTION__, $params, $e->getMessage(), $e->getTraceAsString());
132-
133-
throw $e;
108+
$apiClient = new VPSVirtualMachineApi(config: getHostingerApiConfig($params));
109+
110+
$servers = Capsule::table('tblhosting')
111+
->where('server', $params['serverid'])
112+
->get();
113+
114+
foreach ($servers as $server) {
115+
$serverId = (int) $server->subscriptionid ?? null;
116+
if (!$serverId) {
117+
continue;
118+
}
119+
120+
try {
121+
$response = $apiClient->getMetricsV1(
122+
virtualMachineId: $serverId,
123+
dateFrom: new DateTime('-1 day'),
124+
dateTo: new DateTime(),
125+
);
126+
127+
$diskUsageArray = (array)$response->getDiskSpace()->getUsage();
128+
$incomingTrafficArray = (array)$response->getIncomingTraffic()->getUsage();
129+
$outgoingTrafficArray = (array)$response->getOutgoingTraffic()->getUsage();
130+
$latestDiskUsage = array_pop($diskUsageArray);
131+
$latestIncomingTraffic = array_pop($incomingTrafficArray);
132+
$latestOutgoingTraffic = array_pop($outgoingTrafficArray);
133+
134+
Capsule::table('tblhosting')
135+
->where('server', $params['serverid'])
136+
->update([
137+
'diskusage' => $latestDiskUsage / 1024 / 1024 ?? $params['diskusage'],
138+
'bwusage' => ($latestIncomingTraffic + $latestOutgoingTraffic) / 1024 / 1024 ?? $params['bwusage'],
139+
'lastupdate' => Capsule::raw('now()'),
140+
]);
141+
} catch (Throwable $e) {
142+
logModuleCall('hostinger', __FUNCTION__, $params, $e->getMessage(), $e->getTraceAsString());
143+
}
134144
}
135145
}
136146

modules/servers/hostinger/include/clientarea.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ function hostinger_ClientAreaSetNameservers(array $params, array $details = []):
149149
{
150150
$error = null;
151151

152-
if (!empty($_POST)) {
153-
$error = hostinger_SetNameservers($params, $_POST['ns1'], $_POST['ns2']);
152+
if (!empty($_POST['ns1'])) {
153+
$error = hostinger_SetNameservers($params, $_POST['ns1'], $_POST['ns2'] ?? null);
154154
if ($error === 'success') {
155155
markHostingerServerDetailsObsolete($params);
156156
makeRedirect(makeActionLink($params, 'SetNameservers'));
@@ -171,7 +171,7 @@ function hostinger_ClientAreaChangeRootPassword(array $params, array $details =
171171
{
172172
$error = null;
173173

174-
if (!empty($_POST)) {
174+
if (!empty($_POST['password'])) {
175175
$error = hostinger_ChangeRootPassword($params, $_POST['password']);
176176
if ($error === 'success') {
177177
markHostingerServerDetailsObsolete($params);
@@ -191,7 +191,7 @@ function hostinger_ClientAreaChangePanelPassword(array $params, array $details =
191191
{
192192
$error = null;
193193

194-
if (!empty($_POST)) {
194+
if (!empty($_POST['password'])) {
195195
$error = hostinger_ChangePanelPassword($params, $_POST['password']);
196196
if ($error === 'success') {
197197
markHostingerServerDetailsObsolete($params);

0 commit comments

Comments
 (0)