Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const router = express.Router()
- const {
- updateJSON,
- } = require('../module/json')
- const {
- checkUsername ,
- setVpn
- } = require('../module/user');
- const setDate = require('add-subtract-date')
- router.post('/json/update', (req, res) => {
- let jsonhash = req.body.hash
- let jsoncode = req.body.code
- updateJSON(jsoncode, jsonhash).then(() => {
- res.send(`Panel json was updated.`)
- }).catch(() => {
- res.send(`Panel json update was denied.`)
- })
- })
- // Api auth udp
- router.post('/auth/udp', (req, res) => {
- let addr = req.body.addr
- let user = atob(req.body.payload).split(":")
- let send = req.body.send
- let recv = req.body.recv
- let nowDate = new Date()
- if (user[0].length < 1 || user[1].length < 1) {
- return res.json({
- "ok": false,
- "msg": `Auth Fail`
- })
- }
- checkUsername(user[0].trim()).then((data) => {
- if (data.length < 1) {
- return res.json({
- "ok": false,
- "msg": `Auth Fail`
- })
- }
- if (data[0].username !== user[0] || data[0].password !== user[1]) {
- return res.json({
- "ok": false,
- "msg": `Auth Fail`
- })
- }
- if (data[0].expiredate === "none") {
- if (data[0].type === 4) {
- expireDate = formatDate('yyyy-MM-dd hh:mm:ss', setDate.add(nowDate, 30, "minutes"));
- } else {
- expireDate = formatDate('yyyy-MM-dd hh:mm:ss', setDate.add(nowDate, 30, "days"));
- }
- setVpn(expireDate, user[0])
- }
- res.json({
- "ok": true,
- "msg": `Auth Success`
- })
- }).catch((e) => {
- res.json({
- "ok": false,
- "msg": `Auth Fail`
- })
- })
- })
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement