Skip to content
Permalink
Browse files
lock/unlock packages
  • Loading branch information
usmannasir committed May 5, 2020
1 parent 126c191 commit 78ea0835a4d26e1b14efb1245ed230bde24bbbf1
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 6 deletions.
@@ -788,10 +788,11 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {

$scope.currentPage = 1;
$scope.recordsToShow = 10;
var globalType;

$scope.fetchPackages = function (type = 'installed') {
$scope.cyberpanelLoading = false;

globalType = type;
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
@@ -961,4 +962,51 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {

}

$scope.lockStatus = function (lockPackage, type) {
$scope.cyberpanelLoading = false;

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

var data = {
package: lockPackage,
type: type,
};

dataurl = "/serverstatus/lockStatus";

$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);

function ListInitialData(response) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
new PNotify({
title: 'Success!',
text: 'Status updated.',
type: 'success'
});
$scope.fetchPackages(globalType);
} else {
new PNotify({
title: 'Error!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialData(response) {
$scope.cyberpanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page',
type: 'error'
});
}


};

});
@@ -114,6 +114,7 @@ <h4 class="modal-title">Upgrading {$ package $}
<th>{% trans "Package" %}</th>
<th>{% trans "Version" %}</th>
<th>{% trans "Upgrade" %}</th>
<th>{% trans "Lock" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
@@ -122,6 +123,10 @@ <h4 class="modal-title">Upgrading {$ package $}
<td ng-bind="record.package"></td>
<td ng-bind="record.version"></td>
<td ng-bind="record.upgrade"></td>
<td>
<a ng-click="lockStatus(record.package, 0)" href="#"><i ng-show="record.lock==1" class="glyph-icon tooltip-button demo-icon icon-lock" title="Packed is locked for upgrade."></i></a>
<a ng-click="lockStatus(record.package, 1)" href="#"><i ng-show="record.lock==0" class="glyph-icon tooltip-button demo-icon icon-unlock" title="Package is unlocked"></i></a>
</td>
<td>
<a data-toggle="modal" data-target="#packageDetails"
ng-click="fetchPackageDetails(record.package)"
@@ -176,7 +181,6 @@ <h4 class="modal-title">Package {$ package $}
class="btn btn-border btn-alt border-azure btn-link font-azure"
href="#"
title=""><span>Update</span></a>

<div id="updatePackage" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">

@@ -277,6 +281,7 @@ <h4 class="modal-title">Upgrading {$ package $}
<th>{% trans "Package" %}</th>
<th>{% trans "Version" %}</th>
<th>{% trans "Upgrade" %}</th>
<th>{% trans "Lock" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
@@ -285,10 +290,60 @@ <h4 class="modal-title">Upgrading {$ package $}
<td ng-bind="record.package"></td>
<td ng-bind="record.version"></td>
<td ng-bind="record.upgrade"></td>
<td><a style="float: left ; margin-bottom: 2%"
class="btn btn-border btn-alt border-azure btn-link font-azure"
<td>
<a ng-click="lockStatus(record.package, 0)" href="#"><i ng-show="record.lock==1" class="glyph-icon tooltip-button demo-icon icon-lock" title="Packed is locked for upgrade."></i></a>
<a ng-click="lockStatus(record.package, 1)" href="#"><i ng-show="record.lock==0" class="glyph-icon tooltip-button demo-icon icon-unlock" title="Package is unlocked"></i></a>
</td>
<td>
<a data-toggle="modal" data-target="#packageDetailsInstalled"
ng-click="fetchPackageDetails(record.package)"
class="btn btn-border btn-alt border-blue-alt btn-link font-blue-alt"
href="#"
title=""><span>Upgrade</span></a></td>
title=""><span>Details</span></a>
<div id="packageDetailsInstalled" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal">
&times;
</button>
<h4 class="modal-title">Package {$ package $}
details.
<img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</h4>
</div>
<div class="modal-body">

<div class="form-group">
<div class="col-sm-12">
<div class="col-sm-12">
<textarea ng-model="packageDetails"
class="form-control"
rows="12"></textarea>
</div>
</div>
</div>

<table class="table">
</table>

</div>
<div class="modal-footer">
<button type="button"
ng-disabled="savingSettings"
class="btn btn-default"
data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
@@ -22,5 +22,6 @@
url(r'^fetchPackages$', views.fetchPackages, name='fetchPackages'),
url(r'^fetchPackageDetails$', views.fetchPackageDetails, name='fetchPackageDetails'),
url(r'^updatePackage$', views.updatePackage, name='updatePackage'),
url(r'^lockStatus$', views.lockStatus, name='lockStatus'),

]
@@ -731,6 +731,10 @@ def fetchPackages(request):
type = data['type']

if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:

command = 'apt-mark showhold'
locked = ProcessUtilities.outputExecutioner(command).split('\n')

command = 'apt list --installed'
packages = ProcessUtilities.outputExecutioner(command).split('\n')
packages = packages[4:]
@@ -772,7 +776,12 @@ def fetchPackages(request):
current = nowSplitted[1].split(' ')
upgrade = '%s %s %s' % (current[3], current[4], current[5])

dic = {'package': nowSplitted[0].split('/')[0], 'version': '%s %s' % (nowSplitted[1].split(' ')[1], nowSplitted[1].split(' ')[2]), 'upgrade': upgrade}
if nowSplitted[0].split('/')[0] in locked:
lock = 1
else:
lock = 0

dic = {'package': nowSplitted[0].split('/')[0], 'version': '%s %s' % (nowSplitted[1].split(' ')[1], nowSplitted[1].split(' ')[2]), 'upgrade': upgrade, 'lock': lock}

counter = counter + 1
if checker == 0:
@@ -856,6 +865,39 @@ def updatePackage(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

except BaseException as msg:
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

def lockStatus(request):
try:

userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)

if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()

data = json.loads(request.body)
package = data['package']
type = data['type']

if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:

if type == 0:
command = 'apt-mark unhold %s' % (package)
ProcessUtilities.executioner(command)
else:
command = 'apt-mark hold %s' % (package)
ProcessUtilities.executioner(command)

data_ret = {'status': 1}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

except BaseException as msg:
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)

0 comments on commit 78ea083

Please sign in to comment.