Skip to content

Instantly share code, notes, and snippets.

@Brandon421-ops
Forked from WaveDemure/editor.html
Created May 12, 2024 19:40
Show Gist options
  • Save Brandon421-ops/9cf837a5c36fc8c4f4ea526d032ed4d0 to your computer and use it in GitHub Desktop.
Save Brandon421-ops/9cf837a5c36fc8c4f4ea526d032ed4d0 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>caubdns</title>
<style>
body {
background-color: black;
color: white;
font-family: monospace;
font-size: 18px;
margin: 40px
}
a {
color: cyan
}
.list {
line-height: 2
}
.border {
border: 2px solid white;
padding: 10px
}
</style>
</head>
<body>
<h1>caubdns editor</h1>
<input id="meteredToggle" type="checkbox" checked>enable metered (update blocker)</input>
<br>
<input id="dnsEnabled" type="checkbox">edit dns</input>
<br>
<input type="text" id="dns1" placeholder="Enter IP..." />
<br>
<input type="text" id="dns2" placeholder="Enter IP..." />
<br>
<input type="text" id="dns3" placeholder="Enter IP..." />
<br>
<input type="text" id="dns4" placeholder="Enter IP..." />
<br>
<br>
<input id="proxyEnabled" type="checkbox">edit proxy</input>
<br>
ftp proxy <input type="text" id="ftpProxy" placeholder="socks4://localhost" /><input value="1080" type="number" id="ftpProxyPort"></input>
<br>
HTTP proxy <input type="text" id="httpProxy" placeholder="socks4://localhost" /><input value="1080" type="number" id="httpProxyPort"></input>
<br>
secure HTTPS proxy <input type="text" id="secureHttpProxy" placeholder="socks4://localhost" /><input value="1080" type="number" id="secureHttpProxyPort"></input>
<br>
socks host <input type="text" id="socks" placeholder="localhost" /><input value="1080" type="number" id="socksProxyPort"></input>
<br>
domains to exclude as json array <input type="text" value="[]" id="excludeDomains" />
<br>
example:
<code>["*.com", "google.com"]</code>
<h1>Instructions</h1>
<div class="list">
Edit the settings above<br>
Go to chrome://network#state<br>
Scroll to "Favourite Networks"<br>
Find the wifi network that you are currently connected to<br>
Click the + next to the wifi name<br>
Copy all the data that appears (the {} curly braces)<br>
Paste the data into the box below and press the generate button<br>
</div>
<br>
<input class="inputData" placeholder="read instructions" />
<div id="extraInputs"></div>
<button onclick="addInput()">+</button>
<button onclick="removeInput()">-</button>
<br>
<button onclick="gen()">generate and download file</button>
<br>
<h1>Importing the ONC file</h1>
<div class="list">
Once you have downloaded the file, go to chrome://network#general<br>
Scroll to the bottom and click "Import ONC"<br>
Open the downloaded file, it should say "Networks imported: 1"<br>
Your network should be configured now.
</div>
<script>
let extraInputs = document.querySelector("#extraInputs")
function addInput(){
extraInputs.innerHTML += `<input type="text" class="inputData" />`
}
function removeInput(){
if(extraInputs.lastChild) extraInputs.lastChild.remove()
}
function gen() {
let inputDataElements = document.querySelectorAll(".inputData")
let onc = { Type: "UnencryptedConfiguration", NetworkConfigurations: [] };
inputDataElements.forEach(inputDataElement => {
try {
let network = JSON.parse(inputDataElement.value);
if (!network.GUID || !network.Name || !network.WiFi) throw new Error();
let configuration = {
GUID: network.GUID,
Metered: document.querySelector("#meteredToggle").checked,
Name: network.Name,
Type: "WiFi",
WiFi: {
AutoConnect: true,
SSID: network.Name,
Security: "None",
},
}
if(document.querySelector("#dnsEnabled").checked){
let nameServers = [];
["#dns1", "#dns2", "#dns3", "#dns4"].forEach(dnsSelector => {
let element = document.querySelector(dnsSelector)
nameServers.push(element.value === "" ? "0.0.0.0" : element.value)
})
configuration.NameServersConfigType = "Static"
configuration.StaticIPConfig = {
NameServers: nameServers
}
} else {
configuration.NameServersConfigType = "DHCP"
}
if(document.querySelector("#proxyEnabled").checked){
//parse json
//return error if failed
let parsedExcludeList
try {
parsedExcludeList = JSON.parse(document.querySelector("#excludeDomains").value)
} catch (e){
alert("failed to parse exclude domains list for proxy")
}
if(parsedExcludeList === undefined){
throw new Error()
}
configuration.ProxySettings = {
ExcludeDomains: parsedExcludeList,
Manual: {
FTPProxy: {
Host: document.querySelector("#ftpProxy").value,
Port: parseInt(document.querySelector("#ftpProxyPort").value)
},
HTTPProxy: {
Host: document.querySelector("#httpProxy").value,
Port: parseInt(document.querySelector("#httpProxyPort").value)
},
SOCKS: {
Host: document.querySelector("#socks").value,
Port: parseInt(document.querySelector("#socksProxyPort").value)
},
SecureHTTPProxy: {
Host: document.querySelector("#secureHttpProxy").value,
Port: parseInt(document.querySelector("#secureHttpProxyPort").value)
}
},
Type: "Manual"
}
} else {
configuration.ProxySettings = {
Type: "Direct"
}
}
onc.NetworkConfigurations.push(configuration);
inputDataElement.style.borderColor = "lime";
} catch (error) {
console.error(error);
inputDataElement.style.borderColor = "red";
}
})
if (onc.NetworkConfigurations[0]) download(onc);
}
function download(object, fileName) {
let link = document.createElement("a");
link.href = URL.createObjectURL(new Blob([JSON.stringify(object)]));
link.download = fileName || "network.onc";
link.click().remove();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment