Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: physical emails hos-000 #199

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hajonsoft-eagle",
"version": "2.6.3",
"version": "2.6.6",
"description": "HAJonSoft node app to submit passengers to visa systems",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const nshFromEmail = "[email protected]";
const nskFromEmail = "[email protected]";
const messages = {};

async function fetchNusukIMAPOTP(recipient, password, subject, callback) {
async function fetchNusukIMAPOTP(recipient, password, subject, callback, isNotVirtualEmail) {
var imap = new Imap({
user: `admin@${recipient.split("@")[1]}`,
user: isNotVirtualEmail ? recipient : `admin@${recipient.split("@")[1]}`,
password: password,
host: `mail.${recipient.split("@")[1]}`,
port: 993,
Expand Down
80 changes: 50 additions & 30 deletions src/nsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ async function pageContentHandler(currentConfig) {
[
{
selector: "#CreatePasswordViewModel_Password",
value: () => getPassword(),
value: (row) => getPassword(row),
},
{
selector: "#CreatePasswordViewModel_PasswordConfirmation",
value: () => getPassword(),
value: (row) => getPassword(row),
},
],
passenger
Expand Down Expand Up @@ -544,10 +544,10 @@ async function pageContentHandler(currentConfig) {
"6/2024"
);
// wait 500 ms for the days to load, then select the day
// await page.waitForTimeout(500);
// await page.click(
// "body > div.datepick-popup > div > div.datepick-month-row > div > table > tbody > tr:nth-child(2) > td:nth-child(6) > a"
// );
await page.waitForTimeout(500);
await page.click(
"body > div.datepick-popup > div > div.datepick-month-row > div > table > tbody > tr:nth-child(2) > td:nth-child(6) > a"
);
break;
case "summary":
await util.controller(page, currentConfig, data.travellers);
Expand Down Expand Up @@ -579,9 +579,20 @@ async function pageContentHandler(currentConfig) {
await checkIfNotChecked("#SentencedToPrisonBeforeNo");
await checkIfNotChecked("#ConvictedInSmugglingMoneyLaunderingNo");
await checkIfNotChecked("#BelongedToTerroristOrganizationBeforeNo");
await checkIfNotChecked("#RequiredVaccinationsBeenTakenNo");
await checkIfNotChecked("#RequiredVaccinationsBeenTakenYes");
await checkIfNotChecked("#HaveAnyPhysicalDisabilityNo");
await checkIfNotChecked("#ArrestedOrConvictedForTerrorismBeforeNo");
await page.waitForTimeout(100);
await util.commit(
page,
[
{
selector: "#BackgroundStepTwoViewModel_RequiredVaccinationsBeenTakenAnswer",
value: () => "ACWY",
},
],
{}
);

await page.evaluate(() => {
window.scrollTo(0, document.body.scrollHeight);
Expand Down Expand Up @@ -699,19 +710,19 @@ async function pageContentHandler(currentConfig) {
function suggestEmail(selectedTraveler, companion = false) {
const passenger = data.travellers[selectedTraveler];
if (passenger.email) {
return passenger.email;
return passenger.email.split('/')[0];
}
const domain = data.system.username.includes("@")
? data.system.username.split("@")[1]
: data.system.username;
const friendlyName = `${passenger.name.first}.${passenger.name.last}.${
companion ? "companion." : ""
}${moment().unix().toString(36)}@${domain}`
}${passenger.passportNumber}@${domain}`
.toLowerCase()
.replace(/ /g, "");
const unfriendlyName = `${passenger.name.first}.${data.system.accountId}.${
companion ? "companion." : ""
}${moment().unix().toString(36)}@${domain}`
}${passenger.passportNumber}@${domain}`
.toLowerCase()
.replace(/ /g, "");
const email = data.system.username.includes("@")
Expand Down Expand Up @@ -799,27 +810,31 @@ async function getOTPCode() {
);
await page.$eval(
"#otpForm > label",
(el, email) =>
(el.innerText = `${email} from (admin@${email.split("@")[1]})`),
passenger.email || emailAddress
(el, email, fromString) =>
(el.innerText = `${email.split('/')[0]} ${fromString}`),
passenger.email || emailAddress,
(passenger.email || emailAddress).includes('/') ? '' : `from (admin@${(passenger.email || emailAddress).split("@")[1].split("/")[0]})`

);
try {
if (pageMode.includes("Registration") || pageMode.includes("التسجيل")) {
await fetchNusukIMAPOTP(
passenger.email || emailAddress,
data.system.adminEmailPassword,
(passenger.email || emailAddress).split('/')[0],
(passenger.email || emailAddress).includes('/') ? (passenger.email || emailAddress).split('/')[1] : data.system.adminEmailPassword,
["Email Activation", "تفعيل البريد الالكتروني"],
pasteOTPCode
pasteOTPCode,
(passenger.email || emailAddress).includes('/')
);
} else if (
pageMode.includes("OTP Verification") ||
pageMode.includes("التثبت من رمز التحقق")
) {
await fetchNusukIMAPOTP(
passenger.email || emailAddress,
data.system.adminEmailPassword,
(passenger.email || emailAddress).split('/')[0],
(passenger.email || emailAddress).includes('/') ? (passenger.email || emailAddress).split('/')[1] : data.system.adminEmailPassword,
["One Time Password", "رمز سري لمرة واحدة"],
pasteOTPCode
pasteOTPCode,
(passenger.email || emailAddress).includes('/')
);
}
} catch (e) {
Expand All @@ -837,10 +852,11 @@ async function getCompanionOTPCode() {
const pageMode = "OTP Verification";
try {
await fetchNusukIMAPOTP(
passenger.email || emailAddress,
data.system.adminEmailPassword,
(passenger.email || emailAddress).split('/')[0],
(passenger.email || emailAddress).includes('/') ? (passenger.email || emailAddress).split('/')[1] : data.system.adminEmailPassword,
["One Time Password", "رمز سري لمرة واحدة"],
pasteOTPCodeCompanion
pasteOTPCodeCompanion,
(passenger.email || emailAddress).includes('/')
);
} catch (e) {
await util.infoMessage(page, "Manual code required!");
Expand Down Expand Up @@ -868,7 +884,7 @@ async function addNewMember(selectedTraveler) {
[
{
selector: "#AddMemberViewModel_Email",
value: () => email,
value: () => email.split('/')[0],
},
],
{}
Expand All @@ -888,6 +904,13 @@ async function addNewMember(selectedTraveler) {
},
},
});

await page.$eval(
"#OTPModal > div > div > div > form > label",
(el, email) =>
(el.innerText = `${email.split('/')[0]} from (admin@${email.split("@")[1].split("/")[0]})`),
passenger.email || emailAddress
);
await getCompanionOTPCode();
}
const usedCodes = {};
Expand Down Expand Up @@ -923,7 +946,7 @@ async function signup_step1(selectedTraveler) {
[
{
selector: "#SignupViewModel_Email",
value: (row) => emailAddress,
value: (row) => emailAddress.split("/")[0],
},
{
selector: "#SignupViewModel_CountryResidenceId",
Expand Down Expand Up @@ -974,12 +997,12 @@ async function loginPassenger(selectedTraveler) {
[
{
selector: "#LogInViewModel_Email",
value: (row) => row.email || emailAddress,
value: (row) => (row.email || emailAddress).split("/")[0],
},

{
selector: "#LogInViewModel_Password",
value: () => getPassword(),
value: (row) => getPassword(row),
},
],
passenger
Expand Down Expand Up @@ -1250,10 +1273,7 @@ async function pasteOTPCodeCompanion(err, code) {
await util.clickWhenReady("#OTPModalBtn", page);
}

function getPassword() {
// if (data.system.password.endsWith("+passport")) {
// return `${data.system.password.replace("+passport", "")}${data.travellers[util.getSelectedTraveler()].passportNumber}`;
// }
function getPassword(passenger) {
return data.system.password;
}

Expand Down
2 changes: 1 addition & 1 deletion src/nsk.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async function downloadVisas() {
if (data.travellers[i].email) {
await fetchNusukIMAPPDF(
data.travellers[i].email,
data.system.adminEmailPassword,
data.system.adminEmailPassword || "(HajonSoft123)",
["التأشيرة الإلكترونية", "Electronic Visa"],
(err, pdf) =>
saveVisaPDF(
Expand Down
Loading