working
This commit is contained in:
parent
d4a025fadd
commit
bd5e0fd4f8
194
lib/checker.js
194
lib/checker.js
@ -2,18 +2,24 @@ const { getStreamsNew } = require('../routes/getStreams')
|
|||||||
|
|
||||||
const { updateStreamData } = require('./updateStreams')
|
const { updateStreamData } = require('./updateStreams')
|
||||||
|
|
||||||
const { gotRequest } = require('./gotRequest')
|
|
||||||
|
|
||||||
const { decryptPassword } = require('./password')
|
const { decryptPassword } = require('./password')
|
||||||
|
|
||||||
const { getAllUserAccounts, getUserAccountsCheck } = require('./getUser')
|
const { getAllUserAccounts, getUserAccountsCheck } = require('./getUser')
|
||||||
|
|
||||||
const { setExpired } = require('./setExpired')
|
|
||||||
|
|
||||||
const { removeAccountFromDB, storeAccountToDB } = require('../lib/Accounts')
|
const { removeAccountFromDB, storeAccountToDB } = require('../lib/Accounts')
|
||||||
|
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
axios.defaults.timeout = 10000;
|
const { wrapper } = require('axios-cookiejar-support')
|
||||||
|
// import { wrapper } from 'axios-cookiejar-support';
|
||||||
|
const { CookieJar } = require('tough-cookie')
|
||||||
|
// import { CookieJar } from 'tough-cookie';
|
||||||
|
|
||||||
|
const jar = new CookieJar();
|
||||||
|
const client = wrapper(axios.create({ jar }));
|
||||||
|
|
||||||
|
// axios.defaults.timeout = 5000;
|
||||||
|
|
||||||
const delay = ms => new Promise(res => setTimeout(res, ms));
|
const delay = ms => new Promise(res => setTimeout(res, ms));
|
||||||
|
|
||||||
@ -101,63 +107,95 @@ async function userCheck(accountData) {
|
|||||||
|
|
||||||
await Promise.all(urlList.map(async (url) => {
|
await Promise.all(urlList.map(async (url) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url)
|
const response = await axios({
|
||||||
// console.log(url)
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'User-Agent': 'PostmanRuntime/7.28.4',
|
||||||
|
'Accept': '*/*'
|
||||||
|
},
|
||||||
|
url: url,
|
||||||
|
})
|
||||||
|
console.log(url)
|
||||||
if (response.status == 200 && response.data !== "") {
|
if (response.status == 200 && response.data !== "") {
|
||||||
try {
|
try {
|
||||||
let data = response.data
|
let data = response.data
|
||||||
if (data.user_info.auth) {
|
if (data.user_info.auth) {
|
||||||
|
console.log(url)
|
||||||
updateAccounts(userAccounts, data, url)
|
updateAccounts(userAccounts, data, url)
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// return true
|
console.log(error)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (error) {
|
||||||
// return true
|
console.log(error)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}))
|
})).then((values) => {
|
||||||
return true
|
console.log(values)
|
||||||
|
if (values.includes(true)) {
|
||||||
|
let count = values.filter(function (value) {
|
||||||
|
return value === true;
|
||||||
|
}).length
|
||||||
|
let count2 = values.filter(function (value) {
|
||||||
|
return value === false;
|
||||||
|
}).length
|
||||||
|
console.log('true ' + count)
|
||||||
|
console.log('fail ' + count2)
|
||||||
|
t = count + count2
|
||||||
|
console.log(t)
|
||||||
|
endresponse = true
|
||||||
|
} else {
|
||||||
|
console.log('true ' + count)
|
||||||
|
console.log('fail ' + count2)
|
||||||
|
t = count + count2
|
||||||
|
console.log(t)
|
||||||
|
endresponse = false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return endresponse
|
||||||
}
|
}
|
||||||
|
|
||||||
async function newCheck() {
|
// async function newCheck() {
|
||||||
streamURLS = await getStreamsNew()
|
// streamURLS = await getStreamsNew()
|
||||||
let userAccounts = await getAllUserAccounts()
|
// let userAccounts = await getAllUserAccounts()
|
||||||
userAccounts = userAccounts.map(async user => {
|
// userAccounts = userAccounts.map(async user => {
|
||||||
user.passwordDecryped = decryptPassword(user.password)
|
// user.passwordDecryped = decryptPassword(user.password)
|
||||||
return user
|
// return user
|
||||||
})
|
// })
|
||||||
for (let userAccount of userAccounts) {
|
// for (let userAccount of userAccounts) {
|
||||||
if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
|
// if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
|
||||||
setExpired(userAccount)
|
// setExpired(userAccount)
|
||||||
} else {
|
// } else {
|
||||||
for (let streamURL of streamURLS) {
|
// for (let streamURL of streamURLS) {
|
||||||
process.stdout.write('.')
|
// process.stdout.write('.')
|
||||||
let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)
|
// let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)
|
||||||
let t = await gotRequest(url)
|
// let t = await gotRequest(url)
|
||||||
let body = t.body
|
// let body = t.body
|
||||||
if (t.statusCode == 200 && body !== "") {
|
// if (t.statusCode == 200 && body !== "") {
|
||||||
try {
|
// try {
|
||||||
body = JSON.parse(body)
|
// body = JSON.parse(body)
|
||||||
if (body.user_info.auth) {
|
// if (body.user_info.auth) {
|
||||||
var date = new Date(body.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
|
// var date = new Date(body.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
|
||||||
// process.stdout.write('\n')
|
// // process.stdout.write('\n')
|
||||||
console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`)
|
// console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`)
|
||||||
await updateStreamData(userAccount, streamURL, body.user_info.exp_date)
|
// await updateStreamData(userAccount, streamURL, body.user_info.exp_date)
|
||||||
break
|
// break
|
||||||
}
|
// }
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
// async function updateAccountDNS(userAccount, streamURLS) {
|
// async function updateAccountDNS(userAccount, streamURLS) {
|
||||||
@ -214,39 +252,39 @@ async function newCheck() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function singleCheck(accountData) {
|
// async function singleCheck(accountData) {
|
||||||
streamURLS = await getStreamsNew()
|
// streamURLS = await getStreamsNew()
|
||||||
let userAccounts = await getUserAccountsCheck(accountData.userId)
|
// let userAccounts = await getUserAccountsCheck(accountData.userId)
|
||||||
userAccounts = userAccounts.map(user => {
|
// userAccounts = userAccounts.map(user => {
|
||||||
user.userId = accountData.userId
|
// user.userId = accountData.userId
|
||||||
user.passwordDecryped = decryptPassword(user.password)
|
// user.passwordDecryped = decryptPassword(user.password)
|
||||||
return user
|
// return user
|
||||||
})
|
// })
|
||||||
userAccounts = userAccounts.filter(obj => {
|
// userAccounts = userAccounts.filter(obj => {
|
||||||
return obj.username === accountData.username && obj.passwordDecryped === accountData.password && obj.stream === accountData.stream
|
// return obj.username === accountData.username && obj.passwordDecryped === accountData.password && obj.stream === accountData.stream
|
||||||
})
|
// })
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
for (let i = 0; i < userAccounts.length; ++i) {
|
// for (let i = 0; i < userAccounts.length; ++i) {
|
||||||
const userAccount = userAccounts[i];
|
// const userAccount = userAccounts[i];
|
||||||
if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
|
// if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
|
||||||
setExpired(userAccount)
|
// setExpired(userAccount)
|
||||||
} else {
|
// } else {
|
||||||
await updateAccounts(userAccount, streamURLS)
|
// await updateAccounts(userAccount, streamURLS)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
console.log(Date.now())
|
// console.log(Date.now())
|
||||||
return true
|
// return true
|
||||||
} catch (userAccount) {
|
// } catch (userAccount) {
|
||||||
console.log('notfoundincatch')
|
// console.log('notfoundincatch')
|
||||||
// console.error(error);
|
// // console.error(error);
|
||||||
removeAccountFromDB({
|
// removeAccountFromDB({
|
||||||
"user": userAccount.username,
|
// "user": userAccount.username,
|
||||||
"stream": userAccount.stream,
|
// "stream": userAccount.stream,
|
||||||
"userId": accountData.userId
|
// "userId": accountData.userId
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
async function singleAccountCheck(accountData) {
|
async function singleAccountCheck(accountData) {
|
||||||
@ -292,8 +330,6 @@ async function singleAccountCheck(accountData) {
|
|||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
newCheck,
|
|
||||||
singleCheck,
|
|
||||||
userCheck,
|
userCheck,
|
||||||
singleAccountCheck
|
singleAccountCheck
|
||||||
}
|
}
|
49
package-lock.json
generated
49
package-lock.json
generated
@ -183,6 +183,14 @@
|
|||||||
"follow-redirects": "^1.14.0"
|
"follow-redirects": "^1.14.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"axios-cookiejar-support": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios-cookiejar-support/-/axios-cookiejar-support-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-z3q8j0h051jkLtNRohfAXBTtFEMxWDTTADy8sb4cRl2g0Zmk1/613ioorV132FiSSIHjj3XQnG66ow77qHCrDg==",
|
||||||
|
"requires": {
|
||||||
|
"http-cookie-agent": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"babel-runtime": {
|
"babel-runtime": {
|
||||||
"version": "6.26.0",
|
"version": "6.26.0",
|
||||||
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
|
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
|
||||||
@ -374,6 +382,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
||||||
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
|
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
|
||||||
},
|
},
|
||||||
|
"cookie": {
|
||||||
|
"version": "0.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
|
||||||
|
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA=="
|
||||||
|
},
|
||||||
"cookie-signature": {
|
"cookie-signature": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
@ -714,6 +727,15 @@
|
|||||||
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",
|
||||||
"integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ=="
|
"integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ=="
|
||||||
},
|
},
|
||||||
|
"http-cookie-agent": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/http-cookie-agent/-/http-cookie-agent-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-gde0TzbcynnVRYG38YKBOzJTIZat97FLBJCETHVhwBDe9A5WJS5iKwnHqj3Z+EerRwdADd05ukAT4JBt7XV4BA==",
|
||||||
|
"requires": {
|
||||||
|
"agent-base": "^6.0.2",
|
||||||
|
"cookie": "^0.4.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"http-errors": {
|
"http-errors": {
|
||||||
"version": "1.6.3",
|
"version": "1.6.3",
|
||||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
|
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
|
||||||
@ -1170,6 +1192,17 @@
|
|||||||
"tough-cookie": "~2.5.0",
|
"tough-cookie": "~2.5.0",
|
||||||
"tunnel-agent": "^0.6.0",
|
"tunnel-agent": "^0.6.0",
|
||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"tough-cookie": {
|
||||||
|
"version": "2.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
|
||||||
|
"integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==",
|
||||||
|
"requires": {
|
||||||
|
"psl": "^1.1.28",
|
||||||
|
"punycode": "^2.1.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"resolve-alpn": {
|
"resolve-alpn": {
|
||||||
@ -1359,12 +1392,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tough-cookie": {
|
"tough-cookie": {
|
||||||
"version": "2.5.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz",
|
||||||
"integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==",
|
"integrity": "sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"psl": "^1.1.28",
|
"psl": "^1.1.33",
|
||||||
"punycode": "^2.1.1"
|
"punycode": "^2.1.1",
|
||||||
|
"universalify": "^0.1.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tunnel-agent": {
|
"tunnel-agent": {
|
||||||
@ -1394,6 +1428,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||||
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
|
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
|
||||||
},
|
},
|
||||||
|
"universalify": {
|
||||||
|
"version": "0.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
||||||
|
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
|
||||||
|
},
|
||||||
"unpipe": {
|
"unpipe": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.21.4",
|
"axios": "^0.21.4",
|
||||||
|
"axios-cookiejar-support": "^2.0.0",
|
||||||
"bcrypt": "^5.0.0",
|
"bcrypt": "^5.0.0",
|
||||||
"cryptr": "^6.0.2",
|
"cryptr": "^6.0.2",
|
||||||
"express": "~4.16.1",
|
"express": "~4.16.1",
|
||||||
@ -14,6 +15,7 @@
|
|||||||
"got": "^11.8.1",
|
"got": "^11.8.1",
|
||||||
"http-errors": "~1.6.3",
|
"http-errors": "~1.6.3",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"sync-mysql": "^3.0.1"
|
"sync-mysql": "^3.0.1",
|
||||||
|
"tough-cookie": "^4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
|
|
||||||
const { removeAccountFromDB} = require('../lib/Accounts')
|
const { removeAccountFromDB } = require('../lib/Accounts')
|
||||||
const { getUserId } = require('../lib/getUser')
|
const { getUserId } = require('../lib/getUser')
|
||||||
|
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ router.post('/', async function (req, res, next) {
|
|||||||
let result = await removeAccountFromDB(postData)
|
let result = await removeAccountFromDB(postData)
|
||||||
console.log(result)
|
console.log(result)
|
||||||
if (result.affectedRows < 1) {
|
if (result.affectedRows < 1) {
|
||||||
res.send('Adding account failed')
|
res.sendStatus(500)
|
||||||
} else {
|
} else {
|
||||||
res.send('Account ' + postData.username + ' Deleted from ' + userName)
|
res.send('Account ' + postData.username + ' Deleted from ' + userName)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
|
|
||||||
const { storeAccountToDB } = require('../lib/Accounts')
|
|
||||||
const { getUserId } = require('../lib/getUser')
|
const { getUserId } = require('../lib/getUser')
|
||||||
const { userCheck } = require('../lib/checker')
|
const { userCheck } = require('../lib/checker')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user