mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
feature: allow enforce disk limit via packages
This commit is contained in:
@@ -318,6 +318,22 @@ class FileManager:
|
|||||||
website = Websites.objects.get(domain=domainName)
|
website = Websites.objects.get(domain=domainName)
|
||||||
self.homePath = '/home/%s' % (domainName)
|
self.homePath = '/home/%s' % (domainName)
|
||||||
|
|
||||||
|
RemoveOK = 1
|
||||||
|
|
||||||
|
command = 'touch %s/hello.txt' % (self.homePath)
|
||||||
|
result = ProcessUtilities.outputExecutioner(command)
|
||||||
|
|
||||||
|
if result.find('No such file or directory') > -1:
|
||||||
|
RemoveOK = 0
|
||||||
|
|
||||||
|
command = 'chattr -R -i %s' % (self.homePath)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
else:
|
||||||
|
command = 'rm -f %s/hello.txt' % (self.homePath)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
|
||||||
for item in self.data['fileAndFolders']:
|
for item in self.data['fileAndFolders']:
|
||||||
|
|
||||||
if (self.data['path'] + '/' + item).find('..') > -1 or (self.data['path'] + '/' + item).find(
|
if (self.data['path'] + '/' + item).find('..') > -1 or (self.data['path'] + '/' + item).find(
|
||||||
@@ -326,7 +342,7 @@ class FileManager:
|
|||||||
|
|
||||||
if skipTrash:
|
if skipTrash:
|
||||||
command = 'rm -rf ' + self.returnPathEnclosed(self.data['path'] + '/' + item)
|
command = 'rm -rf ' + self.returnPathEnclosed(self.data['path'] + '/' + item)
|
||||||
ProcessUtilities.executioner(command, website.externalApp)
|
ProcessUtilities.outputExecutioner(command, website.externalApp)
|
||||||
else:
|
else:
|
||||||
trashPath = '%s/.trash' % (self.homePath)
|
trashPath = '%s/.trash' % (self.homePath)
|
||||||
|
|
||||||
@@ -339,6 +355,10 @@ class FileManager:
|
|||||||
command = 'mv %s %s' % (self.returnPathEnclosed(self.data['path'] + '/' + item), trashPath)
|
command = 'mv %s %s' % (self.returnPathEnclosed(self.data['path'] + '/' + item), trashPath)
|
||||||
ProcessUtilities.executioner(command, website.externalApp)
|
ProcessUtilities.executioner(command, website.externalApp)
|
||||||
|
|
||||||
|
if RemoveOK == 0:
|
||||||
|
command = 'chattr -R +i %s' % (self.homePath)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
json_data = json.dumps(finalData)
|
json_data = json.dumps(finalData)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class PackagesManager:
|
|||||||
|
|
||||||
data_ret = {'emails': emails, 'modifyStatus': 1, 'error_message': "None",
|
data_ret = {'emails': emails, 'modifyStatus': 1, 'error_message': "None",
|
||||||
"diskSpace": diskSpace, "bandwidth": bandwidth, "ftpAccounts": ftpAccounts,
|
"diskSpace": diskSpace, "bandwidth": bandwidth, "ftpAccounts": ftpAccounts,
|
||||||
"dataBases": dataBases, "allowedDomains": modifyPack.allowedDomains, 'allowFullDomain': modifyPack.allowFullDomain}
|
"dataBases": dataBases, "allowedDomains": modifyPack.allowedDomains, 'allowFullDomain': modifyPack.allowFullDomain, 'enforceDiskLimits': modifyPack.enforceDiskLimits}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
@@ -193,6 +193,10 @@ class PackagesManager:
|
|||||||
except:
|
except:
|
||||||
modifyPack.allowFullDomain = 1
|
modifyPack.allowFullDomain = 1
|
||||||
|
|
||||||
|
try:
|
||||||
|
modifyPack.enforceDiskLimits = int(data['enforceDiskLimits'])
|
||||||
|
except:
|
||||||
|
modifyPack.enforceDiskLimits = 0
|
||||||
|
|
||||||
modifyPack.save()
|
modifyPack.save()
|
||||||
|
|
||||||
@@ -255,7 +259,8 @@ class PackagesManager:
|
|||||||
'dataBases': items.dataBases,
|
'dataBases': items.dataBases,
|
||||||
'ftpAccounts': items.ftpAccounts,
|
'ftpAccounts': items.ftpAccounts,
|
||||||
'allowedDomains': items.allowedDomains,
|
'allowedDomains': items.allowedDomains,
|
||||||
'allowFullDomain': items.allowFullDomain
|
'allowFullDomain': items.allowFullDomain,
|
||||||
|
'enforceDiskLimits': items.enforceDiskLimits
|
||||||
}
|
}
|
||||||
|
|
||||||
if checker == 0:
|
if checker == 0:
|
||||||
|
|||||||
@@ -197,7 +197,6 @@ app.controller('modifyPackages', function ($scope, $http) {
|
|||||||
$("#successfullyModified").hide();
|
$("#successfullyModified").hide();
|
||||||
|
|
||||||
var packageName = $scope.packageToBeModified;
|
var packageName = $scope.packageToBeModified;
|
||||||
console.log(packageName);
|
|
||||||
|
|
||||||
|
|
||||||
url = "/packages/submitModify";
|
url = "/packages/submitModify";
|
||||||
@@ -234,11 +233,8 @@ app.controller('modifyPackages', function ($scope, $http) {
|
|||||||
$scope.emails = response.data.emails;
|
$scope.emails = response.data.emails;
|
||||||
$scope.allowedDomains = response.data.allowedDomains;
|
$scope.allowedDomains = response.data.allowedDomains;
|
||||||
|
|
||||||
if (response.data.allowFullDomain === 1) {
|
$scope.allowFullDomain = response.data.allowFullDomain === 1;
|
||||||
$scope.allowFullDomain = true;
|
$scope.enforceDiskLimits = response.data.enforceDiskLimits === 1;
|
||||||
} else {
|
|
||||||
$scope.allowFullDomain = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.modifyButton = "Save Details";
|
$scope.modifyButton = "Save Details";
|
||||||
|
|
||||||
@@ -260,7 +256,6 @@ app.controller('modifyPackages', function ($scope, $http) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$scope.modifyPackageFunc = function () {
|
$scope.modifyPackageFunc = function () {
|
||||||
|
|
||||||
var packageName = $scope.packageToBeModified;
|
var packageName = $scope.packageToBeModified;
|
||||||
@@ -286,7 +281,8 @@ app.controller('modifyPackages', function ($scope, $http) {
|
|||||||
dataBases: dataBases,
|
dataBases: dataBases,
|
||||||
emails: emails,
|
emails: emails,
|
||||||
allowedDomains: $scope.allowedDomains,
|
allowedDomains: $scope.allowedDomains,
|
||||||
allowFullDomain: $scope.allowFullDomain
|
allowFullDomain: $scope.allowFullDomain,
|
||||||
|
enforceDiskLimits: $scope.enforceDiskLimits,
|
||||||
};
|
};
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
@@ -446,7 +442,7 @@ app.controller('listPackageTables', function ($scope, $http) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.editInitial = function (package, diskSpace, bandwidth,
|
$scope.editInitial = function (package, diskSpace, bandwidth,
|
||||||
emailAccounts, dataBases, ftpAccounts, allowedDomains, allowFullDomain) {
|
emailAccounts, dataBases, ftpAccounts, allowedDomains, allowFullDomain, enforceDiskLimits) {
|
||||||
$scope.name = package;
|
$scope.name = package;
|
||||||
$scope.diskSpace = diskSpace;
|
$scope.diskSpace = diskSpace;
|
||||||
$scope.bandwidth = bandwidth;
|
$scope.bandwidth = bandwidth;
|
||||||
@@ -455,12 +451,8 @@ app.controller('listPackageTables', function ($scope, $http) {
|
|||||||
$scope.ftpAccounts = ftpAccounts;
|
$scope.ftpAccounts = ftpAccounts;
|
||||||
$scope.allowedDomains = allowedDomains;
|
$scope.allowedDomains = allowedDomains;
|
||||||
$scope.allowFullDomain = allowFullDomain;
|
$scope.allowFullDomain = allowFullDomain;
|
||||||
|
$scope.allowFullDomain = allowFullDomain === 1;
|
||||||
if (allowFullDomain === 1) {
|
$scope.enforceDiskLimits = enforceDiskLimits === 1;
|
||||||
$scope.allowFullDomain = true;
|
|
||||||
} else {
|
|
||||||
$scope.allowFullDomain = false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.saveChanges = function () {
|
$scope.saveChanges = function () {
|
||||||
@@ -482,7 +474,8 @@ app.controller('listPackageTables', function ($scope, $http) {
|
|||||||
dataBases: dataBases,
|
dataBases: dataBases,
|
||||||
emails: emails,
|
emails: emails,
|
||||||
allowedDomains: $scope.allowedDomains,
|
allowedDomains: $scope.allowedDomains,
|
||||||
allowFullDomain: $scope.allowFullDomain
|
allowFullDomain: $scope.allowFullDomain,
|
||||||
|
enforceDiskLimits: $scope.enforceDiskLimits,
|
||||||
};
|
};
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<a data-toggle="modal" data-target="#settings"
|
<a data-toggle="modal" data-target="#settings"
|
||||||
ng-click="editInitial(record.package, record.diskSpace, record.bandwidth,
|
ng-click="editInitial(record.package, record.diskSpace, record.bandwidth,
|
||||||
record.emailAccounts, record.dataBases, record.ftpAccounts, record.allowedDomains, record.allowFullDomain)"
|
record.emailAccounts, record.dataBases, record.ftpAccounts, record.allowedDomains, record.allowFullDomain, record.enforceDiskLimits)"
|
||||||
class="btn btn-border btn-alt border-purple btn-link font-purple" href="#"
|
class="btn btn-border btn-alt border-purple btn-link font-purple" href="#"
|
||||||
title=""><span>{% trans 'Edit' %}</span></a>
|
title=""><span>{% trans 'Edit' %}</span></a>
|
||||||
<a ng-click="deletePackageFinal(record.package)"
|
<a ng-click="deletePackageFinal(record.package)"
|
||||||
@@ -160,6 +160,13 @@
|
|||||||
Child-Domains
|
Child-Domains
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input ng-model="$parent.enforceDiskLimits"
|
||||||
|
type="checkbox" value="">
|
||||||
|
Enforce Disk Limits
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@@ -93,6 +93,12 @@
|
|||||||
Allow Creation of Fully Qualified Domain as Child-Domains
|
Allow Creation of Fully Qualified Domain as Child-Domains
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input ng-model="enforceDiskLimits" type="checkbox" value="">
|
||||||
|
Enforce Disk Limits
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -746,6 +746,14 @@ Automatic backup failed for %s on %s.
|
|||||||
|
|
||||||
config['DiskUsage'], config['DiskUsagePercentage'] = virtualHostUtilities.getDiskUsage("/home/" + website.domain, website.package.diskSpace)
|
config['DiskUsage'], config['DiskUsagePercentage'] = virtualHostUtilities.getDiskUsage("/home/" + website.domain, website.package.diskSpace)
|
||||||
|
|
||||||
|
if website.package.enforceDiskLimits:
|
||||||
|
if config['DiskUsagePercentage'] >= 100:
|
||||||
|
command = 'chattr -R +i /home/%s' % (website.domain)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
else:
|
||||||
|
command = 'chattr -R -i /home/%s' % (website.domain)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
## Calculate bw usage
|
## Calculate bw usage
|
||||||
|
|
||||||
from plogical.vhost import vhost
|
from plogical.vhost import vhost
|
||||||
|
|||||||
@@ -197,7 +197,6 @@ app.controller('modifyPackages', function ($scope, $http) {
|
|||||||
$("#successfullyModified").hide();
|
$("#successfullyModified").hide();
|
||||||
|
|
||||||
var packageName = $scope.packageToBeModified;
|
var packageName = $scope.packageToBeModified;
|
||||||
console.log(packageName);
|
|
||||||
|
|
||||||
|
|
||||||
url = "/packages/submitModify";
|
url = "/packages/submitModify";
|
||||||
@@ -234,11 +233,8 @@ app.controller('modifyPackages', function ($scope, $http) {
|
|||||||
$scope.emails = response.data.emails;
|
$scope.emails = response.data.emails;
|
||||||
$scope.allowedDomains = response.data.allowedDomains;
|
$scope.allowedDomains = response.data.allowedDomains;
|
||||||
|
|
||||||
if (response.data.allowFullDomain === 1) {
|
$scope.allowFullDomain = response.data.allowFullDomain === 1;
|
||||||
$scope.allowFullDomain = true;
|
$scope.enforceDiskLimits = response.data.enforceDiskLimits === 1;
|
||||||
} else {
|
|
||||||
$scope.allowFullDomain = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.modifyButton = "Save Details";
|
$scope.modifyButton = "Save Details";
|
||||||
|
|
||||||
@@ -260,7 +256,6 @@ app.controller('modifyPackages', function ($scope, $http) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$scope.modifyPackageFunc = function () {
|
$scope.modifyPackageFunc = function () {
|
||||||
|
|
||||||
var packageName = $scope.packageToBeModified;
|
var packageName = $scope.packageToBeModified;
|
||||||
@@ -286,7 +281,8 @@ app.controller('modifyPackages', function ($scope, $http) {
|
|||||||
dataBases: dataBases,
|
dataBases: dataBases,
|
||||||
emails: emails,
|
emails: emails,
|
||||||
allowedDomains: $scope.allowedDomains,
|
allowedDomains: $scope.allowedDomains,
|
||||||
allowFullDomain: $scope.allowFullDomain
|
allowFullDomain: $scope.allowFullDomain,
|
||||||
|
enforceDiskLimits: $scope.enforceDiskLimits,
|
||||||
};
|
};
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
@@ -446,7 +442,7 @@ app.controller('listPackageTables', function ($scope, $http) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.editInitial = function (package, diskSpace, bandwidth,
|
$scope.editInitial = function (package, diskSpace, bandwidth,
|
||||||
emailAccounts, dataBases, ftpAccounts, allowedDomains, allowFullDomain) {
|
emailAccounts, dataBases, ftpAccounts, allowedDomains, allowFullDomain, enforceDiskLimits) {
|
||||||
$scope.name = package;
|
$scope.name = package;
|
||||||
$scope.diskSpace = diskSpace;
|
$scope.diskSpace = diskSpace;
|
||||||
$scope.bandwidth = bandwidth;
|
$scope.bandwidth = bandwidth;
|
||||||
@@ -455,12 +451,8 @@ app.controller('listPackageTables', function ($scope, $http) {
|
|||||||
$scope.ftpAccounts = ftpAccounts;
|
$scope.ftpAccounts = ftpAccounts;
|
||||||
$scope.allowedDomains = allowedDomains;
|
$scope.allowedDomains = allowedDomains;
|
||||||
$scope.allowFullDomain = allowFullDomain;
|
$scope.allowFullDomain = allowFullDomain;
|
||||||
|
$scope.allowFullDomain = allowFullDomain === 1;
|
||||||
if (allowFullDomain === 1) {
|
$scope.enforceDiskLimits = enforceDiskLimits === 1;
|
||||||
$scope.allowFullDomain = true;
|
|
||||||
} else {
|
|
||||||
$scope.allowFullDomain = false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.saveChanges = function () {
|
$scope.saveChanges = function () {
|
||||||
@@ -482,7 +474,8 @@ app.controller('listPackageTables', function ($scope, $http) {
|
|||||||
dataBases: dataBases,
|
dataBases: dataBases,
|
||||||
emails: emails,
|
emails: emails,
|
||||||
allowedDomains: $scope.allowedDomains,
|
allowedDomains: $scope.allowedDomains,
|
||||||
allowFullDomain: $scope.allowFullDomain
|
allowFullDomain: $scope.allowFullDomain,
|
||||||
|
enforceDiskLimits: $scope.enforceDiskLimits,
|
||||||
};
|
};
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
|
|||||||
Reference in New Issue
Block a user