Как можно отключить капчу на "забыли пароль/логин?"

Тема в разделе "Вопросы безопасности", создана пользователем AlexChervon, 04.12.2015.

  1. AlexChervon
    Offline

    AlexChervon Пользователь

    Регистрация:
    14.11.2015
    Сообщения:
    63
    Симпатии:
    0
    Пол:
    Мужской
    Все облазил не нашел!
     
  2.  
  3. OlegK
    Offline

    OlegK Russian Joomla! Team Команда форума ⇒ Профи ⇐

    Регистрация:
    17.01.2011
    Сообщения:
    7 813
    Симпатии:
    771
    Пол:
    Мужской
    В менеджере плагинов смотрел ?
     
  4. AlexChervon
    Offline

    AlexChervon Пользователь

    Регистрация:
    14.11.2015
    Сообщения:
    63
    Симпатии:
    0
    Пол:
    Мужской
    Там тоже смотрел!
     

    Вложения:

  5. OlegK
    Offline

    OlegK Russian Joomla! Team Команда форума ⇒ Профи ⇐

    Регистрация:
    17.01.2011
    Сообщения:
    7 813
    Симпатии:
    771
    Пол:
    Мужской
    А справа Включено пробовал менять на Отключено :
     
  6. AlexChervon
    Offline

    AlexChervon Пользователь

    Регистрация:
    14.11.2015
    Сообщения:
    63
    Симпатии:
    0
    Пол:
    Мужской
    Мне не надо полностью отключать! Только в
    "забыли пароль/логин?"
     
  7. OlegK
    Offline

    OlegK Russian Joomla! Team Команда форума ⇒ Профи ⇐

    Регистрация:
    17.01.2011
    Сообщения:
    7 813
    Симпатии:
    771
    Пол:
    Мужской
    Ну извини )) Получи значение компонента и выложи сюда. Вкратце- в коде плагина капчи сделать проверку на компонент, если компонент com_user, то return
    Код (PHP):
    1. class PlgCaptchaRecaptcha extends JPlugin
    2. {
    3. //draff
    4. $input = JFactory::getApplication()->input;
    5. $option = $input->getCmd('option', '');
    6. var_dump($option);
    7. /**  
    8.  * Load the language file on instantiation.  
    9.  *    
    10. * @var    boolean  
    11.  * @since  3.1    */
     
    Последнее редактирование: 04.12.2015
  8. AlexChervon
    Offline

    AlexChervon Пользователь

    Регистрация:
    14.11.2015
    Сообщения:
    63
    Симпатии:
    0
    Пол:
    Мужской
    Код (PHP):
    1. <?php
    2. /**
    3.  * @package     Joomla.Plugin
    4.  * @subpackage  Captcha
    5.  *
    6.  * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
    7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
    8.  */
    9.  
    10. defined('_JEXEC') or die;
    11.  
    12. /**
    13.  * Recaptcha Plugin.
    14.  * Based on the official recaptcha library( https://developers.google.com/recaptcha/docs/php )
    15.  *
    16.  * @since  2.5
    17.  */
    18. class PlgCaptchaRecaptcha extends JPlugin
    19. {
    20.     /**
    21.     * Load the language file on instantiation.
    22.     *
    23.     * @var    boolean
    24.     * @since  3.1
    25.     */
    26.     protected $autoloadLanguage = true;
    27.  
    28.     /**
    29.     * Initialise the captcha
    30.     *
    31.     * @param   string  $id  The id of the field.
    32.     *
    33.     * @return  Boolean    True on success, false otherwise
    34.     *
    35.     * @throws  Exception
    36.     *
    37.     * @since  2.5
    38.     */
    39.     public function onInit($id = 'dynamic_recaptcha_1')
    40.     {
    41.         $document = JFactory::getDocument();
    42.         $app      = JFactory::getApplication();
    43.  
    44.         JHtml::_('jquery.framework');
    45.  
    46.         $lang       = $this->_getLanguage();
    47.         $version    = $this->params->get('version', '1.0');
    48.         $pubkey     = $this->params->get('public_key', '');
    49.  
    50.         if ($pubkey == null || $pubkey == '')
    51.         {
    52.             throw new Exception(JText::_('PLG_RECAPTCHA_ERROR_NO_PUBLIC_KEY'));
    53.         }
    54.  
    55.         switch ($version)
    56.         {
    57.             case '1.0':
    58.                 $theme = $this->params->get('theme', 'clean');
    59.                 $file  = 'https://www.google.com/recaptcha/api/js/recaptcha_ajax.js';
    60.  
    61.                 JHtml::_('script', $file);
    62.  
    63.                 $document->addScriptDeclaration('jQuery( document ).ready(function()
    64.                {
    65.                    Recaptcha.create("' . $pubkey . '", "' . $id . '", {theme: "' . $theme . '",' . $lang . 'tabindex: 0});});'
    66.                 );
    67.                 break;
    68.             case '2.0':
    69.                 $theme = $this->params->get('theme2', 'light');
    70.                 $file  = 'https://www.google.com/recaptcha/api.js?hl=' . JFactory::getLanguage()->getTag() . '&amp;render=explicit';
    71.  
    72.                 JHtml::_('script', $file, true, true);
    73.  
    74.                 $document->addScriptDeclaration('jQuery(document).ready(function($) {$(window).load(function() {'
    75.                     . 'grecaptcha.render("' . $id . '", {sitekey: "' . $pubkey . '", theme: "' . $theme . '"});'
    76.                     . '});});'
    77.                 );
    78.                 break;
    79.         }
    80.  
    81.         return true;
    82.     }
    83.  
    84.     /**
    85.     * Gets the challenge HTML
    86.     *
    87.     * @param   string  $name   The name of the field. Not Used.
    88.     * @param   string  $id     The id of the field.
    89.     * @param   string  $class  The class of the field. This should be passed as
    90.     *                          e.g. 'class="required"'.
    91.     *
    92.     * @return  string  The HTML to be embedded in the form.
    93.     *
    94.     * @since  2.5
    95.     */
    96.     public function onDisplay($name = null, $id = 'dynamic_recaptcha_1', $class = '')
    97.     {
    98.         return '<div id="' . $id . '" ' . $class . '></div>';
    99.     }
    100.  
    101.     /**
    102.     * Calls an HTTP POST function to verify if the user's guess was correct
    103.     *
    104.     * @param   string  $code  Answer provided by user. Not needed for the Recaptcha implementation
    105.     *
    106.     * @return  True if the answer is correct, false otherwise
    107.     *
    108.     * @since  2.5
    109.     */
    110.     public function onCheckAnswer($code = null)
    111.     {
    112.         $input      = JFactory::getApplication()->input;
    113.         $privatekey = $this->params->get('private_key');
    114.         $version    = $this->params->get('version', '1.0');
    115.         $remoteip   = $input->server->get('REMOTE_ADDR', '', 'string');
    116.  
    117.         switch ($version)
    118.         {
    119.             case '1.0':
    120.                 $challenge = $input->get('recaptcha_challenge_field', '', 'string');
    121.                 $response  = $input->get('recaptcha_response_field', '', 'string');
    122.                 $spam      = ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0);
    123.                 break;
    124.             case '2.0':
    125.                 // Challenge Not needed in 2.0 but needed for getResponse call
    126.                 $challenge = null;
    127.                 $response  = $input->get('g-recaptcha-response', '', 'string');
    128.                 $spam      = ($response == null || strlen($response) == 0);
    129.                 break;
    130.         }
    131.  
    132.         // Check for Private Key
    133.         if (empty($privatekey))
    134.         {
    135.             $this->_subject->setError(JText::_('PLG_RECAPTCHA_ERROR_NO_PRIVATE_KEY'));
    136.  
    137.             return false;
    138.         }
    139.  
    140.         // Check for IP
    141.         if (empty($remoteip))
    142.         {
    143.             $this->_subject->setError(JText::_('PLG_RECAPTCHA_ERROR_NO_IP'));
    144.  
    145.             return false;
    146.         }
    147.  
    148.         // Discard spam submissions
    149.         if ($spam)
    150.         {
    151.             $this->_subject->setError(JText::_('PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION'));
    152.  
    153.             return false;
    154.         }
    155.  
    156.         return $this->getResponse($privatekey, $remoteip, $response, $challenge);
    157.     }
    158.  
    159.     /**
    160.     * Get the reCaptcha response.
    161.     *
    162.     * @param   string  $privatekey  The private key for authentication.
    163.     * @param   string  $remoteip    The remote IP of the visitor.
    164.     * @param   string  $response    The response received from Google.
    165.     * @param   string  $challenge   The challenge field from the reCaptcha. Only for 1.0.
    166.     *
    167.     * @return bool True if response is good | False if response is bad.
    168.     *
    169.     * @since   3.4
    170.     */
    171.     private function getResponse($privatekey, $remoteip, $response, $challenge = null)
    172.     {
    173.         $version = $this->params->get('version', '1.0');
    174.  
    175.         switch ($version)
    176.         {
    177.             case '1.0':
    178.                 $response = $this->_recaptcha_http_post(
    179.                     'www.google.com', '/recaptcha/api/verify',
    180.                     array(
    181.                         'privatekey' => $privatekey,
    182.                         'remoteip'   => $remoteip,
    183.                         'challenge'  => $challenge,
    184.                         'response'   => $response
    185.                     )
    186.                 );
    187.  
    188.                 $answers = explode("\n", $response[1]);
    189.  
    190.                 if (trim($answers[0]) !== 'true')
    191.                 {
    192.                     // @todo use exceptions here
    193.                     $this->_subject->setError(JText::_('PLG_RECAPTCHA_ERROR_' . strtoupper(str_replace('-', '_', $answers[1]))));
    194.  
    195.                     return false;
    196.                 }
    197.                 break;
    198.             case '2.0':
    199.                 require_once 'recaptchalib.php';
    200.  
    201.                 $reCaptcha = new JReCaptcha($privatekey);
    202.                 $response  = $reCaptcha->verifyResponse($remoteip, $response);
    203.  
    204.                 if ( !isset($response->success) || !$response->success)
    205.                 {
    206.                     // @todo use exceptions here
    207.                     foreach ($response->errorCodes as $error)
    208.                     {
    209.                         $this->_subject->setError($error);
    210.                     }
    211.  
    212.                     return false;
    213.                 }
    214.                 break;
    215.         }
    216.  
    217.         return true;
    218.     }
    219.  
    220.     /**
    221.     * Encodes the given data into a query string format.
    222.     *
    223.     * @param   array  $data  Array of string elements to be encoded
    224.     *
    225.     * @return  string  Encoded request
    226.     *
    227.     * @since  2.5
    228.     */
    229.     private function _recaptcha_qsencode($data)
    230.     {
    231.         $req = "";
    232.  
    233.         foreach ($data as $key => $value)
    234.         {
    235.             $req .= $key . '=' . urlencode(stripslashes($value)) . '&';
    236.         }
    237.  
    238.         // Cut the last '&'
    239.         $req = rtrim($req, '&');
    240.  
    241.         return $req;
    242.     }
    243.  
    244.     /**
    245.     * Submits an HTTP POST to a reCAPTCHA server.
    246.     *
    247.     * @param   string  $host  Host name to POST to.
    248.     * @param   string  $path  Path on host to POST to.
    249.     * @param   array   $data  Data to be POSTed.
    250.     * @param   int     $port  Optional port number on host.
    251.     *
    252.     * @return  array   Response
    253.     *
    254.     * @since  2.5
    255.     */
    256.     private function _recaptcha_http_post($host, $path, $data, $port = 80)
    257.     {
    258.         $req = $this->_recaptcha_qsencode($data);
    259.  
    260.         $http_request  = "POST $path HTTP/1.0\r\n";
    261.         $http_request .= "Host: $host\r\n";
    262.         $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
    263.         $http_request .= "Content-Length: " . strlen($req) . "\r\n";
    264.         $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
    265.         $http_request .= "\r\n";
    266.         $http_request .= $req;
    267.  
    268.         $response = '';
    269.  
    270.         if (($fs = @fsockopen($host, $port, $errno, $errstr, 10)) == false )
    271.         {
    272.             die('Could not open socket');
    273.         }
    274.  
    275.         fwrite($fs, $http_request);
    276.  
    277.         while (!feof($fs))
    278.         {
    279.             // One TCP-IP packet
    280.             $response .= fgets($fs, 1160);
    281.         }
    282.  
    283.         fclose($fs);
    284.         $response = explode("\r\n\r\n", $response, 2);
    285.  
    286.         return $response;
    287.     }
    288.  
    289.     /**
    290.     * Get the language tag or a custom translation
    291.     *
    292.     * @return  string
    293.     *
    294.     * @since  2.5
    295.     */
    296.     private function _getLanguage()
    297.     {
    298.         $language = JFactory::getLanguage();
    299.  
    300.         $tag = explode('-', $language->getTag());
    301.         $tag = $tag[0];
    302.         $available = array('en', 'pt', 'fr', 'de', 'nl', 'ru', 'es', 'tr');
    303.  
    304.         if (in_array($tag, $available))
    305.         {
    306.             return "lang : '" . $tag . "',";
    307.         }
    308.  
    309.         // If the default language is not available, let's search for a custom translation
    310.         if ($language->hasKey('PLG_RECAPTCHA_CUSTOM_LANG'))
    311.         {
    312.             $custom[] = 'custom_translations : {';
    313.             $custom[] = "\t" . 'instructions_visual : "' . JText::_('PLG_RECAPTCHA_INSTRUCTIONS_VISUAL') . '",';
    314.             $custom[] = "\t" . 'instructions_audio : "' . JText::_('PLG_RECAPTCHA_INSTRUCTIONS_AUDIO') . '",';
    315.             $custom[] = "\t" . 'play_again : "' . JText::_('PLG_RECAPTCHA_PLAY_AGAIN') . '",';
    316.             $custom[] = "\t" . 'cant_hear_this : "' . JText::_('PLG_RECAPTCHA_CANT_HEAR_THIS') . '",';
    317.             $custom[] = "\t" . 'visual_challenge : "' . JText::_('PLG_RECAPTCHA_VISUAL_CHALLENGE') . '",';
    318.             $custom[] = "\t" . 'audio_challenge : "' . JText::_('PLG_RECAPTCHA_AUDIO_CHALLENGE') . '",';
    319.             $custom[] = "\t" . 'refresh_btn : "' . JText::_('PLG_RECAPTCHA_REFRESH_BTN') . '",';
    320.             $custom[] = "\t" . 'help_btn : "' . JText::_('PLG_RECAPTCHA_HELP_BTN') . '",';
    321.             $custom[] = "\t" . 'incorrect_try_again : "' . JText::_('PLG_RECAPTCHA_INCORRECT_TRY_AGAIN') . '",';
    322.             $custom[] = '},';
    323.             $custom[] = "lang : '" . $tag . "',";
    324.  
    325.             return implode("\n", $custom);
    326.         }
    327.  
    328.         // If nothing helps fall back to english
    329.         return '';
    330.     }
    331. }
     

Поделиться этой страницей

Загрузка...