%PDF- %PDF-
Direktori : /opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/user/website_check/ |
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/user/website_check/errors.py |
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2020 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT from clwpos import gettext as _ from clwpos.cl_wpos_exceptions import WposError class WebsiteCheckError(WposError): """ Generic base class for all website post checks. """ def __init__(self, *, header, description, fix_tip, context, details=None): super(WebsiteCheckError, self).__init__( message=description, context=context ) self.header = header self.fix_tip = fix_tip self.details = details class PostCheckRequestException(WebsiteCheckError): HEADER = _('Http request failed') MESSAGE_TEMPLATE = _( 'Fatal error on attempt to request website main page: ' '<a href="%(url)s" target="_blank">%(url)s</a>. ' 'Error message: %(error)s') FIX_TIP = _( 'Manually check website responds on http requests' ) def __init__(self, url, error): super(PostCheckRequestException, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( url=url, error=error ), fix_tip=self.FIX_TIP ) class WebsiteCheckBadHttpCode(WebsiteCheckError): """ Happens when we get unexpected status code from website. Usually user must go check logs and fix this issue himself. """ HEADER = _('Bad http status code response') MESSAGE_TEMPLATE = _( 'Unsuccessful attempt to request website main page: ' '<a href="%(url)s" target="_blank">%(url)s</a>. ' 'Webserver responded with http status code %(http_code)s.') FIX_TIP = _( 'Search your webserver logs for errors and manually ' 'check that WordPress site is working properly.' ) def __init__(self, url, http_code): super(WebsiteCheckBadHttpCode, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( url=url, http_code=http_code ), fix_tip=self.FIX_TIP ) class WebsiteTimeout(WebsiteCheckError): """ Happens when website does not respond in hardcoded timeout. """ HEADER = _('Response timeout reached') MESSAGE_TEMPLATE = _( 'Unsuccessful attempt to request website main page: ' '<a href="%(url)s" target="_blank">%(url)s</a>. ' 'Webserver responds longer than %(timeout)s seconds ' '(most likely it is not working).') FIX_TIP = _( 'Make sure that WordPress site is working properly and ' 'specified url gives response in %(timeout)s seconds. ' 'Search your webserver logs for errors that may cause the timeout issue.' ) def __init__(self, url, timeout): super(WebsiteTimeout, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( url=url, timeout=timeout ), fix_tip=self.FIX_TIP ) class WebsiteHttpsBroken(WebsiteCheckError): """ Happens when website has invalid or outdated https certificate. """ HEADER = _('Broken https certificate') MESSAGE_TEMPLATE = _( 'Unsuccessful attempt to request website main page: ' '<a href="%(url)s" target="_blank">%(url)s</a>. ' 'Webserver redirected http request to https, but the last ' 'one does not have a valid certificate.') FIX_TIP = _( 'Make sure that https certificate is valid and up to date or ' 'disable http to https redirection in your control panel.' ) def __init__(self, url, details): super(WebsiteHttpsBroken, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( url=url ), fix_tip=self.FIX_TIP, details=details ) class WebsiteNotResponding(WebsiteCheckError): """ Happens when website does not have working webserver at all. """ HEADER = _('Website it not responding') MESSAGE_TEMPLATE = _( 'Unsuccessful attempt to request website main page: ' '<a href="%(url)s" target="_blank">%(url)s</a>. ' 'Webserver did not return any response.') FIX_TIP = _( 'Make sure that webserver is working and your website is accessible: ' 'you can use `curl %(url)s` to check response.' ) def __init__(self, url, details): super(WebsiteNotResponding, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( url=url ), fix_tip=self.FIX_TIP, details=details ) class RollbackException(WposError): MESSAGE_TEMPLATE = _( "Action failed and rolled back. Here is why." ) def __init__(self, *reasons: WebsiteCheckError): self.errors = [ dict( header=reason.header, description=reason.message, fix_tip=reason.fix_tip, type='post_check', context=reason.context, details=reason.details ) for reason in reasons ] super(RollbackException, self).__init__(message='rollback') class PhpLogErrorsFound(WebsiteCheckError): HEADER = _('Website server error') MESSAGE_TEMPLATE = _( 'We found some errors in the website log file: %(error_log_path)s. ' 'Here is some context: \n' '%(log_record)s') FIX_TIP = _( 'Check found errors and decide whether they are critical or not. ' 'Contact your system administrator for help if needed.' ) def __init__(self, error_log_path, log_record): super(PhpLogErrorsFound, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( error_log_path=error_log_path, log_record=log_record ), fix_tip=self.FIX_TIP ) class CDNActivationFailed(WebsiteCheckError): """ Happens when website has invalid CDN configuration for some reason """ HEADER = _('CDN malfunction') MESSAGE_TEMPLATE = _( "CDN feature was not activated properly. " "Changes were reverted and CDN module is now disabled.\n" "Event is logged to file: '%(logger_path)s' with stdout and stderr recorded.") FIX_TIP = _( 'Activate feature again. If the issue persists, ' 'ignore error and check your website configuration ' 'with enabled CDN feature. ' 'Contact your hoster\'s support for help.' ) def __init__(self, logger_path): super(CDNActivationFailed, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, fix_tip=self.FIX_TIP, context=dict(logger_path=logger_path) ) class JSCssCheckBadHttpCode(WebsiteCheckError): """ Happens when we get unexpected status code from website. Usually user must go check logs and fix this issue himself. """ HEADER = _('Bad http status code response') MESSAGE_TEMPLATE = _( 'Unsuccessful attempt to request website styles and scripts. ' 'Webserver responded with http status code %(http_code)s.') FIX_TIP = _( 'Search your webserver logs for errors and manually ' 'check that WordPress site is working properly.' ) def __init__(self, http_code): super(JSCssCheckBadHttpCode, self).__init__( header=self.HEADER, description=self.MESSAGE_TEMPLATE, context=dict( http_code=http_code ), fix_tip=self.FIX_TIP )