207 lines
6.3 KiB
JavaScript
207 lines
6.3 KiB
JavaScript
const { getStreamsNew } = require('../routes/getStreams')
|
|
const { updateStreamData } = require('./updateStreams')
|
|
const { decryptPassword } = require('./password')
|
|
const { getUserAccountsCheck } = require('./getUser')
|
|
const { storeAccountToDB } = require('../lib/Accounts')
|
|
|
|
const axios = require('axios')
|
|
const tor_axios = require('tor-axios');
|
|
const tor = tor_axios.torSetup({
|
|
ip: process.env.TORSSRV,
|
|
port: 9050,
|
|
controlPort: '9051',
|
|
controlPassword: process.env.TORSPWD,
|
|
})
|
|
|
|
// axios.defaults.timeout = 10000;
|
|
// tor.defaults.timeout = 10000
|
|
|
|
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 splitURL(url) {
|
|
try {
|
|
let extractedURL = url.match(/[^/]*\/\/[^/]*/)[0]
|
|
let extractedUserPass = url.match(/\/player_api\.php\?username=([\s\S]*)$/)[1]
|
|
let UserPass = extractedUserPass.split('&password=')
|
|
return {
|
|
"extractedUrl": extractedURL,
|
|
"username": UserPass[0],
|
|
"password": UserPass[1]
|
|
}
|
|
} catch {
|
|
|
|
}
|
|
}
|
|
|
|
async function updateAccounts(userAccounts, data, url) {
|
|
try {
|
|
let URL = await splitURL(url)
|
|
|
|
let account = userAccounts.filter(account => account.username == URL.username && account.passwordDecryped == URL.password)[0]
|
|
|
|
await updateStreamData({
|
|
"username": account.username,
|
|
"password": account.password,
|
|
"userId": account.userId
|
|
}, URL.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(`${userAccount.username} - - ${URL.extractedUrl} - Expires ${date}.`)
|
|
} catch (error) {
|
|
}
|
|
}
|
|
|
|
|
|
async function addNewAccount(userAccount, data, url) {
|
|
try {
|
|
let URL = await splitURL(url)
|
|
|
|
await storeAccountToDB({
|
|
"username": userAccount.username,
|
|
"password": userAccount.password,
|
|
"userId": userAccount.userId,
|
|
"streamName": userAccount.stream,
|
|
"streamURL": URL.extractedUrl,
|
|
"expiryDate": data.user_info.exp_date
|
|
}, URL.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(`${userAccount.username} - - ${URL.extractedUrl} - Expires ${date}.`)
|
|
} catch (error) {
|
|
}
|
|
}
|
|
|
|
async function urlChecker(userAccounts, urlList) {
|
|
await tor.torNewSession(); //change tor ip
|
|
let ip = await tor.get('http://api.ipify.org')
|
|
console.log(ip.data);
|
|
await Promise.all(urlList.map(async (url) => {
|
|
try {
|
|
let response
|
|
url
|
|
if (url.includes('https')) {
|
|
try {
|
|
response = await axios.get(url)
|
|
} catch (error) {
|
|
// console.log(error)
|
|
}
|
|
} else {
|
|
response = await tor.get(url)
|
|
}
|
|
if (response.status == 200 && response.data !== "") {
|
|
try {
|
|
let data = response.data
|
|
if (data.user_info.auth) {
|
|
// console.log(url)
|
|
updateAccounts(userAccounts, data, url)
|
|
return true
|
|
}
|
|
} catch {
|
|
}
|
|
}
|
|
} catch (error) {
|
|
// console.log(error)
|
|
}
|
|
})).then((values) => {
|
|
endresponse = values
|
|
});
|
|
return endresponse
|
|
}
|
|
|
|
|
|
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))
|
|
}
|
|
}
|
|
|
|
|
|
values = await urlChecker(userAccounts, urlList)
|
|
if (values.includes(true)) {
|
|
let updatedCount = values.filter(function (value) {
|
|
return value === true;
|
|
}).length
|
|
console.log('true ' + updatedCount)
|
|
|
|
return endresponse = {
|
|
"update": true,
|
|
"count": updatedCount
|
|
}
|
|
} else {
|
|
return endresponse = false
|
|
}
|
|
|
|
}
|
|
|
|
|
|
async function singleAccountCheck(accountData) {
|
|
let endresponse
|
|
console.log(Date.now())
|
|
streamURLS = await getStreamsNew()
|
|
|
|
urlList = []
|
|
|
|
for (let index = 0; index < streamURLS.length; index++) {
|
|
const streamURL = streamURLS[index];
|
|
urlList.push(await buildURL(streamURL, accountData.username, accountData.password))
|
|
}
|
|
urlList
|
|
|
|
await Promise.all(urlList.map(async (url) => {
|
|
try {
|
|
const response = await axios.get({
|
|
method: 'GET',
|
|
headers: {
|
|
'User-Agent': 'GoldPlayer',
|
|
'Accept': '*/*'
|
|
},
|
|
url: url,
|
|
})
|
|
if (response.status == 200 && response.data !== "") {
|
|
try {
|
|
let data = response.data
|
|
if (data.user_info.auth) {
|
|
addNewAccount(accountData, data, url)
|
|
return true
|
|
}
|
|
} catch {
|
|
}
|
|
}
|
|
} catch {
|
|
}
|
|
})).then((values) => {
|
|
console.log(values)
|
|
if (values.includes(true)) {
|
|
endresponse = true
|
|
} else {
|
|
endresponse = false
|
|
}
|
|
});
|
|
return endresponse
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
userCheck,
|
|
singleAccountCheck
|
|
} |