Skip to content

Commit f98161a

Browse files
committed
refresh license button
1 parent 26aa5ce commit f98161a

5 files changed

Lines changed: 150 additions & 2 deletions

File tree

serverStatus/static/serverStatus/serverStatus.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,57 @@ app.controller('litespeedStatus', function ($scope, $http) {
249249

250250
};
251251

252+
$scope.refreshLicense = function () {
253+
254+
$scope.cpLoading = false;
255+
256+
var url = "/serverstatus/refreshLicense";
257+
258+
var config = {
259+
headers: {
260+
'X-CSRFToken': getCookie('csrftoken')
261+
}
262+
};
263+
264+
data = {};
265+
266+
267+
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
268+
269+
270+
function ListInitialDatas(response) {
271+
272+
if (response.data.status === 1) {
273+
$scope.cpLoading = true;
274+
new PNotify({
275+
title: 'Success!',
276+
text: 'License successfully refreshed',
277+
type: 'success'
278+
});
279+
} else {
280+
$scope.cpLoading = true;
281+
new PNotify({
282+
title: 'Operation Failed!',
283+
text: response.data.erroMessage,
284+
type: 'error'
285+
});
286+
}
287+
288+
}
289+
290+
function cantLoadInitialDatas(response) {
291+
$scope.cpLoading = true;
292+
new PNotify({
293+
title: 'Operation Failed!',
294+
text: 'Could not connect to server, please refresh this page.',
295+
type: 'error'
296+
});
297+
298+
}
299+
300+
301+
};
302+
252303
});
253304

254305
/* Java script code to start/stop litespeed */

serverStatus/templates/serverStatus/litespeedStatus.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ <h3 class="content-box-header">
332332
<div class="content-box-wrapper">
333333
<div class="row mt-5 mx-10">
334334

335-
<div class="col-md-6 panel-body">
335+
<div class="col-md-4 panel-body">
336336
<a ng-click="licenseStatus(1)" href="" title="{% trans 'License Status' %}">
337337
<img src="{% static 'images/license-status.png' %}" width="65" class="mr-10 ">
338338
</a>
@@ -342,7 +342,7 @@ <h3 class="content-box-header">
342342
</a>
343343
</div>
344344

345-
<div class="col-md-6 panel-body">
345+
<div class="col-md-4 panel-body">
346346
<a ng-click="showSerialBox()" href="" title="{% trans 'Change License' %}">
347347
<img src="{% static 'images/change-license.png' %}" width="65" class="mr-10">
348348
</a>
@@ -353,6 +353,17 @@ <h3 class="content-box-header">
353353

354354
</div>
355355

356+
<div class="col-md-4 panel-body">
357+
<a ng-click="refreshLicense()" href="" title="{% trans 'Refresh License' %}">
358+
<img src="{% static 'images/change-license.png' %}" width="65" class="mr-10">
359+
</a>
360+
&nbsp;
361+
<a ng-click="refreshLicense()" href="" title="{% trans 'Refresh License' %}">
362+
<span class="h4">{% trans 'Refresh License' %}</span>
363+
</a>
364+
365+
</div>
366+
356367
<div class="col-md-12">
357368

358369
<div ng-hide="fetchedData">

serverStatus/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
url(r'^switchTOLSWSStatus$', views.switchTOLSWSStatus, name='switchTOLSWSStatus'),
1616
url(r'^licenseStatus$', views.licenseStatus, name='licenseStatus'),
1717
url(r'^changeLicense$', views.changeLicense, name='changeLicense'),
18+
url(r'^refreshLicense$', views.refreshLicense, name='refreshLicense'),
1819
url(r'^topProcesses$', views.topProcesses, name='topProcesses'),
1920
url(r'^topProcessesStatus$', views.topProcessesStatus, name='topProcessesStatus'),
2021
url(r'^killProcess$', views.killProcess, name='killProcess'),

serverStatus/views.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ def licenseStatus(request):
417417
command = 'sudo cat /usr/local/lsws/conf/serial.no'
418418
serial = ProcessUtilities.outputExecutioner(command)
419419

420+
if serial.find('No such file or directory') > -1:
421+
final_dic = {'status': 1, "erroMessage": 0, 'lsSerial': 'Trial License in use.', 'lsexpiration': 'Trial license expires 15 days after activation.'}
422+
final_json = json.dumps(final_dic)
423+
return HttpResponse(final_json)
424+
420425
command = 'sudo /usr/local/lsws/bin/lshttpd -V'
421426
expiration = ProcessUtilities.outputExecutioner(command)
422427

@@ -433,6 +438,35 @@ def licenseStatus(request):
433438
final_json = json.dumps(final_dic)
434439
return HttpResponse(final_json)
435440

441+
def refreshLicense(request):
442+
try:
443+
userID = request.session['userID']
444+
445+
try:
446+
currentACL = ACLManager.loadedACL(userID)
447+
448+
if currentACL['admin'] == 1:
449+
pass
450+
else:
451+
return ACLManager.loadErrorJson('status', 0)
452+
453+
454+
command = 'sudo /usr/local/lsws/bin/lshttpd -V'
455+
ProcessUtilities.outputExecutioner(command)
456+
457+
final_dic = {'status': 1}
458+
final_json = json.dumps(final_dic)
459+
return HttpResponse(final_json)
460+
461+
except BaseException as msg:
462+
final_dic = {'status': 0, 'erroMessage': str(msg)}
463+
final_json = json.dumps(final_dic)
464+
return HttpResponse(final_json)
465+
except KeyError as msg:
466+
final_dic = {'status': 0, 'erroMessage': str(msg)}
467+
final_json = json.dumps(final_dic)
468+
return HttpResponse(final_json)
469+
436470

437471
def changeLicense(request):
438472
try:

static/serverStatus/serverStatus.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,57 @@ app.controller('litespeedStatus', function ($scope, $http) {
249249

250250
};
251251

252+
$scope.refreshLicense = function () {
253+
254+
$scope.cpLoading = false;
255+
256+
var url = "/serverstatus/refreshLicense";
257+
258+
var config = {
259+
headers: {
260+
'X-CSRFToken': getCookie('csrftoken')
261+
}
262+
};
263+
264+
data = {};
265+
266+
267+
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
268+
269+
270+
function ListInitialDatas(response) {
271+
272+
if (response.data.status === 1) {
273+
$scope.cpLoading = true;
274+
new PNotify({
275+
title: 'Success!',
276+
text: 'License successfully refreshed',
277+
type: 'success'
278+
});
279+
} else {
280+
$scope.cpLoading = true;
281+
new PNotify({
282+
title: 'Operation Failed!',
283+
text: response.data.erroMessage,
284+
type: 'error'
285+
});
286+
}
287+
288+
}
289+
290+
function cantLoadInitialDatas(response) {
291+
$scope.cpLoading = true;
292+
new PNotify({
293+
title: 'Operation Failed!',
294+
text: 'Could not connect to server, please refresh this page.',
295+
type: 'error'
296+
});
297+
298+
}
299+
300+
301+
};
302+
252303
});
253304

254305
/* Java script code to start/stop litespeed */

0 commit comments

Comments
 (0)