Skip to content

Instantly share code, notes, and snippets.

@aayushmau5
Created February 20, 2022 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aayushmau5/c83b0bc6027ffcec105a27a5d97857ae to your computer and use it in GitHub Desktop.
Save aayushmau5/c83b0bc6027ffcec105a27a5d97857ae to your computer and use it in GitHub Desktop.
Deno code for Sophos login
enum AuthRequestType {
LOGIN,
LOGOUT,
}
function authRequest(
url: string,
username: string,
password: string,
authRequest: AuthRequestType
) {
const urlencoded = new URLSearchParams();
urlencoded.append("username", username);
const headers = {
"Content-Type": "application/x-www-form-urlencoded",
};
if (authRequest === AuthRequestType.LOGIN) {
const mode = "191";
fetch(url + "/login.xml", {
method: "POST",
headers,
body: new URLSearchParams({
mode,
username,
password,
}),
})
.then((response) => response.text())
.then((data) => console.log(data));
} else {
const mode = "193";
fetch(url + "/logout.xml", {
method: "POST",
headers,
body: new URLSearchParams({
mode,
username,
}),
})
.then((response) => response.text())
.then((data) => console.log(data));
}
}
function main() {
const username = Deno.env.get("SOPHOS_USERNAME");
if (!username) {
throw new Error("no username provided");
}
const password = Deno.env.get("SOPHOS_PASSWORD");
if (!password) {
throw new Error("no password provided");
}
const url = "http://172.16.68.6:8090";
authRequest(url, username, password, AuthRequestType.LOGIN);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment