Skip to content

Commit f98ba3b

Browse files
authored
Merge pull request #29 from HXSecurity/develop
Develop
2 parents 57d3b2b + 47e224f commit f98ba3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+436
-96
lines changed

.github/workflows/build_and_upload_package.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,19 @@ jobs:
3737
key-secret: ${{ secrets.OSS_KEY_SECRET }}
3838
region: oss-cn-beijing
3939
bucket: huoqi-public
40-
asset-path: ./dist/dongtai-0.1.0.tar.gz
41-
target-path: /iast/dongtai-test-0.1.0.tar.gz
40+
asset-path: ./dist/dongtai-1.0.3.tar.gz
41+
target-path: /iast/dongtai-test-1.0.3.tar.gz
42+
43+
- name: Upload to oss latest
44+
id: upload_to_oss_latest
45+
uses: tvrcgo/upload-to-oss@master
46+
with:
47+
key-id: ${{ secrets.OSS_KEY_ID }}
48+
key-secret: ${{ secrets.OSS_KEY_SECRET }}
49+
region: oss-cn-beijing
50+
bucket: huoqi-public
51+
asset-path: ./dist/dongtai-1.0.3.tar.gz
52+
target-path: /iast/dongtai-test-latest.tar.gz
4253

4354
- name: finish build
4455
uses: joelwmale/webhook-action@master

dongtai/endpoint/__init__.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
1818
from rest_framework.views import APIView
1919
from rest_framework import status, exceptions
20-
20+
from django.core.paginator import PageNotAnInteger, EmptyPage
2121
from dongtai.permissions import UserPermission, ScopedPermission, SystemAdminPermission, TalentAdminPermission
2222
from dongtai.utils import const
2323

@@ -140,19 +140,29 @@ def parse_args(self, request):
140140
pass
141141

142142
@staticmethod
143-
def get_paginator(queryset, page=1, page_size=20):
143+
def get_paginator(queryset, page: int = 1, page_size: int = 20):
144144
"""
145145
根据模型集合、页号、每页大小获取分页数据
146146
:param queryset:
147147
:param page:
148+
It is recommended to set the pagesize below 50,
149+
if it exceeds 50, it will be changed to 50
148150
:param page_size:
149151
:return:
150152
"""
151-
if int(page_size) > 50:
152-
page_size = 50
153+
page_size = min(50, int(page_size))
154+
page = int(page)
153155
page_info = Paginator(queryset, per_page=page_size)
154-
page_summary = {"alltotal": page_info.count, "num_pages": page_info.num_pages, "page_size": page_size}
155-
return page_summary, page_info.get_page(page).object_list if page != 0 else []
156+
page_summary = {
157+
"alltotal": page_info.count,
158+
"num_pages": page_info.num_pages,
159+
"page_size": page_size
160+
}
161+
try:
162+
page_info.validate_number(page)
163+
except (EmptyPage, PageNotAnInteger):
164+
return page_summary, []
165+
return page_summary, page_info.get_page(page).object_list
156166

157167
@staticmethod
158168
def get_auth_users(user):

dongtai/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
# project: dongtai-models
77

88
from .user import User
9+
from . import api_route

dongtai/models/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from dongtai.models import User
1111
from dongtai.models.server import IastServer
12-
12+
from dongtai.utils.settings import get_managed
1313

1414
class IastAgent(models.Model):
1515
token = models.CharField(max_length=255, blank=True, null=True)
@@ -34,5 +34,5 @@ class IastAgent(models.Model):
3434
language = models.CharField(max_length=10, blank=True, null=True)
3535

3636
class Meta:
37-
managed = False
37+
managed = get_managed()
3838
db_table = 'iast_agent'

dongtai/models/agent_method_pool.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99

1010
from dongtai.models.agent import IastAgent
1111
from dongtai.models.hook_strategy import HookStrategy
12+
from dongtai.utils.settings import get_managed
1213

1314

1415
class MethodPool(models.Model):
1516
agent = models.ForeignKey(IastAgent,
1617
models.DO_NOTHING,
1718
blank=True,
18-
null=True)
19+
null=True,
20+
db_constraint=False)
1921
url = models.CharField(max_length=2000, blank=True, null=True)
2022
uri = models.CharField(max_length=2000, blank=True, null=True)
21-
http_method = models.CharField(max_length=10, blank=True, null=True)
23+
http_method = models.CharField(max_length=10, blank=True, default='')
2224
http_scheme = models.CharField(max_length=20, blank=True, null=True)
2325
http_protocol = models.CharField(max_length=255, blank=True, null=True)
2426
req_header = models.CharField(max_length=2000, blank=True, null=True)
@@ -32,10 +34,17 @@ class MethodPool(models.Model):
3234
context_path = models.CharField(max_length=255, blank=True, null=True)
3335
method_pool = models.TextField(blank=True,
3436
null=True) # This field type is a guess.
35-
pool_sign = models.CharField(unique=True, max_length=40, blank=True, null=True) # This field type is a guess.
37+
pool_sign = models.CharField(unique=True,
38+
max_length=40,
39+
blank=True,
40+
null=True) # This field type is a guess.
3641
clent_ip = models.CharField(max_length=255, blank=True, null=True)
3742
create_time = models.IntegerField(blank=True, null=True)
3843
update_time = models.IntegerField(blank=True, null=True)
44+
uri_sha1 = models.CharField(max_length=40,
45+
blank=True,
46+
default='',
47+
db_index=True)
3948
sinks = models.ManyToManyField(
4049
HookStrategy,
4150
verbose_name=_('sinks'),
@@ -45,5 +54,6 @@ class MethodPool(models.Model):
4554
)
4655

4756
class Meta:
48-
managed = False
57+
managed = get_managed()
4958
db_table = 'iast_agent_method_pool'
59+
indexes = [models.Index(fields=['uri_sha1', 'http_method', 'agent'])]

dongtai/models/agent_properties.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# software: PyCharm
66
# project: dongtai-models
77
from django.db import models
8+
from dongtai.utils.settings import get_managed
89

910
from dongtai.models.agent import IastAgent
1011

@@ -18,5 +19,5 @@ class IastAgentProperties(models.Model):
1819
agent = models.ForeignKey(IastAgent, models.DO_NOTHING, blank=True, null=True)
1920

2021
class Meta:
21-
managed = False
22+
managed = get_managed()
2223
db_table = 'iast_agent_properties'

dongtai/models/api_route.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
######################################################################
2+
# @author : bidaya0 (bidaya0@$HOSTNAME)
3+
# @file : api_route
4+
# @created : Tuesday Aug 17, 2021 17:43:27 CST
5+
#
6+
# @description :
7+
######################################################################
8+
9+
from django.db import models
10+
from dongtai.utils.settings import get_managed
11+
from dongtai.models.agent import IastAgent
12+
13+
14+
class HttpMethod(models.Model):
15+
method = models.CharField(max_length=100, blank=True)
16+
17+
class Meta:
18+
managed = get_managed()
19+
db_table = 'iast_http_method'
20+
21+
22+
class IastApiMethod(models.Model):
23+
method = models.CharField(max_length=100, blank=True)
24+
http_method = models.ManyToManyField(
25+
HttpMethod, blank=True, through='IastApiMethodHttpMethodRelation')
26+
27+
class Meta:
28+
managed = get_managed()
29+
db_table = 'iast_api_methods'
30+
31+
32+
class IastApiMethodHttpMethodRelation(models.Model):
33+
api_method = models.ForeignKey(IastApiMethod,
34+
on_delete=models.CASCADE,
35+
db_constraint=False,
36+
db_column='api_method_id')
37+
http_method = models.ForeignKey(HttpMethod,
38+
on_delete=models.CASCADE,
39+
db_constraint=False,
40+
db_column='http_method_id')
41+
42+
class Meta:
43+
managed = get_managed()
44+
db_table = 'iast_http_method_relation'
45+
unique_together = ['api_method_id', 'http_method_id']
46+
47+
48+
class IastApiRoute(models.Model):
49+
path = models.CharField(max_length=255, blank=True)
50+
code_class = models.CharField(max_length=255,
51+
blank=True,
52+
db_column='code_class')
53+
description = models.CharField(max_length=500, blank=True)
54+
method = models.ForeignKey(IastApiMethod,
55+
on_delete=models.DO_NOTHING,
56+
db_constraint=False,
57+
db_index=True,
58+
db_column='method_id')
59+
code_file = models.CharField(max_length=500,
60+
blank=True,
61+
db_column='code_file')
62+
controller = models.CharField(max_length=100, blank=True)
63+
agent = models.ForeignKey(IastAgent,
64+
on_delete=models.CASCADE,
65+
db_constraint=False,
66+
db_index=True,
67+
db_column='agent_id')
68+
69+
class Meta:
70+
managed = get_managed()
71+
db_table = 'iast_api_route'
72+
unique_together = ['path', 'method']
73+
74+
75+
class IastApiParameter(models.Model):
76+
name = models.CharField(max_length=100, blank=True)
77+
parameter_type = models.CharField(max_length=100,
78+
blank=True,
79+
db_column='type')
80+
annotation = models.CharField(max_length=500, blank=True)
81+
route = models.ForeignKey(IastApiRoute,
82+
on_delete=models.CASCADE,
83+
db_constraint=False,
84+
db_index=True,
85+
db_column='route_id')
86+
87+
class Meta:
88+
managed = get_managed()
89+
db_table = 'iast_api_parameter'
90+
unique_together = ['name', 'route_id']
91+
92+
93+
class IastApiResponse(models.Model):
94+
return_type = models.CharField(max_length=100, blank=True)
95+
route = models.ForeignKey(IastApiRoute,
96+
on_delete=models.CASCADE,
97+
db_constraint=False,
98+
db_index=True,
99+
db_column='route_id')
100+
101+
class Meta:
102+
managed = get_managed()
103+
db_table = 'iast_api_response'
104+
unique_together = ['return_type', 'route_id']

dongtai/models/application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# software: PyCharm
66
# project: dongtai-models
77
from django.db import models
8+
from dongtai.utils.settings import get_managed
89

910
from dongtai.models import User
1011

@@ -19,6 +20,6 @@ class IastApplicationModel(models.Model):
1920
dt = models.IntegerField(blank=True, null=True)
2021

2122
class Meta:
22-
managed = False
23+
managed = get_managed()
2324
db_table = 'iast_application'
2425
unique_together = (('name', 'path'),)

dongtai/models/asset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from dongtai.models.agent import IastAgent
1212
from dongtai.models.vul_level import IastVulLevel
13+
from dongtai.utils.settings import get_managed
1314

1415

1516
class Asset(models.Model):
@@ -32,5 +33,5 @@ class Asset(models.Model):
3233
)
3334

3435
class Meta:
35-
managed = False
36+
managed = get_managed()
3637
db_table = 'iast_asset'

dongtai/models/authorization.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# software: PyCharm
66
# project: dongtai-models
77
from django.db import models
8+
from dongtai.utils.settings import get_managed
89

910

1011
class IastAuthorization(models.Model):
@@ -15,5 +16,5 @@ class IastAuthorization(models.Model):
1516
dt = models.IntegerField(blank=True, null=True)
1617

1718
class Meta:
18-
managed = False
19-
db_table = 'iast_authorization'
19+
managed = get_managed()
20+
db_table = 'iast_authorization'

0 commit comments

Comments
 (0)