working
This commit is contained in:
parent
cded4b8c55
commit
7e4bb69b48
13
.vscode/launch.json
vendored
13
.vscode/launch.json
vendored
@ -11,7 +11,16 @@
|
|||||||
"skipFiles": [
|
"skipFiles": [
|
||||||
"<node_internals>/**"
|
"<node_internals>/**"
|
||||||
],
|
],
|
||||||
"type": "pwa-node"
|
"type": "pwa-node",
|
||||||
|
"env": {
|
||||||
|
"DBHOST": "vps.k-world.me.uk",
|
||||||
|
"DBUSER": "root",
|
||||||
|
"DBPASS": "Grd555269",
|
||||||
|
"DATABASE": "BBLB_DNS",
|
||||||
|
"DBPORT": "3306",
|
||||||
|
"TORSSRV": "localhost",
|
||||||
|
"TORSPWD": "KarlMax",
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
@ -45,6 +54,8 @@
|
|||||||
"DBPASS": "Grd555269",
|
"DBPASS": "Grd555269",
|
||||||
"DATABASE": "BBLB_DNS",
|
"DATABASE": "BBLB_DNS",
|
||||||
"DBPORT": "3306",
|
"DBPORT": "3306",
|
||||||
|
"TORSSRV": "localhost",
|
||||||
|
"TORSPWD": "KarlMax",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
const { actions, configs } = require('apache-api');
|
const { configs } = require('apache-api');
|
||||||
|
|
||||||
const { getStreamsNew } = require('../routes/getStreams')
|
const { getStreamsNew } = require('../routes/getStreams')
|
||||||
|
const { getURLandStreams } = require('./getStreamNames')
|
||||||
|
const { allUserCheck } = require('./checker')
|
||||||
|
|
||||||
apache_config = 'tv.k-world'
|
apache_config = 'tv.k-world'
|
||||||
|
|
||||||
@ -50,22 +52,45 @@ async function split_streams(siteList) {
|
|||||||
return final_array
|
return final_array
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function updateStream(sub, oldUrl, newUrl) {
|
async function updateStream(updatedStreams) {
|
||||||
// config = await get_config()
|
config = await get_config()
|
||||||
// config.children[0].children.map(function (item) {
|
updatedStreams.forEach(async stream => {
|
||||||
// // string = `Redirect 302 /${sub} "${oldUrl}"`
|
config.children[0].children.map(async function (item) {
|
||||||
// if (item.content.includes(oldUrl)) {
|
if (item.content.includes(stream[1])) {
|
||||||
// console.log('found')
|
return item.content = `Redirect 302 /${stream[0]} "${stream[2]}"`
|
||||||
// return item.content = `Redirect 302 /${sub} "${newUrl}"`
|
}
|
||||||
// }
|
})
|
||||||
// })
|
try {
|
||||||
// try {
|
await configs.saveConfig(apache_config, config, true, true)
|
||||||
// await configs.saveConfig(apache_config, config, true, true)
|
console.log(stream[0] + ' url updated')
|
||||||
// } catch (error) {
|
} catch (error) {
|
||||||
// console.log(error)
|
console.log(stream[0] + ' url failed to update')
|
||||||
// }
|
console.log(error)
|
||||||
// await actions.restartApache()
|
}
|
||||||
// }
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function updateStreamCheck(streamsFromKtvDB, streamsFromConfig) {
|
||||||
|
updatedStreams = []
|
||||||
|
streamsFromConfig.forEach(sfc => {
|
||||||
|
streamsFromKtvDB.forEach(sfktv => {
|
||||||
|
if (sfc[0] == sfktv.stream) {
|
||||||
|
sfc[0]
|
||||||
|
sfktv.stream
|
||||||
|
if (sfc[1] != sfktv.streamURL) {
|
||||||
|
console.log(sfc[0] + ' url changed')
|
||||||
|
updatedStreams.push([sfc[0], sfc[1], sfktv.streamURL])
|
||||||
|
} else {
|
||||||
|
// console.log(sfc[0] + ' not updated')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return updatedStreams
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function checkExists(fullStreamList, mappedStreams) {
|
async function checkExists(fullStreamList, mappedStreams) {
|
||||||
newstreams = mappedStreams.map(function (s) {
|
newstreams = mappedStreams.map(function (s) {
|
||||||
@ -94,16 +119,32 @@ async function addNewStreams(config, streamList) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update('DIAZ', 'http://google.com', 'https://watchtower.ddns.net:8443')
|
async function syncApache() {
|
||||||
|
// console.log('Updating all user account from ktv')
|
||||||
|
// await allUserCheck()
|
||||||
|
// console.log('Update complete')
|
||||||
|
console.log('Comparing streams from ktv and apache')
|
||||||
|
streams = await getStreamsNew()
|
||||||
|
config = await get_config()
|
||||||
|
streamsFromConfig = await split_streams(config.children[0].children)
|
||||||
|
|
||||||
|
streamsFromKtvDB = await getURLandStreams()
|
||||||
async function main() {
|
updatedStreams = await updateStreamCheck(streamsFromKtvDB, streamsFromConfig)
|
||||||
|
await updateStream(updatedStreams)
|
||||||
|
console.log('Complete')
|
||||||
|
console.log('Adding any missing streams to apache')
|
||||||
streams = await getStreamsNew()
|
streams = await getStreamsNew()
|
||||||
config = await get_config()
|
config = await get_config()
|
||||||
streamsFromConfig = await split_streams(config.children[0].children)
|
streamsFromConfig = await split_streams(config.children[0].children)
|
||||||
missingStreamsInApache = await checkExists(streams, streamsFromConfig)
|
missingStreamsInApache = await checkExists(streams, streamsFromConfig)
|
||||||
resultOfAddStreams = await addNewStreams(config, missingStreamsInApache)
|
resultOfAddStreams = await addNewStreams(config, missingStreamsInApache)
|
||||||
|
console.log('Complete')
|
||||||
|
console.log('Restarting Apache')
|
||||||
await restart()
|
await restart()
|
||||||
|
console.log('Complete')
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
syncApache
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
|
||||||
|
172
lib/checker.js
172
lib/checker.js
@ -1,8 +1,10 @@
|
|||||||
const { getStreamsNew } = require('../routes/getStreams')
|
const { getStreamsNew } = require('../routes/getStreams')
|
||||||
const { updateStreamData } = require('./updateStreams')
|
const { updateStreamData } = require('./updateStreams')
|
||||||
const { decryptPassword } = require('./password')
|
const { decryptPassword } = require('./password')
|
||||||
const { getUserAccountsCheck } = require('./getUser')
|
const { getUserAccountsCheck, getAllUniqueAccounts, getAllUserAccounts } = require('./getUser')
|
||||||
const { storeAccountToDB } = require('../lib/Accounts')
|
const { storeAccountToDB } = require('../lib/Accounts')
|
||||||
|
const { syncApache } = require('./apache_functions')
|
||||||
|
|
||||||
|
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const tor_axios = require('tor-axios');
|
const tor_axios = require('tor-axios');
|
||||||
@ -13,6 +15,9 @@ const tor = tor_axios.torSetup({
|
|||||||
controlPassword: process.env.TORSPWD,
|
controlPassword: process.env.TORSPWD,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
axios.defaults.timeout = 3000;
|
||||||
|
tor.defaults.timeout = 3000
|
||||||
|
|
||||||
const inst = axios.create({
|
const inst = axios.create({
|
||||||
httpAgent: tor.httpAgent(),
|
httpAgent: tor.httpAgent(),
|
||||||
httpsagent: tor.httpsAgent(),
|
httpsagent: tor.httpsAgent(),
|
||||||
@ -23,8 +28,7 @@ let axiosOptions = {
|
|||||||
'User-Agent': 'IPTV Smarters Pro'
|
'User-Agent': 'IPTV Smarters Pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// axios.defaults.timeout = 10000;
|
|
||||||
// tor.defaults.timeout = 10000
|
|
||||||
|
|
||||||
const delay = ms => new Promise(res => setTimeout(res, ms));
|
const delay = ms => new Promise(res => setTimeout(res, ms));
|
||||||
|
|
||||||
@ -81,13 +85,12 @@ async function addNewAccount(userAccount, data, url) {
|
|||||||
"maxConnections": data.user_info.max_connections
|
"maxConnections": data.user_info.max_connections
|
||||||
}, URL.extractedUrl, 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' })
|
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}.`)
|
console.log(`${userAccount.username} - ${URL.extractedUrl} - Expires ${date}.`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function urlChecker(userAccounts, urlList) {
|
async function urlChecker(userAccounts, urlList) {
|
||||||
// await tor.torNewSession(); //change tor ip
|
|
||||||
let ip = await inst.get('http://api.ipify.org')
|
let ip = await inst.get('http://api.ipify.org')
|
||||||
console.log(ip.data);
|
console.log(ip.data);
|
||||||
await Promise.all(urlList.map(async (url) => {
|
await Promise.all(urlList.map(async (url) => {
|
||||||
@ -99,7 +102,7 @@ async function urlChecker(userAccounts, urlList) {
|
|||||||
try {
|
try {
|
||||||
let data = response.data
|
let data = response.data
|
||||||
if (data.user_info.auth) {
|
if (data.user_info.auth) {
|
||||||
console.log(url)
|
console.log('.')
|
||||||
updateAccounts(userAccounts, data, url)
|
updateAccounts(userAccounts, data, url)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -115,6 +118,89 @@ async function urlChecker(userAccounts, urlList) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
async function userCheck(accountData) {
|
async function userCheck(accountData) {
|
||||||
let start = Date.now()
|
let start = Date.now()
|
||||||
console.log(start)
|
console.log(start)
|
||||||
@ -156,9 +242,44 @@ async function userCheck(accountData) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function singleAccountCheck(accountData) {
|
async function singleAccountCheck(accountData) {
|
||||||
let endresponse
|
|
||||||
streamURLS = await getStreamsNew()
|
streamURLS = await getStreamsNew()
|
||||||
|
|
||||||
urlList = []
|
urlList = []
|
||||||
@ -168,39 +289,16 @@ async function singleAccountCheck(accountData) {
|
|||||||
urlList.push(await buildURL(streamURL, accountData.username, accountData.password))
|
urlList.push(await buildURL(streamURL, accountData.username, accountData.password))
|
||||||
}
|
}
|
||||||
urlList
|
urlList
|
||||||
|
return await accountChecker(accountData, urlList)
|
||||||
let ip = await inst.get('http://api.ipify.org')
|
|
||||||
console.log(ip.data);
|
|
||||||
|
|
||||||
await Promise.all(urlList.map(async (url) => {
|
|
||||||
|
|
||||||
try {
|
|
||||||
response = await inst.get(url, axiosOptions)
|
|
||||||
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 = {
|
module.exports = {
|
||||||
userCheck,
|
userCheck,
|
||||||
singleAccountCheck
|
singleAccountCheck,
|
||||||
|
// allUserCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// singleAccountCheck({ "username": "Karl0ss01", "password": "YqQjYH9Nzw", "userId": 1, "stream": "Badger" })
|
@ -10,7 +10,19 @@ function getStreamNames() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getStreamNames
|
function getURLandStreams() {
|
||||||
|
let data = sql.query(`SELECT DISTINCT stream, streamURL FROM BBLB_DNS.userAccounts`)
|
||||||
|
// console.log(data)
|
||||||
|
if (data.length == 0) {
|
||||||
|
return 'StreamsFailed'
|
||||||
|
} else {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getStreamNames,
|
||||||
|
getURLandStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,17 @@ ORDER BY userAccounts.id DESC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAllUniqueAccounts() {
|
||||||
|
let data = sql.query(`SELECT DISTINCT(userAccounts.stream), userAccounts.username, userAccounts.password, userAccounts.stream FROM userAccounts
|
||||||
|
WHERE userAccounts.expiaryDate != '0'
|
||||||
|
GROUP BY userAccounts.stream;`)
|
||||||
|
if (data.length == 0) {
|
||||||
|
return 'User Not Found'
|
||||||
|
} else {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getUserId(user) {
|
function getUserId(user) {
|
||||||
let data = sql.query(`SELECT id FROM users WHERE userName = '${user}'`)
|
let data = sql.query(`SELECT id FROM users WHERE userName = '${user}'`)
|
||||||
// console.log(data)
|
// console.log(data)
|
||||||
@ -71,6 +82,7 @@ module.exports = {
|
|||||||
getUserAccounts,
|
getUserAccounts,
|
||||||
getAllUserAccounts,
|
getAllUserAccounts,
|
||||||
getUserId,
|
getUserId,
|
||||||
getUserAccountsCheck
|
getUserAccountsCheck,
|
||||||
|
getAllUniqueAccounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user