2021-03-26 12:42:13 +00:00
|
|
|
const { getStreamsNew } = require('../routes/getStreams')
|
|
|
|
const { updateStreamData } = require('./updateStreams')
|
|
|
|
const { decryptPassword } = require('./password')
|
2021-11-19 11:52:28 +00:00
|
|
|
const { getUserAccountsCheck, getAllUniqueAccounts, getAllUserAccounts } = require('./getUser')
|
2021-09-23 15:26:24 +00:00
|
|
|
const { storeAccountToDB } = require('../lib/Accounts')
|
2021-11-19 11:52:28 +00:00
|
|
|
const { syncApache } = require('./apache_functions')
|
|
|
|
|
2021-03-26 12:42:13 +00:00
|
|
|
|
2021-09-21 13:37:32 +00:00
|
|
|
const axios = require('axios')
|
2021-09-23 15:26:24 +00:00
|
|
|
const tor_axios = require('tor-axios');
|
|
|
|
const tor = tor_axios.torSetup({
|
2021-09-23 17:25:44 +00:00
|
|
|
ip: process.env.TORSSRV,
|
2021-09-23 15:26:24 +00:00
|
|
|
port: 9050,
|
2021-11-16 17:37:04 +00:00
|
|
|
controlPort: 9051,
|
2021-09-23 17:25:44 +00:00
|
|
|
controlPassword: process.env.TORSPWD,
|
2021-09-23 15:26:24 +00:00
|
|
|
})
|
2021-09-23 13:54:01 +00:00
|
|
|
|
2021-11-19 11:52:28 +00:00
|
|
|
axios.defaults.timeout = 3000;
|
|
|
|
tor.defaults.timeout = 3000
|
|
|
|
|
2021-09-24 11:34:49 +00:00
|
|
|
const inst = axios.create({
|
|
|
|
httpAgent: tor.httpAgent(),
|
|
|
|
httpsagent: tor.httpsAgent(),
|
|
|
|
});
|
|
|
|
|
|
|
|
let axiosOptions = {
|
|
|
|
headers: {
|
|
|
|
'User-Agent': 'IPTV Smarters Pro'
|
|
|
|
}
|
|
|
|
}
|
2021-11-19 11:52:28 +00:00
|
|
|
|
2021-09-21 13:37:32 +00:00
|
|
|
|
2021-02-13 13:14:15 +00:00
|
|
|
const delay = ms => new Promise(res => setTimeout(res, ms));
|
|
|
|
|
2021-09-20 10:57:49 +00:00
|
|
|
|
2021-03-26 12:42:13 +00:00
|
|
|
async function buildURL(streamURL, username, password) {
|
|
|
|
let url = streamURL + "/player_api.php?username=" + username + "&password=" + password
|
|
|
|
return url
|
|
|
|
}
|
|
|
|
|
2021-09-21 13:37:32 +00:00
|
|
|
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) {
|
2021-09-21 13:26:03 +00:00
|
|
|
try {
|
2021-09-21 13:37:32 +00:00
|
|
|
let URL = await splitURL(url)
|
2021-09-21 13:26:03 +00:00
|
|
|
|
2021-09-21 13:37:32 +00:00
|
|
|
let account = userAccounts.filter(account => account.username == URL.username && account.passwordDecryped == URL.password)[0]
|
2021-09-21 13:26:03 +00:00
|
|
|
|
|
|
|
await updateStreamData({
|
|
|
|
"username": account.username,
|
|
|
|
"password": account.password,
|
|
|
|
"userId": account.userId
|
2021-09-21 13:37:32 +00:00
|
|
|
}, URL.extractedUrl, data.user_info.exp_date)
|
2021-09-21 13:26:03 +00:00
|
|
|
var date = new Date(data.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
|
2021-09-21 13:37:32 +00:00
|
|
|
console.log(`${userAccount.username} - - ${URL.extractedUrl} - Expires ${date}.`)
|
2021-09-21 13:26:03 +00:00
|
|
|
} catch (error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function addNewAccount(userAccount, data, url) {
|
|
|
|
try {
|
2021-09-21 13:37:32 +00:00
|
|
|
let URL = await splitURL(url)
|
2021-09-21 13:26:03 +00:00
|
|
|
|
|
|
|
await storeAccountToDB({
|
|
|
|
"username": userAccount.username,
|
|
|
|
"password": userAccount.password,
|
|
|
|
"userId": userAccount.userId,
|
|
|
|
"streamName": userAccount.stream,
|
2021-09-21 13:37:32 +00:00
|
|
|
"streamURL": URL.extractedUrl,
|
2021-11-16 17:37:04 +00:00
|
|
|
"expiryDate": data.user_info.exp_date,
|
|
|
|
"maxConnections": data.user_info.max_connections
|
2021-09-21 13:37:32 +00:00
|
|
|
}, URL.extractedUrl, data.user_info.exp_date)
|
2021-09-21 13:26:03 +00:00
|
|
|
var date = new Date(data.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
|
2021-11-19 11:52:28 +00:00
|
|
|
console.log(`${userAccount.username} - ${URL.extractedUrl} - Expires ${date}.`)
|
2021-09-21 13:26:03 +00:00
|
|
|
} catch (error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:26:24 +00:00
|
|
|
async function urlChecker(userAccounts, urlList) {
|
2021-09-24 11:34:49 +00:00
|
|
|
let ip = await inst.get('http://api.ipify.org')
|
2021-09-23 15:26:24 +00:00
|
|
|
console.log(ip.data);
|
|
|
|
await Promise.all(urlList.map(async (url) => {
|
|
|
|
try {
|
2021-09-23 17:25:44 +00:00
|
|
|
let response
|
|
|
|
url
|
2021-09-24 11:34:49 +00:00
|
|
|
response = await inst.get(url, axiosOptions)
|
2021-09-23 15:26:24 +00:00
|
|
|
if (response.status == 200 && response.data !== "") {
|
|
|
|
try {
|
|
|
|
let data = response.data
|
|
|
|
if (data.user_info.auth) {
|
2021-11-19 11:52:28 +00:00
|
|
|
console.log('.')
|
2021-09-23 15:26:24 +00:00
|
|
|
updateAccounts(userAccounts, data, url)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
}
|
|
|
|
}
|
2021-09-24 11:34:49 +00:00
|
|
|
} catch {
|
2021-09-23 15:26:24 +00:00
|
|
|
}
|
|
|
|
})).then((values) => {
|
|
|
|
endresponse = values
|
|
|
|
});
|
|
|
|
return endresponse
|
|
|
|
}
|
|
|
|
|
2021-09-21 13:26:03 +00:00
|
|
|
|
2021-11-19 11:52:28 +00:00
|
|
|
// async function allUserCheck() {
|
|
|
|
// let start = Date.now()
|
|
|
|
// console.log(start)
|
|
|
|
// streamURLS = await getStreamsNew()
|
|
|
|
// let userAccounts = await getAllUserAccounts()
|
|
|
|
|
|
|
|
// 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 urlCheckerNew(userAccounts[3], urlList)
|
|
|
|
// if (values.includes(true)) {
|
|
|
|
// let updatedCount = values.filter(function (value) {
|
|
|
|
// return value === true;
|
|
|
|
// }).length
|
|
|
|
// console.log('true ' + updatedCount)
|
|
|
|
// console.log((Date.now() - start) / 1000)
|
|
|
|
// return endresponse = {
|
|
|
|
// "update": true,
|
|
|
|
// "count": updatedCount
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// return endresponse = false
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// async function allUserCheck() {
|
|
|
|
// let start = Date.now()
|
|
|
|
// console.log(start)
|
|
|
|
// streamURLS = await getStreamsNew()
|
|
|
|
// let userAccounts = await getAllUserAccounts()
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
// console.log((Date.now() - start) / 1000)
|
|
|
|
// return endresponse = {
|
|
|
|
// "update": true,
|
|
|
|
// "count": updatedCount
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// return endresponse = false
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
2021-09-21 13:26:03 +00:00
|
|
|
async function userCheck(accountData) {
|
2021-09-24 11:34:49 +00:00
|
|
|
let start = Date.now()
|
|
|
|
console.log(start)
|
2021-09-21 13:26:03 +00:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-14 13:05:07 +00:00
|
|
|
|
2021-09-23 15:26:24 +00:00
|
|
|
values = await urlChecker(userAccounts, urlList)
|
|
|
|
if (values.includes(true)) {
|
|
|
|
let updatedCount = values.filter(function (value) {
|
|
|
|
return value === true;
|
|
|
|
}).length
|
|
|
|
console.log('true ' + updatedCount)
|
2021-09-24 11:34:49 +00:00
|
|
|
console.log((Date.now() - start) / 1000)
|
2021-09-23 15:26:24 +00:00
|
|
|
return endresponse = {
|
|
|
|
"update": true,
|
|
|
|
"count": updatedCount
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return endresponse = false
|
|
|
|
}
|
2021-09-14 13:05:07 +00:00
|
|
|
|
2021-09-23 15:26:24 +00:00
|
|
|
}
|
2021-03-26 12:42:13 +00:00
|
|
|
|
2021-11-19 11:52:28 +00:00
|
|
|
async function accountChecker(accountData, urlList) {
|
|
|
|
let ip = await inst.get('http://api.ipify.org')
|
|
|
|
console.log(ip.data);
|
|
|
|
|
|
|
|
for (let index = 0; index < urlList.length; index++) {
|
|
|
|
const url = urlList[index];
|
|
|
|
console.log(index + 1 + ' of ' + urlList.length + ' urls checked')
|
|
|
|
try {
|
|
|
|
let response = await inst.get(url, axiosOptions)
|
|
|
|
if (response.data.user_info.auth) {
|
|
|
|
addNewAccount(accountData, data, url)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
try {
|
|
|
|
if (error.response.status == 403) {
|
|
|
|
let response2 = await axios.get(url, axiosOptions)
|
|
|
|
if (response2.data.user_info.auth) {
|
|
|
|
try {
|
|
|
|
await addNewAccount(accountData, response2.data, url)
|
|
|
|
console.log('New Account Added')
|
|
|
|
syncApache()
|
|
|
|
return true
|
|
|
|
} catch (error) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-09-20 19:30:47 +00:00
|
|
|
|
|
|
|
async function singleAccountCheck(accountData) {
|
|
|
|
streamURLS = await getStreamsNew()
|
2021-09-21 13:26:03 +00:00
|
|
|
|
2021-09-20 19:30:47 +00:00
|
|
|
urlList = []
|
|
|
|
|
|
|
|
for (let index = 0; index < streamURLS.length; index++) {
|
|
|
|
const streamURL = streamURLS[index];
|
|
|
|
urlList.push(await buildURL(streamURL, accountData.username, accountData.password))
|
|
|
|
}
|
2021-09-21 13:26:03 +00:00
|
|
|
urlList
|
2021-11-19 11:52:28 +00:00
|
|
|
return await accountChecker(accountData, urlList)
|
|
|
|
}
|
2021-09-20 19:30:47 +00:00
|
|
|
|
2021-09-24 11:34:49 +00:00
|
|
|
|
2021-09-20 19:30:47 +00:00
|
|
|
|
2021-09-21 13:26:03 +00:00
|
|
|
|
2021-02-13 13:14:15 +00:00
|
|
|
module.exports = {
|
2021-09-20 19:30:47 +00:00
|
|
|
userCheck,
|
2021-11-19 11:52:28 +00:00
|
|
|
singleAccountCheck,
|
|
|
|
// allUserCheck
|
|
|
|
}
|
|
|
|
|
|
|
|
// singleAccountCheck({ "username": "Karl0ss01", "password": "YqQjYH9Nzw", "userId": 1, "stream": "Badger" })
|