Skip to content

Instantly share code, notes, and snippets.

@kenrick95
Last active January 5, 2018 13:16
Show Gist options
  • Save kenrick95/5126864b6768bffb0a919d16a9d0c0c0 to your computer and use it in GitHub Desktop.
Save kenrick95/5126864b6768bffb0a919d16a9d0c0c0 to your computer and use it in GitHub Desktop.
IDHostinger SSL Install Helper
// ==UserScript==
// @name IDHostinger SSL Install Helper
// @author Kenrick
// @version 1.2
// @description This script will help installation process of Let's Encrypt SSL on IDHostinger.
// @grant none
// @run-at document-end
// @include https://cpanel.hostinger.co.id/advanced/ssl/aid/*
// @include https://cpanel.hostinger.co.id/cart/finish/aid/*
// ==/UserScript==
(function() {
if (window.location.href.includes("cart/finish")) {
window.history.go(-1);
return;
}
var configForm = document.querySelector(".portlet-body");
var settingsBox = document.createElement("div");
configForm.insertBefore(settingsBox, configForm.firstChild);
settingsBox.setAttribute(
"style",
"border-top: 3px double #D11141;" +
" border-bottom: 3px double #D11141; padding: 5px 0 5px;"
);
var logBox = document.createElement("div");
logBox.setAttribute(
"style",
"color: #f90; font-size: 1.125em; display: none;"
);
/*
{
index: int
len: int
domains: []
crt: str
key: str
}
*/
var data = sessionStorage.getItem("sslhelper-data");
if (data !== null) {
data = JSON.parse(data);
runSSLHelper(data.index);
}
function runSSLHelper(index) {
var realDomainField = document.querySelector("select[name='domain']"),
realCrtField = document.querySelector("textarea[name='crt']"),
realKeyField = document.querySelector("textarea[name='key']");
if (index >= data.len) {
alert("Done");
sessionStorage.removeItem("sslhelper-data");
return;
}
var currentDomain = data.domains[index];
realDomainField.value = currentDomain;
realCrtField.value = data.crt;
realKeyField.value = data.key;
data.index += 1;
sessionStorage.setItem("sslhelper-data", JSON.stringify(data));
document
.querySelector("#advanced-php-config-form button[type='submit']")
.click();
}
function submitSSLHelper(e) {
e.preventDefault();
var fakeDomainField = document.querySelector("#sslhelper-domains"),
fakeCrtField = document.querySelector("#sslhelper-crt"),
fakeKeyField = document.querySelector("#sslhelper-key");
var domains = document
.querySelector("#sslhelper-domains")
.value.split(",")
.map(v => {
return v.trim();
}),
crt = document.querySelector("#sslhelper-crt").value,
key = document.querySelector("#sslhelper-key").value;
if (domains.length === 0 || domains[0] === "") {
alert("Domains can't be empty");
return;
}
if (crt.length === 0) {
alert("CRT can't be empty");
return;
}
if (key.length === 0) {
alert("KEY can't be empty");
return;
}
var submitPrompt = window.confirm(
'Use at your own risk; CRT & KEY is stored in browser\'s session storage and will be cleared once submission are completed\n"OK" to continue, "Cancel" to Cancel.'
);
if (!submitPrompt) {
return;
}
data = {
index: 0,
len: domains.length,
domains: domains,
crt: crt,
key: key
};
sessionStorage.setItem("sslhelper-data", JSON.stringify(data));
runSSLHelper(0);
}
// Settings_Box content
(function() {
var div, temp, helpText;
/* Line 1 */
div = document.createElement("div");
temp = document.createElement("a");
temp.textContent = "IDHostinger SSL Install Helper";
temp.target = "_blank";
temp.setAttribute("style", "font-weight: bold");
div.appendChild(temp);
settingsBox.appendChild(div);
/* Line 2 */
div = document.createElement("div");
temp = document.createElement("b");
temp.appendChild(document.createTextNode("Domains (comma-separated): "));
div.appendChild(temp);
temp = document.createElement("input");
temp.setAttribute("type", "text");
temp.setAttribute("id", "sslhelper-domains");
div.appendChild(temp);
settingsBox.appendChild(div);
/* Line 3 */
div = document.createElement("div");
temp = document.createElement("b");
temp.appendChild(document.createTextNode("Certificate (CRT): "));
div.appendChild(temp);
temp = document.createElement("textarea");
temp.setAttribute("id", "sslhelper-crt");
div.appendChild(temp);
settingsBox.appendChild(div);
/* Line 4 */
div = document.createElement("div");
temp = document.createElement("b");
temp.appendChild(document.createTextNode("Private Key (KEY): "));
div.appendChild(temp);
temp = document.createElement("textarea");
temp.setAttribute("id", "sslhelper-key");
div.appendChild(temp);
settingsBox.appendChild(div);
/* Line 5 */
div = document.createElement("div");
temp = document.createElement("button");
temp.setAttribute("class", "btn blue");
temp.textContent = "Submit";
temp.onclick = submitSSLHelper;
div.appendChild(temp);
settingsBox.appendChild(div);
/* Line 6 */
settingsBox.appendChild(logBox);
})();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment