Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dsTw5 authored Oct 20, 2023
1 parent d863600 commit 2e42a6d
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 86 deletions.
103 changes: 77 additions & 26 deletions transfers/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ <h2>
info.style.display = "none";
error.style.display = "none";
status_acc.style.display = "none";

data = {
phone: phoneSID,
laccount: losingAccountSID,
Expand All @@ -269,18 +269,23 @@ <h2>

if (json.er === 0) {
error.style.display = "";
info.style.display = "none";
error.innerHTML = `Wrong password.`;
console.log(response);
return;
}

if (response.status === 200) {
info.style.display = "";
info.innerHTML = `<pre>Success:<br />${JSON.stringify(json, null, 2)}</pre>`;
info.innerHTML = `<pre>Success :<br />${JSON.stringify(
json,
null,
2,
)}</pre>`;
} else {
console.error(json.error);
error.style.display = "";
error.innerHTML = `Something Wrong: ${json.error} - if you see the error "An internal server error has occurred", check that the Bundle SID is correct, present on the gaining account and approved for the number type you are transferring`;
error.innerHTML = `Something Wrong: ${json.error} <br />If you see the error "An internal server error has occurred", check that the Bundle SID is correct, present on the gaining account and approved for the number type you are transferring`;
}
} catch (err) {
//console.log (err);
Expand All @@ -291,9 +296,12 @@ <h2>
}

async function number_fetch() {
let adata = null;
let fdata = null;
let aresponse = null;
let fresponse = null;
let json2 = null;
let ajson = null;
let sid = null;
let asid = null;
let phoneNumber = null;
Expand All @@ -308,40 +316,81 @@ <h2>
warning.style.display = "none";
status_acc.style.display = "none";

fdata = {
phone: phoneNumber,
adata = {
pass: password,
};

fresponse = await fetch("./fetch_sid", {
aresponse = await fetch("./list_accounts", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(fdata),
body: JSON.stringify(adata),
});
console.log("return from function");
json2 = await fresponse.json();
console.log("return from Acc function");
console.log(aresponse);
if (aresponse.status === 200) {
ajson = await aresponse.json();
console.log(ajson);

if (json2.er === 0) {
if (ajson.er === 0) {
warning.style.display = "";
status_acc.style.display="none";
success.style.display = "none";
warning.innerHTML = `Wrong password.`;
return;
}
} else {
warning.style.display = "";
warning.innerHTML = `Wrong password.`;

warning.innerHTML = `Something went wrong with getting the list of accounts:<br /> Server error is ${aresponse.message}<br /> Server status is ${aresponse.status}`;
return;
}

for (a = 0; a < ajson.length; a++) {
fdata = {
phone: phoneNumber,
sub: ajson[a],
pass: password,
};

fresponse = await fetch("./fetch_sid", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(fdata),
});
console.log("return from function");
json2 = await fresponse.json();
success.style.display = "";
success.innerHTML = `<pre>Checked ${a} accounts.</pre>`;

if (json2.er === 0) {
warning.style.display = "";
success.style.display = "none";
status_acc.style.display="none";
warning.innerHTML = `Wrong password.`;
return;
}
if (json2 !== "not here") {
console.log(json2);
sid = json2.SID;
console.log(sid);
asid = json2.Acc;
phoneNumber = json2.pnumber;
numStatus = json2.status;
addReq = json2.addressReq;
break;
} else if (json2 === "not here") {
json2 = "number not found";
}
}

if (json2 === "number not found") {
warning.style.display = "";
success.style.display = "none";
warning.innerHTML = `<pre> ${JSON.stringify(json2, null, 2)}</pre>`;
} else {
console.log(json2);
sid = json2.SID;
console.log(sid);
asid = json2.Acc;
phoneNumber = json2.pnumber;
numStatus = json2.status;
addReq=json2.addressReq;

if (fresponse.status === 200) {
success.style.display = "";
success.innerHTML = `<pre>Number ${JSON.stringify(
Expand All @@ -359,15 +408,12 @@ <h2>
)} <br>Number Status ${JSON.stringify(
numStatus,
null,
2
)} <br>Address Requirements ${JSON.stringify(
addReq,
null,
2
)} </pre>`;
2,
)} <br>Address Requirements ${JSON.stringify(addReq, null, 2)} </pre>`;
} else {
console.error(json2.error);
warning.style.display = "";
success.style.display = "none";
warning.innerHTML = `Something Wrong: ${json2.error}`;
}
}
Expand Down Expand Up @@ -412,11 +458,16 @@ <h2>
acc = await response.json();

if (acc.er === 0) {
status_acc.style.display = "";
warning.style.display="none";
warning.innerHTML="";
status_acc.innerHTML = `Wrong password.`;

return;
}
status_acc.style.display = "none";
warning.style.display="none";
warning.innerHTML="";
masking.innerHTML = acc.acc;
status_acc.innerHTML = ``;
}
Expand Down
85 changes: 29 additions & 56 deletions transfers/functions/fetch_sid.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,51 @@
exports.handler = async function (context, event, callback) {
let phoneNumber = event.phone;
let finalData = null;
let allAccounts = [];
let i = 0;
let numAccounts = 1;
let subA = null;
let subClient = null;
let sSid = null;
let pNum = null;
let numStatus = null;
let addReq=null;
let sub = null;
let subResp = null;
let addReq = null;
const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const client = require("twilio")(accountSid, authToken);
const password = event.pass;
const client = require("twilio")(accountSid, authToken, {
accountSid: event.sub,
});

const response = new Twilio.Response();

response.appendHeader("Content-Type", "application/json");

if (password != process.env.Password) {
if (event.pass !== process.env.Password) {
finalData = { er: 0 };
return callback(null, finalData);
}

try {
sub = await client.api.v2010.accounts
.list()
.then((accounts) => accounts.forEach((a) => (allAccounts[i++] = a.sid)));

numAccounts = allAccounts.length;
try {
for (let j = 0; j < numAccounts; j++) {
subA = allAccounts[j].replace(/\"/g, "");

subClient = require("twilio")(accountSid, authToken, {
accountSid: subA,
});

subResp = await subClient.incomingPhoneNumbers
.list({ phoneNumber: phoneNumber })
.then((incomingPhoneNumbers) =>
incomingPhoneNumbers.forEach((k) => {
pNum = k.phoneNumber;
sSid = k.sid;
numStatus = k.status;
addReq = k.addressRequirements;
}),
);

finalData = {
Acc: subA,
pnumber: pNum,
SID: sSid,
status: numStatus,
addressReq: addReq,
};
if (pNum != null) {
response.setStatusCode(200);
response.setBody(sSid);
return callback(null, finalData);
}
}

await client.incomingPhoneNumbers
.list({ phoneNumber: event.phone })
.then((incomingPhoneNumbers) =>
incomingPhoneNumbers.forEach((k) => {
pNum = k.phoneNumber;
sSid = k.sid;
numStatus = k.status;
addReq = k.addressRequirements;
}),
);

if (pNum !== null) {
finalData = {
Acc: event.sub,
pnumber: pNum,
SID: sSid,
status: numStatus,
addressReq: addReq,
};
response.setStatusCode(200);
response.setBody("number not found");
return callback(null, response);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
response.setBody(finalData);
return callback(null, response);
}
response.setStatusCode(200);
response.setBody("not here");
return callback(null, response);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
Expand Down
2 changes: 1 addition & 1 deletion transfers/functions/get_account.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ exports.handler = async function (context, event, callback) {
const accountSid = { acc: process.env.ACCOUNT_SID };
const password = event.pass;

if (password != process.env.Password) {
if (password !== process.env.Password) {
finalData = { er: 0 };
return callback(null, finalData);
}
Expand Down
35 changes: 35 additions & 0 deletions transfers/functions/list_accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
exports.handler = async function (context, event, callback) {
let finalData = null;
let i = 0;

const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const client = require("twilio")(accountSid, authToken);
const response = new Twilio.Response();
const allAccounts = [];

response.appendHeader("Content-Type", "application/json");

if (event.pass !== process.env.Password) {
finalData = { er: 0 };
return callback(null, finalData);
}

try {
sub = await client.api.v2010.accounts.list().then((accounts) =>
accounts.forEach((a) => {
allAccounts[i] = a.sid;
i = i + 1;

Check failure on line 22 in transfers/functions/list_accounts.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14)

Assignment can be replaced with operator assignment

Check failure on line 22 in transfers/functions/list_accounts.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16)

Assignment can be replaced with operator assignment
}),
);

response.setStatusCode(200);
response.setBody(allAccounts);
return callback(null, response);
} catch (error) {
console.error(error.message);
response.setStatusCode(error.status || 400);
response.setBody({ error: error.message });
return callback(null, response);
}
};
6 changes: 3 additions & 3 deletions transfers/functions/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports.handler = async function (context, event, callback) {
const response = new Twilio.Response();
response.appendHeader("Content-Type", "application/json");

if (event.pass != process.env.Password) {
if (event.pass !== process.env.Password) {
finalData = { er: 0 };
return callback(null, finalData);
}
Expand All @@ -17,12 +17,12 @@ exports.handler = async function (context, event, callback) {
});

resp = await client
.incomingPhoneNumbers(event.phone) //number SID
.incomingPhoneNumbers(event.phone) // number SID
.update({
accountSid: event.gaccount,
bundleSid: event.bSID,
addressSid: event.aSID,
}); //account sid where the number should be transferred to
}); // account sid where the number should be transferred to

response.setStatusCode(200);
response.setBody(resp);
Expand Down

0 comments on commit 2e42a6d

Please sign in to comment.