Şimdiden çok teşekkürler.
bu kodda askıya al dediğimde bu hatayı veriyor.
WHM API hatası: API failure: (XID rea57m) 147 adında bir kullanıcınız yok. You do not have a user named 147.
<?php
// WHM giriş bilgileri
$whmHost = '-----------------------'; // WHM URL (örneğin: example.com)
$whmPort = '----------------------- '; // WHM port numarası
$whmUser = ----------------------- '; // WHM kullanıcı adı
$whmPass = '----------------------- '; // WHM parolası
// Hesabı askıya alma fonksiyonu
function suspendAccount() {
global $whmHost, $whmPort, $whmUser, $whmPass;
// API çağrısı için gerekli parametreler
$apiCall = "https://$whmHost:$whmPort/json-api/listaccts?api.version=1";
// WHM API'ye bağlanma ve isteği gönderme
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"Authorization: Basic " . base64_encode("$whmUser:$whmPass")
]);
curl_setopt($curl, CURLOPT_URL, $apiCall);
$result = curl_exec($curl);
// API yanıtını işleme
if ($result === false) {
echo 'Curl error: ' . curl_error($curl);
} else {
$decodedResult = json_decode($result, true);
if (isset($decodedResult['metadata']['result']) && $decodedResult['metadata']['result'] == 1) {
// İlk hesabı askıya al
$accountId = $decodedResult['data']['acct'][0]['user'];
suspendSingleAccount($accountId);
} else {
echo 'WHM API hatası: ' . $decodedResult['metadata']['reason'] . "<br>";
}
}
// Curl bağlantısını kapatma
curl_close($curl);
}
// Tek bir hesabı askıya alma fonksiyonu
function suspendSingleAccount($accountId) {
global $whmHost, $whmPort, $whmUser, $whmPass;
// Askıya alma isteği için gerekli API çağrısı
$apiCall = "https://$whmHost:$whmPort/json-api/suspendacct?api.version=1&user=$accountId";
// WHM API'ye bağlanma ve isteği gönderme
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"Authorization: Basic " . base64_encode("$whmUser:$whmPass")
]);
curl_setopt($curl, CURLOPT_URL, $apiCall);
$result = curl_exec($curl);
// API yanıtını işleme
if ($result === false) {
echo 'Curl error: ' . curl_error($curl);
} else {
$decodedResult = json_decode($result, true);
if ($decodedResult['metadata']['result'] == 1) {
echo 'Hesap başarıyla askıya alındı.';
} else {
echo 'WHM API hatası: ' . $decodedResult['metadata']['reason'] . "<br>";
}
}
// Curl bağlantısını kapatma
curl_close($curl);
}
// Askıya al butonuna tıklanınca işlevi tetikle
if (isset($_POST['suspend'])) {
// Hesapları çekip askıya alma işlemini başlat
suspendAccount();
}
?>
<form method="post">
<!-- Askıya al butonu -->
<button type="submit" name="suspend" class="btn btn-warning waves-effect waves-light m-b-5" onclick="return confirm('Hesabı askıya almak istediğinize emin misiniz?')">
<input type="hidden" name="account_id" value="<?= $snc->id; ?>">
<strong><i class="fa fa-ban" aria-hidden="true"></i> Askıya Al</strong>
</button>
</form>