Skip to content

Commit

Permalink
change how packages are fetched on ubuntu;
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed May 3, 2020
1 parent 765c5e0 commit 332b9ff
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 25 deletions.
6 changes: 4 additions & 2 deletions serverStatus/static/serverStatus/serverStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
$scope.currentPage = 1;
$scope.recordsToShow = 10;

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

var config = {
Expand All @@ -800,7 +800,8 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {

var data = {
page: $scope.currentPage,
recordsToShow: $scope.recordsToShow
recordsToShow: $scope.recordsToShow,
type: type
};

dataurl = "/serverstatus/fetchPackages";
Expand Down Expand Up @@ -833,6 +834,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {


};
$scope.fetchPackages('upgrade');

$scope.killProcess = function (pid) {

Expand Down
80 changes: 74 additions & 6 deletions serverStatus/templates/serverStatus/packageManager.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,80 @@ <h2>{% trans "Package Manager" %}</h2>

<div class="example-box-wrapper">
<ul class="nav-responsive nav nav-tabs">
<li class="active"><a href="#tab4" data-toggle="tab">Updates</a></li>
<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>
<img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab4">
<p>Howdy, I'm in Section 4.</p>
<a style="float: left ; margin-bottom: 2%"
class="btn btn-border btn-alt border-azure btn-link font-azure" href="#"
title=""><span>Total Upgradeable 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 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 "Upgrade" %}</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 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"
href="#"
title=""><span>Upgrade</span></a></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 class="tab-pane" id="tab6">
<a style="float: left ; margin-bottom: 2%"
Expand Down Expand Up @@ -63,17 +128,20 @@ <h2>{% trans "Package Manager" %}</h2>
<thead>
<tr>
<th>{% trans "Package" %}</th>
<th>{% trans "Description" %}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "Version" %}</th>
<th>{% trans "Upgrade" %}</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.description"></td>
<td ng-bind="record.status"></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"
href="#"
title=""><span>Upgrade</span></a></td>
</tr>
</tbody>
</table>
Expand Down
47 changes: 32 additions & 15 deletions serverStatus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,18 +728,25 @@ def fetchPackages(request):
data = json.loads(request.body)
page = int(str(data['page']).rstrip('\n'))
recordsToShow = int(data['recordsToShow'])

packageInformation = '/home/cyberpanel/OSPackages'
f = open(packageInformation, "w")
type = data['type']

if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
command = 'dpkg-query -f \'{"status":"${db:Status-Abbrev}","package":"${binary:Package}","version":"${Version}","description":"${binary:Summary}"}\n\' -W'
subprocess.call(shlex.split(command), stdout=f)
command = 'apt list --installed'
packages = ProcessUtilities.outputExecutioner(command).split('\n')
packages = packages[4:]

upgradePackages = []

if type == 'upgrade':
for pack in packages:
if pack.find('upgradable') > -1:
upgradePackages.append(pack)

packages = ProcessUtilities.outputExecutioner('cat %s' % (packageInformation)).split('\n')
packages = upgradePackages

# if os.path.exists(ProcessUtilities.debugPath):
# logging.CyberCPLogFileWriter.writeToFile('All packages: %s' % (str(packages)))

#if os.path.exists(ProcessUtilities.debugPath):
# logging.CyberCPLogFileWriter.writeToFile('All packages: %s' % (str(packages)))

from s3Backups.s3Backups import S3Backups

Expand All @@ -751,20 +758,30 @@ def fetchPackages(request):
checker = 0
counter = 0

# if os.path.exists(ProcessUtilities.debugPath):
# logging.CyberCPLogFileWriter.writeToFile('Final packages: %s' % (str(finalPackages)))
if os.path.exists(ProcessUtilities.debugPath):
logging.CyberCPLogFileWriter.writeToFile('Final packages: %s' % (str(finalPackages)))

import re
for items in finalPackages:
items = re.sub(r'("[\s\w]*)"([\s\w])*"([\s\w]*)',r"\1\2\3", items)
try:
nowSplitted = items.split('now')

upgrade = 'Not Needed'

if nowSplitted[1].split(' ')[3].find('upgradable') > -1:
upgrade = nowSplitted[1].split(' ')[3]

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

counter = counter + 1
if checker == 0:
json_data = json_data + items
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + items
except:
logging.CyberCPLogFileWriter.writeToFile(items)
json_data = json_data + ',' + json.dumps(dic)

except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile('[ERROR] %s. [fetchPackages:773]' % (str(msg)))

json_data = json_data + ']'

Expand Down
6 changes: 4 additions & 2 deletions static/serverStatus/serverStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
$scope.currentPage = 1;
$scope.recordsToShow = 10;

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

var config = {
Expand All @@ -800,7 +800,8 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {

var data = {
page: $scope.currentPage,
recordsToShow: $scope.recordsToShow
recordsToShow: $scope.recordsToShow,
type: type
};

dataurl = "/serverstatus/fetchPackages";
Expand Down Expand Up @@ -833,6 +834,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {


};
$scope.fetchPackages('upgrade');

$scope.killProcess = function (pid) {

Expand Down

0 comments on commit 332b9ff

Please sign in to comment.