mirror of
				https://github.com/usmannasir/cyberpanel.git
				synced 2025-10-31 10:26:01 +01:00 
			
		
		
		
	Email Forwarding.
This commit is contained in:
		
							
								
								
									
										10
									
								
								api/views.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								api/views.py
									
									
									
									
									
								
							| @@ -220,16 +220,17 @@ def deleteWebsite(request): | ||||
|                 json_data = json.dumps(data_ret) | ||||
|                 return HttpResponse(json_data) | ||||
|  | ||||
|             numberOfWebsites = str(Websites.objects.count() + ChildDomains.objects.count()) | ||||
|  | ||||
|             ## Deleting master domain | ||||
|  | ||||
|             website = Websites.objects.get(domain=websiteName) | ||||
|             websiteOwner = website.admin | ||||
|  | ||||
|             if admin.websites_set.all().count() == 0: | ||||
|                 websiteOwner.delete() | ||||
|  | ||||
|             ## Deleting master domain | ||||
|  | ||||
|             numberOfWebsites = str(Websites.objects.count() + ChildDomains.objects.count()) | ||||
|  | ||||
|  | ||||
|             execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" | ||||
|  | ||||
|             execPath = execPath + " deleteVirtualHostConfigurations --virtualHostName " + websiteName + \ | ||||
| @@ -246,7 +247,6 @@ def deleteWebsite(request): | ||||
|         json_data = json.dumps(data_ret) | ||||
|         return HttpResponse(json_data) | ||||
|  | ||||
|  | ||||
| def submitWebsiteStatus(request): | ||||
|     try: | ||||
|         if request.method == 'POST': | ||||
|   | ||||
| @@ -390,6 +390,7 @@ | ||||
|             <ul> | ||||
|                 <li id="normalUserC"><a href="{% url 'createEmailAccount' %}" title="{% trans 'Create Email Account' %}"><span>{% trans "Create Email" %}</span></a></li> | ||||
|                 <li><a href="{% url 'deleteEmailAccount' %}" title="{% trans 'Delete Email Account' %}"><span>{% trans "Delete Email" %}</span></a></li> | ||||
|                 <li><a href="{% url 'emailForwarding' %}" title="{% trans 'Email Forwarding' %}"><span>{% trans "Email Forwarding" %}</span></a></li> | ||||
|                 <li><a href="{% url 'changeEmailAccountPassword' %}" title="{% trans 'Change Password' %}"><span>{% trans "Change Password" %}</span></a></li> | ||||
|                 <li><a href="{% url 'dkimManager' %}" title="{% trans 'DKIM Manager' %}"><span>{% trans "DKIM Manager" %}</span></a></li> | ||||
|                 <li><a href="/rainloop/index.php" title="{% trans 'Access Webmail' %}" target="_blank"><span>{% trans "Access Webmail" %}</span></a></li> | ||||
|   | ||||
| @@ -28,7 +28,7 @@ class EUsers(models.Model): | ||||
|  | ||||
|  | ||||
| class Forwardings(models.Model): | ||||
|     source = models.CharField(primary_key=True, max_length=80) | ||||
|     source = models.CharField(max_length=80) | ||||
|     destination = models.TextField() | ||||
|  | ||||
|     class Meta: | ||||
|   | ||||
| @@ -827,3 +827,351 @@ app.controller('dkimManager', function($scope, $http, $timeout, $window) { | ||||
|  | ||||
| }); | ||||
|  | ||||
| /* Java script code for email forwarding */ | ||||
| app.controller('emailForwarding', function($scope,$http) { | ||||
|  | ||||
|     $scope.creationBox = true; | ||||
|     $scope.emailDetails = true; | ||||
|     $scope.forwardLoading = true; | ||||
|     $scope.forwardError = true; | ||||
|     $scope.forwardSuccess = true; | ||||
|     $scope.couldNotConnect = true; | ||||
|     $scope.notifyBox = true; | ||||
|  | ||||
|  | ||||
|     $scope.showEmailDetails = function(){ | ||||
|  | ||||
|         $scope.creationBox = true; | ||||
|         $scope.emailDetails = true; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|  | ||||
|         var url = "/email/getEmailsForDomain"; | ||||
|  | ||||
|  | ||||
|                 var data = { | ||||
|                     domain:$scope.emailDomain | ||||
|                 }; | ||||
|  | ||||
|                 var config = { | ||||
|                     headers : { | ||||
|                         'X-CSRFToken': getCookie('csrftoken') | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); | ||||
|  | ||||
|  | ||||
|                 function ListInitialDatas(response) { | ||||
|  | ||||
|  | ||||
|                     if(response.data.fetchStatus === 1){ | ||||
|  | ||||
|                         $scope.emails = JSON.parse(response.data.data); | ||||
|  | ||||
|                         $scope.creationBox = true; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = true; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     else | ||||
|                     { | ||||
|                         $scope.creationBox = true; | ||||
|                         $scope.emailDetails = true; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = false; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                         $scope.errorMessage = response.data.error_message; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|  | ||||
|  | ||||
|                 } | ||||
|                 function cantLoadInitialDatas(response) { | ||||
|  | ||||
|                     $scope.creationBox = true; | ||||
|                     $scope.emailDetails = true; | ||||
|                     $scope.forwardLoading = true; | ||||
|                     $scope.forwardError = true; | ||||
|                     $scope.forwardSuccess = true; | ||||
|                     $scope.couldNotConnect = false; | ||||
|                     $scope.notifyBox = false; | ||||
|  | ||||
|  | ||||
|                 } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     $scope.selectForwardingEmail = function () { | ||||
|  | ||||
|         $scope.creationBox = true; | ||||
|         $scope.emailDetails = false; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|         $scope.fetchCurrentForwardings(); | ||||
|     }; | ||||
|  | ||||
|     $scope.fetchCurrentForwardings = function(){ | ||||
|  | ||||
|         $scope.creationBox = false; | ||||
|         $scope.emailDetails = false; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|  | ||||
|         var url = "/email/fetchCurrentForwardings"; | ||||
|  | ||||
|  | ||||
|                 var data = { | ||||
|                     emailAddress:$scope.selectedEmail | ||||
|                 }; | ||||
|  | ||||
|                 var config = { | ||||
|                     headers : { | ||||
|                         'X-CSRFToken': getCookie('csrftoken') | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); | ||||
|  | ||||
|  | ||||
|                 function ListInitialDatas(response) { | ||||
|  | ||||
|  | ||||
|                     if(response.data.fetchStatus === 1){ | ||||
|  | ||||
|                         $scope.records = JSON.parse(response.data.data); | ||||
|  | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = true; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = true; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     else | ||||
|                     { | ||||
|                         $scope.creationBox = true; | ||||
|                         $scope.emailDetails = true; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = false; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                         $scope.errorMessage = response.data.error_message; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|  | ||||
|  | ||||
|                 } | ||||
|                 function cantLoadInitialDatas(response) { | ||||
|  | ||||
|                     $scope.creationBox = true; | ||||
|                     $scope.emailDetails = true; | ||||
|                     $scope.forwardLoading = true; | ||||
|                     $scope.forwardError = true; | ||||
|                     $scope.forwardSuccess = true; | ||||
|                     $scope.couldNotConnect = false; | ||||
|                     $scope.notifyBox = false; | ||||
|  | ||||
|  | ||||
|                 } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     $scope.deleteForwarding = function(destination){ | ||||
|  | ||||
|         $scope.creationBox = true; | ||||
|         $scope.emailDetails = true; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|  | ||||
|         var url = "/email/submitForwardDeletion"; | ||||
|  | ||||
|  | ||||
|                 var data = { | ||||
|                     destination:destination | ||||
|                 }; | ||||
|  | ||||
|                 var config = { | ||||
|                     headers : { | ||||
|                         'X-CSRFToken': getCookie('csrftoken') | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); | ||||
|  | ||||
|  | ||||
|                 function ListInitialDatas(response) { | ||||
|  | ||||
|  | ||||
|                     if(response.data.deleteForwardingStatus === 1){ | ||||
|  | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = true; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = true; | ||||
|  | ||||
|                         $scope.fetchCurrentForwardings(); | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     else | ||||
|                     { | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = false; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                         $scope.errorMessage = response.data.error_message; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|  | ||||
|  | ||||
|                 } | ||||
|                 function cantLoadInitialDatas(response) { | ||||
|  | ||||
|                     $scope.creationBox = true; | ||||
|                     $scope.emailDetails = true; | ||||
|                     $scope.forwardLoading = true; | ||||
|                     $scope.forwardError = true; | ||||
|                     $scope.forwardSuccess = true; | ||||
|                     $scope.couldNotConnect = false; | ||||
|                     $scope.notifyBox = false; | ||||
|  | ||||
|  | ||||
|                 } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     $scope.forwardEmail = function(){ | ||||
|  | ||||
|         $scope.creationBox = false; | ||||
|         $scope.emailDetails = false; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|  | ||||
|         var url = "/email/submitEmailForwardingCreation"; | ||||
|  | ||||
|  | ||||
|                 var data = { | ||||
|                     source: $scope.selectedEmail, | ||||
|                     destination:$scope.destinationEmail | ||||
|                 }; | ||||
|  | ||||
|                 var config = { | ||||
|                     headers : { | ||||
|                         'X-CSRFToken': getCookie('csrftoken') | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); | ||||
|  | ||||
|  | ||||
|                 function ListInitialDatas(response) { | ||||
|  | ||||
|  | ||||
|                     if(response.data.createStatus === 1){ | ||||
|  | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = true; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = true; | ||||
|  | ||||
|                         $scope.fetchCurrentForwardings(); | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     else | ||||
|                     { | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = false; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                         $scope.errorMessage = response.data.error_message; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|  | ||||
|  | ||||
|                 } | ||||
|                 function cantLoadInitialDatas(response) { | ||||
|  | ||||
|                     $scope.creationBox = true; | ||||
|                     $scope.emailDetails = true; | ||||
|                     $scope.forwardLoading = true; | ||||
|                     $scope.forwardError = true; | ||||
|                     $scope.forwardSuccess = true; | ||||
|                     $scope.couldNotConnect = false; | ||||
|                     $scope.notifyBox = false; | ||||
|  | ||||
|  | ||||
|                 } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     }; | ||||
|  | ||||
|  | ||||
| }); | ||||
| /* Java script for email forwarding */ | ||||
							
								
								
									
										132
									
								
								mailServer/templates/mailServer/emailForwarding.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								mailServer/templates/mailServer/emailForwarding.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,132 @@ | ||||
| {% extends "baseTemplate/index.html" %} | ||||
| {% load i18n %} | ||||
| {% block title %}{% trans "Setup Email Forwarding - CyberPanel" %}{% endblock %} | ||||
| {% block content %} | ||||
|  | ||||
| {% load static %} | ||||
| {% get_current_language as LANGUAGE_CODE %} | ||||
| <!-- Current language: {{ LANGUAGE_CODE }} --> | ||||
|  | ||||
| <div class="container"> | ||||
| <div id="page-title"> | ||||
|    <h2>{% trans "Setup Email Forwarding" %}</h2> | ||||
|    <p>{% trans "This page help you setup email forwarding for your emails." %}</p> | ||||
| </div> | ||||
|  | ||||
| <div ng-controller="emailForwarding" class="panel"> | ||||
|     <div class="panel-body"> | ||||
|         <h3 class="title-hero"> | ||||
|             {% trans "Setup Email Forwarding" %} <img ng-hide="forwardLoading" src="{% static 'images/loading.gif' %}"> | ||||
|         </h3> | ||||
|         <div  class="example-box-wrapper"> | ||||
|  | ||||
|  | ||||
|             <form  action="/" class="form-horizontal bordered-row"> | ||||
|  | ||||
|  | ||||
|                  <div class="form-group"> | ||||
|                     <label class="col-sm-3 control-label">{% trans "Select Website" %} </label> | ||||
|                     <div class="col-sm-6"> | ||||
|                         <select ng-change="showEmailDetails()" ng-model="emailDomain" class="form-control"> | ||||
|                             {% for items in websiteList %} | ||||
|                                 <option>{{ items }}</option> | ||||
|                             {% endfor %} | ||||
|                         </select> | ||||
|                     </div> | ||||
|                 </div> | ||||
|  | ||||
|  | ||||
|             <!------ Modification form that appears after a click ---------------> | ||||
|  | ||||
|                 <div ng-hide="emailDetails" class="form-group"> | ||||
|                     <label class="col-sm-3 control-label">{% trans "Select Email" %} </label> | ||||
|                     <div class="col-sm-6"> | ||||
|                         <select ng-change="selectForwardingEmail()" ng-model="selectedEmail" class="form-control"> | ||||
|                                 <option ng-repeat="email in emails track by $index">{$ email.email $}</option> | ||||
|                         </select> | ||||
|                     </div> | ||||
|                 </div> | ||||
|  | ||||
|             <!------ Modification form that appears after a click ---------------> | ||||
|  | ||||
|             <div ng-hide="notifyBox" class="form-group"> | ||||
|                     <label class="col-sm-3 control-label"></label> | ||||
|                     <div class="col-sm-4"> | ||||
|                             <div ng-hide="forwardError" class="alert alert-danger"> | ||||
|                                         <p>{$ errorMessage $}</p> | ||||
|                             </div> | ||||
|  | ||||
|                             <div ng-hide="forwardSuccess" class="alert alert-success"> | ||||
|                                         <p>{$ successMessage $}</p> | ||||
|                             </div> | ||||
|                             <div ng-hide="couldNotConnect" class="alert alert-danger"> | ||||
|                                         <p>{% trans "Could not connect to server. Please refresh this page." %}</p> | ||||
|                             </div> | ||||
|  | ||||
|                     </div> | ||||
|  | ||||
|  | ||||
|  | ||||
|                 </div> | ||||
|  | ||||
|             <!------ List of records ---------------> | ||||
|  | ||||
|             <div ng-hide="creationBox" class="form-group"> | ||||
|  | ||||
|                     <div class="col-sm-4"> | ||||
|                         <input placeholder="{% trans 'Source' %}"  type="email" class="form-control" ng-model="selectedEmail" readonly> | ||||
|                     </div> | ||||
|  | ||||
|                     <div class="col-sm-4"> | ||||
|                         <input placeholder="{% trans 'Destination' %}"   type="email" class="form-control" ng-model="destinationEmail" required> | ||||
|                     </div> | ||||
|  | ||||
|  | ||||
|                     <div class="col-sm-4"> | ||||
|                         <button style="width: 100%;"  type="button" ng-click="forwardEmail()" class="btn btn-primary">{% trans "Forward Email" %}</button> | ||||
|                     </div> | ||||
|             </div> | ||||
|  | ||||
|             <div ng-hide="creationBox" class="form-group"> | ||||
|  | ||||
|                     <div  class="col-sm-12"> | ||||
|  | ||||
|                         <table class="table"> | ||||
|                             <thead> | ||||
|                             <tr> | ||||
|                                 <th>{% trans "ID" %}</th> | ||||
|                                 <th>{% trans "Source" %}</th> | ||||
|                                 <th>{% trans "Destination" %}</th> | ||||
|                                 <th>{% trans "Actions" %}</th> | ||||
|                             </tr> | ||||
|                             </thead> | ||||
|                             <tbody> | ||||
|                             <tr ng-repeat="record in records track by $index"> | ||||
|                                 <td ng-bind="record.id"></td> | ||||
|                                 <td ng-bind="record.source"></td> | ||||
|                                 <td ng-bind="record.destination"></td> | ||||
|                                 <td ng-click="deleteForwarding(record.destination)"><img src="{% static 'images/delete.png' %}"></td> | ||||
|                             </tr> | ||||
|                             </tbody> | ||||
|                         </table> | ||||
|                     </div> | ||||
|                 </div> | ||||
|  | ||||
|             <!------ List of records ---------------> | ||||
|  | ||||
|  | ||||
|  | ||||
|             </form> | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|         </div> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
|  | ||||
| </div> | ||||
|  | ||||
|  | ||||
| {% endblock %} | ||||
| @@ -7,6 +7,13 @@ urlpatterns = [ | ||||
|     url(r'^submitEmailCreation', views.submitEmailCreation, name='submitEmailCreation'), | ||||
|  | ||||
|  | ||||
|     ## Mail Forwardings | ||||
|     url(r'^emailForwarding$', views.emailForwarding, name='emailForwarding'), | ||||
|     url(r'^submitEmailForwardingCreation$', views.submitEmailForwardingCreation, name='submitEmailForwardingCreation'), | ||||
|     url(r'^fetchCurrentForwardings$', views.fetchCurrentForwardings, name='fetchCurrentForwardings'), | ||||
|     url(r'^submitForwardDeletion$', views.submitForwardDeletion, name='submitForwardDeletion'), | ||||
|  | ||||
|  | ||||
|     ## Delete email | ||||
|     url(r'^deleteEmailAccount', views.deleteEmailAccount, name='deleteEmailAccount'), | ||||
|     url(r'^getEmailsForDomain$', views.getEmailsForDomain, name='getEmailsForDomain'), | ||||
|   | ||||
| @@ -17,6 +17,7 @@ from plogical.mailUtilities import mailUtilities | ||||
| import thread | ||||
| from dns.models import Domains as dnsDomains | ||||
| from dns.models import Records as dnsRecords | ||||
| from mailServer.models import Forwardings | ||||
|  | ||||
| def loadEmailHome(request): | ||||
|     try: | ||||
| @@ -195,6 +196,142 @@ def submitEmailDeletion(request): | ||||
|         json_data = json.dumps(data_ret) | ||||
|         return HttpResponse(json_data) | ||||
|  | ||||
| def emailForwarding(request): | ||||
|     try: | ||||
|         val = request.session['userID'] | ||||
|         try: | ||||
|             admin = Administrator.objects.get(pk=request.session['userID']) | ||||
|  | ||||
|             if admin.type == 1: | ||||
|                 websites = admin.websites_set.all() | ||||
|             else: | ||||
|                 websites = Websites.objects.filter(admin=admin) | ||||
|  | ||||
|             websitesName = [] | ||||
|  | ||||
|             for items in websites: | ||||
|                 websitesName.append(items.domain) | ||||
|  | ||||
|             return render(request, 'mailServer/emailForwarding.html', {'websiteList':websitesName}) | ||||
|         except BaseException, msg: | ||||
|             logging.CyberCPLogFileWriter.writeToFile(str(msg)) | ||||
|             return HttpResponse(str(msg)) | ||||
|  | ||||
|     except KeyError: | ||||
|         return redirect(loadLoginPage) | ||||
|  | ||||
|  | ||||
| def fetchCurrentForwardings(request): | ||||
|     try: | ||||
|         val = request.session['userID'] | ||||
|         try: | ||||
|             if request.method == 'POST': | ||||
|  | ||||
|                 data = json.loads(request.body) | ||||
|                 emailAddress = data['emailAddress'] | ||||
|  | ||||
|                 currentForwardings = Forwardings.objects.filter(source=emailAddress) | ||||
|  | ||||
|                 json_data = "[" | ||||
|                 checker = 0 | ||||
|                 id = 1 | ||||
|                 for items in currentForwardings: | ||||
|                     if items.source == items.destination: | ||||
|                         continue | ||||
|                     dic = {'id': id, | ||||
|                            'source': items.source, | ||||
|                            'destination':items.destination} | ||||
|  | ||||
|                     id = id + 1 | ||||
|  | ||||
|                     if checker == 0: | ||||
|                         json_data = json_data + json.dumps(dic) | ||||
|                         checker = 1 | ||||
|                     else: | ||||
|                         json_data = json_data + ',' + json.dumps(dic) | ||||
|  | ||||
|                 json_data = json_data + ']' | ||||
|  | ||||
|                 final_dic = {'fetchStatus': 1, 'error_message': "None", "data": json_data} | ||||
|  | ||||
|                 final_json = json.dumps(final_dic) | ||||
|  | ||||
|                 return HttpResponse(final_json) | ||||
|  | ||||
|  | ||||
|         except BaseException,msg: | ||||
|             data_ret = {'fetchStatus': 0, 'error_message': str(msg)} | ||||
|             json_data = json.dumps(data_ret) | ||||
|             return HttpResponse(json_data) | ||||
|     except KeyError,msg: | ||||
|         data_ret = {'fetchStatus': 0, 'error_message': str(msg)} | ||||
|         json_data = json.dumps(data_ret) | ||||
|         return HttpResponse(json_data) | ||||
|  | ||||
| def submitForwardDeletion(request): | ||||
|     try: | ||||
|         val = request.session['userID'] | ||||
|         try: | ||||
|             if request.method == 'POST': | ||||
|  | ||||
|                 data = json.loads(request.body) | ||||
|                 destination = data['destination'] | ||||
|  | ||||
|                 forwarding = Forwardings.objects.get(destination=destination) | ||||
|                 forwarding.delete() | ||||
|  | ||||
|                 data_ret = {'deleteForwardingStatus': 1, 'error_message': "None", 'successMessage':'Successfully deleted!'} | ||||
|                 json_data = json.dumps(data_ret) | ||||
|                 return HttpResponse(json_data) | ||||
|  | ||||
|  | ||||
|         except BaseException,msg: | ||||
|             data_ret = {'deleteForwardingStatus': 0, 'error_message': str(msg)} | ||||
|             json_data = json.dumps(data_ret) | ||||
|             return HttpResponse(json_data) | ||||
|     except KeyError,msg: | ||||
|         data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)} | ||||
|         json_data = json.dumps(data_ret) | ||||
|         return HttpResponse(json_data) | ||||
|  | ||||
| def submitEmailForwardingCreation(request): | ||||
|     try: | ||||
|         val = request.session['userID'] | ||||
|         try: | ||||
|  | ||||
|             if request.method == 'POST': | ||||
|  | ||||
|                 data = json.loads(request.body) | ||||
|                 source = data['source'] | ||||
|                 destination = data['destination'] | ||||
|  | ||||
|                 if Forwardings.objects.filter(source=source, destination=destination).count() > 0: | ||||
|                     data_ret = {'createStatus': 0, 'error_message': "You have already forwared to this destination."} | ||||
|                     json_data = json.dumps(data_ret) | ||||
|                     return HttpResponse(json_data) | ||||
|  | ||||
|                 if Forwardings.objects.filter(source=source).count() == 0: | ||||
|                     forwarding = Forwardings(source=source, destination=source) | ||||
|                     forwarding.save() | ||||
|  | ||||
|  | ||||
|                 forwarding = Forwardings(source=source, destination=destination) | ||||
|                 forwarding.save() | ||||
|  | ||||
|                 data_ret = {'createStatus': 1, 'error_message': "None", 'successMessage':'Successfully Created!'} | ||||
|                 json_data = json.dumps(data_ret) | ||||
|                 return HttpResponse(json_data) | ||||
|  | ||||
|  | ||||
|         except BaseException,msg: | ||||
|             data_ret = {'createStatus': 0, 'error_message': str(msg)} | ||||
|             json_data = json.dumps(data_ret) | ||||
|             return HttpResponse(json_data) | ||||
|     except KeyError,msg: | ||||
|         data_ret = {'createStatus': 0, 'error_message': str(msg)} | ||||
|         json_data = json.dumps(data_ret) | ||||
|         return HttpResponse(json_data) | ||||
|  | ||||
|  | ||||
|  | ||||
| ####### | ||||
|   | ||||
| @@ -827,3 +827,351 @@ app.controller('dkimManager', function($scope, $http, $timeout, $window) { | ||||
|  | ||||
| }); | ||||
|  | ||||
| /* Java script code for email forwarding */ | ||||
| app.controller('emailForwarding', function($scope,$http) { | ||||
|  | ||||
|     $scope.creationBox = true; | ||||
|     $scope.emailDetails = true; | ||||
|     $scope.forwardLoading = true; | ||||
|     $scope.forwardError = true; | ||||
|     $scope.forwardSuccess = true; | ||||
|     $scope.couldNotConnect = true; | ||||
|     $scope.notifyBox = true; | ||||
|  | ||||
|  | ||||
|     $scope.showEmailDetails = function(){ | ||||
|  | ||||
|         $scope.creationBox = true; | ||||
|         $scope.emailDetails = true; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|  | ||||
|         var url = "/email/getEmailsForDomain"; | ||||
|  | ||||
|  | ||||
|                 var data = { | ||||
|                     domain:$scope.emailDomain | ||||
|                 }; | ||||
|  | ||||
|                 var config = { | ||||
|                     headers : { | ||||
|                         'X-CSRFToken': getCookie('csrftoken') | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); | ||||
|  | ||||
|  | ||||
|                 function ListInitialDatas(response) { | ||||
|  | ||||
|  | ||||
|                     if(response.data.fetchStatus === 1){ | ||||
|  | ||||
|                         $scope.emails = JSON.parse(response.data.data); | ||||
|  | ||||
|                         $scope.creationBox = true; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = true; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     else | ||||
|                     { | ||||
|                         $scope.creationBox = true; | ||||
|                         $scope.emailDetails = true; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = false; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                         $scope.errorMessage = response.data.error_message; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|  | ||||
|  | ||||
|                 } | ||||
|                 function cantLoadInitialDatas(response) { | ||||
|  | ||||
|                     $scope.creationBox = true; | ||||
|                     $scope.emailDetails = true; | ||||
|                     $scope.forwardLoading = true; | ||||
|                     $scope.forwardError = true; | ||||
|                     $scope.forwardSuccess = true; | ||||
|                     $scope.couldNotConnect = false; | ||||
|                     $scope.notifyBox = false; | ||||
|  | ||||
|  | ||||
|                 } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     $scope.selectForwardingEmail = function () { | ||||
|  | ||||
|         $scope.creationBox = true; | ||||
|         $scope.emailDetails = false; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|         $scope.fetchCurrentForwardings(); | ||||
|     }; | ||||
|  | ||||
|     $scope.fetchCurrentForwardings = function(){ | ||||
|  | ||||
|         $scope.creationBox = false; | ||||
|         $scope.emailDetails = false; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|  | ||||
|         var url = "/email/fetchCurrentForwardings"; | ||||
|  | ||||
|  | ||||
|                 var data = { | ||||
|                     emailAddress:$scope.selectedEmail | ||||
|                 }; | ||||
|  | ||||
|                 var config = { | ||||
|                     headers : { | ||||
|                         'X-CSRFToken': getCookie('csrftoken') | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); | ||||
|  | ||||
|  | ||||
|                 function ListInitialDatas(response) { | ||||
|  | ||||
|  | ||||
|                     if(response.data.fetchStatus === 1){ | ||||
|  | ||||
|                         $scope.records = JSON.parse(response.data.data); | ||||
|  | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = true; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = true; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     else | ||||
|                     { | ||||
|                         $scope.creationBox = true; | ||||
|                         $scope.emailDetails = true; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = false; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                         $scope.errorMessage = response.data.error_message; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|  | ||||
|  | ||||
|                 } | ||||
|                 function cantLoadInitialDatas(response) { | ||||
|  | ||||
|                     $scope.creationBox = true; | ||||
|                     $scope.emailDetails = true; | ||||
|                     $scope.forwardLoading = true; | ||||
|                     $scope.forwardError = true; | ||||
|                     $scope.forwardSuccess = true; | ||||
|                     $scope.couldNotConnect = false; | ||||
|                     $scope.notifyBox = false; | ||||
|  | ||||
|  | ||||
|                 } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     $scope.deleteForwarding = function(destination){ | ||||
|  | ||||
|         $scope.creationBox = true; | ||||
|         $scope.emailDetails = true; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|  | ||||
|         var url = "/email/submitForwardDeletion"; | ||||
|  | ||||
|  | ||||
|                 var data = { | ||||
|                     destination:destination | ||||
|                 }; | ||||
|  | ||||
|                 var config = { | ||||
|                     headers : { | ||||
|                         'X-CSRFToken': getCookie('csrftoken') | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); | ||||
|  | ||||
|  | ||||
|                 function ListInitialDatas(response) { | ||||
|  | ||||
|  | ||||
|                     if(response.data.deleteForwardingStatus === 1){ | ||||
|  | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = true; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = true; | ||||
|  | ||||
|                         $scope.fetchCurrentForwardings(); | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     else | ||||
|                     { | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = false; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                         $scope.errorMessage = response.data.error_message; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|  | ||||
|  | ||||
|                 } | ||||
|                 function cantLoadInitialDatas(response) { | ||||
|  | ||||
|                     $scope.creationBox = true; | ||||
|                     $scope.emailDetails = true; | ||||
|                     $scope.forwardLoading = true; | ||||
|                     $scope.forwardError = true; | ||||
|                     $scope.forwardSuccess = true; | ||||
|                     $scope.couldNotConnect = false; | ||||
|                     $scope.notifyBox = false; | ||||
|  | ||||
|  | ||||
|                 } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     $scope.forwardEmail = function(){ | ||||
|  | ||||
|         $scope.creationBox = false; | ||||
|         $scope.emailDetails = false; | ||||
|         $scope.forwardLoading = false; | ||||
|         $scope.forwardError = true; | ||||
|         $scope.forwardSuccess = true; | ||||
|         $scope.couldNotConnect = true; | ||||
|         $scope.notifyBox = true; | ||||
|  | ||||
|         var url = "/email/submitEmailForwardingCreation"; | ||||
|  | ||||
|  | ||||
|                 var data = { | ||||
|                     source: $scope.selectedEmail, | ||||
|                     destination:$scope.destinationEmail | ||||
|                 }; | ||||
|  | ||||
|                 var config = { | ||||
|                     headers : { | ||||
|                         'X-CSRFToken': getCookie('csrftoken') | ||||
|                     } | ||||
|                 }; | ||||
|  | ||||
|                 $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); | ||||
|  | ||||
|  | ||||
|                 function ListInitialDatas(response) { | ||||
|  | ||||
|  | ||||
|                     if(response.data.createStatus === 1){ | ||||
|  | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = true; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = true; | ||||
|  | ||||
|                         $scope.fetchCurrentForwardings(); | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     else | ||||
|                     { | ||||
|                         $scope.creationBox = false; | ||||
|                         $scope.emailDetails = false; | ||||
|                         $scope.forwardLoading = true; | ||||
|                         $scope.forwardError = false; | ||||
|                         $scope.forwardSuccess = true; | ||||
|                         $scope.couldNotConnect = true; | ||||
|                         $scope.notifyBox = false; | ||||
|  | ||||
|                         $scope.errorMessage = response.data.error_message; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|  | ||||
|  | ||||
|                 } | ||||
|                 function cantLoadInitialDatas(response) { | ||||
|  | ||||
|                     $scope.creationBox = true; | ||||
|                     $scope.emailDetails = true; | ||||
|                     $scope.forwardLoading = true; | ||||
|                     $scope.forwardError = true; | ||||
|                     $scope.forwardSuccess = true; | ||||
|                     $scope.couldNotConnect = false; | ||||
|                     $scope.notifyBox = false; | ||||
|  | ||||
|  | ||||
|                 } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     }; | ||||
|  | ||||
|  | ||||
| }); | ||||
| /* Java script for email forwarding */ | ||||
		Reference in New Issue
	
	Block a user