Files
CyberPanel/static/ftp/ftp.js

461 lines
11 KiB
JavaScript
Raw Normal View History

2017-10-24 19:16:36 +05:00
/**
* Created by usman on 8/4/17.
*/
/* Java script code to create account */
app.controller('createFTPAccount', function ($scope, $http) {
2017-10-24 19:16:36 +05:00
$scope.ftpLoading = true;
$scope.ftpDetails = true;
$scope.canNotCreate = true;
$scope.successfullyCreated = true;
$scope.couldNotConnect = true;
$scope.showFTPDetails = function () {
2017-10-24 19:16:36 +05:00
$scope.ftpLoading = true;
$scope.ftpDetails = false;
$scope.canNotCreate = true;
$scope.successfullyCreated = true;
$scope.couldNotConnect = true;
};
$scope.createFTPAccount = function () {
2017-10-24 19:16:36 +05:00
$scope.ftpLoading = false;
$scope.ftpDetails = false;
$scope.canNotCreate = true;
$scope.successfullyCreated = true;
$scope.couldNotConnect = true;
2017-10-24 19:16:36 +05:00
var ftpDomain = $scope.ftpDomain;
var ftpUserName = $scope.ftpUserName;
var ftpPassword = $scope.ftpPassword;
var path = $scope.ftpPath;
2017-10-24 19:16:36 +05:00
if (typeof path === 'undefined') {
path = "";
}
2017-10-24 19:16:36 +05:00
var url = "/ftp/submitFTPCreation";
2017-10-24 19:16:36 +05:00
var data = {
ftpDomain: ftpDomain,
ftpUserName: ftpUserName,
passwordByPass: ftpPassword,
path: path,
};
2017-10-24 19:16:36 +05:00
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
2017-10-24 19:16:36 +05:00
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
2017-10-24 19:16:36 +05:00
function ListInitialDatas(response) {
2017-10-24 19:16:36 +05:00
if (response.data.creatFTPStatus == 1) {
2017-10-24 19:16:36 +05:00
$scope.ftpLoading = true;
$scope.ftpDetails = false;
$scope.canNotCreate = true;
$scope.successfullyCreated = false;
$scope.couldNotConnect = true;
2017-10-24 19:16:36 +05:00
} else {
$scope.ftpLoading = true;
$scope.ftpDetails = false;
$scope.canNotCreate = false;
$scope.successfullyCreated = true;
$scope.couldNotConnect = true;
2017-10-24 19:16:36 +05:00
$scope.errorMessage = response.data.error_message;
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
function cantLoadInitialDatas(response) {
2017-10-24 19:16:36 +05:00
$scope.ftpLoading = true;
$scope.ftpDetails = false;
$scope.canNotCreate = true;
$scope.successfullyCreated = true;
$scope.couldNotConnect = false;
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
};
$scope.hideFewDetails = function () {
2017-10-24 19:16:36 +05:00
$scope.successfullyCreated = true;
};
2019-03-13 18:22:12 +05:00
///
$scope.generatedPasswordView = true;
$scope.generatePassword = function () {
$scope.generatedPasswordView = false;
$scope.ftpPassword = randomPassword(12);
2019-03-13 18:22:12 +05:00
};
$scope.usePassword = function () {
$scope.generatedPasswordView = true;
};
2017-10-24 19:16:36 +05:00
});
/* Java script code to create account ends here */
/* Java script code to delete ftp account */
app.controller('deleteFTPAccount', function ($scope, $http) {
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsOfDomain = true;
$scope.deleteFTPButton = true;
$scope.deleteFailure = true;
$scope.deleteSuccess = true;
$scope.couldNotConnect = true;
$scope.deleteFTPButtonInit = true;
$scope.getFTPAccounts = function () {
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsOfDomain = true;
$scope.deleteFTPButton = true;
$scope.deleteFailure = true;
$scope.deleteSuccess = true;
$scope.couldNotConnect = true;
$scope.deleteFTPButtonInit = true;
var url = "/ftp/fetchFTPAccounts";
var data = {
ftpDomain: $scope.selectedDomain,
};
2017-10-24 19:16:36 +05:00
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
2017-10-24 19:16:36 +05:00
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
2017-10-24 19:16:36 +05:00
function ListInitialDatas(response) {
2017-10-24 19:16:36 +05:00
if (response.data.fetchStatus == 1) {
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsFeteched = JSON.parse(response.data.data);
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsOfDomain = false;
$scope.deleteFTPButton = true;
$scope.deleteFailure = true;
$scope.deleteSuccess = true;
$scope.couldNotConnect = true;
$scope.deleteFTPButtonInit = false;
2017-10-24 19:16:36 +05:00
} else {
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsOfDomain = true;
$scope.deleteFTPButton = true;
$scope.deleteFailure = true;
$scope.deleteSuccess = true;
$scope.couldNotConnect = false;
$scope.deleteFTPButtonInit = true;
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
function cantLoadInitialDatas(response) {
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsOfDomain = true;
$scope.deleteFTPButton = true;
$scope.deleteFailure = true;
$scope.deleteSuccess = true;
$scope.couldNotConnect = false;
$scope.deleteFTPButtonInit = true;
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
};
$scope.deleteFTPAccount = function () {
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsOfDomain = false;
$scope.deleteFTPButton = false;
$scope.deleteFailure = true;
$scope.deleteSuccess = true;
$scope.couldNotConnect = true;
$scope.deleteFTPButtonInit = false;
2017-10-24 19:16:36 +05:00
};
$scope.deleteFTPFinal = function () {
2017-10-24 19:16:36 +05:00
var url = "/ftp/submitFTPDelete";
var data = {
ftpUsername: $scope.selectedFTPAccount,
};
2017-10-24 19:16:36 +05:00
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
2017-10-24 19:16:36 +05:00
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
2017-10-24 19:16:36 +05:00
function ListInitialDatas(response) {
2017-10-24 19:16:36 +05:00
if (response.data.deleteStatus == 1) {
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsOfDomain = true;
$scope.deleteFTPButton = true;
$scope.deleteFailure = true;
$scope.deleteSuccess = false;
$scope.couldNotConnect = true;
$scope.deleteFTPButtonInit = true;
2017-10-24 19:16:36 +05:00
$scope.ftpUserNameDeleted = $scope.selectedFTPAccount;
2017-10-24 19:16:36 +05:00
} else {
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsOfDomain = true;
$scope.deleteFTPButton = true;
$scope.deleteFailure = false;
$scope.deleteSuccess = true;
$scope.couldNotConnect = true;
$scope.deleteFTPButtonInit = false;
2017-10-24 19:16:36 +05:00
$scope.errorMessage = response.data.error_message;
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
function cantLoadInitialDatas(response) {
2017-10-24 19:16:36 +05:00
$scope.ftpAccountsOfDomain = true;
$scope.deleteFTPButton = true;
$scope.deleteFailure = false;
$scope.deleteSuccess = true;
$scope.couldNotConnect = false;
$scope.deleteFTPButtonInit = true;
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
};
});
/* Java script code to delete ftp account ends here */
app.controller('listFTPAccounts', function ($scope, $http) {
2017-10-24 19:16:36 +05:00
$scope.recordsFetched = true;
$scope.passwordChanged = true;
$scope.canNotChangePassword = true;
$scope.couldNotConnect = true;
$scope.ftpLoading = true;
$scope.ftpAccounts = true;
$scope.changePasswordBox = true;
$scope.notificationsBox = true;
var globalFTPUsername = "";
$scope.fetchFTPAccounts = function () {
populateCurrentRecords();
2017-10-24 19:16:36 +05:00
};
$scope.changePassword = function (ftpUsername) {
$scope.recordsFetched = true;
$scope.passwordChanged = true;
$scope.canNotChangePassword = true;
$scope.couldNotConnect = true;
$scope.ftpLoading = true;
$scope.changePasswordBox = false;
$scope.notificationsBox = true;
$scope.ftpUsername = ftpUsername;
globalFTPUsername = ftpUsername;
2017-10-24 19:16:36 +05:00
};
$scope.changePasswordBtn = function () {
$scope.ftpLoading = false;
2017-10-24 19:16:36 +05:00
url = "/ftp/changePassword";
2017-10-24 19:16:36 +05:00
var data = {
ftpUserName: globalFTPUsername,
ftpPassword: $scope.ftpPassword,
};
2017-10-24 19:16:36 +05:00
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
2017-10-24 19:16:36 +05:00
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
2017-10-24 19:16:36 +05:00
function ListInitialDatas(response) {
2017-10-24 19:16:36 +05:00
if (response.data.changePasswordStatus == 1) {
$scope.notificationsBox = false;
$scope.passwordChanged = false;
$scope.ftpLoading = true;
$scope.domainFeteched = $scope.selectedDomain;
2017-10-24 19:16:36 +05:00
} else {
$scope.notificationsBox = false;
$scope.canNotChangePassword = false;
$scope.ftpLoading = true;
$scope.canNotChangePassword = false;
$scope.errorMessage = response.data.error_message;
}
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
function cantLoadInitialDatas(response) {
$scope.notificationsBox = false;
$scope.couldNotConnect = false;
$scope.ftpLoading = true;
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
};
2017-10-24 19:16:36 +05:00
function populateCurrentRecords() {
$scope.recordsFetched = true;
$scope.passwordChanged = true;
$scope.canNotChangePassword = true;
$scope.couldNotConnect = true;
$scope.ftpLoading = false;
$scope.ftpAccounts = true;
$scope.changePasswordBox = true;
2017-10-24 19:16:36 +05:00
var selectedDomain = $scope.selectedDomain;
2017-10-24 19:16:36 +05:00
url = "/ftp/getAllFTPAccounts";
2017-10-24 19:16:36 +05:00
var data = {
selectedDomain: selectedDomain,
};
2017-10-24 19:16:36 +05:00
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
2017-10-24 19:16:36 +05:00
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
2017-10-24 19:16:36 +05:00
function ListInitialDatas(response) {
2017-10-24 19:16:36 +05:00
if (response.data.fetchStatus == 1) {
2017-10-24 19:16:36 +05:00
$scope.records = JSON.parse(response.data.data);
2017-10-24 19:16:36 +05:00
$scope.notificationsBox = false;
$scope.recordsFetched = false;
$scope.passwordChanged = true;
$scope.canNotChangePassword = true;
$scope.couldNotConnect = true;
$scope.ftpLoading = true;
$scope.ftpAccounts = false;
$scope.changePasswordBox = true;
2017-10-24 19:16:36 +05:00
$scope.domainFeteched = $scope.selectedDomain;
2017-10-24 19:16:36 +05:00
} else {
$scope.notificationsBox = false;
$scope.recordsFetched = true;
$scope.passwordChanged = true;
$scope.canNotChangePassword = true;
$scope.couldNotConnect = true;
$scope.ftpLoading = true;
$scope.ftpAccounts = true;
$scope.changePasswordBox = true;
2017-10-24 19:16:36 +05:00
$scope.errorMessage = response.data.error_message;
}
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
function cantLoadInitialDatas(response) {
$scope.notificationsBox = false;
$scope.recordsFetched = true;
$scope.passwordChanged = true;
$scope.canNotChangePassword = true;
$scope.couldNotConnect = false;
$scope.ftpLoading = true;
$scope.ftpAccounts = true;
$scope.changePasswordBox = true;
2017-10-24 19:16:36 +05:00
}
2017-10-24 19:16:36 +05:00
}
2019-03-13 18:22:12 +05:00
////
$scope.generatedPasswordView = true;
$scope.generatePassword = function () {
$scope.generatedPasswordView = false;
$scope.ftpPassword = randomPassword(12);
2019-03-13 18:22:12 +05:00
};
$scope.usePassword = function () {
$scope.generatedPasswordView = true;
};
2017-10-24 19:16:36 +05:00
});