#NEWLINE# def _enable_redirect( self , ssl_vhost , unused_options ) : #NEWLINE# #INDENT# 'Redirect all equivalent HTTP traffic to ssl_vhost.\n\n        .. todo:: This enhancement should be rewritten and will\n           unfortunately require lots of debugging by hand.\n\n        Adds Redirect directive to the port 80 equivalent of ssl_vhost\n        First the function attempts to find the vhost with equivalent\n        ip addresses that serves on non-ssl ports\n        The function then adds the directive\n\n        .. note:: This function saves the configuration\n\n        :param ssl_vhost: Destination of traffic, an ssl enabled vhost\n        :type ssl_vhost: :class:`~certbot_apache.obj.VirtualHost`\n\n        :param unused_options: Not currently used\n        :type unused_options: Not Available\n\n        :returns: Success, general_vhost (HTTP vhost)\n        :rtype: (bool, :class:`~certbot_apache.obj.VirtualHost`)\n\n        :raises .errors.PluginError: If no viable HTTP host can be created or\n            used for the redirect.\n\n        ' #NEWLINE# if ( 'rewrite_module' not in self . parser . modules ) : #NEWLINE# #INDENT# self . enable_mod ( 'rewrite' ) #NEWLINE# #UNINDENT# general_vh = self . _get_http_vhost ( ssl_vhost ) #NEWLINE# if ( general_vh is None ) : #NEWLINE# #INDENT# logger . debug ( 'Did not find http version of ssl virtual host attempting to create' ) #NEWLINE# redirect_addrs = self . _get_proposed_addrs ( ssl_vhost ) #NEWLINE# for vhost in self . vhosts : #NEWLINE# #INDENT# if ( vhost . enabled and vhost . conflicts ( redirect_addrs ) ) : #NEWLINE# #INDENT# raise errors . PluginError ( 'Unable to find corresponding HTTP vhost; Unable to create one as intended addresses conflict; Current configuration does not support automated redirection' ) #NEWLINE# #UNINDENT# #UNINDENT# self . _create_redirect_vhost ( ssl_vhost ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _verify_no_certbot_redirect ( general_vh ) #NEWLINE# if self . _is_rewrite_exists ( general_vh ) : #NEWLINE# #INDENT# logger . warn ( 'Added an HTTP->HTTPS rewrite in addition to other RewriteRules; you may wish to check for overall consistency.' ) #NEWLINE# #UNINDENT# if ( not self . _is_rewrite_engine_on ( general_vh ) ) : #NEWLINE# #INDENT# self . parser . add_dir ( general_vh . path , 'RewriteEngine' , 'on' ) #NEWLINE# #UNINDENT# names = ssl_vhost . get_names ( ) #NEWLINE# for ( idx , name ) in enumerate ( names ) : #NEWLINE# #INDENT# args = [ '%{SERVER_NAME}' , '={0}' . format ( name ) , '[OR]' ] #NEWLINE# if ( idx == ( len ( names ) - 1 ) ) : #NEWLINE# #INDENT# args . pop ( ) #NEWLINE# #UNINDENT# self . parser . add_dir ( general_vh . path , 'RewriteCond' , args ) #NEWLINE# #UNINDENT# if ( self . get_version ( ) >= ( 2 , 3 , 9 ) ) : #NEWLINE# #INDENT# self . parser . add_dir ( general_vh . path , 'RewriteRule' , constants . REWRITE_HTTPS_ARGS_WITH_END ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . parser . add_dir ( general_vh . path , 'RewriteRule' , constants . REWRITE_HTTPS_ARGS ) #NEWLINE# #UNINDENT# self . save_notes += ( 'Redirecting host in %s to ssl vhost in %s\n' % ( general_vh . filep , ssl_vhost . filep ) ) #NEWLINE# self . save ( ) #NEWLINE# logger . info ( 'Redirecting vhost in %s to ssl vhost in %s' , general_vh . filep , ssl_vhost . filep )