Bulk Delete DNS Record di Cloudflare

Share ke Sosmed

Ada 190 record yang perlu dihapus. Cilakanya, Cloudflare itu tidak menyediakan fitur hapus ala centang. Alias bulk. Hanya ada API.

Beberapa workaround memakai api untuk hapus all record di domain. Namun itu perlu input API Key dan email serta perlu waktu untuk code dan nyesuaiken.

Ketemulah dengan gist ini. gist js ini hanya menggunakan console. di browser.

https://gist.github.com/AidasK/9550e1eb97b3b121c5122aef0d778608

Pada gist diatas, kopas kode ini di console browser. Inspect element, masuk tab console. Pastikan dahulu kamu sudah di halaman DNS record

Cloudflare support import/export DNS record, yang nanti bentukan file nya seperti format Bind

in case code diatas sudah tidak ada atau something, berikut code js nya

// paste all of this in your browser developer console

deleteAllRecords();

async function deleteAllRecords() {
    let e;
    filterEditButtons().forEach((e) => e.click());
    while (e = filterDeleteButtons()[0]) {
        e.click();
        await confirmDelete();
    }
}
function filterDeleteButtons() {
    return [
        ...[...document.querySelectorAll('a')].filter((e) => e.innerHTML === '<span>Delete</span>'),
        ...[...document.querySelectorAll('button')].filter((e) => e.innerHTML === 'Delete'),
    ];
}
function filterEditButtons() {
    return [
        ...document.querySelectorAll('a'),//old layout
        ...document.querySelectorAll('button')
    ].filter((e) => e.innerHTML.indexOf('<span>Edit</span>') != -1 );
}
function confirmDelete(iteration) {
    iteration = iteration || 1;
    return new Promise((resolve, reject) => {
        setTimeout(async () => {
            let button = [...document.querySelectorAll('button')].filter((e) => e.innerHTML === '<span>Delete</span>')[0];
            if (button) {
                button.click();
                await waitConfirmDelete();
                resolve();
            } else if (iteration > 30) {
                console.log('failed confirmDelete');
                reject();
            } else {
                confirmDelete(iteration + 1)
            }
        }, 100);
    });
}
function waitConfirmDelete() {
    return new Promise((resolve, reject) => {
        let iteration = 1;
        let i = setInterval(() => {
            if (iteration++ > 30) {
                clearInterval(i);
                reject();
                return;
            }
            if ([...document.querySelectorAll('button')].filter((e) => e.innerHTML === '<span>Delete</span>')[0]) {
                return;
            }
            clearInterval(i);
            resolve();
        }, 100)
    });
}
Share ke Sosmed

Leave a Reply

Your email address will not be published. Required fields are marked *