示例#1
0
 def __init__(self):
     self.__request = Request()
     self.__response = Response()
     self.__helpers = Helpers()
     self.__form = Form()
     self.__install = Install_Module()
     self.__logger = self.__helpers.get_logger(__name__)
示例#2
0
class Install(View):

    template_name = 'templates/install.html'
    __context = None
    __install = None
    __option_entity = None
    __correlation_id = None

    def get(self, request):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context = Context()
        self.__install = InstallModule()
        self.__option_entity = OptionEntity()

        if self.__install.is_installed():
            return redirect("app.web.login")

        self.__context.push({
            "page_title":
            _("Installation · %s") % self.__option_entity.get_value_by_key(
                "app_name", os.getenv("APP_NAME", "Silverback"))
        })

        return render(request, self.template_name, self.__context.get())
示例#3
0
class TestingBase():

    __install_module = None

    def __init__(self):
        self.__install_module = Install_Module()

    def login(self):
        pass

    def install(self, data):

        if self.__install_module.is_installed():
            return True

        self.__install_module.set_app_data(data["app_name"], data["app_email"],
                                           data["app_url"])
        self.__install_module.set_admin_data(data["admin_username"],
                                             data["admin_email"],
                                             data["admin_password"])

        return self.__install_module.install()

    def uninstall(self):
        return self.__install_module.uninstall()
示例#4
0
 def __init__(self):
     self.__request = Request()
     self.__response = Response()
     self.__helpers = Helpers()
     self.__form = Form()
     self.__install = InstallModule()
     self.__notification = NotificationModule()
     self.__logger = self.__helpers.get_logger(__name__)
     self.__form.add_validator(ExtraRules())
示例#5
0
    def get(self, request):

        self.__install = InstallModule()
        self.__option_entity = OptionEntity()

        if self.__install.is_installed():
            return redirect("app.web.login")

        self.context_push({
            "page_title":
            _("Installation · %s") % self.__option_entity.get_value_by_key(
                "app_name", os.getenv("APP_NAME", "Silverback"))
        })

        return render(request, self.template_name, self.context_get())
示例#6
0
class Install(View):

    template_name = 'templates/install.html'
    __context = None
    __install = None
    __option_entity = None

    def get(self, request):

        self.__context = Context()
        self.__install = Install_Module()
        self.__option_entity = Option_Entity()

        if self.__install.is_installed():
            return redirect("app.web.login")

        self.__context.push({
            "page_title":
            _("Installation · %s") % self.__option_entity.get_value_by_key(
                "app_name", os.getenv("APP_NAME", "Kraven"))
        })

        return render(request, self.template_name, self.__context.get())
示例#7
0
class Install(View):

    __request = None
    __response = None
    __helpers = None
    __form = None
    __install = None
    __logger = None
    __notification = None
    __correlation_id = None

    def __init__(self):
        self.__request = Request()
        self.__response = Response()
        self.__helpers = Helpers()
        self.__form = Form()
        self.__install = InstallModule()
        self.__notification = NotificationModule()
        self.__logger = self.__helpers.get_logger(__name__)
        self.__form.add_validator(ExtraRules())

    @stop_request_if_installed
    def post(self, request):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""

        if self.__install.is_installed():
            return JsonResponse(
                self.__response.send_private_failure(
                    [{
                        "type": "error",
                        "message":
                        _("Error! Application is already installed.")
                    }], {}, self.__correlation_id))

        self.__request.set_request(request)

        request_data = self.__request.get_request_data(
            "post", {
                "app_name": "",
                "app_email": "",
                "app_url": "",
                "admin_username": "",
                "admin_email": "",
                "admin_password": ""
            })

        self.__form.add_inputs({
            'app_name': {
                'value': request_data["app_name"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'alpha_numeric': {
                        'error':
                        _('Error! Application name must be alpha numeric.')
                    },
                    'length_between': {
                        'param': [2, 30],
                        'error':
                        _('Error! Application name must be 2 to 30 characters long.'
                          )
                    }
                }
            },
            'app_email': {
                'value': request_data["app_email"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'sv_email': {
                        'error': _('Error! Application email is invalid.')
                    }
                }
            },
            'app_url': {
                'value': request_data["app_url"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'sv_url': {
                        'error': _('Error! Application url is invalid.')
                    }
                }
            },
            'admin_username': {
                'value': request_data["admin_username"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'alpha_numeric': {
                        'error': _('Error! Username must be alpha numeric.')
                    },
                    'length_between': {
                        'param': [4, 10],
                        'error':
                        _('Error! Username must be 5 to 10 characters long.')
                    }
                }
            },
            'admin_email': {
                'value': request_data["admin_email"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'sv_email': {
                        'error': _('Error! Admin email is invalid.')
                    }
                }
            },
            'admin_password': {
                'value': request_data["admin_password"],
                'validate': {
                    'sv_password': {
                        'error':
                        _('Error! Password must contain at least uppercase letter, lowercase letter, numbers and special character.'
                          )
                    },
                    'length_between': {
                        'param': [7, 20],
                        'error':
                        _('Error! Password length must be from 8 to 20 characters.'
                          )
                    }
                }
            }
        })

        self.__form.process()

        if not self.__form.is_passed():
            return JsonResponse(
                self.__response.send_errors_failure(self.__form.get_errors(),
                                                    {}, self.__correlation_id))

        self.__install.set_app_data(self.__form.get_sinput("app_name"),
                                    self.__form.get_sinput("app_email"),
                                    self.__form.get_sinput("app_url"))
        self.__install.set_admin_data(self.__form.get_sinput("admin_username"),
                                      self.__form.get_sinput("admin_email"),
                                      self.__form.get_sinput("admin_password"))

        try:
            user_id = self.__install.install()
        except Exception as exception:
            self.__logger.error(
                _("Internal server error during installation: %(exception)s {'correlationId':'%(correlationId)s'}"
                  ) % {
                      "exception": exception,
                      "correlationId": self.__correlation_id
                  })

        if user_id:
            self.__notification.create_notification({
                "highlight":
                _('Installation'),
                "notification":
                _('Silverback installed successfully'),
                "url":
                "#",
                "type":
                NotificationModule.MESSAGE,
                "delivered":
                False,
                "user_id":
                user_id,
                "task_id":
                None
            })

            return JsonResponse(
                self.__response.send_private_success(
                    [{
                        "type": "success",
                        "message": _("Application installed successfully.")
                    }], {}, self.__correlation_id))
        else:
            return JsonResponse(
                self.__response.send_private_failure([{
                    "type":
                    "error",
                    "message":
                    _("Error! Something goes wrong during installing.")
                }], {}, self.__correlation_id))
示例#8
0
class Install(View):

    __request = None
    __response = None
    __helpers = None
    __form = None
    __install = None
    __logger = None

    def __init__(self):
        self.__request = Request()
        self.__response = Response()
        self.__helpers = Helpers()
        self.__form = Form()
        self.__install = Install_Module()
        self.__logger = self.__helpers.get_logger(__name__)

    @stop_request_if_installed
    def post(self, request):

        if self.__install.is_installed():
            return JsonResponse(
                self.__response.send_private_failure([{
                    "type":
                    "error",
                    "message":
                    _("Error! Application is already installed.")
                }]))

        self.__request.set_request(request)

        request_data = self.__request.get_request_data(
            "post", {
                "app_name": "",
                "app_email": "",
                "app_url": "",
                "admin_username": "",
                "admin_email": "",
                "admin_password": ""
            })

        self.__form.add_inputs({
            'app_name': {
                'value': request_data["app_name"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'alpha_numeric': {
                        'error':
                        _('Error! Application name must be alpha numeric.')
                    },
                    'length_between': {
                        'param': [3, 10],
                        'error':
                        _('Error! Application name must be 5 to 10 characters long.'
                          )
                    }
                }
            },
            'app_email': {
                'value': request_data["app_email"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'email': {
                        'error': _('Error! Application email is invalid.')
                    }
                }
            },
            'app_url': {
                'value': request_data["app_url"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'url': {
                        'error': _('Error! Application url is invalid.')
                    }
                }
            },
            'admin_username': {
                'value': request_data["admin_username"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'alpha_numeric': {
                        'error': _('Error! Username must be alpha numeric.')
                    },
                    'length_between': {
                        'param': [4, 10],
                        'error':
                        _('Error! Username must be 5 to 10 characters long.')
                    }
                }
            },
            'admin_email': {
                'value': request_data["admin_email"],
                'sanitize': {
                    'escape': {},
                    'strip': {}
                },
                'validate': {
                    'email': {
                        'error': _('Error! Admin email is invalid.')
                    }
                }
            },
            'admin_password': {
                'value': request_data["admin_password"],
                'validate': {
                    'password': {
                        'error':
                        _('Error! Password must contain at least uppercase letter, lowercase letter, numbers and special character.'
                          )
                    },
                    'length_between': {
                        'param': [7, 20],
                        'error':
                        _('Error! Password length must be from 8 to 20 characters.'
                          )
                    }
                }
            }
        })

        self.__form.process()

        if not self.__form.is_passed():
            return JsonResponse(
                self.__response.send_private_failure(
                    self.__form.get_errors(with_type=True)))

        self.__install.set_app_data(self.__form.get_input_value("app_name"),
                                    self.__form.get_input_value("app_email"),
                                    self.__form.get_input_value("app_url"))
        self.__install.set_admin_data(
            self.__form.get_input_value("admin_username"),
            self.__form.get_input_value("admin_email"),
            self.__form.get_input_value("admin_password"))

        if self.__install.install():
            return JsonResponse(
                self.__response.send_private_success([{
                    "type":
                    "success",
                    "message":
                    _("Application installed successfully.")
                }]))
        else:
            return JsonResponse(
                self.__response.send_private_failure([{
                    "type":
                    "error",
                    "message":
                    _("Error! Something goes wrong during installing.")
                }]))
示例#9
0
 def __init__(self):
     self.__install = InstallModule()
     self.__notification = NotificationModule()
示例#10
0
class Install(View, Controller):
    """Install Private Endpoint Controller"""
    def __init__(self):
        self.__install = InstallModule()
        self.__notification = NotificationModule()

    @stop_request_if_installed
    def post(self, request):

        if self.__install.is_installed():
            return self.json([{
                "type":
                "error",
                "message":
                _("Error! Application is already installed.")
            }])

        request_data = self.get_request_data(
            request, "post", {
                "app_name": "",
                "app_email": "",
                "app_url": "",
                "admin_username": "",
                "admin_email": "",
                "admin_password": ""
            })

        self.form().add_inputs({
            'app_name': {
                'value': request_data["app_name"],
                'sanitize': {
                    'strip': {}
                },
                'validate': {
                    'alpha_numeric': {
                        'error':
                        _('Error! Application name must be alpha numeric.')
                    },
                    'length_between': {
                        'param': [2, 30],
                        'error':
                        _('Error! Application name must be 2 to 30 characters long.'
                          )
                    }
                }
            },
            'app_email': {
                'value': request_data["app_email"],
                'sanitize': {
                    'strip': {}
                },
                'validate': {
                    'sv_email': {
                        'error': _('Error! Application email is invalid.')
                    }
                }
            },
            'app_url': {
                'value': request_data["app_url"],
                'sanitize': {
                    'strip': {}
                },
                'validate': {
                    'sv_url': {
                        'error': _('Error! Application url is invalid.')
                    }
                }
            },
            'admin_username': {
                'value': request_data["admin_username"],
                'sanitize': {
                    'strip': {}
                },
                'validate': {
                    'alpha_numeric': {
                        'error': _('Error! Username must be alpha numeric.')
                    },
                    'length_between': {
                        'param': [4, 10],
                        'error':
                        _('Error! Username must be 5 to 10 characters long.')
                    }
                }
            },
            'admin_email': {
                'value': request_data["admin_email"],
                'sanitize': {
                    'strip': {}
                },
                'validate': {
                    'sv_email': {
                        'error': _('Error! Admin email is invalid.')
                    }
                }
            },
            'admin_password': {
                'value': request_data["admin_password"],
                'validate': {
                    'sv_password': {
                        'error':
                        _('Error! Password must contain at least uppercase letter, lowercase letter, numbers and special character.'
                          )
                    },
                    'length_between': {
                        'param': [7, 20],
                        'error':
                        _('Error! Password length must be from 8 to 20 characters.'
                          )
                    }
                }
            }
        })

        self.form().process()

        if not self.form().is_passed():
            return self.json(self.form().get_errors())

        self.__install.set_app_data(self.form().get_sinput("app_name"),
                                    self.form().get_sinput("app_email"),
                                    self.form().get_sinput("app_url"))
        self.__install.set_admin_data(self.form().get_sinput("admin_username"),
                                      self.form().get_sinput("admin_email"),
                                      self.form().get_sinput("admin_password"))

        try:
            user_id = self.__install.install()
        except Exception as exception:
            self.logger().error(
                _("Internal server error during installation: %(exception)s") %
                {"exception": exception})

        if user_id:
            self.__notification.create_notification({
                "highlight":
                _('Installation'),
                "notification":
                _('Silverback installed successfully'),
                "url":
                "#",
                "type":
                NotificationModule.MESSAGE,
                "delivered":
                False,
                "user_id":
                user_id,
                "task_id":
                None
            })

            return self.json([{
                "type":
                "success",
                "message":
                _("Application installed successfully.")
            }])
        else:
            return self.json([{
                "type":
                "error",
                "message":
                _("Error! Something went wrong during installation.")
            }])
示例#11
0
 def __init__(self):
     self.__install_module = Install_Module()