Initial Commit

This commit is contained in:
usmannasir
2017-10-24 19:16:36 +05:00
commit 11eae3f9fe
2124 changed files with 528735 additions and 0 deletions

0
mailServer/__init__.py Normal file
View File

BIN
mailServer/__init__.pyc Normal file

Binary file not shown.

6
mailServer/admin.py Normal file
View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.

BIN
mailServer/admin.pyc Normal file

Binary file not shown.

8
mailServer/apps.py Normal file
View File

@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class MailserverConfig(AppConfig):
name = 'mailServer'

View File

43
mailServer/models.py Normal file
View File

@@ -0,0 +1,43 @@
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey has `on_delete` set to the desired behavior.
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from __future__ import unicode_literals
from django.db import models
from websiteFunctions.models import Websites
class Domains(models.Model):
domainOwner = models.ForeignKey(Websites,on_delete=models.CASCADE)
domain = models.CharField(primary_key=True, max_length=50)
class Meta:
db_table = 'e_domains'
class EUsers(models.Model):
emailOwner = models.ForeignKey(Domains, on_delete=models.CASCADE)
email = models.CharField(primary_key=True, max_length=80)
password = models.CharField(max_length=20)
class Meta:
db_table = 'e_users'
class Forwardings(models.Model):
source = models.CharField(primary_key=True, max_length=80)
destination = models.TextField()
class Meta:
db_table = 'e_forwardings'
class Transport(models.Model):
domain = models.CharField(unique=True, max_length=128)
transport = models.CharField(max_length=128)
class Meta:
db_table = 'e_transport'

BIN
mailServer/models.pyc Normal file

Binary file not shown.

View File

@@ -0,0 +1,510 @@
/**
* Created by usman on 8/15/17.
*/
/* Java script code to create account */
app.controller('createEmailAccount', function($scope,$http) {
$scope.emailDetails = true;
$scope.emailLoading = true;
$scope.canNotCreate = true;
$scope.successfullyCreated = true;
$scope.couldNotConnect = true;
$scope.showEmailDetails = function(){
$scope.emailDetails = false;
$scope.emailLoading = true;
$scope.canNotCreate = true;
$scope.successfullyCreated = true;
$scope.couldNotConnect = true;
$scope.selectedDomain = $scope.emailDomain;
};
$scope.createEmailAccount = function(){
$scope.emailDetails = false;
$scope.emailLoading = false;
$scope.canNotCreate = true;
$scope.successfullyCreated = true;
$scope.couldNotConnect = true;
var url = "/email/submitEmailCreation";
var domain = $scope.emailDomain;
var username = $scope.emailUsername;
var password = $scope.emailPassword;
var data = {
domain:domain,
username:username,
password:password,
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.createEmailStatus == 1){
$scope.emailDetails = false;
$scope.emailLoading = true;
$scope.canNotCreate = true;
$scope.successfullyCreated = false;
$scope.couldNotConnect = true;
$scope.createdID = username + "@" + domain;
}
else
{
$scope.emailDetails = false;
$scope.emailLoading = true;
$scope.canNotCreate = false;
$scope.successfullyCreated = true;
$scope.couldNotConnect = true;
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$scope.emailDetails = false;
$scope.emailLoading = true;
$scope.canNotCreate = true;
$scope.successfullyCreated = true;
$scope.couldNotConnect = false;
}
};
$scope.hideFewDetails = function(){
$scope.successfullyCreated = true;
};
});
/* Java script code to create account ends here */
/* Java script code to create account */
app.controller('deleteEmailAccount', function($scope,$http) {
$scope.emailDetails = true;
$scope.emailLoading = true;
$scope.canNotDelete = true;
$scope.successfullyDeleted = true;
$scope.couldNotConnect = true;
$scope.emailDetailsFinal = true;
$scope.noEmails = true;
$scope.showEmailDetails = function(){
$scope.emailDetails = true;
$scope.emailLoading = false;
$scope.canNotDelete = true;
$scope.successfullyDeleted = true;
$scope.couldNotConnect = true;
$scope.emailDetailsFinal = true;
$scope.noEmails = true;
var url = "/email/getEmailsForDomain";
var domain = $scope.emailDomain;
var data = {
domain:domain,
};
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.emailDetails = false;
$scope.emailLoading = true;
$scope.canNotDelete = true;
$scope.successfullyDeleted = true;
$scope.couldNotConnect = true;
$scope.emailDetailsFinal = true;
$scope.noEmails = true;
}
else
{
$scope.emailDetails = true;
$scope.emailLoading = true;
$scope.canNotDelete = true;
$scope.successfullyDeleted = true;
$scope.couldNotConnect = true;
$scope.emailDetailsFinal = true;
$scope.noEmails = false;
}
}
function cantLoadInitialDatas(response) {
$scope.emailDetails = true;
$scope.emailLoading = true;
$scope.canNotDelete = true;
$scope.successfullyDeleted = true;
$scope.couldNotConnect = false;
$scope.emailDetailsFinal = true;
$scope.noEmails = true;
}
};
$scope.deleteEmailAccountFinal = function(){
$scope.emailLoading = false;
var url = "/email/submitEmailDeletion";
var email = $scope.selectedEmail;
var data = {
email:email,
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.deleteEmailStatus == 1){
$scope.emailDetails = true;
$scope.emailLoading = true;
$scope.canNotDelete = true;
$scope.successfullyDeleted = false;
$scope.couldNotConnect = true;
$scope.emailDetailsFinal = true;
$scope.noEmails = true;
$scope.deletedID = email;
}
else
{
$scope.emailDetails = true;
$scope.emailLoading = true;
$scope.canNotDelete = false;
$scope.successfullyDeleted = true;
$scope.couldNotConnect = true;
$scope.emailDetailsFinal = true;
$scope.noEmails = true;
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$scope.emailDetails = true;
$scope.emailLoading = true;
$scope.canNotDelete = true;
$scope.successfullyDeleted = true;
$scope.couldNotConnect = false;
$scope.emailDetailsFinal = true;
$scope.noEmails = true;
}
};
$scope.deleteEmailAccount = function(){
var domain = $scope.selectedEmail;
if(domain.length>0) {
$scope.emailDetailsFinal = false;
}
};
});
/* Java script code to create account ends here */
/* Java script code to create account */
app.controller('changeEmailPassword', function($scope,$http) {
$scope.emailLoading = true;
$scope.emailDetails = true;
$scope.canNotChangePassword = true;
$scope.passwordChanged = true;
$scope.couldNotConnect = true;
$scope.noEmails = true;
$scope.showEmailDetails = function(){
$scope.emailLoading = false;
$scope.emailDetails = true;
$scope.canNotChangePassword = true;
$scope.passwordChanged = true;
$scope.couldNotConnect = true;
$scope.noEmails = true;
var url = "/email/getEmailsForDomain";
var domain = $scope.emailDomain;
var data = {
domain:domain,
};
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.emailLoading = true;
$scope.emailDetails = false;
$scope.canNotChangePassword = true;
$scope.passwordChanged = true;
$scope.couldNotConnect = true;
$scope.noEmails = true;
}
else
{
$scope.emailLoading = true;
$scope.emailDetails = true;
$scope.canNotChangePassword = true;
$scope.passwordChanged = true;
$scope.couldNotConnect = true;
$scope.noEmails = false;
}
}
function cantLoadInitialDatas(response) {
$scope.emailLoading = true;
$scope.emailDetails = true;
$scope.canNotChangePassword = true;
$scope.passwordChanged = true;
$scope.couldNotConnect = false;
$scope.noEmails = true;
}
};
$scope.changePassword = function(){
$scope.emailLoading = false;
var url = "/email/submitPasswordChange";
var email = $scope.selectedEmail;
var password = $scope.emailPassword;
var domain = $scope.emailDomain;
var data = {
domain:domain,
email:email,
password:password,
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.passChangeStatus == 1){
$scope.emailLoading = true;
$scope.emailDetails = true;
$scope.canNotChangePassword = true;
$scope.passwordChanged = false;
$scope.couldNotConnect = true;
$scope.noEmails = true;
$scope.passEmail = email;
}
else
{
$scope.emailLoading = true;
$scope.emailDetails = false;
$scope.canNotChangePassword = false;
$scope.passwordChanged = true;
$scope.couldNotConnect = true;
$scope.noEmails = true;
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$scope.emailLoading = true;
$scope.emailDetails = false;
$scope.canNotChangePassword = true;
$scope.passwordChanged = true;
$scope.couldNotConnect = false;
$scope.noEmails = true;
}
};
$scope.deleteEmailAccount = function(){
var domain = $scope.selectedEmail;
if(domain.length>0) {
$scope.emailDetailsFinal = false;
}
};
});
/* Java script code to create account ends here */

View File

@@ -0,0 +1,107 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Change Email Password - 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 "Change Email Password" %}</h2>
<p>{% trans "Select a website from the list, to change its password." %}</p>
</div>
<div ng-controller="changeEmailPassword" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Change Email Password" %} <img ng-hide="emailLoading" 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-model="selectedEmail" class="form-control">
<option ng-repeat="email in emails track by $index">{$ email.email $}</option>
</select>
</div>
</div>
<div ng-hide="emailDetails" class="form-group">
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
<div class="col-sm-6">
<input type="password" class="form-control" ng-model="emailPassword" required>
</div>
</div>
<!------ Modification form that appears after a click --------------->
<div ng-hide="emailDetails" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="changePassword()" class="btn btn-primary btn-lg btn-block">{% trans "Change Password" %}</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<div ng-hide="canNotChangePassword" class="alert alert-danger">
<p>{% trans "Cannot delete email account. Error message:" %} {$ errorMessage $}</p>
</div>
<div ng-hide="passwordChanged" class="alert alert-success">
<p>{% trans "Password successfully changed for :" %} {$ passEmail $}.</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
</div>
<div ng-hide="noEmails" class="alert alert-danger">
<p>{% trans "Currently no email accounts exist for this domain." %}</p>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,102 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Create Email Account - 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 "Create Email Account" %}</h2>
<p>{% trans "Select a website from the list, to create an email account." %}</p>
</div>
<div ng-controller="createEmailAccount" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Create Email Account" %} <img ng-hide="emailLoading" 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 "User Name" %}</label>
<div class="col-sm-6">
<input ng-change="hideFewDetails" type="text" class="form-control" ng-model="emailUsername" required>
</div>
<div class="current-pack">@{$ selectedDomain $}</div>
</div>
<div ng-hide="emailDetails" class="form-group">
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
<div class="col-sm-6">
<input type="password" class="form-control" ng-model="emailPassword" required>
</div>
</div>
<!------ Modification form that appears after a click --------------->
<div ng-hide="emailDetails" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="createEmailAccount()" class="btn btn-primary btn-lg btn-block">{% trans "Create Email" %}</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<div ng-hide="canNotCreate" class="alert alert-danger">
<p>{% trans "Cannot create email account. Error message:" %} {$ errorMessage $}</p>
</div>
<div ng-hide="successfullyCreated" class="alert alert-success">
<p>{% trans "Email with id :" %} {$ createdID $}{% trans " is successfully created." %}</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>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,106 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Delete Email Account - 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 "Delete Email Account" %}</h2>
<p>{% trans "Select a website from the list, to delete an email account." %}</p>
</div>
<div ng-controller="deleteEmailAccount" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Delete Email Account" %} <img ng-hide="emailLoading" 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-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="emailDetails" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="deleteEmailAccount()" class="btn btn-primary btn-lg btn-block">{% trans "Delete Email" %}</button>
</div>
</div>
<div ng-hide="emailDetailsFinal" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="deleteEmailAccountFinal()" class="btn btn-primary btn-lg btn-block">{% trans "Are you sure?" %}</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<div ng-hide="canNotDelete" class="alert alert-danger">
<p>{% trans "Cannot delete email account. Error message:" %} {$ errorMessage $}</p>
</div>
<div ng-hide="successfullyDeleted" class="alert alert-success">
<p>{% trans "Email with id : {$ deletedID $} is successfully deleted." %}</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
</div>
<div ng-hide="noEmails" class="alert alert-danger">
<p>{% trans "Currently no email accounts exist for this domain." %}</p>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,70 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Mail Functions - 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 "Mail Functions" %}</h2>
<p>{% trans "Manage email accounts on this page." %}</p>
</div>
<div class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Available Functions" %}
</h3>
<div class="example-box-wrapper">
<div class="row">
<div class="col-md-4">
<a href="{% url 'createEmailAccount' %}" title="{% trans 'Create Email' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Create Email" %}
</div>
<div class="tile-content-wrapper">
<i class="glyph-icon icon-dashboard"></i>
</div>
</a>
</div>
<div class="col-md-4">
<a href="{% url 'deleteEmailAccount' %}" title="{% trans 'Delete Email' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Delete Email" %}
</div>
<div class="tile-content-wrapper">
<i class="glyph-icon icon-dashboard"></i>
</div>
</a>
</div>
<div class="col-md-4">
<a href="{% url 'changeEmailAccountPassword' %}" title="{% trans 'Change Password' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Change Password" %}
</div>
<div class="tile-content-wrapper">
<i class="glyph-icon icon-dashboard"></i>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

6
mailServer/tests.py Normal file
View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.

20
mailServer/urls.py Normal file
View File

@@ -0,0 +1,20 @@
from django.conf.urls import url
import views
urlpatterns = [
url(r'^$', views.loadEmailHome, name='loadEmailHome'),
url(r'^createEmailAccount', views.createEmailAccount, name='createEmailAccount'),
url(r'^submitEmailCreation', views.submitEmailCreation, name='submitEmailCreation'),
## Delete email
url(r'^deleteEmailAccount', views.deleteEmailAccount, name='deleteEmailAccount'),
url(r'^getEmailsForDomain', views.getEmailsForDomain, name='getEmailsForDomain'),
url(r'^submitEmailDeletion', views.submitEmailDeletion, name='submitEmailDeletion'),
## Change email password
url(r'^changeEmailAccountPassword', views.changeEmailAccountPassword, name='changeEmailAccountPassword'),
url(r'^submitPasswordChange', views.submitPasswordChange, name='submitPasswordChange'),
]

300
mailServer/views.py Normal file
View File

@@ -0,0 +1,300 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render,redirect
from django.http import HttpResponse
from models import Domains,EUsers
# Create your views here.
from loginSystem.models import Administrator
from websiteFunctions.models import Websites
from loginSystem.views import loadLoginPage
import plogical.CyberCPLogFileWriter as logging
import json
import os
import shutil
import shlex
import subprocess
def loadEmailHome(request):
try:
val = request.session['userID']
return render(request, 'mailServer/index.html')
except KeyError:
return redirect(loadLoginPage)
def createEmailAccount(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/createEmailAccount.html', {'websiteList':websitesName})
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg))
return HttpResponse(str(msg))
except KeyError:
return redirect(loadLoginPage)
def submitEmailCreation(request):
try:
val = request.session['userID']
try:
if request.method == 'POST':
data = json.loads(request.body)
domain = data['domain']
userName = data['username']
password = data['password']
path = "/usr/local/CyberCP/install/rainloop/cyberpanel.net.ini"
if not os.path.exists("/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/"):
os.makedirs("/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/")
finalPath = "/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/" + domain + ".ini"
if not os.path.exists(finalPath):
shutil.copy(path,finalPath)
command = 'chown -R nobody:nobody /usr/local/lscp/rainloop'
cmd = shlex.split(command)
res = subprocess.call(cmd)
command = 'chown -R nobody:nobody /usr/local/lscp/cyberpanel/rainloop/data/_data_'
cmd = shlex.split(command)
res = subprocess.call(cmd)
finalEmailUsername = userName+"@"+domain
website = Websites.objects.get(domain=domain)
if EUsers.objects.filter(email=finalEmailUsername).exists():
data_ret = {'createEmailStatus': 0, 'error_message': "This account already exists"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
if not Domains.objects.filter(domain=domain).exists():
newEmailDomain = Domains(domainOwner=website,domain=domain)
newEmailDomain.save()
emailAcct = EUsers(emailOwner=newEmailDomain,email=finalEmailUsername,password=password)
emailAcct.save()
data_ret = {'createEmailStatus': 1, 'error_message': "None"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
emailDomain = Domains.objects.get(domain=domain)
emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password)
emailAcct.save()
data_ret = {'createEmailStatus': 1, 'error_message': "None"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException,msg:
data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except KeyError,msg:
data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def deleteEmailAccount(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/deleteEmailAccount.html', {'websiteList':websitesName})
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg))
return HttpResponse(str(msg))
except KeyError:
return redirect(loadLoginPage)
def getEmailsForDomain(request):
try:
val = request.session['userID']
try:
if request.method == 'POST':
data = json.loads(request.body)
domain = data['domain']
domain = Domains.objects.get(domain=domain)
emails = domain.eusers_set.all()
if emails.count() == 0:
final_dic = {'fetchStatus': 0, 'error_message': "No email accounts exits"}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
json_data = "["
checker = 0
for items in emails:
dic = {'email': items.email}
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 submitEmailDeletion(request):
try:
val = request.session['userID']
try:
if request.method == 'POST':
data = json.loads(request.body)
email = data['email']
email = EUsers(email=email)
email.delete()
data_ret = {'deleteEmailStatus': 1, 'error_message': "None"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException,msg:
data_ret = {'deleteEmailStatus': 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 changeEmailAccountPassword(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/changeEmailPassword.html', {'websiteList':websitesName})
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg))
return HttpResponse(str(msg))
except KeyError:
return redirect(loadLoginPage)
def submitPasswordChange(request):
try:
val = request.session['userID']
try:
if request.method == 'POST':
data = json.loads(request.body)
domain = data['domain']
email = data['email']
password = data['password']
dom = Domains(domain=domain)
emailAcct = EUsers(email=email)
emailAcct.delete()
emailAcct = EUsers(emailOwner=dom, email=email, password=password)
emailAcct.save()
data_ret = {'passChangeStatus': 1, 'error_message': "None"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException,msg:
data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except KeyError,msg:
data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)