Skip to content

Commit c302061

Browse files
committed
several fixes for cpanel web termination handling'
1 parent 12039a7 commit c302061

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

src/Plugin.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -493,44 +493,42 @@ function_requirements('whm_api');
493493
} else {
494494
$response = json_decode($whm->removeacct($serviceClass->getUsername(), false), true);
495495
}
496+
myadmin_log(self::$module, 'info', str_replace('\n', "\n", json_encode($response)), __LINE__, __FILE__, self::$module, $serviceClass->getId());
496497
} catch (\Exception $e) {
497498
$event['success'] = false;
498499
myadmin_log('cpanel', 'error', 'removeacct('.$serviceClass->getUsername().') tossed exception '.$e->getMessage(), __LINE__, __FILE__, self::$module, $serviceClass->getId());
499500
add_output('Caught exception: '.$e->getMessage().'<br>');
500501
}
501-
502-
myadmin_log(self::$module, 'info', str_replace('\n', "\n", json_encode($response)), __LINE__, __FILE__, self::$module, $serviceClass->getId());
503502
} else {
504503
myadmin_log(self::$module, 'info', "Skipping WHMAPI/Server Removal for {$serviceClass->getHostname()} because username is blank", __LINE__, __FILE__, self::$module, $serviceClass->getId());
505504
}
506505
try {
507506
$dnsr = json_decode($whm->dumpzone($serviceClass->getHostname()), true);
507+
if ($dnsr['result'][0]['status'] == 1) {
508+
$db = get_module_db(self::$module);
509+
$db->query("select * from {$settings['TABLE']} where {$settings['PREFIX']}_hostname='{$serviceClass->getHostname()}' and {$settings['PREFIX']}_id != {$serviceClass->getId()} and {$settings['PREFIX']}_status = 'active'", __LINE__, __FILE__);
510+
if ($db->num_rows() == 0) {
511+
myadmin_log(self::$module, 'info', "Removing Hanging DNS entry for {$serviceClass->getHostname()}", __LINE__, __FILE__, self::$module, $serviceClass->getId());
512+
try {
513+
$whm->killdns($serviceClass->getHostname());
514+
} catch (\Exception $e) {
515+
myadmin_log('cpanel', 'error', 'killdns('.$serviceClass->getHostname().') tossed exception '.$e->getMessage(), __LINE__, __FILE__, self::$module, $serviceClass->getId());
516+
add_output('Caught exception: '.$e->getMessage().'<br>');
517+
}
518+
} else {
519+
myadmin_log(self::$module, 'info', "Skipping Removing DNS entry for {$serviceClass->getHostname()} because other non deleted sites w/ the same hostname exist", __LINE__, __FILE__, self::$module, $serviceClass->getId());
520+
}
521+
}
508522
} catch (\Exception $e) {
509523
myadmin_log('cpanel', 'error', 'dumpzone('.$serviceClass->getHostname().') tossed exception '.$e->getMessage(), __LINE__, __FILE__, self::$module, $serviceClass->getId());
510524
add_output('Caught exception: '.$e->getMessage().'<br>');
511525
}
512-
513-
if ($dnsr['result'][0]['status'] == 1) {
514-
$db = get_module_db(self::$module);
515-
$db->query("select * from {$settings['TABLE']} where {$settings['PREFIX']}_hostname='{$serviceClass->getHostname()}' and {$settings['PREFIX']}_id != {$serviceClass->getId()} and {$settings['PREFIX']}_status = 'active'", __LINE__, __FILE__);
516-
if ($db->num_rows() == 0) {
517-
myadmin_log(self::$module, 'info', "Removing Hanging DNS entry for {$serviceClass->getHostname()}", __LINE__, __FILE__, self::$module, $serviceClass->getId());
518-
try {
519-
$whm->killdns($serviceClass->getHostname());
520-
} catch (\Exception $e) {
521-
myadmin_log('cpanel', 'error', 'killdns('.$serviceClass->getHostname().') tossed exception '.$e->getMessage(), __LINE__, __FILE__, self::$module, $serviceClass->getId());
522-
add_output('Caught exception: '.$e->getMessage().'<br>');
523-
}
524-
} else {
525-
myadmin_log(self::$module, 'info', "Skipping Removing DNS entry for {$serviceClass->getHostname()} because other non deleted sites w/ the same hostname exist", __LINE__, __FILE__, self::$module, $serviceClass->getId());
526-
}
527-
}
528526
$event->stopPropagation();
529527
if (trim($serviceClass->getUsername()) == '') {
530528
return true;
531-
} elseif ($response['result'][0]['status'] == 1) {
529+
} elseif (isset($response) && $response['result'][0]['status'] == 1) {
532530
return true;
533-
} elseif ($response['result'][0]['statusmsg'] == "System user {$serviceClass->getUsername()} does not exist!") {
531+
} elseif (isset($response) && $response['result'][0]['statusmsg'] == "System user {$serviceClass->getUsername()} does not exist!") {
534532
return true;
535533
} else {
536534
$event['success'] = false;

0 commit comments

Comments
 (0)