CP Packages

This commit is contained in:
Usman Nasir
2020-05-05 18:03:19 +05:00
parent 78ea0835a4
commit 1fc67b07bf
4 changed files with 403 additions and 48 deletions

View File

@@ -25,7 +25,7 @@
<li class="active"><a ng-click="fetchPackages('upgrade')" href="#tab4"
data-toggle="tab">Updates</a></li>
<li><a ng-click="fetchPackages()" href="#tab6" data-toggle="tab">All Packages</a></li>
<li><a href="#tab7" data-toggle="tab">Settings</a></li>
<li><a ng-click="fetchPackages('CyberPanel')" href="#tab7" data-toggle="tab">CyberPanel Packages</a></li>
<img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</ul>
@@ -368,7 +368,214 @@
</div>
</div>
<div class="tab-pane" id="tab7">
<p>Howdy, I'm in Section 7.</p>
<a style="float: left ; margin-bottom: 2%"
class="btn btn-border btn-alt border-azure btn-link font-azure" href="#"
title=""><span>Total Packages: {$ totalPackages $}</span></a>
<a style="float: left; margin-bottom: 2%; margin-left: 2%"
class="btn btn-border btn-alt border-blue-alt btn-link font-blue-alt" href="#"
title=""><span>Fetched Packages: {$ fetchedPackages $}</span></a>
<div id="updatePackage" 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">Upgrading {$ package $}
package(s).
<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="requestData"
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>
<div class="col-sm-10"
style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888; margin-bottom: 2%">
<input placeholder="Search..."
ng-model="packSearch" name="packSearch" type="text"
class="form-control" required>
</div>
<div class="col-sm-2">
<div class="form-group">
<select ng-model="recordsToShow" ng-change="fetchPackages('upgrade')"
class="form-control" id="example-select">
<option>10</option>
<option>50</option>
<option>100</option>
<option>500</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<table class="table" style="margin: 0px; padding: 0px">
<thead>
<tr>
<th>{% trans "Package" %}</th>
<th>{% trans "Version" %}</th>
<th>{% trans "Lock" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="record in allPackages | filter:packSearch">
<td ng-bind="record.package"></td>
<td ng-bind="record.version"></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="#packageDetailsCyberPanel"
ng-click="fetchPackageDetails(record.package)"
class="btn btn-border btn-alt border-blue-alt btn-link font-blue-alt"
href="#"
title=""><span>Details</span></a>
<div id="packageDetailsCyberPanel" 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>
<a ng-click="updatePackage(record.package)" data-toggle="modal"
data-target="#updatePackageCyberPanel" style="margin-left: 1%"
class="btn btn-border btn-alt border-azure btn-link font-azure"
href="#"
title=""><span>Update</span></a>
<div id="updatePackageCyberPanel" 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">Upgrading {$ package $}
package(s).
<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="requestData"
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>
</div>
</div>
<div style="margin-top: 2%" class="row">
<div style="margin-top: 2%" class="col-md-12">
<div class="row">
<div class="col-md-9">
</div>
<div class="col-md-3">
<div class="form-group">
<select ng-model="currentPage" class="form-control"
ng-change="fetchPackages('upgrade')">
<option ng-repeat="page in pagination">{$ $index + 1 $}
</option>
</select>
</div>
</div>
</div> <!-- end row -->
</div>
</div>
</div>
</div>
</div>

View File

@@ -735,6 +735,12 @@ def fetchPackages(request):
command = 'apt-mark showhold'
locked = ProcessUtilities.outputExecutioner(command).split('\n')
if type == 'CyberPanel':
command = 'cat /usr/local/CyberCP/AllCPUbuntu.json'
packages = json.loads(ProcessUtilities.outputExecutioner(command))
else:
command = 'apt list --installed'
packages = ProcessUtilities.outputExecutioner(command).split('\n')
packages = packages[4:]
@@ -768,6 +774,26 @@ def fetchPackages(request):
import re
for items in finalPackages:
try:
if type == 'CyberPanel':
packageName = items['Package'].split('/')[0]
if packageName in locked:
lock = 1
else:
lock = 0
dic = {'package': packageName,
'version': items['Version'], 'lock': lock}
counter = counter + 1
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
else:
nowSplitted = items.split('now')
upgrade = 'Not Needed'

View File

@@ -2171,8 +2171,6 @@ app.controller('installImunify', function ($scope, $http, $timeout, $window) {
text: 'Could not connect to server, please refresh this page',
type: 'error'
});
}
}

View File

@@ -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')
@@ -836,16 +837,98 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
};
$scope.fetchPackages('upgrade');
$scope.killProcess = function (pid) {
$scope.fetchPackageDetails = function (packageFetch) {
$scope.cyberpanelLoading = false;
$scope.package = packageFetch;
$scope.cyberPanelLoading = false;
url = "/serverstatus/killProcess";
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
var data = {
pid: pid
package: packageFetch
};
dataurl = "/serverstatus/fetchPackageDetails";
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
function ListInitialData(response) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
$scope.packageDetails = response.data.packageDetails;
} 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'
});
}
};
$scope.updatePackage = function (packageToUpgrade = 'all') {
$scope.cyberpanelLoading = false;
$scope.package = packageToUpgrade;
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
var data = {
package: packageToUpgrade
};
dataurl = "/serverstatus/updatePackage";
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
function ListInitialData(response) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
getRequestStatus();
} 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'
});
}
};
function getRequestStatus() {
$scope.cyberpanelLoading = false;
url = "/serverstatus/switchTOLSWSStatus";
var data = {};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
@@ -857,25 +940,19 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
function ListInitialDatas(response) {
$scope.cyberPanelLoading = true;
if (response.data.status === 1) {
new PNotify({
title: 'Success',
text: 'Process successfully killed.',
type: 'success'
});
if (response.data.abort === 0) {
$scope.requestData = response.data.requestStatus;
$timeout(getRequestStatus, 1000);
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
// Notifications
$timeout.cancel();
$scope.cyberpanelLoading = true;
$scope.requestData = response.data.requestStatus;
}
}
function cantLoadInitialDatas(response) {
$scope.cyberPanelLoading = true;
$scope.cyberpanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page',
@@ -883,6 +960,53 @@ 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'
});
}
};
});