def submitFTPDelete(self): try: userID = self.request.session['userID'] currentACL = ACLManager.loadedACL(userID) if ACLManager.currentContextPermission(currentACL, 'deleteFTPAccount') == 0: return ACLManager.loadErrorJson('deleteStatus', 0) data = json.loads(self.request.body) ftpUserName = data['ftpUsername'] admin = Administrator.objects.get(pk=userID) ftp = Users.objects.get(user=ftpUserName) if ftp.domain.admin != admin: return ACLManager.loadErrorJson() FTPUtilities.submitFTPDeletion(ftpUserName) final_json = json.dumps({'status': 1, 'deleteStatus': 1, 'error_message': "None"}) return HttpResponse(final_json) except BaseException, msg: data_ret = {'status': 0, 'deleteStatus': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) return HttpResponse(json_data)
def deleteFTPAccount(self, userName): try: result = FTPUtilities.submitFTPDeletion(userName) if result[0] == 1: self.printStatus(1, 'None') else: self.printStatus(1, result[1]) except BaseException, msg: logger.writeforCLI(str(msg), "Error", stack()[0][3]) self.printStatus(0, str(msg))
def submitFTPDelete(request): try: val = request.session['userID'] admin = Administrator.objects.get(id=val) try: if request.method == 'POST': data = json.loads(request.body) ftpUserName = data['ftpUsername'] ftp = Users.objects.get(user=ftpUserName) if admin.type != 1: if ftp.domain.admin != admin: data_ret = { 'deleteStatus': 0, 'error_message': 'Not enough privileges.' } json_data = json.dumps(data_ret) return HttpResponse(json_data) FTPUtilities.submitFTPDeletion(ftpUserName) final_json = json.dumps({ 'deleteStatus': 1, 'error_message': "None" }) return HttpResponse(final_json) except BaseException, msg: data_ret = {'deleteStatus': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) return HttpResponse(json_data) except KeyError, msg: data_ret = {'deleteStatus': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) return HttpResponse(json_data)