Compare commits
17 Commits
31ec07ea15
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fde7f08303 | |||
| 4b8e48ac18 | |||
| ac0a7c6473 | |||
| 55142ec793 | |||
| bda213bdd5 | |||
| b460f145be | |||
| f08c4e4afb | |||
| 64b2157161 | |||
| 8ea73527db | |||
| 4d508568c6 | |||
| 5e52cadd57 | |||
| 685aa8014d | |||
| 3f6e66f2b1 | |||
| 6a511ca381 | |||
| bc9a196cad | |||
| b780a834cc | |||
| 5ad898f97d |
4
api.py
4
api.py
@ -31,7 +31,7 @@ class AdminContainers(Resource):
|
|||||||
@admins_only
|
@admins_only
|
||||||
def get():
|
def get():
|
||||||
page = abs(request.args.get("page", 1, type=int))
|
page = abs(request.args.get("page", 1, type=int))
|
||||||
results_per_page = abs(request.args.get("per_page", 20, type=int))
|
results_per_page = abs(request.args.get("per_page", 10, type=int))
|
||||||
page_start = results_per_page * (page - 1)
|
page_start = results_per_page * (page - 1)
|
||||||
page_end = results_per_page * (page - 1) + results_per_page
|
page_end = results_per_page * (page - 1) + results_per_page
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class AdminContainers(Resource):
|
|||||||
@admins_only
|
@admins_only
|
||||||
def logs():
|
def logs():
|
||||||
page = abs(request.args.get("page", 1, type=int))
|
page = abs(request.args.get("page", 1, type=int))
|
||||||
results_per_page = abs(request.args.get("per_page", 20, type=int))
|
results_per_page = abs(request.args.get("per_page", 10, type=int))
|
||||||
page_start = results_per_page * (page - 1)
|
page_start = results_per_page * (page - 1)
|
||||||
page_end = results_per_page * (page - 1) + results_per_page
|
page_end = results_per_page * (page - 1) + results_per_page
|
||||||
|
|
||||||
|
|||||||
@ -110,6 +110,7 @@ class WhaleContainerLog(db.Model):
|
|||||||
challenge_id = db.Column(None, db.ForeignKey("challenges.id"))
|
challenge_id = db.Column(None, db.ForeignKey("challenges.id"))
|
||||||
start_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
start_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||||
uuid = db.Column(db.String(256))
|
uuid = db.Column(db.String(256))
|
||||||
|
port = db.Column(db.Integer, nullable=True, default=0)
|
||||||
flag = db.Column(db.String(128), nullable=False)
|
flag = db.Column(db.String(128), nullable=False)
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
@ -124,8 +125,9 @@ class WhaleContainerLog(db.Model):
|
|||||||
self.challenge_id = container.challenge_id
|
self.challenge_id = container.challenge_id
|
||||||
self.start_time = container.start_time
|
self.start_time = container.start_time
|
||||||
self.uuid = container.uuid
|
self.uuid = container.uuid
|
||||||
|
self.port = container.port
|
||||||
self.flag = container.flag
|
self.flag = container.flag
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<WhaleContainer ID:{0} {1} {2} {3} {4} {5}>".format(self.id, self.user_id, self.challenge_id,
|
return "<WhaleContainer ID:{0} {1} {2} {3} {4} {5}>".format(self.id, self.user_id, self.challenge_id,
|
||||||
self.start_time, self.uuid, self.flag)
|
self.start_time, self.uuid, self.port)
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
>{{ container.user.name | truncate(5) }}
|
>{{ container.user.name | truncate(5) }}
|
||||||
</a>
|
</a>
|
||||||
</h6>
|
</h6>
|
||||||
<p class="card-text">UUID: {{ container.uuid }}</p>
|
<p class="card-text">Container: {{ container.uuid }}</p>
|
||||||
<p class="card-text">{{ container.flag }}</p>
|
<p class="card-text">{{ container.flag }}</p>
|
||||||
Time Started: {{ container.start_time }}
|
Time Started: {{ container.start_time }}
|
||||||
<span class="badge badge-secondary float-right">Log Record</span>
|
<span class="badge badge-secondary float-right">Log Record</span>
|
||||||
|
|||||||
@ -11,10 +11,10 @@
|
|||||||
<th class="sort-col text-center"><b>ID</b></td>
|
<th class="sort-col text-center"><b>ID</b></td>
|
||||||
<th class="text-center"><b>User</b></td>
|
<th class="text-center"><b>User</b></td>
|
||||||
<th class="sort-col text-center"><b>Challenge</b></td>
|
<th class="sort-col text-center"><b>Challenge</b></td>
|
||||||
<th class="text-center"><b>UUID</b></td>
|
<th class="text-center"><b>Container</b></td>
|
||||||
|
<th class="text-center"><b>Port</b></td>
|
||||||
<th class="text-center"><b>Flag</b></td>
|
<th class="text-center"><b>Flag</b></td>
|
||||||
<th class="sort-col text-center"><b>Startup Time</b></td>
|
<th class="sort-col text-center"><b>Startup Time</b></td>
|
||||||
<th class="text-center"><b>Actions</b></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="border-right" data-checkbox>
|
<td class="border-right" data-checkbox>
|
||||||
<div class="form-check text-center">
|
<div class="form-check text-center">
|
||||||
<input type="checkbox" class="form-check-input" data-user-id="{{ container.user.id }}">
|
<input type="checkbox" class="form-check-input" data-user-id="{{ container.user.id if container.user else '' }}">
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
@ -38,11 +38,15 @@
|
|||||||
{{ container.challenge.name }}
|
{{ container.challenge.name }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center" style="word-break: break-all; white-space: normal; max-width: 200px;">
|
||||||
<button class="btn btn-link p-0 click-copy" data-copy="{{ container.uuid }}">
|
<span class="d-inline-block">{{ container.uuid }}</span>
|
||||||
|
<button class="btn btn-link p-0 click-copy ml-1" data-copy="{{ container.uuid }}" title="复制UUID">
|
||||||
<i class="fas fa-clipboard"></i>
|
<i class="fas fa-clipboard"></i>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
{{ container.port if container.port else '-' }}
|
||||||
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<button class="btn btn-link p-0 click-copy" data-copy="{{ container.flag }}">
|
<button class="btn btn-link p-0 click-copy" data-copy="{{ container.flag }}">
|
||||||
<i class="fas fa-clipboard"></i>
|
<i class="fas fa-clipboard"></i>
|
||||||
@ -51,9 +55,6 @@
|
|||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<span data-time="{{ container.start_time | isoformat }}"></span>
|
<span data-time="{{ container.start_time | isoformat }}"></span>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
|
||||||
<span class="badge badge-secondary">Log Record</span>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
<a class="nav-link" data-toggle="pill" href="#challenges">Challenges</a>
|
<a class="nav-link" data-toggle="pill" href="#challenges">Challenges</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/plugins/ctfd-whale/admin/containers">🔗 Instances</a>
|
<a class="nav-link" href="/plugins/ctfd-whale/admin/containers">🔗 Containers</a>
|
||||||
</li>
|
</li>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@ -41,13 +41,13 @@
|
|||||||
{% for page in range(range_l, range_r + 1) %}
|
{% for page in range(range_l, range_r + 1) %}
|
||||||
<li class="page-item{{ ' active' if curr_page == page }}">
|
<li class="page-item{{ ' active' if curr_page == page }}">
|
||||||
<a class="page-link"
|
<a class="page-link"
|
||||||
href="/plugins/ctfd-whale/admin/containers?page={{ page }}&type={{ request.args.get('type', 'instances') }}"
|
href="/plugins/ctfd-whale/admin/containers?page={{ page }}&type={{ session.get('page_type', 'containers') }}"
|
||||||
>{{ page }}</a>
|
>{{ page }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li class="page-item{{ ' disabled' if curr_page >= pages else '' }}">
|
<li class="page-item{{ ' disabled' if curr_page >= pages else '' }}">
|
||||||
<a class="page-link" aria-label="Next"
|
<a class="page-link" aria-label="Next"
|
||||||
href="/plugins/ctfd-whale/admin/containers?page={{ curr_page + 1 }}&type={{ request.args.get('type', 'instances') }}"
|
href="/plugins/ctfd-whale/admin/containers?page={{ curr_page + 1 }}&type={{ session.get('page_type', 'containers') }}"
|
||||||
>
|
>
|
||||||
<span aria-hidden="true">»</span>
|
<span aria-hidden="true">»</span>
|
||||||
<span class="sr-only">Next</span>
|
<span class="sr-only">Next</span>
|
||||||
|
|||||||
@ -66,6 +66,7 @@ class DBContainer:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_container_logs_page(page_start, page_end):
|
def get_all_container_logs_page(page_start, page_end):
|
||||||
q = db.session.query(WhaleContainerLog)
|
q = db.session.query(WhaleContainerLog)
|
||||||
|
q = q.order_by(WhaleContainerLog.id.desc())
|
||||||
q = q.slice(page_start, page_end)
|
q = q.slice(page_start, page_end)
|
||||||
|
|
||||||
return q.all()
|
return q.all()
|
||||||
@ -85,6 +86,7 @@ class DBContainer:
|
|||||||
WhaleContainer.start_time >=
|
WhaleContainer.start_time >=
|
||||||
datetime.datetime.now() - datetime.timedelta(seconds=timeout)
|
datetime.datetime.now() - datetime.timedelta(seconds=timeout)
|
||||||
)
|
)
|
||||||
|
q = q.order_by(WhaleContainer.id.desc())
|
||||||
q = q.slice(page_start, page_end)
|
q = q.slice(page_start, page_end)
|
||||||
return q.all()
|
return q.all()
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class DockerUtils:
|
|||||||
'if you are using unix:///var/run/docker.sock, check if the socket is correctly mapped'
|
'if you are using unix:///var/run/docker.sock, check if the socket is correctly mapped'
|
||||||
)
|
)
|
||||||
credentials = get_config("whale:docker_credentials")
|
credentials = get_config("whale:docker_credentials")
|
||||||
if credentials and credentials.count(':') == 1:
|
if credentials and credentials.count(':') == 3:
|
||||||
try:
|
try:
|
||||||
DockerUtils.client.login(*credentials.split(':'))
|
DockerUtils.client.login(*credentials.split(':'))
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user