mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-02-02 04:44:25 +01:00
Delay update check by 12 hours each call and call update check in admin panel (#526)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from flask import current_app as app, render_template, request, redirect, jsonify, url_for, Blueprint
|
||||
from CTFd.utils import admins_only, is_admin, cache
|
||||
from CTFd.utils import admins_only, is_admin, cache, update_check
|
||||
from CTFd.models import db, Teams, Solves, Awards, Challenges, WrongKeys, Keys, Tags, Files, Tracking, Pages, Config, DatabaseError
|
||||
|
||||
from CTFd import utils
|
||||
@@ -60,6 +60,7 @@ def admin_graph(graph_type):
|
||||
@admin_statistics.route('/admin/statistics', methods=['GET'])
|
||||
@admins_only
|
||||
def admin_stats():
|
||||
update_check()
|
||||
teams_registered = db.session.query(db.func.count(Teams.id)).first()[0]
|
||||
|
||||
wrong_count = WrongKeys.query.join(Teams, WrongKeys.teamid == Teams.id).filter(Teams.banned == False).count()
|
||||
|
||||
@@ -727,30 +727,36 @@ def base64decode(s, urldecode=False):
|
||||
return decoded
|
||||
|
||||
|
||||
def update_check():
|
||||
update = app.config.get('UPDATE_CHECK')
|
||||
def update_check(force=False):
|
||||
update = app.config.get('UPDATE_CHECK') or force
|
||||
if update:
|
||||
try:
|
||||
params = {
|
||||
'current': app.VERSION
|
||||
}
|
||||
check = requests.get(
|
||||
'https://versioning.ctfd.io/versions/latest',
|
||||
params=params,
|
||||
timeout=0.1
|
||||
).json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
pass
|
||||
else:
|
||||
next_update_check = get_config('next_update_check') or 0
|
||||
if (next_update_check < time.time()) or force:
|
||||
try:
|
||||
latest = check['resource']['tag']
|
||||
html_url = check['resource']['html_url']
|
||||
if StrictVersion(latest) > StrictVersion(app.VERSION):
|
||||
set_config('version_latest', html_url)
|
||||
elif StrictVersion(latest) <= StrictVersion(app.VERSION):
|
||||
params = {
|
||||
'current': app.VERSION
|
||||
}
|
||||
check = requests.get(
|
||||
'https://versioning.ctfd.io/versions/latest',
|
||||
params=params,
|
||||
timeout=0.1
|
||||
).json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
latest = check['resource']['tag']
|
||||
html_url = check['resource']['html_url']
|
||||
if StrictVersion(latest) > StrictVersion(app.VERSION):
|
||||
set_config('version_latest', html_url)
|
||||
elif StrictVersion(latest) <= StrictVersion(app.VERSION):
|
||||
set_config('version_latest', None)
|
||||
except KeyError:
|
||||
set_config('version_latest', None)
|
||||
except KeyError:
|
||||
set_config('version_latest', None)
|
||||
finally:
|
||||
# 12 hours later
|
||||
next_update_check_time = int(time.time() + 43200)
|
||||
set_config('next_update_check', next_update_check_time)
|
||||
else:
|
||||
set_config('version_latest', None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user