working
This commit is contained in:
parent
6e235425f9
commit
1863addb17
@ -1,11 +1,12 @@
|
||||
const Cryptr = require('cryptr');
|
||||
const cryptr = new Cryptr('BBLBTV-DNS-PASSWORDS');
|
||||
|
||||
|
||||
const sql = require('./mysql')
|
||||
|
||||
function storeAccountToDB(accountDetails) {
|
||||
const encryptedPassword = cryptr.encrypt(accountDetails.password);
|
||||
const result = sql.query(`INSERT userAccounts (username, password, stream, userID, expiaryDate) VALUES ("${accountDetails.username}", "${encryptedPassword}", "${accountDetails.stream}", ${accountDetails.userId}, 123)`);
|
||||
const result = sql.query(`INSERT userAccounts (username, password, stream, userID, expiaryDate, streamURL) VALUES ("${accountDetails.username}", "${encryptedPassword}", "${accountDetails.streamName}", ${accountDetails.userId}, ${accountDetails.expiryDate}, "${accountDetails.streamURL}")`);
|
||||
return result
|
||||
}
|
||||
|
||||
|
224
lib/checker.js
224
lib/checker.js
@ -13,7 +13,7 @@ const { getAllUserAccounts, getUserAccountsCheck } = require('./getUser')
|
||||
|
||||
const { setExpired } = require('./setExpired')
|
||||
|
||||
const { removeAccountFromDB } = require('../lib/Accounts')
|
||||
const { removeAccountFromDB, storeAccountToDB } = require('../lib/Accounts')
|
||||
|
||||
const delay = ms => new Promise(res => setTimeout(res, ms));
|
||||
|
||||
@ -23,6 +23,100 @@ async function buildURL(streamURL, username, password) {
|
||||
return url
|
||||
}
|
||||
|
||||
async function splitURL(userAccounts, data, url) {
|
||||
try {
|
||||
re = /[^/]*\/\/[^/]*/
|
||||
let starturl = url.match(/[^/]*\/\/[^/]*/)[0]
|
||||
let nextbit = url.match(/\/player_api\.php\?username=([\s\S]*)$/)[1]
|
||||
let a = nextbit.split('&password=')
|
||||
|
||||
let account = userAccounts.filter(account => account.username == a[0] && account.passwordDecryped == a[1])[0]
|
||||
|
||||
await updateStreamData({
|
||||
"username": account.username,
|
||||
"password": account.password,
|
||||
"userId": account.userId
|
||||
}, starturl, data.user_info.exp_date)
|
||||
var date = new Date(data.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
|
||||
console.log(`${a[0]} - - ${starturl} - Expires ${date}.`)
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function addNewAccount(userAccount, data, url) {
|
||||
try {
|
||||
re = /[^/]*\/\/[^/]*/
|
||||
let extractedURL = url.match(/[^/]*\/\/[^/]*/)[0]
|
||||
let extractedUserPass = url.match(/\/player_api\.php\?username=([\s\S]*)$/)[1]
|
||||
let UserPass = extractedUserPass.split('&password=')
|
||||
|
||||
await storeAccountToDB({
|
||||
"username": userAccount.username,
|
||||
"password": userAccount.password,
|
||||
"userId": userAccount.userId,
|
||||
"streamName": userAccount.stream,
|
||||
"streamURL": extractedURL,
|
||||
"expiryDate": data.user_info.exp_date
|
||||
}, extractedURL, data.user_info.exp_date)
|
||||
var date = new Date(data.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
|
||||
console.log(`${UserPass[0]} - - ${extractedURL} - Expires ${date}.`)
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function userCheck(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
|
||||
})
|
||||
urlList = []
|
||||
|
||||
for (let index = 0; index < userAccounts.length; index++) {
|
||||
let userAccount = userAccounts[index];
|
||||
userAccount.urls = []
|
||||
for (let index = 0; index < streamURLS.length; index++) {
|
||||
const streamURL = streamURLS[index];
|
||||
userAccount.urls.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped))
|
||||
urlList.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped))
|
||||
}
|
||||
}
|
||||
userAccounts
|
||||
urlList
|
||||
|
||||
await Promise.all(urlList.map(async (url) => {
|
||||
try {
|
||||
const response = await axios.get(url)
|
||||
// console.log(url)
|
||||
if (response.status == 200 && response.data !== "") {
|
||||
try {
|
||||
let data = response.data
|
||||
if (data.user_info.auth) {
|
||||
splitURL(userAccounts, data, url)
|
||||
return true
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
} catch (error) {
|
||||
// return true
|
||||
}
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
} catch {
|
||||
// return true
|
||||
}
|
||||
}))
|
||||
return true
|
||||
}
|
||||
|
||||
async function newCheck() {
|
||||
streamURLS = await getStreamsNew()
|
||||
@ -58,56 +152,31 @@ async function newCheck() {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function updateAccountDNS(userAccount, streamURLS) {
|
||||
// return new Promise(async (resolve, reject) => {
|
||||
await Promise.all(streamURLS.map(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 {
|
||||
}
|
||||
}));
|
||||
}
|
||||
// async function updateAccountDNS(userAccount, streamURLS) {
|
||||
// // return new Promise(async (resolve, reject) => {
|
||||
// await Promise.all(streamURLS.map(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 {
|
||||
// }
|
||||
// }));
|
||||
// }
|
||||
|
||||
async function updateAccounts(userAccount, streamURLS) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
@ -136,28 +205,6 @@ async function updateAccounts(userAccount, streamURLS) {
|
||||
})
|
||||
}
|
||||
|
||||
async function userCheck(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
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
async function singleCheck(accountData) {
|
||||
@ -195,42 +242,51 @@ async function singleCheck(accountData) {
|
||||
}
|
||||
|
||||
const axios = require('axios')
|
||||
axios.defaults.timeout = 10000;
|
||||
|
||||
|
||||
async function singleAccountCheck(accountData) {
|
||||
let endresponse
|
||||
console.log(Date.now())
|
||||
streamURLS = await getStreamsNew()
|
||||
accountData
|
||||
|
||||
urlList = []
|
||||
|
||||
for (let index = 0; index < streamURLS.length; index++) {
|
||||
const streamURL = streamURLS[index];
|
||||
urlList.push(await buildURL(streamURL, accountData.username, accountData.password))
|
||||
|
||||
}
|
||||
urlList
|
||||
|
||||
for (let index = 0; index < urlList.length; index++) {
|
||||
const streamURL = urlList[index];
|
||||
await Promise.all(urlList.map(async (url) => {
|
||||
try {
|
||||
const response = await axios.get(streamURL)
|
||||
console.log(url)
|
||||
const response = await axios.get(url)
|
||||
console.log(response)
|
||||
if (response.status == 200 && response.data !== "") {
|
||||
try {
|
||||
let data = response.data
|
||||
if (data.user_info.auth) {
|
||||
var date = new Date(data.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
|
||||
// process.stdout.write('\n')
|
||||
console.log(`${accountData.username} - ${accountData.stream} - ${streamURL} - Expires ${date}.`)
|
||||
await updateStreamData(accountData, streamURL, data.user_info.exp_date)
|
||||
addNewAccount(accountData, data, url)
|
||||
return true
|
||||
}
|
||||
} catch (error) {
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
})).then((values) => {
|
||||
console.log(values)
|
||||
if (values.includes(true)) {
|
||||
endresponse = true
|
||||
} else {
|
||||
endresponse = false
|
||||
}
|
||||
});
|
||||
return endresponse
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
newCheck,
|
||||
singleCheck,
|
||||
|
@ -3,18 +3,19 @@ var router = express.Router();
|
||||
|
||||
const { storeAccountToDB } = require('../lib/Accounts')
|
||||
const { getUserId } = require('../lib/getUser')
|
||||
const { newUserCheck } = require('../lib/checker')
|
||||
const { userCheck } = require('../lib/checker')
|
||||
|
||||
/* POST postUser page. */
|
||||
router.get('/', async function (req, res, next) {
|
||||
let postData = req.body
|
||||
postData.userId = getUserId(req.auth.user)
|
||||
// postData.userId = 5
|
||||
a = await newUserCheck(postData)
|
||||
a = await userCheck(postData)
|
||||
console.log(Date.now())
|
||||
if (a) {
|
||||
res.send(200)
|
||||
res.sendStatus(200)
|
||||
} else {
|
||||
res.send(500);
|
||||
res.sendStatus(500);
|
||||
}
|
||||
// }
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user