Skip to content

Commit

Permalink
refresh license button
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Aug 31, 2020
1 parent 26aa5ce commit f98161a
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 2 deletions.
51 changes: 51 additions & 0 deletions serverStatus/static/serverStatus/serverStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,57 @@ app.controller('litespeedStatus', function ($scope, $http) {

};

$scope.refreshLicense = function () {

$scope.cpLoading = false;

var url = "/serverstatus/refreshLicense";

var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};

data = {};


$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);


function ListInitialDatas(response) {

if (response.data.status === 1) {
$scope.cpLoading = true;
new PNotify({
title: 'Success!',
text: 'License successfully refreshed',
type: 'success'
});
} else {
$scope.cpLoading = true;
new PNotify({
title: 'Operation Failed!',
text: response.data.erroMessage,
type: 'error'
});
}

}

function cantLoadInitialDatas(response) {
$scope.cpLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});

}


};

});

/* Java script code to start/stop litespeed */
Expand Down
15 changes: 13 additions & 2 deletions serverStatus/templates/serverStatus/litespeedStatus.html
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ <h3 class="content-box-header">
<div class="content-box-wrapper">
<div class="row mt-5 mx-10">

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

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

</div>

<div class="col-md-4 panel-body">
<a ng-click="refreshLicense()" href="" title="{% trans 'Refresh License' %}">
<img src="{% static 'images/change-license.png' %}" width="65" class="mr-10">
</a>
&nbsp;
<a ng-click="refreshLicense()" href="" title="{% trans 'Refresh License' %}">
<span class="h4">{% trans 'Refresh License' %}</span>
</a>

</div>

<div class="col-md-12">

<div ng-hide="fetchedData">
Expand Down
1 change: 1 addition & 0 deletions serverStatus/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
url(r'^switchTOLSWSStatus$', views.switchTOLSWSStatus, name='switchTOLSWSStatus'),
url(r'^licenseStatus$', views.licenseStatus, name='licenseStatus'),
url(r'^changeLicense$', views.changeLicense, name='changeLicense'),
url(r'^refreshLicense$', views.refreshLicense, name='refreshLicense'),
url(r'^topProcesses$', views.topProcesses, name='topProcesses'),
url(r'^topProcessesStatus$', views.topProcessesStatus, name='topProcessesStatus'),
url(r'^killProcess$', views.killProcess, name='killProcess'),
Expand Down
34 changes: 34 additions & 0 deletions serverStatus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ def licenseStatus(request):
command = 'sudo cat /usr/local/lsws/conf/serial.no'
serial = ProcessUtilities.outputExecutioner(command)

if serial.find('No such file or directory') > -1:
final_dic = {'status': 1, "erroMessage": 0, 'lsSerial': 'Trial License in use.', 'lsexpiration': 'Trial license expires 15 days after activation.'}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)

command = 'sudo /usr/local/lsws/bin/lshttpd -V'
expiration = ProcessUtilities.outputExecutioner(command)

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

def refreshLicense(request):
try:
userID = request.session['userID']

try:
currentACL = ACLManager.loadedACL(userID)

if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadErrorJson('status', 0)


command = 'sudo /usr/local/lsws/bin/lshttpd -V'
ProcessUtilities.outputExecutioner(command)

final_dic = {'status': 1}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)

except BaseException as msg:
final_dic = {'status': 0, 'erroMessage': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except KeyError as msg:
final_dic = {'status': 0, 'erroMessage': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)


def changeLicense(request):
try:
Expand Down
51 changes: 51 additions & 0 deletions static/serverStatus/serverStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,57 @@ app.controller('litespeedStatus', function ($scope, $http) {

};

$scope.refreshLicense = function () {

$scope.cpLoading = false;

var url = "/serverstatus/refreshLicense";

var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};

data = {};


$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);


function ListInitialDatas(response) {

if (response.data.status === 1) {
$scope.cpLoading = true;
new PNotify({
title: 'Success!',
text: 'License successfully refreshed',
type: 'success'
});
} else {
$scope.cpLoading = true;
new PNotify({
title: 'Operation Failed!',
text: response.data.erroMessage,
type: 'error'
});
}

}

function cantLoadInitialDatas(response) {
$scope.cpLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});

}


};

});

/* Java script code to start/stop litespeed */
Expand Down

0 comments on commit f98161a

Please sign in to comment.