341 lines
13 KiB
JavaScript
341 lines
13 KiB
JavaScript
|
|
let streamArrays = require('./streamArray.json')
|
|
|
|
let users = require('./logins.json')
|
|
|
|
const { getStreamsNew } = require('../routes/getStreams')
|
|
|
|
const { updateStreamData } = require('./updateStreams')
|
|
|
|
const { gotRequest } = require('./gotRequest')
|
|
|
|
const { decryptPassword } = require('./password')
|
|
|
|
const { getAllUserAccounts, getUserAccountsCheck } = require('./getUser')
|
|
|
|
const { setExpired } = require('./setExpired')
|
|
|
|
const { removeAccountFromDB } = require('../lib/Accounts')
|
|
|
|
const delay = ms => new Promise(res => setTimeout(res, ms));
|
|
|
|
|
|
async function buildURL(streamURL, username, password) {
|
|
let url = streamURL + "/player_api.php?username=" + username + "&password=" + password
|
|
return url
|
|
}
|
|
|
|
async function singleCheck(username) {
|
|
let user = users.find(user => user.username === username)
|
|
for (let index = 0; index < streamArrays.length; index++) {
|
|
await delay(500);
|
|
const stream = streamArrays[index];
|
|
process.stdout.write('.')
|
|
// let url = stream.StreamURL + "/player_api.php?username=" + user.username + "&password=" + user.password
|
|
let url = await buildURL(stream.streamURL, user.username, user.password)
|
|
let t = await gotRequest(url)
|
|
let body = t.body
|
|
if (t.statusCode == 200 && body !== "") {
|
|
body = JSON.parse(body)
|
|
if (body.user_info.auth) {
|
|
var date = new Date(body.user_info.exp_date * 1000)
|
|
process.stdout.write('\n')
|
|
console.log('Match - ' + user.username + ' - ' + stream.StreamURL + ' - ' + stream.StreamName + ' - Expires - ' + date)
|
|
stream.username = user.username
|
|
stream.expiaryDate = date.toLocaleDateString('en-GB')
|
|
return (stream)
|
|
}
|
|
}
|
|
}
|
|
process.stdout.write('\nEnd Of Streams\n\n')
|
|
}
|
|
|
|
async function main() {
|
|
for (let index = 0; index < users.length; index++) {
|
|
const user = users[index];
|
|
console.log('Trying ' + user.username)
|
|
for (let index = 0; index < streamArrays.length; index++) {
|
|
await delay(500);
|
|
const stream = streamArrays[index];
|
|
process.stdout.write('.')
|
|
let url = await buildURL(stream.streamURL, user.username, user.password)
|
|
let t = await gotRequest(url)
|
|
let body = t.body
|
|
if (t.statusCode == 200 && body !== "") {
|
|
try {
|
|
body = JSON.parse(body)
|
|
if (body.user_info.auth) {
|
|
// var date = new Date(body.user_info.exp_date * 1000).toLocaleDateString('en-GB')
|
|
process.stdout.write('\n')
|
|
console.log('Match - ' + user.username + ' - ' + stream.StreamURL + ' - ' + stream.StreamName + ' - Expires - ' + body.user_info.exp_date)
|
|
break
|
|
}
|
|
} catch (error) {
|
|
}
|
|
}
|
|
}
|
|
process.stdout.write('\nEnd Of Streams\n\n')
|
|
}
|
|
console.log('Finished')
|
|
}
|
|
|
|
async function newCheck() {
|
|
streamURLS = await getStreamsNew()
|
|
let userAccounts = await getAllUserAccounts()
|
|
userAccounts = userAccounts.map(async user => {
|
|
user.passwordDecryped = decryptPassword(user.password)
|
|
return user
|
|
})
|
|
for (let userAccount of userAccounts) {
|
|
if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
|
|
setExpired(userAccount)
|
|
} else {
|
|
for (let streamURL of streamURLS) {
|
|
process.stdout.write('.')
|
|
let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)
|
|
let t = await gotRequest(url)
|
|
let body = t.body
|
|
if (t.statusCode == 200 && body !== "") {
|
|
try {
|
|
body = JSON.parse(body)
|
|
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' })
|
|
// process.stdout.write('\n')
|
|
console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`)
|
|
await updateStreamData(userAccount, streamURL, body.user_info.exp_date)
|
|
break
|
|
}
|
|
} catch (error) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async function test(userAccount, streamURLS) {
|
|
streamURLS.forEach(async streamURL => {
|
|
process.stdout.write('.')
|
|
let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)
|
|
// console.log('tested url ' + url)
|
|
let t = await gotRequest(url)
|
|
let body = t.body
|
|
if (t.statusCode == 200 && body !== "") {
|
|
try {
|
|
body = JSON.parse(body)
|
|
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' })
|
|
// process.stdout.write('\n')
|
|
console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`)
|
|
await updateStreamData(userAccount, streamURL, body.user_info.exp_date)
|
|
return true
|
|
}
|
|
} catch (error) {
|
|
// break
|
|
}
|
|
} else {
|
|
return false
|
|
}
|
|
})
|
|
}
|
|
|
|
function updateAccountDNS(userAccount, streamURLS) {
|
|
return new Promise((resolve, reject) => {
|
|
streamURLS.forEach(async streamURL => {
|
|
process.stdout.write('.')
|
|
let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)
|
|
// console.log('tested url ' + url)
|
|
let t = await gotRequest(url)
|
|
let body = t.body
|
|
if (t.statusCode == 200 && body !== "") {
|
|
try {
|
|
body = JSON.parse(body)
|
|
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' })
|
|
// process.stdout.write('\n')
|
|
console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`)
|
|
await updateStreamData(userAccount, streamURL, body.user_info.exp_date)
|
|
resolve(true)
|
|
}
|
|
} catch (error) {
|
|
// break
|
|
}
|
|
} else {
|
|
// resolve(false)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
async function updateAccounts(userAccount, streamURLS) {
|
|
return new Promise(async (resolve, reject) => {
|
|
await streamURLS.forEach(async streamURL => {
|
|
process.stdout.write('.')
|
|
let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)
|
|
console.log('tested url ' + url)
|
|
let t = await gotRequest(url)
|
|
let body = t.body
|
|
if (t.statusCode == 200 && body !== "") {
|
|
try {
|
|
body = JSON.parse(body)
|
|
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' })
|
|
// process.stdout.write('\n')
|
|
console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`)
|
|
await updateStreamData(userAccount, streamURL, body.user_info.exp_date)
|
|
resolve(true)
|
|
}
|
|
} catch (error) {
|
|
}
|
|
} else {
|
|
}
|
|
})
|
|
reject(userAccount)
|
|
})
|
|
}
|
|
|
|
async function newUserCheck(accountData) {
|
|
console.log(Date.now())
|
|
streamURLS = await getStreamsNew()
|
|
let userAccounts = await getUserAccountsCheck(accountData.userId)
|
|
|
|
userAccounts = userAccounts.map(user => {
|
|
user.userId = accountData.userId
|
|
user.passwordDecryped = decryptPassword(user.password)
|
|
return user
|
|
})
|
|
|
|
try {
|
|
for (let i = 0; i < userAccounts.length; ++i) {
|
|
const userAccount = userAccounts[i];
|
|
if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
|
|
setExpired(userAccount)
|
|
} else {
|
|
await updateAccountDNS(userAccount, streamURLS)
|
|
}
|
|
}
|
|
console.log(Date.now())
|
|
return true
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
|
|
async function newSingleCheck(accountData) {
|
|
streamURLS = await getStreamsNew()
|
|
let userAccounts = await getUserAccountsCheck(accountData.userId)
|
|
userAccounts = userAccounts.map(user => {
|
|
user.userId = accountData.userId
|
|
user.passwordDecryped = decryptPassword(user.password)
|
|
return user
|
|
})
|
|
userAccounts = userAccounts.filter(obj => {
|
|
return obj.username === accountData.username && obj.passwordDecryped === accountData.password && obj.stream === accountData.stream
|
|
})
|
|
|
|
try {
|
|
for (let i = 0; i < userAccounts.length; ++i) {
|
|
const userAccount = userAccounts[i];
|
|
if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
|
|
setExpired(userAccount)
|
|
} else {
|
|
await updateAccounts(userAccount, streamURLS)
|
|
}
|
|
}
|
|
console.log(Date.now())
|
|
return true
|
|
} catch (userAccount) {
|
|
console.log('notfoundincatch')
|
|
// console.error(error);
|
|
removeAccountFromDB({
|
|
"user": userAccount.username,
|
|
"stream": userAccount.stream,
|
|
"userId": accountData.userId
|
|
})
|
|
}
|
|
// console.log('not found')
|
|
|
|
// for (let userAccount of result) {
|
|
// if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
|
|
// setExpired(userAccount)
|
|
// } else {
|
|
// for (let streamURL of streamURLS) {
|
|
// process.stdout.write('.')
|
|
// let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)
|
|
// console.log('trying ' + url)
|
|
// let t = await gotRequest(url)
|
|
// let body = t.body
|
|
// if (t.statusCode == 200 && body !== "") {
|
|
// try {
|
|
// body = JSON.parse(body)
|
|
// 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' })
|
|
// // process.stdout.write('\n')
|
|
// console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`)
|
|
// await updateStreamData(userAccount, streamURL, body.user_info.exp_date)
|
|
// return true
|
|
// }
|
|
// } catch (error) {
|
|
// }
|
|
// }
|
|
// }
|
|
// removeAccountFromDB({
|
|
// "user": userAccount.username,
|
|
// "stream": userAccount.stream,
|
|
// "userId": accountData.userId
|
|
// })
|
|
// return false
|
|
// }
|
|
// }
|
|
}
|
|
|
|
|
|
// async function newSingleCheck(userData) {
|
|
// streamURLS = await getStreamsNew()
|
|
// for (let streamURL of streamURLS) {
|
|
// process.stdout.write('.')
|
|
// let url = await buildURL(streamURL, userData.username, userData.password)
|
|
// // console.log(url)
|
|
// let t = await gotRequest(url)
|
|
// let body = t.body
|
|
// if (t.statusCode == 200 && body !== "") {
|
|
// try {
|
|
// body = JSON.parse(body)
|
|
// if (body.user_info.auth) {
|
|
// // var date = new Date(body.user_info.exp_date * 1000).toLocaleDateString('en-GB')
|
|
// // process.stdout.write('\n')
|
|
// await updateStreamData(userAccount, streamURL, body.user_info.exp_date)
|
|
// console.log(`Match - ${username} - ${streamURL} - Expires - ${body.user_info.exp_date}`)
|
|
// return (`Match - ${username} - ${streamURL} - Expires - ${body.user_info.exp_date}`)
|
|
// // break
|
|
// }
|
|
// } catch (error) {
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// // }
|
|
|
|
// newSingleCheck
|
|
|
|
// main()
|
|
// singleCheck('Karl2903')
|
|
// newCheck()
|
|
// newUserCheck({
|
|
// "username": 'Karl0ss1709',
|
|
// "password": 'YEfbZskEH2Zu',
|
|
// "stream": "Badger",
|
|
// "userId": 1
|
|
// })
|
|
|
|
|
|
// newUserCheck(1)
|
|
|
|
module.exports = {
|
|
newCheck,
|
|
singleCheck,
|
|
main,
|
|
newSingleCheck,
|
|
newUserCheck
|
|
} |