Skip to content

Commit

Permalink
work on the deactivate parallels code so it lookps through all the ke…
Browse files Browse the repository at this point in the history
…ys on a given ip for paralllels deactivating them and improved logging
  • Loading branch information
detain committed Oct 15, 2019
1 parent 51bf3f6 commit 6d74fa7
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/parallels.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,25 @@ function deactivate_parallels($ipAddress)
myadmin_log('licenses', 'info', "Parallels Deactivation ({$ipAddress})", __LINE__, __FILE__);
function_requirements('class.Parallels');
$parallels = new \Detain\Parallels\Parallels();
$key = $parallels->getMainKeyFromIp($ipAddress);
request_log('licenses', false, __FUNCTION__, 'parallels', 'getMainKeyFromIp', $ipAddress, $key);
myadmin_log('licenses', 'info', "Parallels getMainKeyFromIp({$ipAddress}) = {$key} Raw Response: ".json_encode($parallels->response), __LINE__, __FILE__);
if ($key !== false) {
$response = $parallels->terminateKey($key);
request_log('licenses', false, __FUNCTION__, 'parallels', 'terminateKey', $key, $response);
myadmin_log('licenses', 'info', "Parallels TerminateKey({$key}) Response: ".json_encode($response), __LINE__, __FILE__);
$response = $parallels->getKeyNumbers($ipAddress);
request_log('licenses', false, __FUNCTION__, 'parallels', 'getMainKeyFromIp', $ipAddress, $response);
myadmin_log('licenses', 'info', "Parallels getMainKeyFromIp({$ipAddress}): ".json_encode($response), __LINE__, __FILE__);
if (isset($response['keyNumbers'])) {
$keys = $response['keyNumbers'];
$status = json_decode(file_get_contents(__DIR__.'/../../../../include/config/plesk.json'), true);
foreach ($keys as $key) {
$response = $parallels->terminateKey($key);
request_log('licenses', false, __FUNCTION__, 'parallels', 'terminateKey', $key, $response);
myadmin_log('licenses', 'info', "Parallels TerminateKey({$key}) Response: ".json_encode($response), __LINE__, __FILE__);
if (array_key_exists($key, $status)) {
$status[$key]['terminated'] = true;
file_put_contents(__DIR__.'/../../../../include/config/plesk.json', json_encode($status, JSON_PRETTY_PRINT));
}
if (array_key_exists(str_replace('0001', '0000', $key), $status)) {
$status[str_replace('0001', '0000', $key)]['terminated'] = true;
file_put_contents(__DIR__.'/../../../../include/config/plesk.json', json_encode($status, JSON_PRETTY_PRINT));
}
}
} else {
myadmin_log('licenses', 'info', 'Parallels No Key Found to Terminate', __LINE__, __FILE__);
}
Expand Down

0 comments on commit 6d74fa7

Please sign in to comment.