mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-05-07 07:47:05 +02:00
Add notification center button and fix stat-card/activity board loading
This commit is contained in:
@@ -6,29 +6,53 @@
|
||||
/* Java script code to create account */
|
||||
app.controller('createFTPAccount', function ($scope, $http) {
|
||||
|
||||
|
||||
// Initialize all ng-hide variables to hide alerts on page load
|
||||
$scope.ftpLoading = false;
|
||||
$scope.ftpDetails = true;
|
||||
$scope.canNotCreateFTP = true;
|
||||
$scope.successfullyCreatedFTP = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.generatedPasswordView = true;
|
||||
|
||||
$(document).ready(function () {
|
||||
$( ".ftpDetails" ).hide();
|
||||
$( ".ftpPasswordView" ).hide();
|
||||
$('.create-ftp-acct-select').select2();
|
||||
|
||||
// Check if select2 is available
|
||||
if ($.fn.select2) {
|
||||
$('.create-ftp-acct-select').select2();
|
||||
|
||||
$('.create-ftp-acct-select').on('select2:select', function (e) {
|
||||
var data = e.params.data;
|
||||
$scope.ftpDomain = data.text;
|
||||
$( ".ftpDetails" ).show();
|
||||
});
|
||||
} else {
|
||||
// Fallback for regular select
|
||||
$('.create-ftp-acct-select').on('change', function (e) {
|
||||
$scope.ftpDomain = $(this).val();
|
||||
$scope.$apply();
|
||||
$( ".ftpDetails" ).show();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('.create-ftp-acct-select').on('select2:select', function (e) {
|
||||
var data = e.params.data;
|
||||
$scope.ftpDomain = data.text;
|
||||
$( ".ftpDetails" ).show();
|
||||
|
||||
});
|
||||
|
||||
$scope.ftpLoading = true;
|
||||
|
||||
$scope.showFTPDetails = function() {
|
||||
if ($scope.ftpDomain && $scope.ftpDomain !== "") {
|
||||
$(".ftpDetails").show();
|
||||
$scope.ftpDetails = false;
|
||||
} else {
|
||||
$(".ftpDetails").hide();
|
||||
$scope.ftpDetails = true;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.createFTPAccount = function () {
|
||||
|
||||
$scope.ftpLoading = false;
|
||||
$scope.ftpLoading = true; // Show loading while creating
|
||||
$scope.ftpDetails = false;
|
||||
$scope.canNotCreate = true;
|
||||
$scope.successfullyCreated = true;
|
||||
$scope.canNotCreateFTP = true;
|
||||
$scope.successfullyCreatedFTP = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
var ftpDomain = $scope.ftpDomain;
|
||||
@@ -36,8 +60,45 @@ app.controller('createFTPAccount', function ($scope, $http) {
|
||||
var ftpPassword = $scope.ftpPassword;
|
||||
var path = $scope.ftpPath;
|
||||
|
||||
if (typeof path === 'undefined') {
|
||||
// Enhanced path validation
|
||||
if (typeof path === 'undefined' || path === null) {
|
||||
path = "";
|
||||
} else {
|
||||
path = path.trim();
|
||||
}
|
||||
|
||||
// Client-side path validation
|
||||
if (path && path !== "") {
|
||||
// Check for dangerous characters
|
||||
var dangerousChars = /[;&|$`'"<>*?~]/;
|
||||
if (dangerousChars.test(path)) {
|
||||
$scope.ftpLoading = false;
|
||||
$scope.canNotCreateFTP = false;
|
||||
$scope.successfullyCreatedFTP = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.errorMessage = "Invalid path: Path contains dangerous characters";
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for path traversal attempts
|
||||
if (path.indexOf("..") !== -1 || path.indexOf("~") !== -1) {
|
||||
$scope.ftpLoading = false;
|
||||
$scope.canNotCreateFTP = false;
|
||||
$scope.successfullyCreatedFTP = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.errorMessage = "Invalid path: Path cannot contain '..' or '~'";
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if path starts with slash (should be relative)
|
||||
if (path.startsWith("/")) {
|
||||
$scope.ftpLoading = false;
|
||||
$scope.canNotCreateFTP = false;
|
||||
$scope.successfullyCreatedFTP = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.errorMessage = "Invalid path: Path must be relative (not starting with '/')";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var url = "/ftp/submitFTPCreation";
|
||||
@@ -48,6 +109,8 @@ app.controller('createFTPAccount', function ($scope, $http) {
|
||||
ftpUserName: ftpUserName,
|
||||
passwordByPass: ftpPassword,
|
||||
path: path,
|
||||
enableCustomQuota: $scope.enableCustomQuota || false,
|
||||
customQuotaSize: $scope.customQuotaSize || 0,
|
||||
};
|
||||
|
||||
var config = {
|
||||
@@ -60,60 +123,82 @@ app.controller('createFTPAccount', function ($scope, $http) {
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
|
||||
|
||||
if (response.data.creatFTPStatus === 1) {
|
||||
$scope.ftpLoading = true;
|
||||
new PNotify({
|
||||
title: 'Success!',
|
||||
text: 'FTP account successfully created.',
|
||||
type: 'success'
|
||||
});
|
||||
|
||||
|
||||
$scope.ftpLoading = false; // Hide loading on success
|
||||
$scope.successfullyCreatedFTP = false;
|
||||
$scope.canNotCreateFTP = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.createdFTPUsername = ftpDomain + "_" + ftpUserName;
|
||||
|
||||
// Also show PNotify if available
|
||||
if (typeof PNotify !== 'undefined') {
|
||||
new PNotify({
|
||||
title: 'Success!',
|
||||
text: 'FTP account successfully created.',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
$scope.ftpLoading = true;
|
||||
$scope.ftpLoading = false; // Hide loading on error
|
||||
$scope.canNotCreateFTP = false;
|
||||
$scope.successfullyCreatedFTP = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
// Also show PNotify if available
|
||||
if (typeof PNotify !== 'undefined') {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.ftpLoading = false; // Hide loading on connection error
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.canNotCreateFTP = true;
|
||||
$scope.successfullyCreatedFTP = true;
|
||||
|
||||
// Also show PNotify if available
|
||||
if (typeof PNotify !== 'undefined') {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
function cantLoadInitialDatas(response) {
|
||||
|
||||
$scope.ftpLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
$scope.hideFewDetails = function () {
|
||||
|
||||
$scope.successfullyCreated = true;
|
||||
|
||||
|
||||
$scope.successfullyCreatedFTP = true;
|
||||
$scope.canNotCreateFTP = true;
|
||||
$scope.couldNotConnect = true;
|
||||
};
|
||||
|
||||
///
|
||||
|
||||
$scope.generatePassword = function () {
|
||||
$( ".ftpPasswordView" ).show();
|
||||
$(".ftpPasswordView").show();
|
||||
$scope.generatedPasswordView = false;
|
||||
$scope.ftpPassword = randomPassword(16);
|
||||
};
|
||||
|
||||
$scope.usePassword = function () {
|
||||
$(".ftpPasswordView" ).hide();
|
||||
$(".ftpPasswordView").hide();
|
||||
$scope.generatedPasswordView = true;
|
||||
};
|
||||
|
||||
// Quota management functions
|
||||
$scope.toggleCustomQuota = function() {
|
||||
if (!$scope.enableCustomQuota) {
|
||||
$scope.customQuotaSize = 0;
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
@@ -285,15 +370,16 @@ app.controller('deleteFTPAccount', function ($scope, $http) {
|
||||
/* Java script code to delete ftp account ends here */
|
||||
|
||||
|
||||
app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
app.controller('listFTPAccounts', function ($scope, $http, ) {
|
||||
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.ftpLoading = true;
|
||||
$scope.ftpLoading = false;
|
||||
$scope.ftpAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
$scope.quotaManagementBox = true;
|
||||
$scope.notificationsBox = true;
|
||||
|
||||
var globalFTPUsername = "";
|
||||
@@ -307,7 +393,7 @@ app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.ftpLoading = true;
|
||||
$scope.ftpLoading = false; // Don't show loading when opening password dialog
|
||||
$scope.changePasswordBox = false;
|
||||
$scope.notificationsBox = true;
|
||||
$scope.ftpUsername = ftpUsername;
|
||||
@@ -317,7 +403,7 @@ app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
|
||||
$scope.changePasswordBtn = function () {
|
||||
|
||||
$scope.ftpLoading = false;
|
||||
$scope.ftpLoading = true; // Show loading while changing password
|
||||
|
||||
|
||||
url = "/ftp/changePassword";
|
||||
@@ -343,13 +429,13 @@ app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
if (response.data.changePasswordStatus == 1) {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.passwordChanged = false;
|
||||
$scope.ftpLoading = true;
|
||||
$scope.ftpLoading = false; // Hide loading when done
|
||||
$scope.domainFeteched = $scope.selectedDomain;
|
||||
|
||||
} else {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.canNotChangePassword = false;
|
||||
$scope.ftpLoading = true;
|
||||
$scope.ftpLoading = false; // Hide loading on error
|
||||
$scope.canNotChangePassword = false;
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
}
|
||||
@@ -359,7 +445,7 @@ app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.ftpLoading = true;
|
||||
$scope.ftpLoading = false; // Hide loading on connection error
|
||||
|
||||
}
|
||||
|
||||
@@ -370,7 +456,7 @@ app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.ftpLoading = false;
|
||||
$scope.ftpLoading = true; // Show loading while fetching
|
||||
$scope.ftpAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
|
||||
@@ -405,7 +491,7 @@ app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.ftpLoading = true;
|
||||
$scope.ftpLoading = false; // Hide loading when done
|
||||
$scope.ftpAccounts = false;
|
||||
$scope.changePasswordBox = true;
|
||||
|
||||
@@ -417,7 +503,7 @@ app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.ftpLoading = true;
|
||||
$scope.ftpLoading = false; // Hide loading on error
|
||||
$scope.ftpAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
|
||||
@@ -432,7 +518,7 @@ app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.ftpLoading = true;
|
||||
$scope.ftpLoading = false; // Hide loading on connection error
|
||||
$scope.ftpAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
|
||||
@@ -454,4 +540,250 @@ app.controller('listFTPAccounts', function ($scope, $http) {
|
||||
$scope.generatedPasswordView = true;
|
||||
};
|
||||
|
||||
// Quota management functions
|
||||
$scope.manageQuota = function (record) {
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.ftpLoading = false;
|
||||
$scope.quotaManagementBox = false;
|
||||
$scope.notificationsBox = true;
|
||||
$scope.ftpUsername = record.user;
|
||||
globalFTPUsername = record.user;
|
||||
|
||||
// Set current quota info
|
||||
$scope.currentQuotaInfo = record.quotasize;
|
||||
$scope.packageQuota = record.package_quota;
|
||||
$scope.enableCustomQuotaEdit = record.custom_quota_enabled;
|
||||
$scope.customQuotaSizeEdit = record.custom_quota_size || 0;
|
||||
};
|
||||
|
||||
$scope.toggleCustomQuotaEdit = function() {
|
||||
if (!$scope.enableCustomQuotaEdit) {
|
||||
$scope.customQuotaSizeEdit = 0;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.updateQuotaBtn = function () {
|
||||
$scope.ftpLoading = true;
|
||||
|
||||
url = "/ftp/updateFTPQuota";
|
||||
|
||||
var data = {
|
||||
ftpUserName: globalFTPUsername,
|
||||
customQuotaSize: parseInt($scope.customQuotaSizeEdit) || 0,
|
||||
enableCustomQuota: $scope.enableCustomQuotaEdit || false,
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
if (response.data.updateQuotaStatus == 1) {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.quotaUpdated = false;
|
||||
$scope.ftpLoading = false;
|
||||
$scope.domainFeteched = $scope.selectedDomain;
|
||||
|
||||
// Refresh the records to show updated quota
|
||||
populateCurrentRecords();
|
||||
|
||||
// Show success notification
|
||||
if (typeof PNotify !== 'undefined') {
|
||||
new PNotify({
|
||||
title: 'Success!',
|
||||
text: 'FTP quota updated successfully.',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.quotaUpdateFailed = false;
|
||||
$scope.ftpLoading = false;
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
// Show error notification
|
||||
if (typeof PNotify !== 'undefined') {
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.ftpLoading = false;
|
||||
|
||||
// Show error notification
|
||||
if (typeof PNotify !== 'undefined') {
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: 'Could not connect to server.',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
app.controller('Resetftpconf', function ($scope, $http, $timeout){
|
||||
$scope.Loading = true;
|
||||
$scope.NotifyBox = true;
|
||||
$scope.InstallBox = true;
|
||||
|
||||
|
||||
$scope.resetftp = function () {
|
||||
$scope.Loading = false;
|
||||
$scope.installationDetailsForm = true;
|
||||
$scope.InstallBox = false;
|
||||
|
||||
|
||||
|
||||
url = "/ftp/resetftpnow";
|
||||
|
||||
var data = {
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
|
||||
|
||||
|
||||
function ListInitialData(response) {
|
||||
|
||||
if (response.data.status === 1) {
|
||||
$scope.NotifyBox = true;
|
||||
$scope.InstallBox = false;
|
||||
$scope.Loading = false;
|
||||
$scope.failedToStartInallation = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.modSecSuccessfullyInstalled = true;
|
||||
$scope.installationFailed = true;
|
||||
|
||||
$scope.statusfile = response.data.tempStatusPath
|
||||
|
||||
$timeout(getRequestStatus, 1000);
|
||||
|
||||
} else {
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
$scope.NotifyBox = false;
|
||||
$scope.InstallBox = true;
|
||||
$scope.Loading = true;
|
||||
$scope.failedToStartInallation = false;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.modSecSuccessfullyInstalled = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialData(response) {
|
||||
$scope.cyberhosting = true;
|
||||
new PNotify({
|
||||
title: 'Error!',
|
||||
text: 'Could not connect to server, please refresh this page.',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getRequestStatus() {
|
||||
|
||||
$scope.NotifyBox = true;
|
||||
$scope.InstallBox = false;
|
||||
$scope.Loading = false;
|
||||
$scope.failedToStartInallation = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.modSecSuccessfullyInstalled = true;
|
||||
$scope.installationFailed = true;
|
||||
|
||||
url = "/ftp/getresetstatus";
|
||||
|
||||
var data = {
|
||||
statusfile: $scope.statusfile
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
|
||||
|
||||
if (response.data.abort === 0) {
|
||||
|
||||
$scope.NotifyBox = true;
|
||||
$scope.InstallBox = false;
|
||||
$scope.Loading = false;
|
||||
$scope.failedToStartInallation = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.modSecSuccessfullyInstalled = true;
|
||||
$scope.installationFailed = true;
|
||||
|
||||
$scope.requestData = response.data.requestStatus;
|
||||
$timeout(getRequestStatus, 1000);
|
||||
} else {
|
||||
// Notifications
|
||||
$timeout.cancel();
|
||||
$scope.NotifyBox = false;
|
||||
$scope.InstallBox = false;
|
||||
$scope.Loading = true;
|
||||
$scope.failedToStartInallation = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
$scope.requestData = response.data.requestStatus;
|
||||
|
||||
if (response.data.installed === 0) {
|
||||
$scope.installationFailed = false;
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
} else {
|
||||
$scope.modSecSuccessfullyInstalled = false;
|
||||
$timeout(function () {
|
||||
$window.location.reload();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
|
||||
$scope.NotifyBox = false;
|
||||
$scope.InstallBox = false;
|
||||
$scope.Loading = true;
|
||||
$scope.failedToStartInallation = true;
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.modSecSuccessfullyInstalled = true;
|
||||
$scope.installationFailed = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user