Advertisement
imKobz

Untitled

May 17th, 2023
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. const router = express.Router()
  2. const {
  3. updateJSON,
  4. } = require('../module/json')
  5. const {
  6. checkUsername ,
  7. setVpn
  8. } = require('../module/user');
  9. const setDate = require('add-subtract-date')
  10.  
  11. router.post('/json/update', (req, res) => {
  12.  
  13. let jsonhash = req.body.hash
  14. let jsoncode = req.body.code
  15.  
  16. updateJSON(jsoncode, jsonhash).then(() => {
  17. res.send(`Panel json was updated.`)
  18. }).catch(() => {
  19. res.send(`Panel json update was denied.`)
  20. })
  21. })
  22.  
  23. // Api auth udp
  24.  
  25. router.post('/auth/udp', (req, res) => {
  26.  
  27. let addr = req.body.addr
  28. let user = atob(req.body.payload).split(":")
  29. let send = req.body.send
  30. let recv = req.body.recv
  31. let nowDate = new Date()
  32.  
  33. if (user[0].length < 1 || user[1].length < 1) {
  34. return res.json({
  35. "ok": false,
  36. "msg": `Auth Fail`
  37. })
  38. }
  39.  
  40. checkUsername(user[0].trim()).then((data) => {
  41.  
  42. if (data.length < 1) {
  43. return res.json({
  44. "ok": false,
  45. "msg": `Auth Fail`
  46. })
  47. }
  48.  
  49. if (data[0].username !== user[0] || data[0].password !== user[1]) {
  50. return res.json({
  51. "ok": false,
  52. "msg": `Auth Fail`
  53. })
  54. }
  55.  
  56. if (data[0].expiredate === "none") {
  57. if (data[0].type === 4) {
  58. expireDate = formatDate('yyyy-MM-dd hh:mm:ss', setDate.add(nowDate, 30, "minutes"));
  59. } else {
  60. expireDate = formatDate('yyyy-MM-dd hh:mm:ss', setDate.add(nowDate, 30, "days"));
  61. }
  62.  
  63. setVpn(expireDate, user[0])
  64. }
  65.  
  66. res.json({
  67. "ok": true,
  68. "msg": `Auth Success`
  69. })
  70. }).catch((e) => {
  71. res.json({
  72. "ok": false,
  73. "msg": `Auth Fail`
  74. })
  75. })
  76.  
  77.  
  78. })
  79.  
  80. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement