diff --git a/.vscode/launch.json b/.vscode/launch.json index 82b8256..edb5cbb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -21,10 +21,11 @@ ], "program": "${workspaceFolder}/bin/www", "env": { - "HOST": "localhost", + "DBHOST": "vps.k-world.me.uk", "DBUSER": "root", - "DBPASS": "example", - "DATABASE":"BBLB_DNS" + "DBPASS": "Grd555269", + "DATABASE": "BBLB_DNS", + "DBPORT": "3306", } }, { @@ -36,10 +37,27 @@ ], "program": "${workspaceFolder}/lib/checker.js", "env": { - "HOST": "localhost", + "DBHOST": "vps.k-world.me.uk", "DBUSER": "root", - "DBPASS": "example", - "DATABASE":"BBLB_DNS" + "DBPASS": "Grd555269", + "DATABASE": "BBLB_DNS", + "DBPORT": "3306", + } + }, + { + "type": "node", + "request": "launch", + "name": "AddAcccount", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/lib/addAccounts.js", + "env": { + "DBHOST": "vps.k-world.me.uk", + "DBUSER": "root", + "DBPASS": "Grd555269", + "DATABASE": "BBLB_DNS", + "DBPORT": "3306", } }, { @@ -54,7 +72,7 @@ "HOST": "localhost", "DBUSER": "root", "DBPASS": "example", - "DATABASE":"BBLB_DNS" + "DATABASE": "BBLB_DNS" } } ] diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/app.js b/app.js index 838955c..f64a2ad 100644 --- a/app.js +++ b/app.js @@ -12,6 +12,7 @@ var streamsRouter = require('./routes/getStreams'); var getUserAccounts = require('./routes/getUserAccounts') var singleUserCheck = require('./routes/singleCheck') var addAccount = require('./routes/addAccount') +var deleteAccount = require('./routes/deleteAccount') var readCookie = require('./routes/readCookie') var getStreamNames = require('./routes/getStreamNames') var login = require('./routes/login') @@ -39,12 +40,13 @@ const users = { app.use('/', indexRouter); app.use('/login', basicAuth(users), login) -app.use('/getStreams', streamsRouter); -app.use('/getUserAccounts', getUserAccounts); +// app.use('/getStreams', streamsRouter); +app.use('/getUserAccounts', basicAuth(users), getUserAccounts); app.use('/singleCheck', basicAuth(users), singleUserCheck) -app.use('/addAccount', addAccount) -app.use('/readCookie', readCookie) -app.use('/getStreamNames', getStreamNames) +app.use('/addAccount', basicAuth(users), addAccount) +app.use('/deleteAccount', basicAuth(users), deleteAccount) +// app.use('/readCookie', readCookie) +// app.use('/getStreamNames', getStreamNames) // catch 404 and forward to error handler diff --git a/client/package-lock.json b/client/package-lock.json index 7a8fd85..5660ce3 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1910,14 +1910,6 @@ "@testing-library/dom": "^7.28.1" } }, - "@testing-library/user-event": { - "version": "12.7.3", - "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-12.7.3.tgz", - "integrity": "sha512-IdSHkWfbeSSJRFlldvHDWfVX0U18TbXIvLSGII+JbqkJrsflFr4OWlQIua0TvcVVJNna3BNrNvRSvpQ0yvSXlA==", - "requires": { - "@babel/runtime": "^7.12.5" - } - }, "@types/anymatch": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@types/anymatch/-/anymatch-1.3.1.tgz", diff --git a/docker-compose.yml b/docker-compose.yml index b5f9135..c4e6781 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,7 @@ services: build: context: ./client dockerfile: Dockerfile.prod + # dockerfile: .dockerfile image: "karl0ss/bblbtv_dns-frontend" ports: - "6969:6969" diff --git a/lib/addAccounts.js b/lib/Accounts.js similarity index 64% rename from lib/addAccounts.js rename to lib/Accounts.js index bb6babe..40accf1 100644 --- a/lib/addAccounts.js +++ b/lib/Accounts.js @@ -5,10 +5,19 @@ const sql = require('./mysql') function storeAccountToDB(accountDetails) { const encryptedPassword = cryptr.encrypt(accountDetails.password); - const result = sql.query(`INSERT userAccounts (username, password, stream, userID) VALUES ("${accountDetails.username}", "${encryptedPassword}", "${accountDetails.stream}", ${accountDetails.userId})`); + const result = sql.query(`INSERT userAccounts (username, password, stream, userID, expiaryDate) VALUES ("${accountDetails.username}", "${encryptedPassword}", "${accountDetails.stream}", ${accountDetails.userId}, 123)`); return result } +function removeAccountFromDB(accountDetails) { + const result = sql.query(`DELETE FROM userAccounts WHERE + username = '${accountDetails.user}' AND + stream = '${accountDetails.stream}' AND + userId = ${accountDetails.userId} `); + return result +} + + function retrievePasswordFromDB(user, userAccUser) { let userId try { @@ -39,11 +48,20 @@ WHERE userAccounts.userID = ${userId} AND userAccounts.username = '${userAccUser } } +// accountDetails = { +// "username": "Darren110921", +// "password" :"saD2V2kjyNqH", +// "stream": "Badger", +// "userId" : "2" +// } -// retrievePasswordFromDB('Karl', 'Karl2903') + +// retrievePasswordFromDB('Karl', 'Maxine2206') +// storeAccountToDB(accountDetails) module.exports = { + removeAccountFromDB, storeAccountToDB, retrievePasswordFromDB } diff --git a/lib/DNSArray.json b/lib/DNSArray.json index c67c7bb..d070b08 100644 --- a/lib/DNSArray.json +++ b/lib/DNSArray.json @@ -1,4 +1,4 @@ [ "http://webservgroup.xyz/smarters4567891/api/home.php?action=dns", - "https://topsapp.xyz/SMARTERS/scotslad/api/home.php?action=dns" + "http://panelhost.xyz/cli3nts/Funky/Smarters/api/home.php?action=dns" ] \ No newline at end of file diff --git a/lib/checker.js b/lib/checker.js index b3ed3f5..2674596 100644 --- a/lib/checker.js +++ b/lib/checker.js @@ -11,7 +11,11 @@ const { gotRequest } = require('./gotRequest') const { decryptPassword } = require('./password') -const { getAllUserAccounts } = require('./getUser') +const { getAllUserAccounts, getUserAccountsCheck } = require('./getUser') + +const { setExpired } = require('./setExpired') + +const { removeAccountFromDB } = require('../lib/Accounts') const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -82,36 +86,153 @@ async function newCheck() { return user }) for (let userAccount of userAccounts) { - console.log(userAccount.username, userAccount.passwordDecryped) - for (let streamURL of streamURLS) { - process.stdout.write('.') - let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped) - // 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') - console.log(`Match - ${userAccount.username} - ${streamURL} - Expires - ${body.user_info.exp_date}`) - await updateStreamData(userAccount, streamURL, body.user_info.exp_date) - break + 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) { } - } catch (error) { } } } } } + + + +async function newUserCheck(accountData) { + streamURLS = await getStreamsNew() + let userAccounts = await getUserAccountsCheck(accountData.userId) + userAccounts = userAccounts.map(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) { + } + } + } + } + } + return true +} + + +async function newSingleCheck(accountData) { + streamURLS = await getStreamsNew() + let userAccounts = await getUserAccountsCheck(accountData.userId) + userAccounts = userAccounts.map(user => { + user.passwordDecryped = decryptPassword(user.password) + return user + }) + var result = userAccounts.filter(obj => { + return obj.username === accountData.username && obj.passwordDecryped === accountData.password && obj.stream === accountData.stream + }) + + 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) + 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) { +// } +// } +// } +// } +// // } + + // main() // singleCheck('Karl2903') -newCheck() +// newCheck() +// newSingleCheck('Karl1607', 'Ybkjqszr1z') module.exports = { newCheck, singleCheck, - main + main, + newSingleCheck, + newUserCheck } \ No newline at end of file diff --git a/lib/getUser.js b/lib/getUser.js index b086545..d01fd34 100644 --- a/lib/getUser.js +++ b/lib/getUser.js @@ -1,41 +1,75 @@ const sql = require('./mysql') function getUserAccounts(user) { - let data = sql.query(`SELECT - userAccounts.username, - streams.streamName, - streams.streamURL, - userAccounts.expiaryDate - FROM users - INNER JOIN userAccounts - ON users.id = userAccounts.userID - INNER JOIN streams - ON userAccounts.stream = streams.streamName - WHERE users.id = '${user}'`) - // console.log(data) - if (data.length == 0) { - return 'User Not Found' - } else { - return data - } + let data = sql.query(`SELECT + userAccounts.username, + userAccounts.stream, + userAccounts.streamURL, + userAccounts.expiaryDate + FROM users + INNER JOIN userAccounts + ON users.id = userAccounts.userID + WHERE users.id = '${user}'`) + // console.log(data) + if (data.length == 0) { + return 'User Not Found' + } else { + return data + } +} + +function getUserAccountsCheck(user) { + let data = sql.query(`SELECT + userAccounts.username, + userAccounts.stream, + userAccounts.streamURL, + userAccounts.expiaryDate, + userAccounts.password + FROM users + INNER JOIN userAccounts + ON users.id = userAccounts.userID + WHERE users.id = '${user}'`) + // console.log(data) + if (data.length == 0) { + return 'User Not Found' + } else { + return data + } } function getAllUserAccounts() { let data = sql.query(`SELECT userAccounts.username, - userAccounts.password + userAccounts.password, + userAccounts.expiaryDate, + userAccounts.stream FROM userAccounts +WHERE userAccounts.expiaryDate != '0' +ORDER BY userAccounts.id DESC `) // console.log(data) if (data.length == 0) { - return 'User Not Found' + return 'User Not Found' } else { - return data + return data } } -module.exports = { - getUserAccounts, - getAllUserAccounts +function getUserId(user) { + let data = sql.query(`SELECT id FROM users WHERE userName = '${user}'`) + // console.log(data) + if (data.length == 0) { + return 'User Not Found' + } else { + return data[0].id + } +} + + +module.exports = { + getUserAccounts, + getAllUserAccounts, + getUserId, + getUserAccountsCheck } diff --git a/lib/getUsers.js b/lib/getUsers.js index 28c4dcd..6ae293d 100644 --- a/lib/getUsers.js +++ b/lib/getUsers.js @@ -2,6 +2,7 @@ const sql = require('./mysql') function getUsers() { let data = sql.query(`SELECT + userName, password FROM users diff --git a/lib/otherDNS.json b/lib/otherDNS.json deleted file mode 100644 index 387d41b..0000000 --- a/lib/otherDNS.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "https://trippy.pro:443", - "https://itty.in:443" -] \ No newline at end of file diff --git a/lib/otherURLs.json b/lib/otherURLs.json new file mode 100644 index 0000000..05ad5ef --- /dev/null +++ b/lib/otherURLs.json @@ -0,0 +1,7 @@ +[ + "https://trippy.pro:443", + "https://itty.in:443", + "https://tictacs.win", + "http://sting.ltd:25461", + "http://37723998.to:2052" +] \ No newline at end of file diff --git a/lib/setExpired.js b/lib/setExpired.js new file mode 100644 index 0000000..762a8c6 --- /dev/null +++ b/lib/setExpired.js @@ -0,0 +1,17 @@ +const sql = require('./mysql') + +function setExpired(userAccount) { + console.log(userAccount.username + ' ' + userAccount.stream + ' Expired on ' + userAccount.expiaryDate.toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })) + let result + try { + result = sql.query(`UPDATE userAccounts SET expiaryDate = "0" WHERE username = "${userAccount.username}" AND password = "${userAccount.password}"; `); + } catch (error) { + console.log(error) + } + return result +} + +module.exports = { + setExpired +} + diff --git a/routes/addAccount.js b/routes/addAccount.js index 5c660a7..b13e7c7 100644 --- a/routes/addAccount.js +++ b/routes/addAccount.js @@ -1,20 +1,28 @@ var express = require('express'); var router = express.Router(); -const { storeAccountToDB } = require('../lib/addAccounts') -const { getUserName } = require('../lib/getUsers') +const { storeAccountToDB } = require('../lib/Accounts') +const { getUserId } = require('../lib/getUser') +const { newSingleCheck } = require('../lib/checker') + + /* POST postUser page. */ router.post('/', async function (req, res, next) { let postData = req.body - postData.userId = Number(req.signedCookies.user) - let userName = await getUserName(req.signedCookies.user) + postData.userId = getUserId(req.auth.user) + let userName = req.auth.user let result = await storeAccountToDB(postData) console.log(result) if (result.affectedRows < 1) { res.send('Adding account failed') } else { - res.send('Account ' + postData.username + ' Added successfully to ' + userName) + a = await newSingleCheck(postData) + if (a) { + res.send('Account ' + postData.username + ' Added successfully to ' + userName) + } else { + res.send(500); + } } }); diff --git a/routes/deleteAccount.js b/routes/deleteAccount.js new file mode 100644 index 0000000..1290f47 --- /dev/null +++ b/routes/deleteAccount.js @@ -0,0 +1,22 @@ +var express = require('express'); +var router = express.Router(); + +const { removeAccountFromDB} = require('../lib/Accounts') +const { getUserId } = require('../lib/getUser') + + +/* POST postUser page. */ +router.post('/', async function (req, res, next) { + let postData = req.body + postData.userId = getUserId(req.auth.user) + let userName = req.auth.user + let result = await removeAccountFromDB(postData) + console.log(result) + if (result.affectedRows < 1) { + res.send('Adding account failed') + } else { + res.send('Account ' + postData.username + ' Deleted from ' + userName) + } +}); + +module.exports = router; diff --git a/routes/getStreams.js b/routes/getStreams.js index 9af2401..aa31287 100644 --- a/routes/getStreams.js +++ b/routes/getStreams.js @@ -4,7 +4,7 @@ const fs = require('fs'); let DNSArray = require('../lib/DNSArray.json') let streamArrays = require('../lib/streamArray.json') -const otherDNS = require('../lib/otherDNS.json') +const otherURLs = require('../lib/otherURLs.json') const { gotRequest } = require('../lib/gotRequest') @@ -54,12 +54,17 @@ async function getStreamsNew() { for (let index = 0; index < DNSArray.length; index++) { const url = DNSArray[index]; requestData = await gotRequest(url) - let DNSList = JSON.parse(requestData.body) + let DNSList = requestData.body + if (typeof DNSList === 'string' || DNSList instanceof String) { + DNSList = JSON.parse(DNSList) + } DNSList = splitToArray(DNSList.su) DNSList.forEach(url => { jointArray.push(url) }); } + jointArray.unshift(...otherURLs) + return jointArray } /* GET users listing. */ @@ -71,4 +76,3 @@ router.get('/', async function (req, res, next) { module.exports = { router, getStreams, getStreamsNew } - ; \ No newline at end of file diff --git a/routes/getUserAccounts.js b/routes/getUserAccounts.js index ff2b0fd..b72bcb7 100644 --- a/routes/getUserAccounts.js +++ b/routes/getUserAccounts.js @@ -1,16 +1,13 @@ var express = require('express'); var router = express.Router(); -const { getUserAccounts } = require('../lib/getUser') +const { getUserAccounts, getUserId } = require('../lib/getUser') /* POST postUser page. */ router.get('/', async function (req, res, next) { - if (req.cookies.user === undefined) { - res.send('Cookie Not Set') - } else { - let data = await getUserAccounts(req.cookies.user) + let userId = await getUserId(req.auth.user) + let data = await getUserAccounts(userId) res.send(data) - } }); module.exports = router; diff --git a/routes/singleCheck.js b/routes/singleCheck.js index 5b11bfd..e32bb78 100644 --- a/routes/singleCheck.js +++ b/routes/singleCheck.js @@ -1,14 +1,21 @@ var express = require('express'); var router = express.Router(); -const { singleCheck } = require('../lib/checker') +const { storeAccountToDB } = require('../lib/Accounts') +const { getUserId } = require('../lib/getUser') +const { newUserCheck } = require('../lib/checker') + /* POST postUser page. */ -router.post('/', async function (req, res, next) { - let postedUsername = req.body.username - - let data = await singleCheck(postedUsername) - - res.send(data); +router.get('/', async function (req, res, next) { + let postData = req.body + postData.userId = getUserId(req.auth.user) + a = await newUserCheck(postData) + if (a) { + res.send(200) + } else { + res.send(500); + } +// } }); module.exports = router;