Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
fix: make hiddenInputNameValueMap props enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Mar 22, 2021
1 parent bbeb9a4 commit 83b7a53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions crawler/casLogIn.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const cheerio = require('cheerio')
const fetch = require('node-fetch')

const crypto = require('crypto')
const fetch = require('node-fetch')
const log = require('../interface/colorLog')
const ocr = require('./captcha')

Expand All @@ -16,7 +15,7 @@ module.exports = async (school, user) => {
const schoolEdgeCases = require('./school-edge-cases')(school.name, school.casOrigin.includes('iap'))

const headers = {
'Cache-control': 'max-age=0',
'Cache-Control': 'max-age=0',
'Accept-Encoding': 'gzip, deflate',
'Upgrade-Insecure-Requests': '1',
'User-agent':
Expand All @@ -38,7 +37,7 @@ module.exports = async (school, user) => {
headers.Origin = `https://${headers.Host}`

// get base session -> cookie
res = await fetch(school.login, { headers })
res = await fetch(school.login, { headers, redirect: 'manual' })
reCook(res, 1)

// grab hidden input name-value, this maybe error-prone, but compatible
Expand All @@ -64,18 +63,21 @@ module.exports = async (school, user) => {
} else {
// if we got there, this site definitely uses AJAX to get those props (`iap`)
// we need to request those properties manually
headers.Referer = res.headers.get('location')
const ltWrapper = new URL(headers.Referer).search
if (Object.keys(hiddenInputNameValueMap).length === 0) {
res = await fetch(`${school.casOrigin}${schoolEdgeCases.lt}`, {
res = await fetch(`${school.casOrigin}${schoolEdgeCases.lt}${ltWrapper}`, {
headers,
method: 'POST',
})
const { result } = await res.json()
Object.defineProperties(hiddenInputNameValueMap, {
lt: { value: result._lt },
needCaptcha: { value: result.needCapt },
dllt: { value: '' },
iap: { value: true },
lt: { value: result._lt, enumerable: true },
needCaptcha: { value: result.needCapt, enumerable: true },
dllt: { value: '', enumerable: true },
iap: { value: true, enumerable: true },
})
// seems dcampus forgot to impl _encryptSalt, comment it out temporarily
// pwdSalt = result._encryptSalt
reCook(res, 1)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beetcb/cea",
"version": "2.1.5",
"version": "2.1.6",
"description": "campusphere-elegant-auth: login to swms/campusphere at ease",
"main": "dist/index.js",
"bin": "dist/cli.js",
Expand Down

0 comments on commit 83b7a53

Please sign in to comment.