# Path: ovizart/main/forms.py
# class LoginForm(ModelForm):
#     user_email = forms.EmailField()
#     class Meta:
#         model = User
#         fields = ('username', 'user_email', 'password')
# 
#     def clean(self):
#         data = self.cleaned_data
#         email = data.get('user_email')
#         if not email:
#             raise forms.ValidationError(u'Email can not be empty!')
#         hash = hashlib.sha1()
#         hash.update(email)
#         email_hash = hash.hexdigest()
#         username = self.cleaned_data.get('username')
#         if not username:
#             raise forms.ValidationError(u'Username can not be empty!')
#         try:
#             user = User.objects.get(username=username)
#         except User.DoesNotExist:
#             raise forms.ValidationError(u'User does not exist.')
#         if email and UserProfile.objects.filter(user_email=email_hash, user=user).count():
#             return data
#         else:
#             raise forms.ValidationError(u'Profile for the user does not exist')
# 
# Path: ovizart/pcap/models.py
# class UserJSonFile(models.Model):
#     user_id = models.CharField(max_length=100)
#     json_type = models.CharField(max_length=10) # possible value is summary for the summary view
#     json_file_name = models.CharField(max_length=100) # save the name of the already created file name on disk
# 
# Path: ovizart/modules/traffic/log/logger.py
# class Logger:
# 
#     def __init__(self, log_name, log_mode):
#         logging.basicConfig(format='%(asctime)-6s: %(name)s - %(levelname)s - %(message)s')
#         self.mode = log_mode
#         self.log = logging.getLogger(log_name)
#         self.log.setLevel(log_mode)
# 
#     def set_log_level(self, level="DEBUG"):
#         self.log.setLevel(level)
# 
#     def message(self, message):
#         if self.mode == "DEBUG":
#             self.log.debug(message)
#         if self.mode == "ERROR":
#             self.log.error(message)
#         if self.mode == "INFO":
#             self.log.info(message)
# 
# Path: ovizart/pcap/models.py
# class Flow(models.Model):
#     user_id = models.CharField(max_length=100)
#     hash_value = models.CharField(max_length=50)
#     file_name = models.CharField(max_length=50)
#     upload_time = models.DateTimeField()
#     file_type = models.CharField(max_length=150)
#     file_size = models.IntegerField()
#     path = models.FilePathField()
#     pcaps = ListField(EmbeddedModelField('Pcap', null=True, blank=True))
#     details = ListField(EmbeddedModelField('FlowDetails', null=True, blank=True))
# 
#     def __unicode__(self):
#         return u'%s/%s' % (self.path, self.file_name)
# 
#     def get_upload_path(self):
#         hash_dir = os.path.basename(self.path)
#         root = os.path.basename(os.path.dirname(self.path))
#         return os.path.join(root, hash_dir)
# 
# class FlowDetails(models.Model):
#     parent_hash_value = models.CharField(max_length=50)
#     user_id = models.CharField(max_length=100)
#     src_ip = models.IPAddressField()
#     dst_ip = models.IPAddressField()
#     sport = models.IntegerField()
#     dport = models.IntegerField()
#     protocol = models.CharField(max_length=10)
#     timestamp = models.DateTimeField()
# 
#     objects = MongoDBManager()
# 
# class PacketDetails(models.Model):
#     #datetime.datetime.fromtimestamp(float("1286715787.71")).strftime('%Y-%m-%d %H:%M:%S')
#     ident = models.IntegerField()
#     flow_hash = models.CharField(max_length=50)
#     timestamp = models.DateTimeField()
#     length = models.IntegerField()
#     protocol = models.IntegerField()
#     src_ip = models.IPAddressField()
#     dst_ip = models.IPAddressField()
#     sport = models.IntegerField()
#     dport = models.IntegerField()
#     data = models.TextField(null=True, blank=True)
# 
#     def __unicode__(self):
#         return u'(%s, %s, %s, %s, %s)' % (self.protocol, self.src_ip, self.sport, self.dst_ip, self.dport)
# 
#     objects = MongoDBManager()


from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.conf import settings
from ovizart.main.forms import LoginForm
from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth import logout
from ovizart.pcap.models import UserJSonFile
from django.utils import simplejson as json
from ovizart.modules.traffic.log.logger import Logger
from ovizart.pcap.models import Flow, FlowDetails, PacketDetails
from django.core.paginator import Paginator, InvalidPage, EmptyPage
import urllib2
import tempfile
import os
                        'page_title': 'Welcome to %s' % settings.PROJECT_NAME,
                        'pcap_operation': "welcome",
                        'json_file_url': os.path.join(settings.ALTERNATE_BASE_URL, "json_media", file_name),
                        'json_response': json_response
                    }

                    return render_to_response("main/welcome.html", context,
                            context_instance=RequestContext(request))
                else:
                    context = {
                            'error_message': 'User is not activated!',
                            'page_title': 'Login Page'
                        }
                    return render_to_response("main/login.html", context,
                        context_instance=RequestContext(request))
            else:
                context = {
                    'error_message': 'Error occured at the user authentication',
                    'page_title': 'Login Page'
                }
                return render_to_response("main/login.html", context,
                    context_instance=RequestContext(request))
        else:
            context = {
            'form': form,
            'page_title': 'Login Page'
            }
            return render_to_response("main/login.html", context,
                context_instance=RequestContext(request))
    else:

# Path: ovizart/main/forms.py
# class LoginForm(ModelForm):
#     user_email = forms.EmailField()
#     class Meta:
#         model = User
#         fields = ('username', 'user_email', 'password')
# 
#     def clean(self):
#         data = self.cleaned_data
#         email = data.get('user_email')
#         if not email:
#             raise forms.ValidationError(u'Email can not be empty!')
#         hash = hashlib.sha1()
#         hash.update(email)
#         email_hash = hash.hexdigest()
#         username = self.cleaned_data.get('username')
#         if not username:
#             raise forms.ValidationError(u'Username can not be empty!')
#         try:
#             user = User.objects.get(username=username)
#         except User.DoesNotExist:
#             raise forms.ValidationError(u'User does not exist.')
#         if email and UserProfile.objects.filter(user_email=email_hash, user=user).count():
#             return data
#         else:
#             raise forms.ValidationError(u'Profile for the user does not exist')
# 
# Path: ovizart/pcap/models.py
# class UserJSonFile(models.Model):
#     user_id = models.CharField(max_length=100)
#     json_type = models.CharField(max_length=10) # possible value is summary for the summary view
#     json_file_name = models.CharField(max_length=100) # save the name of the already created file name on disk
# 
# Path: ovizart/modules/traffic/log/logger.py
# class Logger:
# 
#     def __init__(self, log_name, log_mode):
#         logging.basicConfig(format='%(asctime)-6s: %(name)s - %(levelname)s - %(message)s')
#         self.mode = log_mode
#         self.log = logging.getLogger(log_name)
#         self.log.setLevel(log_mode)
# 
#     def set_log_level(self, level="DEBUG"):
#         self.log.setLevel(level)
# 
#     def message(self, message):
#         if self.mode == "DEBUG":
#             self.log.debug(message)
#         if self.mode == "ERROR":
#             self.log.error(message)
#         if self.mode == "INFO":
#             self.log.info(message)
# 
# Path: ovizart/pcap/models.py
# class Flow(models.Model):
#     user_id = models.CharField(max_length=100)
#     hash_value = models.CharField(max_length=50)
#     file_name = models.CharField(max_length=50)
#     upload_time = models.DateTimeField()
#     file_type = models.CharField(max_length=150)
#     file_size = models.IntegerField()
#     path = models.FilePathField()
#     pcaps = ListField(EmbeddedModelField('Pcap', null=True, blank=True))
#     details = ListField(EmbeddedModelField('FlowDetails', null=True, blank=True))
# 
#     def __unicode__(self):
#         return u'%s/%s' % (self.path, self.file_name)
# 
#     def get_upload_path(self):
#         hash_dir = os.path.basename(self.path)
#         root = os.path.basename(os.path.dirname(self.path))
#         return os.path.join(root, hash_dir)
# 
# class FlowDetails(models.Model):
#     parent_hash_value = models.CharField(max_length=50)
#     user_id = models.CharField(max_length=100)
#     src_ip = models.IPAddressField()
#     dst_ip = models.IPAddressField()
#     sport = models.IntegerField()
#     dport = models.IntegerField()
#     protocol = models.CharField(max_length=10)
#     timestamp = models.DateTimeField()
# 
#     objects = MongoDBManager()
# 
# class PacketDetails(models.Model):
#     #datetime.datetime.fromtimestamp(float("1286715787.71")).strftime('%Y-%m-%d %H:%M:%S')
#     ident = models.IntegerField()
#     flow_hash = models.CharField(max_length=50)
#     timestamp = models.DateTimeField()
#     length = models.IntegerField()
#     protocol = models.IntegerField()
#     src_ip = models.IPAddressField()
#     dst_ip = models.IPAddressField()
#     sport = models.IntegerField()
#     dport = models.IntegerField()
#     data = models.TextField(null=True, blank=True)
# 
#     def __unicode__(self):
#         return u'(%s, %s, %s, %s, %s)' % (self.protocol, self.src_ip, self.sport, self.dst_ip, self.dport)
# 
#     objects = MongoDBManager()


# Path: ovizart/main/views.py
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.conf import settings
from ovizart.main.forms import LoginForm
from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth import logout
from ovizart.pcap.models import UserJSonFile
from django.utils import simplejson as json
from ovizart.modules.traffic.log.logger import Logger
from ovizart.pcap.models import Flow, FlowDetails, PacketDetails
from django.core.paginator import Paginator, InvalidPage, EmptyPage
import urllib2
import tempfile
import os

                        'page_title': 'Welcome to %s' % settings.PROJECT_NAME,
                        'pcap_operation': "welcome",
                        'json_file_url': os.path.join(settings.ALTERNATE_BASE_URL, "json_media", file_name),
                        'json_response': json_response
                    }

                    return render_to_response("main/welcome.html", context,
                            context_instance=RequestContext(request))
                else:
                    context = {
                            'error_message': 'User is not activated!',
                            'page_title': 'Login Page'
                        }
                    return render_to_response("main/login.html", context,
                        context_instance=RequestContext(request))
            else:
                context = {
                    'error_message': 'Error occured at the user authentication',
                    'page_title': 'Login Page'
                }
                return render_to_response("main/login.html", context,
                    context_instance=RequestContext(request))
        else:
            context = {
            'form': form,
            'page_title': 'Login Page'
            }
            return render_to_response("main/login.html", context,
                context_instance=RequestContext(request))
    else:

        form = LoginForm()