Skip to content

Commit 3415734

Browse files
committed
adding terminate and suspend code
1 parent ddc23f4 commit 3415734

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

src/Plugin.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,27 @@ public static function getDeactivate(GenericEvent $event) {
293293
$serviceClass = $event->getSubject();
294294
$serviceTypes = run_event('get_service_types', FALSE, self::$module);
295295
$settings = get_module_settings(self::$module);
296+
$extra = run_event('parse_service_extra', $serviceClass->getExtra(), self::$module);
297+
$serverdata = get_service_master($serviceClass->getServer(), self::$module);
298+
$hash = $serverdata[$settings['PREFIX'].'_key'];
299+
$ip = $serverdata[$settings['PREFIX'].'_ip'];
300+
function_requirements('whm_api');
301+
$user = 'root';
302+
$whm = new \xmlapi($ip);
303+
//$whm->set_debug('true');
304+
$whm->set_port('2087');
305+
$whm->set_protocol('https');
306+
$whm->set_output('json');
307+
$whm->set_auth_type('hash');
308+
$whm->set_user($user);
309+
$whm->set_hash($hash);
310+
//$whm = whm_api('faith.interserver.net');
311+
$field1 = explode(',', $service_types[$serviceClass->getType()]['services_field1']);
312+
if (in_array('reseller', $field1))
313+
$response = json_decode($whm->suspendreseller($serviceClass->getUsername(), 'Canceled Service'), true);
314+
else
315+
$response = json_decode($whm->suspendacct($serviceClass->getUsername(), 'Canceled Service'), true);
316+
myadmin_log(self::$module, 'info', json_encode($response), __LINE__, __FILE__);
296317
$event->stopPropagation();
297318
}
298319
}
@@ -303,6 +324,47 @@ public static function getTerminate(GenericEvent $event) {
303324
$serviceClass = $event->getSubject();
304325
$serviceTypes = run_event('get_service_types', FALSE, self::$module);
305326
$settings = get_module_settings(self::$module);
327+
$extra = run_event('parse_service_extra', $serviceClass->getExtra(), self::$module);
328+
$serverdata = get_service_master($serviceClass->getServer(), self::$module);
329+
$hash = $serverdata[$settings['PREFIX'].'_key'];
330+
$ip = $serverdata[$settings['PREFIX'].'_ip'];
331+
function_requirements('whm_api');
332+
$user = 'root';
333+
$whm = new \xmlapi($ip);
334+
//$whm->set_debug('true');
335+
$whm->set_port('2087');
336+
$whm->set_protocol('https');
337+
$whm->set_output('json');
338+
$whm->set_auth_type('hash');
339+
$whm->set_user($user);
340+
$whm->set_hash($hash);
341+
//$whm = whm_api('faith.interserver.net');
342+
if (trim($serviceClass->getUsername()) != '') {
343+
$field1 = explode(',', $service_types[$serviceClass->getType()]['services_field1']);
344+
if (in_array('reseller', $field1))
345+
$response = json_decode($whm->terminatereseller($serviceClass->getUsername(), true));
346+
else
347+
$response = json_decode($whm->removeacct($serviceClass->getUsername(), false));
348+
myadmin_log(self::$module, 'info', json_encode($response), __LINE__, __FILE__);
349+
} else
350+
myadmin_log(self::$module, 'info', "Skipping WHMAPI/Server Removal for {$serviceClass->getHostname()} because username is blank", __LINE__, __FILE__);
351+
$dnsr = json_decode($whm->dumpzone($serviceClass->getHostname()));
352+
if ($dnsr->result[0]->status == 1) {
353+
$db->query("select * from {$settings['TABLE']} where {$settings['PREFIX']}_hostname='{$serviceClass->getHostname()}' and {$settings['PREFIX']}_id != {$id} and {$settings['PREFIX']}_status = 'active'", __LINE__, __FILE__);
354+
if ($db->num_rows() == 0) {
355+
myadmin_log(self::$module, 'info', "Removing Hanging DNS entry for {$serviceClass->getHostname()}", __LINE__, __FILE__);
356+
$whm->killdns($serviceClass->getHostname());
357+
} else
358+
myadmin_log(self::$module, 'info', "Skipping Removing DNS entry for {$serviceClass->getHostname()} because other non deleted sites w/ the same hostname exist", __LINE__, __FILE__);
359+
}
360+
if (trim($serviceClass->getUsername()) == '')
361+
return true;
362+
elseif ($response->result[0]->status == 1)
363+
return true;
364+
elseif ($response->result[0]->statusmsg == "System user {$serviceClass->getUsername()} does not exist!")
365+
return true;
366+
else
367+
return false;
306368
$event->stopPropagation();
307369
}
308370
}

0 commit comments

Comments
 (0)