def changed_cookies(request, cookies, order):
    new_packages_cookie = cookies.get(str(order.id)+'_new_packages')
    updated_packages_cookie = cookies.get(str(order.id)+'_updated_packages')

    origin_address = get_or_create_origin_address(request)
    destination_address = get_or_create_destination_address(request)

    rate = float(request.POST.get('rate').replace('₪', ''))
    phone_number = request.POST.get('phone-number')
    full_name = request.POST.get('name')
    notes = request.POST.get('notes')

    package_id = request.POST.get('package-id')

    package = Package(origin=origin_address, destination=destination_address, rate=rate, phone_number=phone_number,
                      full_name=full_name, order=order, notes=notes)
    if package_id:
        package.id = package_id

        if not Package.objects.filter(id=package_id):
            json = edit_new_package(package, new_packages_cookie)

            cookies[str(order.id)+'_new_packages'] = json
        else:
            json = add_package_to_json(package, updated_packages_cookie)

            cookies[str(order.id)+'_updated_packages'] = json

    else:
        json = add_package_to_json(package, new_packages_cookie)

        cookies[str(order.id)+'_new_packages'] = json

    return cookies
Example #2
0
def submitPackage(sender, **kwargs):
    from packages.models import Package
    from loginSystem.models import Administrator
    from plogical.acl import ACLManager
    try:
        request = kwargs['request']
        userID = request.session['userID']

        currentACL = ACLManager.loadedACL(userID)
        if ACLManager.currentContextPermission(currentACL,
                                               'createPackage') == 0:
            return ACLManager.loadErrorJson('saveStatus', 0)

        data = json.loads(request.body)
        packageName = data['packageName']
        packageSpace = int(data['diskSpace'])
        packageBandwidth = int(data['bandwidth'])
        packageDatabases = int(data['dataBases'])
        ftpAccounts = int(data['ftpAccounts'])
        emails = int(data['emails'])
        allowedDomains = int(data['allowedDomains'])

        if packageSpace < 0 or packageBandwidth < 0 or packageDatabases < 0 or ftpAccounts < 0 or emails < 0 or allowedDomains < 0:
            data_ret = {
                'saveStatus': 0,
                'error_message': "All values should be positive or 0."
            }
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)

        admin = Administrator.objects.get(pk=userID)

        package = Package(admin=admin,
                          packageName=packageName,
                          diskSpace=packageSpace,
                          bandwidth=packageBandwidth,
                          ftpAccounts=ftpAccounts,
                          dataBases=packageDatabases,
                          emailAccounts=emails,
                          allowedDomains=allowedDomains)

        package.save()

        data_ret = {'saveStatus': 1, 'error_message': "None"}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)

    except BaseException, msg:
        data_ret = {'saveStatus': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
Example #3
0
def main():

    parser = argparse.ArgumentParser(description='Reset admin user password!')
    parser.add_argument('--password', help='New Password')
    args = parser.parse_args()

    adminPass = args.password

    numberOfAdministrator = Administrator.objects.count()
    if numberOfAdministrator == 0:
        ACLManager.createDefaultACLs()
        acl = ACL.objects.get(name='admin')
        token = hashPassword.generateToken('admin', '1234567')

        email = '*****@*****.**'
        admin = Administrator(userName="******",
                              password=hashPassword.hash_password(adminPass),
                              type=1,
                              email=email,
                              firstName="Cyber",
                              lastName="Panel",
                              acl=acl,
                              token=token)
        admin.save()

        vers = version(currentVersion="1.9", build=2)
        vers.save()

        package = Package(admin=admin,
                          packageName="Default",
                          diskSpace=1000,
                          bandwidth=1000,
                          ftpAccounts=1000,
                          dataBases=1000,
                          emailAccounts=1000,
                          allowedDomains=20)
        package.save()
        print("Admin password successfully changed!")
        return 1

    token = hashPassword.generateToken('admin', adminPass)
    admin = Administrator.objects.get(userName="******")
    admin.password = hashPassword.hash_password(adminPass)
    admin.token = token
    admin.save()

    print("Admin password successfully changed!")
def stats():
    """
        templatetag for main page
    """
    data = {}
    data['repositories'] = Repository.objects.exclude(default_mirror=None).count()
    data['mirrors'] = Mirror.objects.filter(available=True).count()
    data['packages'] = Package.objects.filter(visible=True).count()
    data['size_compressed'], data['size_uncompressed'] = Package.sum_sizes()
    
    return data
Example #5
0
def stats():
    """
        templatetag for main page
    """
    data = {}
    data['repositories'] = Repository.objects.exclude(
        default_mirror=None).count()
    data['mirrors'] = Mirror.objects.filter(available=True).count()
    data['packages'] = Package.objects.filter(visible=True).count()
    data['size_compressed'], data['size_uncompressed'] = Package.sum_sizes()

    return data
Example #6
0
    def createPackage(self, owner, packageName, diskSpace, bandwidth,
                      emailAccounts, dataBases, ftpAccounts, allowedDomains):
        try:

            admin = Administrator.objects.get(userName=owner)

            newPack = Package(admin=admin,
                              packageName=packageName,
                              diskSpace=diskSpace,
                              bandwidth=bandwidth,
                              emailAccounts=emailAccounts,
                              dataBases=dataBases,
                              ftpAccounts=ftpAccounts,
                              allowedDomains=allowedDomains)

            newPack.save()

            self.printStatus(1, 'None')

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Example #7
0
    def parse_package(self, data):

        package = Package(pc_checksum=self.pc_checksum,
                          section=self.section,
                          distversion=self.section.distversion,
                          repository=self.section.repository,
                          visible=False)

        parse_raito = {
            'PACKAGE LOCATION': 'location',
            'PACKAGE SIZE (compressed)': 'size_compressed',
            'PACKAGE SIZE (uncompressed)': 'size_uncompressed',
            'PACKAGE REQUIRED': 'requires',
            'PACKAGE SUGGESTS': 'suggests',
            'PACKAGE CONFLICTS': 'conflicts',
            'PACKAGE NAME': 'raw_name',
        }

        def size_item(value):

            res = re.findall('(\d+)', value)
            if len(res) <= 0:
                return 0
            else:
                return int(res[0])

        description = []

        for line in data:

            if self.format_matches[0].match(line[:]):
                param, value = line.split(':', 1)

                model_attr = parse_raito.get(param)

                if model_attr is None:
                    continue

                if param == 'PACKAGE SIZE (compressed)' or param == 'PACKAGE SIZE (uncompressed)':
                    value = size_item(value)
                try:
                    setattr(package, model_attr, value)
                except (AttributeError, ValueError), e:
                    print e
                    return

            elif line is not None:
                description.append(line)
Example #8
0
def upload(request, problem):
	package = Package()
	context = {}

	if request.method == 'POST':
		package.user = request.user
		package.comment = request.POST.get('comment', '')
		package.problem = problem

		if re.search(r'^[a-zA-Z0-9_\.\-]+$', request.FILES['input_file'].name) is None:
			error_msg(request, "The file name may contain only those characters: {}{}_.-".format(string.ascii_letters, string.digits))
		else:
			package.package.save(request.FILES['input_file'].name, request.FILES['input_file'])
			package.save()
			success_msg(request, "Package uploaded successfully.")
			return redirect('problems-problem-packages', problem.id)

	context['problem'] = problem
	context['package'] = package
	context['tab'] = 'packages'

	return render(request, 'problems/problem/packages/upload.html', context)
Example #9
0
def upload(request, problem):
	package = Package()
	context = {}

	if request.method == 'POST':
		package.user = request.user
		package.comment = request.POST.get('comment', '')
		package.problem = problem

		if re.search(r'^[a-zA-Z0-9_\.\-]+$', request.FILES['input_file'].name) is None:
			error_msg(request, "The file name may contain only those characters: {}{}_.-".format(string.ascii_letters, string.digits))
		else:
			package.package.save(request.FILES['input_file'].name, request.FILES['input_file'])
			package.save()
			success_msg(request, "Package uploaded successfully.")
			return redirect('problems-problem-packages', problem.id)

	context['problem'] = problem
	context['package'] = package
	context['tab'] = 'packages'

	return render(request, 'problems/problem/packages/upload.html', context)
Example #10
0
def loadLoginPage(request):
    try:
        userID = request.session['userID']
        admin = Administrator.objects.get(pk=userID)

        cpuRamDisk = SystemInformation.cpuRamDisk()

        finaData = {
            "type": admin.type,
            'ramUsage': cpuRamDisk['ramUsage'],
            'cpuUsage': cpuRamDisk['cpuUsage'],
            'diskUsage': cpuRamDisk['diskUsage']
        }

        return render(request, 'baseTemplate/homePage.html', finaData)
    except KeyError:

        numberOfAdministrator = Administrator.objects.count()

        password = hashPassword.hash_password('1234567')

        if numberOfAdministrator == 0:
            email = '*****@*****.**'
            admin = Administrator(userName="******",
                                  password=password,
                                  type=1,
                                  email=email,
                                  firstName="Cyber",
                                  lastName="Panel")
            admin.save()

            vers = version(currentVersion="1.6", build=4)
            vers.save()

            package = Package(admin=admin,
                              packageName="Default",
                              diskSpace=1000,
                              bandwidth=1000,
                              ftpAccounts=1000,
                              dataBases=1000,
                              emailAccounts=1000,
                              allowedDomains=20)
            package.save()

            newFWRule = FirewallRules(name="panel", proto="tcp", port="8090")
            newFWRule.save()

            newFWRule = FirewallRules(name="http", proto="tcp", port="80")
            newFWRule.save()

            newFWRule = FirewallRules(name="https", proto="tcp", port="443")
            newFWRule.save()

            newFWRule = FirewallRules(name="ftp", proto="tcp", port="21")
            newFWRule.save()

            newFWRule = FirewallRules(name="smtp", proto="tcp", port="25")
            newFWRule.save()

            newFWRule = FirewallRules(name="smtps", proto="tcp", port="587")
            newFWRule.save()

            newFWRule = FirewallRules(name="ssmtp", proto="tcp", port="465")
            newFWRule.save()

            newFWRule = FirewallRules(name="pop3", proto="tcp", port="110")
            newFWRule.save()

            newFWRule = FirewallRules(name="imap", proto="tcp", port="143")
            newFWRule.save()

            newFWRule = FirewallRules(name="simap", proto="tcp", port="993")
            newFWRule.save()

            newFWRule = FirewallRules(name="dns", proto="udp", port="53")
            newFWRule.save()

            newFWRule = FirewallRules(name="dnstcp", proto="tcp", port="53")
            newFWRule.save()

            newFWRule = FirewallRules(name="ftptls",
                                      proto="tcp",
                                      port="40110-40210")
            newFWRule.save()

            return render(request, 'loginSystem/login.html', {})
        else:
            return render(request, 'loginSystem/login.html', {})
Example #11
0
def changeAdminPassword(request):
    try:

        data = json.loads(request.body)

        adminPass = data['password']
        randomFile = data['randomFile']

        if os.path.exists(randomFile):
            numberOfAdministrator = Administrator.objects.count()
            if numberOfAdministrator == 0:
                ACLManager.createDefaultACLs()
                acl = ACL.objects.get(name='admin')
                token = hashPassword.generateToken('admin', '1234567')

                email = '*****@*****.**'
                admin = Administrator(userName="******", password=hashPassword.hash_password(adminPass), type=1, email=email,
                                      firstName="Cyber", lastName="Panel", acl=acl, token=token)
                admin.save()

                vers = version(currentVersion="1.7", build=7)
                vers.save()

                package = Package(admin=admin, packageName="Default", diskSpace=1000,
                                  bandwidth=1000, ftpAccounts=1000, dataBases=1000,
                                  emailAccounts=1000, allowedDomains=20)
                package.save()

                newFWRule = FirewallRules(name="panel", proto="tcp", port="8090")
                newFWRule.save()

                newFWRule = FirewallRules(name="http", proto="tcp", port="80")
                newFWRule.save()

                newFWRule = FirewallRules(name="https", proto="tcp", port="443")
                newFWRule.save()

                newFWRule = FirewallRules(name="ftp", proto="tcp", port="21")
                newFWRule.save()

                newFWRule = FirewallRules(name="smtp", proto="tcp", port="25")
                newFWRule.save()

                newFWRule = FirewallRules(name="smtps", proto="tcp", port="587")
                newFWRule.save()

                newFWRule = FirewallRules(name="ssmtp", proto="tcp", port="465")
                newFWRule.save()

                newFWRule = FirewallRules(name="pop3", proto="tcp", port="110")
                newFWRule.save()

                newFWRule = FirewallRules(name="imap", proto="tcp", port="143")
                newFWRule.save()

                newFWRule = FirewallRules(name="simap", proto="tcp", port="993")
                newFWRule.save()

                newFWRule = FirewallRules(name="dns", proto="udp", port="53")
                newFWRule.save()

                newFWRule = FirewallRules(name="dnstcp", proto="tcp", port="53")
                newFWRule.save()

                newFWRule = FirewallRules(name="ftptls", proto="tcp", port="40110-40210")
                newFWRule.save()

                data_ret = {"changed": 1,
                            'error_message': "None"}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)
            os.remove(randomFile)
            admin = Administrator.objects.get(userName="******")
            admin.password = hashPassword.hash_password(adminPass)
            admin.save()
            data_ret = {"changed": 1,
                        'error_message': "None"}

            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
        else:
            data_ret = {"changed": 0,
                        'error_message': "Failed to authorize access to change password!"}

            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
    except BaseException, msg:
        data_ret = {"changed": 0,
                    'error_message': str(msg)}

        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
Example #12
0
 def create(self, validated_data):
     """IMPLEMENT ME"""
     user = self.context["request"].user
     package = Package(**validated_data)
     package.save()
     return package
Example #13
0
def loadLoginPage(request):
    try:
        userID = request.session['userID']
        admin = Administrator.objects.get(pk=userID)

        cpuRamDisk = SystemInformation.cpuRamDisk()

        finaData = {"type": admin.type, 'ramUsage': cpuRamDisk['ramUsage'], 'cpuUsage': cpuRamDisk['cpuUsage'],
                    'diskUsage': cpuRamDisk['diskUsage']}

        return render(request, 'baseTemplate/homePage.html', finaData)
    except KeyError:

        numberOfAdministrator = Administrator.objects.count()


        password = hashPassword.hash_password('1234567')

        if numberOfAdministrator == 0:
            email = '*****@*****.**'
            admin = Administrator(userName="******", password=password, type=1,email=email,
                                  firstName="Cyber",lastName="Panel")
            admin.save()

            vers = version(currentVersion="1.6",build=0)
            vers.save()

            package = Package(admin=admin, packageName="Default", diskSpace=1000,
                                  bandwidth=1000, ftpAccounts=1000, dataBases=1000,
                                  emailAccounts=1000,allowedDomains=20)
            package.save()

            newFWRule = FirewallRules(name="panel", proto="tcp", port="8090")
            newFWRule.save()

            newFWRule = FirewallRules(name="http", proto="tcp", port="80")
            newFWRule.save()

            newFWRule = FirewallRules(name="https", proto="tcp", port="443")
            newFWRule.save()

            newFWRule = FirewallRules(name="ftp", proto="tcp", port="21")
            newFWRule.save()

            newFWRule = FirewallRules(name="smtp", proto="tcp", port="25")
            newFWRule.save()

            newFWRule = FirewallRules(name="smtps", proto="tcp", port="587")
            newFWRule.save()

            newFWRule = FirewallRules(name="ssmtp", proto="tcp", port="465")
            newFWRule.save()

            newFWRule = FirewallRules(name="pop3", proto="tcp", port="110")
            newFWRule.save()

            newFWRule = FirewallRules(name="imap", proto="tcp", port="143")
            newFWRule.save()

            newFWRule = FirewallRules(name="simap", proto="tcp", port="993")
            newFWRule.save()

            newFWRule = FirewallRules(name="dns", proto="udp", port="53")
            newFWRule.save()

            newFWRule = FirewallRules(name="dnstcp", proto="tcp", port="53")
            newFWRule.save()

            newFWRule = FirewallRules(name="ftptls", proto="tcp", port="40110-40210")
            newFWRule.save()

            return render(request, 'loginSystem/login.html', {})
        else:
            return render(request, 'loginSystem/login.html', {})
Example #14
0
def loadLoginPage(request):
    try:
        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)

        cpuRamDisk = SystemInformation.cpuRamDisk()

        if currentACL['admin'] == 1:
            admin = 1
        else:
            admin = 0

        finaData = {
            "admin": admin,
            'ramUsage': cpuRamDisk['ramUsage'],
            'cpuUsage': cpuRamDisk['cpuUsage'],
            'diskUsage': cpuRamDisk['diskUsage']
        }

        return render(request, 'baseTemplate/homePage.html', finaData)
    except KeyError:

        numberOfAdministrator = Administrator.objects.count()
        password = hashPassword.hash_password('1234567')
        noOfRules = FirewallRules.objects.count()

        if noOfRules == 0:
            newFWRule = FirewallRules(name="panel", proto="tcp", port="8090")
            newFWRule.save()

            newFWRule = FirewallRules(name="http", proto="tcp", port="80")
            newFWRule.save()

            newFWRule = FirewallRules(name="https", proto="tcp", port="443")
            newFWRule.save()

            newFWRule = FirewallRules(name="ftp", proto="tcp", port="21")
            newFWRule.save()

            newFWRule = FirewallRules(name="smtp", proto="tcp", port="25")
            newFWRule.save()

            newFWRule = FirewallRules(name="smtps", proto="tcp", port="587")
            newFWRule.save()

            newFWRule = FirewallRules(name="ssmtp", proto="tcp", port="465")
            newFWRule.save()

            newFWRule = FirewallRules(name="pop3", proto="tcp", port="110")
            newFWRule.save()

            newFWRule = FirewallRules(name="imap", proto="tcp", port="143")
            newFWRule.save()

            newFWRule = FirewallRules(name="simap", proto="tcp", port="993")
            newFWRule.save()

            newFWRule = FirewallRules(name="dns", proto="udp", port="53")
            newFWRule.save()

            newFWRule = FirewallRules(name="dnstcp", proto="tcp", port="53")
            newFWRule.save()

            newFWRule = FirewallRules(name="ftptls",
                                      proto="tcp",
                                      port="40110-40210")
            newFWRule.save()

            newFWRule = FirewallRules(name="quic", proto="udp", port="443")
            newFWRule.save()

        if numberOfAdministrator == 0:
            ACLManager.createDefaultACLs()
            acl = ACL.objects.get(name='admin')

            token = hashPassword.generateToken('admin', '1234567')

            email = '*****@*****.**'
            admin = Administrator(userName="******",
                                  password=password,
                                  type=1,
                                  email=email,
                                  firstName="Cyber",
                                  lastName="Panel",
                                  acl=acl,
                                  token=token)
            admin.save()

            vers = version(currentVersion="1.9", build=1)
            vers.save()

            package = Package(admin=admin,
                              packageName="Default",
                              diskSpace=1000,
                              bandwidth=1000,
                              ftpAccounts=1000,
                              dataBases=1000,
                              emailAccounts=1000,
                              allowedDomains=20)
            package.save()
            return render(request, 'loginSystem/login.html', {})
        else:
            return render(request, 'loginSystem/login.html', {})
Example #15
0
 def setUp(self):
     self.package = Package()