From 5d7761ee0f5ac5b9cd7c8daaeda03800900f397a Mon Sep 17 00:00:00 2001 From: lian Date: Sat, 24 Oct 2015 15:53:02 +0800 Subject: [PATCH 1/2] [sys-admin] check seafile license expiration --- seahub/templates/sysadmin/sys_useradmin.html | 30 +++++++++++++++- seahub/urls.py | 1 + seahub/views/sysadmin.py | 36 ++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/seahub/templates/sysadmin/sys_useradmin.html b/seahub/templates/sysadmin/sys_useradmin.html index c5bafce2e9..ea04356cdb 100644 --- a/seahub/templates/sysadmin/sys_useradmin.html +++ b/seahub/templates/sysadmin/sys_useradmin.html @@ -81,10 +81,38 @@ $(function(){ if (data['need_update']) { var tip = "{% trans "A new server version %(v)s is available." %}"; tip = tip.replace('%(v)s', data['new_version']); - $('#title-panel').html('

' + tip + '

').removeClass('hide'); + $('#title-panel').html('

' + tip + '

').removeClass('hide'); } } }); + + {% if is_pro %} + // check if seafile license expired + $.ajax({ + url: "{% url 'sys_check_license' %}", + dataType: 'json', + cache: false, + success: function(data) { + var tip, $title_panel = $('#title-panel'); + + if (data['already_expired']) { + tip = "Your license is already expired in %(v)s.", + tip = tip.replace('%(v)s', data['expiration']); + } else if (data['to_be_expired']) { + tip = "Your license will be expired in %(v)s.", + tip = tip.replace('%(v)s', data['expiration']); + } + + if (typeof(tip) != 'undefined') { + if ($title_panel.find('p').length) { + $title_panel.find('p').append('
' + tip + ''); + } else { + $title_panel.html('

' + tip + '

').removeClass('hide'); + } + } + } + }); + {% endif %} }); $('#add-user-btn').click(function() { diff --git a/seahub/urls.py b/seahub/urls.py index 862dcac2f8..b095b8c30f 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -238,6 +238,7 @@ urlpatterns = patterns( url(r'^sys/uploadlink/remove/$', sys_upload_link_remove, name='sys_upload_link_remove'), url(r'^sys/notificationadmin/', notification_list, name='notification_list'), url(r'^sys/sudo/', sys_sudo_mode, name='sys_sudo_mode'), + url(r'^sys/check-license/', sys_check_license, name='sys_check_license'), url(r'^useradmin/add/$', user_add, name="user_add"), url(r'^useradmin/remove/(?P[^/]+)/$', user_remove, name="user_remove"), url(r'^useradmin/removetrial/(?P[^/]+)/$', remove_trial, name="remove_trial"), diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index 4d085cad07..b2f1c29c65 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -8,6 +8,7 @@ import re import datetime import stat import csv, chardet, StringIO +import time from constance import config from django.core.urlresolvers import reverse @@ -2030,3 +2031,38 @@ def sys_settings(request): return render_to_response('sysadmin/settings.html', { 'config_dict': config_dict, }, context_instance=RequestContext(request)) + +@login_required_ajax +@sys_staff_required +def sys_check_license(request): + """Check seafile license expiration. + """ + if not is_pro_version(): + raise Http404 + + content_type = 'application/json; charset=utf-8' + result = {} + + license_file = os.path.join(settings.PROJECT_ROOT, '../../seafile-license.txt') + license_dict = parse_license(license_file) + if license_dict: + try: + expiration = license_dict['Expiration'] + except KeyError as e: + logger.error(e) + result['error'] = str(e) + return HttpResponse(json.dumps(result), status=500, content_type=content_type) + + struct_time = datetime.datetime.strptime(expiration, "%Y-%m-%d") + expiration_timestamp = time.mktime(struct_time.timetuple()) + + if time.time() > expiration_timestamp: + # already expired + result['already_expired'] = True + elif time.time() + 30 * 24 * 60 * 60 > expiration_timestamp: + # will be expired in 30 days + result['to_be_expired'] = True + + result['expiration'] = expiration + + return HttpResponse(json.dumps(result), content_type=content_type) From 96cbd7debc62ea0e0d0a82fc4f7b930b0217a8fc Mon Sep 17 00:00:00 2001 From: llj Date: Sat, 24 Oct 2015 18:14:58 +0800 Subject: [PATCH 2/2] [sys-admin] license expiration: modification --- media/css/seahub.css | 6 ++++++ seahub/templates/sysadmin/sys_useradmin.html | 19 +++++++------------ seahub/views/sysadmin.py | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/media/css/seahub.css b/media/css/seahub.css index a2522aab39..d217380f03 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -316,6 +316,12 @@ p { margin:0.5em 0; } .alc { text-align: center;} .cspt { cursor:pointer; } .pos-rel { position:relative; } +.top-tip { + background:#fddaa4; + color:#1f0600; + text-align:center; + margin:0 0 15px; +} /** for input, textarea in form **/ /* e.g repo-create */ .input, .textarea { width:260px; diff --git a/seahub/templates/sysadmin/sys_useradmin.html b/seahub/templates/sysadmin/sys_useradmin.html index ea04356cdb..b307170eda 100644 --- a/seahub/templates/sysadmin/sys_useradmin.html +++ b/seahub/templates/sysadmin/sys_useradmin.html @@ -81,7 +81,7 @@ $(function(){ if (data['need_update']) { var tip = "{% trans "A new server version %(v)s is available." %}"; tip = tip.replace('%(v)s', data['new_version']); - $('#title-panel').html('

' + tip + '

').removeClass('hide'); + $('#title-panel').append('

' + tip + '

').addClass('top-tip').removeClass('hide'); } } }); @@ -93,22 +93,17 @@ $(function(){ dataType: 'json', cache: false, success: function(data) { - var tip, $title_panel = $('#title-panel'); + var tip; if (data['already_expired']) { - tip = "Your license is already expired in %(v)s.", - tip = tip.replace('%(v)s', data['expiration']); + tip = "Your license expired on %(date)s."; } else if (data['to_be_expired']) { - tip = "Your license will be expired in %(v)s.", - tip = tip.replace('%(v)s', data['expiration']); + tip = "Your license will expire on %(date)s."; } - if (typeof(tip) != 'undefined') { - if ($title_panel.find('p').length) { - $title_panel.find('p').append('
' + tip + ''); - } else { - $title_panel.html('

' + tip + '

').removeClass('hide'); - } + if (data['already_expired'] || data['to_be_expired']) { + tip = tip.replace('%(date)s', data['expiration_date']); + $('#title-panel').append('

' + tip + '

').addClass('top-tip').removeClass('hide'); } } }); diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index b2f1c29c65..b42011aefe 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -2063,6 +2063,6 @@ def sys_check_license(request): # will be expired in 30 days result['to_be_expired'] = True - result['expiration'] = expiration + result['expiration_date'] = expiration return HttpResponse(json.dumps(result), content_type=content_type)