Last active
November 5, 2021 05:36
-
-
Save callaginn/e8c3a578cf6620ee5d3eaa8862f4a54e to your computer and use it in GitHub Desktop.
Fetch and Download Dreamhost Domain Info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*/ | |
Fetch Dreamhost Domain Info | |
The Dreamhost API command domain-list_domains was retired on Nov 2nd 2021. This function is a makeshift replacement for that. | |
Usage: | |
1. Log into your Dreamhost account and click Domains / Manage Domains | |
2. Paste this entire gist into the console | |
3. Press enter and wait for "sites.json" to be downloaded | |
Let me know if this helps anyone else or if you have any suggestions. | |
/*/ | |
function exportToJson(data, filename) { | |
let contentType = "application/json;charset=utf-8;"; | |
var str = JSON.stringify(data, null, "\t"); | |
var a = document.createElement('a'); | |
a.download = filename; | |
a.href = 'data:' + contentType + ',' + encodeURIComponent(str); | |
a.target = '_blank'; | |
document.body.appendChild(a); | |
a.click(); | |
document.body.removeChild(a); | |
} | |
function getSites(accountID = window.accId) { | |
return autocomplete_data.filter(site => { | |
if (site.link.includes("active_account=" + accountID) && site.text.includes("edit hosted domain")) { | |
site.domain = site.text.replace("edit hosted domain ", ""); | |
site.id = site.link.match(/(?<=&dsid=)[0-9]+/)[0]; | |
site.url = `https://panel.dreamhost.com/index.cgi?active_account=${accountID}&tree=domain.manage¤t_step=Index&next_step=ShowEdithttp&dsid=${site.id}`; | |
delete site.text; | |
delete site.link; | |
// Grab Additional Info from Dashboard's DOM | |
var tr = document.querySelector(`[href*="${site.id}"]`).closest('tr'), | |
edituser = tr.querySelector("#tracking_link_domain_manage_edituser"); | |
site.hosting = tr.querySelector('[data-title="Web Hosting"] li').innerText; | |
site.https = (tr.querySelector('[href*="domain.secure"]').text == "HTTPS Secure"); | |
if (edituser) site.user = edituser.text; | |
return site; | |
} | |
}); | |
} | |
function getSiteInfo(sites) { | |
return new Promise((resolve, reject) => { | |
var promiseList = []; | |
sites.forEach((site, i) => { | |
promiseList[i] = new Promise((resolve, reject) => { | |
fetch(site.url, { | |
method: 'GET' | |
}).then(res => res.text()).then(str => { | |
var parser = new DOMParser(); | |
return parser.parseFromString(str, 'text/html'); | |
}).then(doc => { | |
site.docroot = `/home/${site.user}/${doc.forms.cgi.docroot.value}`; | |
delete site.url; | |
resolve(site); | |
}).catch(err => { | |
reject(err); | |
}); | |
}); | |
}); | |
Promise.all(promiseList).then(() => { | |
resolve(sites); | |
}).catch(messages => { | |
reject(messages); | |
}); | |
}); | |
} | |
var sites = getSites(); | |
getSiteInfo(sites).then(sites => { | |
exportToJson(sites, 'sites.json'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment