Skip to content

Instantly share code, notes, and snippets.

@callaginn
Last active November 5, 2021 05:36
Show Gist options
  • Save callaginn/e8c3a578cf6620ee5d3eaa8862f4a54e to your computer and use it in GitHub Desktop.
Save callaginn/e8c3a578cf6620ee5d3eaa8862f4a54e to your computer and use it in GitHub Desktop.
Fetch and Download Dreamhost Domain Info
/*/
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&current_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