-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmtm_action.py
More file actions
214 lines (201 loc) · 7.02 KB
/
mtm_action.py
File metadata and controls
214 lines (201 loc) · 7.02 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import datetime
ACTIONS_QUERY = "SELECT idaction, `name`, `type`, url_prefix FROM matomo_log_action;"
class ActionItem:
"""
This class encapsulates Matomo's matomo_log_action table
"""
Db_Conn = None
ActionsItems = {}
TYPES = ['NO_TYPE', # = 0
'TYPE_PAGE_URL', # = 1 the action is a URL to a page on the website being tracked.
'TYPE_OUTLINK', # = 2: the action is a URL is of a link on the website being tracked. A visitor clicked it.
'TYPE_DOWNLOAD', # = 3: the action is a URL of a file that was downloaded from the website being tracked.
'TYPE_PAGE_TITLE', # = 4: the action is the page title of a page on the website being tracked.
'TYPE_ECOMMERCE_ITEM_SKU', #= 5: the action is the SKU of an ecommerce item that is sold on the site.
'TYPE_ECOMMERCE_ITEM_NAME', # = 6: the action is the name of an ecommerce item that is sold on the site.
'TYPE_ECOMMERCE_ITEM_CATEGORY', # = 7: the action is the name of an ecommerce item category that is used on the site.
'TYPE_SITE_SEARCH', # = 8: the action type is a site search action.
'TYPE_EVENT_CATEGORY', # = 10: the action is an event category (see Tracking Events user guide)
'TYPE_EVENT_ACTION', # = 11: the action is an event action
'TYPE_EVENT_NAME', # = 12: the action is an event name
'TYPE_CONTENT_NAME', # = 13: the action is a content name (see Content Tracking user guide and developer guide)
'TYPE_CONTENT_PIECE', # = 14: the action is a content piece
'TYPE_CONTENT_TARGET', # = 15: the action is a content target
'TYPE_CONTENT_INTERACTION', # = 16: the action is a content interaction
]
URL_PREFIXES = ['http://', # 0:
'http://www.', # 1:
'https://', # 2:
'https://www.' #3:
]
ALLOWED_SCHEMES = ['http','https']
LOC_PATTERNS = [
{
'string': 'localhost',
'label' : "LOCALTESTING"
},
{
'string': 'dafneplus.northeurope.cloudapp.azure.com',
'label' : "TESTING"
},
{
'string': 'dafne-production.northeurope.cloudapp.azure.com',
'label' : "TESTING"
},
{
'string': 'your-ip-address',
'label' : "TESTING"
},
{
'string': '20.234.60.181|40.67.233.126',
'label' : "TESTING"
},
{
'string': 'dafneplus.eng.it',
'label' : "VISIT"
},
{
'string': 'bxss.me|dicrpdbjmemujemfyopp.zzz',
'label' : "HACK"
},
]
PATH_PATTERNS = [
{
'string': r'/register/?|/signup/?',
'label' : "REGISTER"
},
{
'string': r'/login/?|/accounts/login/?|/app-auth/login/?',
'label' : "LOGIN"
},
{
'string': r'/home/?|/$|/about/?',
'label' : "HOME"
},
{
'string': r'/reset-password/?|/restore-password/?',
'label' : "PASSWORD"
},
{
'string': r'/profile/?',
'label' : "PROFILE"
},
{
'string': r'/content/?',
'label' : "CONTENT"
},
{
'string': r'/team/?|/my-team/?',
'label' : "TEAM"
},
{
'string': r'/organization/?',
'label' : "ORGANISATION"
},
{
'string': r'/marketplace(?!-)/?|/nft-marketplace/?(?!-)|/sub-app-partner-nft-marketplace/?|/marketplace-item/public/',
'label' : "MARKETPLACE"
},
{
'string': r'/wishlist/?',
'label' : "WISHLIST"
},
{
'string': r'/portfolio/?',
'label' : "PORTFOLIO"
},
{
'string': r'/moderation/?',
'label' : "MODERATION"
},
{
'string': r'/dao/?',
'label' : "DAO"
},
{
'string': r'/tool/?|/style-transfer|/virtual-avatar|/webpd|/nft-content-analysis|/pose-estimation|/3d-object-reconstruction|/sub-app-partner-vue|/sub-app-partner-content-creation-tools|/sub-app-vue|/art-generator',
'label' : "TOOLS"
},
{
'string': r'/competitions/?',
'label' : "COMPETITIONS"
},
{
'string': r'/faq/?|/sub-app-partner-faq-chat/?',
'label' : "FAQ"
},
{
'string': r'/privacy-policy?',
'label' : "PRIVACYPOLICY"
},
{
'string': r'/admin/?|/dozzle/?',
'label' : "ADMIN"
},
{
'string': r'/api/?|/marketplace-api/?|/nft-marketplace-api/?',
'label' : "API"
},
]
HACK_PATTERNS =[
'sleep(',
'XOR',
'SELECT',
'echo',
'waitfor',
'DBMS',
'include src',
'</ScRiPt>',
'env',
]
@classmethod
def init(cls, db):
cls.Db_Conn = db
cls.get_actions()
@classmethod
def get_actions(cls):
actions_query = cls.Db_Conn.run_query(ACTIONS_QUERY)
columns = [column[0] for column in actions_query.description]
for row in actions_query:
ags = dict(zip(columns, row))
action = ActionItem(**ags)
cls.ActionsItems[f'{action.idaction}'] = action
# breakpoint()
@classmethod
def retrieve_entry(cls, id:int):
if f'{id}' in cls.ActionsItems:
return cls.ActionsItems[f'{id}']
return None
def __init__(self, idaction, name, type, url_prefix):
self.idaction = idaction
self.name = name
self.type = self.TYPES[type]
if url_prefix != None:
self.url_prefix = self.URL_PREFIXES[url_prefix]
else:
self.url_prefix = None
def __str__(self):
return f'idaction {self.idaction}, name {self.name}, type {self.type}, url_prefix {self.url_prefix}'
class Action:
"""
This class represents an action during a visit
"""
def __init__(self, idlink_va:int, url:str, name:str, url_ref:str, name_ref:str,pageview_position:int,server_time:datetime.datetime):
# breakpoint()
self.idlink_va = idlink_va
self.url = url
self.name = name
self.url_ref = url_ref
self.name_ref = name_ref
self.pageview_position = pageview_position
self.server_time = server_time
self.label = None
self.sublabel = None
def set_label(self, label:str, sublabel:str=None):
self.label = label
if sublabel != None:
self.sublabel = sublabel
def __str__(self):
prtn = f'url {self.url}, name {self.name}, url_ref {self.url_ref}, name_ref {self.name_ref}, pageview_position {self.pageview_position}, ' \
f'server_time {self.server_time}, label {self.label}, sublabel {self.sublabel}'
return prtn