Skip to content

Commit

Permalink
ip address check for client and server
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfly722 committed Sep 14, 2024
1 parent 8362bf6 commit 016ecf8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions cloak-wg-helper/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,49 @@ function fill(){
}
}

function isValidIPaddress(ipaddress) {
return (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))
}

/*
function zeroPad(num, places) {
return String(num).padStart(places, '0')
}
function linesNumbers(str) {
var n = str.split(/\r\n|\r|\n/).length
return [...Array(n).keys()].map((i)=> zeroPad(i+1,3)).join("\n")
}
*/

function cloakClientUpdate(value){
if (isValidIPaddress(value)) {
document.getElementById("cloakClient").style.color="green"
onChange("cloakClient", value);
} else {
document.getElementById("cloakClient").style.color="red"
}
}

function cloakGatewayUpdate(value){
if (isValidIPaddress(value)) {
document.getElementById("cloakGateway").style.color="green"
onChange("cloakGateway", value);
} else {
document.getElementById("cloakGateway").style.color="red"
}
}

function cloakServerUpdate(value){
if (isValidIPaddress(value)) {
document.getElementById("cloakServer").style.color="green"
onChange("cloakServer", value);
} else {
document.getElementById("cloakServer").style.color="red"
}
}


function subst(string, data) {
return string.replace(/:([a-zA-Z]+)/g, (m, i) => i in data ? "<b style='background-color:powderblue;' id='"+i+"_'>"+data[i]+"</b>" : m)
}
Expand Down Expand Up @@ -200,8 +243,7 @@ sudo sysctl -p</code></pre>
`

let server = `
<pre><code>
# ----------------- 2.1 Install Cloak Server binary ----------------------
<pre><code># ----------------- 2.1 Install Cloak Server binary ----------------------
wget https://github.com/cbeuw/Cloak/releases/download/v2.7.0/ck-server-:serverOS-:serverArch-v2.7.0 -O ck-server
chmod +x ck-server
sudo mv ck-server /usr/bin/ck-server
Expand Down Expand Up @@ -289,7 +331,6 @@ sudo systemctl restart [email protected]
sudo systemctl status [email protected]
sudo wg</code></pre>
`

document.getElementById("client").innerHTML = subst(client, params);
document.getElementById("server").innerHTML = subst(server, params);
}
Expand All @@ -298,6 +339,5 @@ window.onload = function() {
regenerateWireguard();
regenerateCloak();
fill();
update();
};

update();
};
Binary file modified cloak-wg-helper/index.html
Binary file not shown.

0 comments on commit 016ecf8

Please sign in to comment.