/** * Construtor da classe * * @see Twitter_Bootstrap_Form_Vertical * @return Auth_form_login_FormLogin|void */ public function init() { $oTradutor = $this->getTranslator(); $oBaseUrlHelper = new Zend_View_Helper_BaseUrl(); $this->setName('form_login')->setAction($oBaseUrlHelper->baseUrl('/auth/login/post')); $oElm = $this->createElement('text', 'login'); $oElm->setLabel('Login'); $oElm->setAttrib('class', 'span3'); $oElm->setAttrib('autofocus', 'autofocus'); $oElm->setRequired(TRUE); $this->addElement($oElm); $oElm = $this->createElement('password', 'senha'); $oElm->setLabel('Senha'); $oElm->setAttrib('class', 'span3'); $oElm->setRequired(TRUE); $this->addElement($oElm); $iTotalErros = 0; if ($oSessao = new Zend_Session_Namespace('captcha')) { $iTotalErros = $oSessao->errors; } if ($iTotalErros > 0) { $oKeysRecaptcha = Zend_Registry::get('config')->recaptcha; if (!empty($oKeysRecaptcha->publicKey) && !empty($oKeysRecaptcha->privateKey)) { $oRecaptcha = new Zend_Service_ReCaptcha($oKeysRecaptcha->publicKey, $oKeysRecaptcha->privateKey); $oRecaptcha->setOption('theme', 'clean'); $oCaptcha = new Zend_Form_Element_Captcha('challenge', array('captcha' => 'ReCaptcha', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $oRecaptcha))); $oCaptcha->setLabel('Informe as palavras abaixo:'); $this->addElement($oCaptcha); } else { $oSessao->errors = 0; } } $this->addElement('submit', 'submit', array('label' => 'Entrar', 'class' => 'pull-right', 'data-loading-text' => $oTradutor->_('Aguarde...'), 'buttonType' => Twitter_Bootstrap_Form_Element_Submit::BUTTON_PRIMARY)); return $this; }
public static function captchaElement() { $registry = Zend_Registry::getInstance(); $config = $registry->get("config"); $keys = $config['services']['recaptcha']['keys']; $recaptcha = new Zend_Service_ReCaptcha($keys['public'], $keys['private'], array("ssl" => true, "xhtml" => true)); $recaptcha->setOption('theme', 'clean'); $captcha = new Zend_Form_Element_Captcha('challenge', array('label' => 'Type the challenge below', 'captcha' => 'ReCaptcha', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha))); return $captcha; }
/** * */ public function getReCapcha() { $reCaptcha = ''; if ($this->publicKey && $this->privateKey) { $reCaptcha = new Zend_Service_ReCaptcha($this->publicKey, $this->privateKey); if ($this->theme) { $reCaptcha->setOptions(array('theme' => $this->theme)); } } return $reCaptcha; }
/** * Check if user has filled in correct recaptcha word. * * @param $requestParams incoming request parameters * @return true if valid, otherwise, return false */ public function validReCaptcha($requestParams) { if (empty($requestParams['recaptcha_response_field'])) { return false; } else { $config = Zend_Registry::get("config"); $publickey = $config->recaptcha->public->key; $privatekey = $config->recaptcha->private->key; $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey); $result = $recaptcha->verify($requestParams['recaptcha_challenge_field'], $requestParams['recaptcha_response_field']); return $result->isValid(); } }
public function addReCaptcha($form) { $config = Zend_Registry::get("config"); $publickey = $config->recaptcha->public->key; $privatekey = $config->recaptcha->private->key; $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey); //Translate in your language $recaptcha_cn_translation = array('visual_challenge' => "图片验证", 'audio_challenge' => "音频验证", 'refresh_btn' => "看不清,换一张", 'instructions_visual' => "图片验证说明", 'instructions_audio' => "音频验证说明", 'help_btn' => "帮助", 'play_again' => "重放", 'cant_hear_this' => "听不到? 点这里", 'incorrect_try_again' => "验证码错误!"); $recaptcha->setOption('custom_translations', $recaptcha_cn_translation); //Change theme $recaptcha->setOption('theme', 'clean'); $captcha = new Zend_Form_Element_Captcha('challenge', array('captcha' => 'ReCaptcha', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha), 'ignore' => false)); $captcha->setRequired(true); $form->addElement($captcha); }
public function getHtml() { if (Mage::getStoreConfig('webforms/captcha/api') != 'ajax') { return parent::getHtml(); } $return = ""; $div_id = "webform_recaptcha"; if (Mage::registry('webform')) { $div_id = "webform_" . Mage::registry('webform')->getId() . "_recaptcha"; } $return .= <<<HTML \t\t<div id="{$div_id}"></div> HTML; $return .= <<<SCRIPT <script type="text/javascript" src="https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script> SCRIPT; if (!empty($this->_options)) { $encoded = Zend_Json::encode($this->_options); } $return .= <<<SCRIPT <script type="text/javascript"> \tRecaptcha.create("{$this->_publicKey}", "{$div_id}", {$encoded}); </script> SCRIPT; return $return; }
public function init() { $this->setMethod('post'); //Add your elements here... $config = Zend_Registry::get("config"); $publickey = $config->recaptcha->public->key; $privatekey = $config->recaptcha->private->key; $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey); //Translate in your language $recaptcha_it_translation = array('visual_challenge' => "Verifica video", 'audio_challenge' => "Verifica audio", 'refresh_btn' => "Effettua una nuova verifica", 'instructions_visual' => "Scrivi le due parole", 'instructions_audio' => "Scrivi quello che ascolti", 'help_btn' => "Aiuto", 'play_again' => "Riascolto di nuovo l'audio", 'cant_hear_this' => "Scarica l'audio come MP3", 'incorrect_try_again' => "Incorretto. Prova ancora."); $recaptcha->setOption('custom_translations', $recaptcha_it_translation); //Change theme $recaptcha->setOption('theme', 'clean'); $captcha = new Zend_Form_Element_Captcha('challenge', array('captcha' => 'ReCaptcha', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha), 'ignore' => true)); $this->addElement($captcha); // Add the submit button $this->addElement('submit', 'submit', array('label' => 'Submit')); }
/** * Determines if CAPTCHA is valid (passed). * * @see XenForo_Captcha_Abstract::isValid() */ public function isValid(array $input) { if (!$this->_config['privateKey'] || !$this->_config['publicKey']) { return true; // if not configured, always pass } if (empty($input['recaptcha_challenge_field']) || empty($input['recaptcha_response_field'])) { return false; } try { $recaptcha = new Zend_Service_ReCaptcha($this->_config['publicKey'], $this->_config['privateKey']); $result = $recaptcha->verify($input['recaptcha_challenge_field'], $input['recaptcha_response_field']); return $result->isValid(); } catch (Zend_Http_Client_Adapter_Exception $e) { // this is an exception with the underlying request, so let it go through XenForo_Error::logException($e, false); return true; } }
/** * Get captcha display box using Zend_Service_ReCaptcha api * @access public * @return Zend_Service_ReCaptcha */ public function getRecaptcha() { $option = Zend_Registry::get('option'); // add secure image using ReCaptcha $recaptcha = new Zend_Service_ReCaptcha($option->captchaOptions->recaptchaPublicKey, $option->captchaOptions->recaptchaPrivateKey); $recaptcha->setOptions($option->captchaOptions->toArray()); return $recaptcha; }
public function testAction() { /* $form = new ReCaptcha(); $this->view->form = $form; if ($this->_request->isPost()) { $config = Zend_Registry::get("config"); $publickey = $config->recaptcha->public->key; $privatekey = $config->recaptcha->private->key; $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey); $result = $recaptcha->verify($this->_getParam('recaptcha_challenge_field'), $this->_getParam('recaptcha_response_field')); print_r($result); if ($result->isValid()){ echo "right"; } else { echo "wrong"; } }*/ $form = new ReCaptcha(); $this->view->form = $form; if ($this->_request->isPost()) { //if ($form->isValidPartial ( $_POST )) { $config = Zend_Registry::get("config"); $publickey = $config->recaptcha->public->key; $privatekey = $config->recaptcha->private->key; $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey); $result = $recaptcha->verify($this->_getParam('recaptcha_challenge_field'), $this->_getParam('recaptcha_response_field')); print_r($result); $isValid = $this->_helper->common->validReCaptcha($this->_getAllParams()); if (!$isValid) { echo "adfa"; //ReCaptcha validation error //Your action here... } else { echo "right"; } //} } }
protected function _testVerifyOffline() { $adapter = new Zend_Http_Client_Adapter_Test(); $client = new Zend_Http_Client(null, array('adapter' => $adapter)); Zend_Service_ReCaptcha::setHttpClient($client); $resp = $this->_reCaptcha->verify('challengeField', 'responseField'); // See if we have a valid object and that the status is false $this->assertTrue($resp instanceof Zend_Service_ReCaptcha_Response); $this->assertFalse($resp->getStatus()); }
/** * Generate new recaptcha * * @static * @return recaptcha code */ public static function generateRecaptcha($captchaTheme = 'red', $captchaId = null) { $websiteConfig = Zend_Controller_Action_HelperBroker::getExistingHelper('config')->getConfig(); if (!empty($websiteConfig) && !empty($websiteConfig[self::RECAPTCHA_PUBLIC_KEY]) && !empty($websiteConfig[self::RECAPTCHA_PRIVATE_KEY])) { $options = array('theme' => $captchaTheme); $params = null; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") { $params = array('ssl' => Zend_Controller_Front::getInstance()->getRequest()->isSecure(), 'error' => null, 'xhtml' => false); } if (null !== $captchaId) { $options['custom_theme_widget'] = $captchaId; } $recaptcha = new Zend_Service_ReCaptcha($websiteConfig[self::RECAPTCHA_PUBLIC_KEY], $websiteConfig[self::RECAPTCHA_PRIVATE_KEY], $params, $options); return $recaptcha->getHTML(); } return false; }
public function receiveformAction() { if ($this->getRequest()->isPost()) { $xmlHttpRequest = $this->_request->isXmlHttpRequest(); $formParams = $this->getRequest()->getParams(); $sessionHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Session'); if (!empty($formParams)) { $websiteConfig = Zend_Controller_Action_HelperBroker::getExistingHelper('config')->getConfig(); $formMapper = Application_Model_Mappers_FormMapper::getInstance(); // get the form details $form = $formMapper->findByName($formParams['formName']); $useCaptcha = $form->getCaptcha(); //hidden input validation $formName = $form->getName(); $formId = $form->getId(); if (!isset($formParams[md5($formName . $formId)]) || $formParams[md5($formName . $formId)] != '') { if ($xmlHttpRequest) { $this->_helper->response->success($form->getMessageSuccess()); } $this->_redirect($formParams['formUrl']); } unset($formParams[md5($formName . $formId)]); //validating recaptcha if ($useCaptcha == 1) { if (!empty($websiteConfig) && !empty($websiteConfig[Tools_System_Tools::RECAPTCHA_PUBLIC_KEY]) && !empty($websiteConfig[Tools_System_Tools::RECAPTCHA_PRIVATE_KEY]) && isset($formParams['recaptcha_challenge_field']) || isset($formParams['captcha'])) { if (isset($formParams['recaptcha_challenge_field']) && isset($formParams['recaptcha_response_field'])) { if ($formParams['recaptcha_response_field'] == '') { if ($xmlHttpRequest) { $this->_helper->response->fail($this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.')); } $sessionHelper->toasterFormError = $this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.'); $this->_redirect($formParams['formUrl']); } $recaptcha = new Zend_Service_ReCaptcha($websiteConfig[Tools_System_Tools::RECAPTCHA_PUBLIC_KEY], $websiteConfig[Tools_System_Tools::RECAPTCHA_PRIVATE_KEY]); $result = $recaptcha->verify($formParams['recaptcha_challenge_field'], $formParams['recaptcha_response_field']); if (!$result->isValid()) { if ($xmlHttpRequest) { $this->_helper->response->fail($this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.')); } $sessionHelper->toasterFormError = $this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.'); $this->_redirect($formParams['formUrl']); } unset($formParams['recaptcha_challenge_field']); unset($formParams['recaptcha_response_field']); } else { //validating captcha if (!$this->_validateCaptcha(strtolower($formParams['captcha']), $formParams['captchaId'])) { if ($xmlHttpRequest) { $this->_helper->response->fail($this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.')); } $sessionHelper->toasterFormError = $this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.'); $this->_redirect($formParams['formUrl']); } } } else { if ($xmlHttpRequest) { $this->_helper->response->fail($this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.')); } $sessionHelper->toasterFormError = $this->_helper->language->translate('You\'ve entered an incorrect security text. Please try again.'); $this->_redirect($formParams['formUrl']); } } $sessionHelper->formName = $formParams['formName']; $sessionHelper->formPageId = $formParams['formPageId']; unset($formParams['formPageId']); unset($formParams['submit']); if (isset($formParams['conversionPageUrl'])) { $conversionPageUrl = $formParams['conversionPageUrl']; unset($formParams['conversionPageUrl']); } $attachment = array(); if (!$xmlHttpRequest) { //Adding attachments to email $websitePathTemp = $this->_helper->website->getPath() . $this->_helper->website->getTmp(); $uploader = new Zend_File_Transfer_Adapter_Http(); $uploader->setDestination($websitePathTemp); $uploader->addValidator('Extension', false, self::ATTACHMENTS_FILE_TYPES); //Adding Size limitation $uploader->addValidator('Size', false, $formParams['uploadLimitSize'] * 1024 * 1024); //Adding mime types validation $uploader->addValidator('MimeType', true, array('application/pdf', 'application/xml', 'application/zip', 'text/csv', 'text/plain', 'image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'application/msword', 'application/vnd.ms-excel')); $files = $uploader->getFileInfo(); foreach ($files as $file => $fileInfo) { if ($fileInfo['name'] != '') { if ($uploader->isValid($file)) { $uploader->receive($file); $at = new Zend_Mime_Part(file_get_contents($uploader->getFileName($file))); $at->type = $uploader->getMimeType($file); $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $at->encoding = Zend_Mime::ENCODING_BASE64; $at->filename = $fileInfo['name']; $attachment[] = $at; unset($at); Tools_Filesystem_Tools::deleteFile($this->_helper->website->getPath() . $this->_helper->website->getTmp() . $fileInfo['name']); } else { $validationErrors = $uploader->getErrors(); $errorMessage = ''; foreach ($validationErrors as $errorType) { if ($errorType == 'fileMimeTypeFalse') { $errorMessage .= 'Invalid file format type. '; } if ($errorType == 'fileSizeTooBig') { $errorMessage .= $this->_helper->language->translate('Maximum size upload') . ' ' . $formParams['uploadLimitSize'] . 'mb.'; } if ($errorType == 'fileExtensionFalse') { $errorMessage .= 'File extension not valid. '; } } $sessionHelper->toasterFormError = $this->_helper->language->translate($errorMessage); $this->_redirect($formParams['formUrl']); } } } } unset($formParams['uploadLimitSize']); // sending mails $sysMailWatchdog = new Tools_Mail_SystemMailWatchdog(array('trigger' => Tools_Mail_SystemMailWatchdog::TRIGGER_FORMSENT, 'data' => $formParams, 'attachment' => $attachment)); $mailWatchdog = new Tools_Mail_Watchdog(array('trigger' => Tools_Mail_SystemMailWatchdog::TRIGGER_FORMSENT, 'data' => $formParams, 'attachment' => $attachment)); $mailWatchdog->notify($form); $mailsSent = $sysMailWatchdog->notify($form); if ($mailsSent) { $form->notifyObservers(); if ($xmlHttpRequest) { $this->_helper->response->success($form->getMessageSuccess()); } //redirect to conversion page if ($conversionPageUrl) { $this->_redirect($conversionPageUrl); } $sessionHelper->toasterFormSuccess = $form->getMessageSuccess(); $this->_redirect($formParams['formUrl']); } if ($xmlHttpRequest) { $this->_helper->response->fail($form->getMessageError()); } $sessionHelper->toasterFormError = $form->getMessageError(); $this->_redirect($formParams['formUrl']); } } }
<?php require_once 'library.php'; $errors = array(); try { $public_key = '6LfeneMSAAAAAK3fEbrQNNJGr93eGrRXfehA-tGs'; $private_key = '6LfeneMSAAAAABRYmV5zuUe9AO4i9wppVJAclRlM'; $recaptcha = new Zend_Service_ReCaptcha($public_key, $private_key); if (isset($_POST['send'])) { // validate the user input // if (empty($_POST['recaptcha_response_field'])) { $errors['recaptcha'] = 'reCAPTCHA field is required'; } else { $result = $recaptcha->verify($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); if (!$result->isValid()) { $errors['recaptcha'] = 'Try again'; } } // Validate nmae // $val = new Zend_Validate_Alnum(TRUE); if (!$val->isValid($_POST['name'])) { $errors['name'] = 'Name is required'; } // Validate email address // $val = new Zend_Validate_EmailAddress(); if (!$val->isValid($_POST['email'])) { $errors['email'] = 'Email address is required'; }
public function testVerify() { $this->_reCaptcha->setPublicKey($this->_publicKey); $this->_reCaptcha->setPrivateKey($this->_privateKey); $this->_reCaptcha->setIp('127.0.0.1'); $adapter = new Zend_Http_Client_Adapter_Test(); $client = new Zend_Http_Client(null, array('adapter' => $adapter)); Zend_Service_ReCaptcha::setHttpClient($client); // Set a header that will be reset in the recaptcha class before sending the request $client->setHeaders('host', 'example.com'); $resp = $this->_reCaptcha->verify('challengeField', 'responseField'); $this->assertNotSame('example.com', $client->getHeader('host')); // See if we have a valid object and that the status is false $this->assertTrue($resp instanceof Zend_Service_ReCaptcha_Response); $this->assertFalse($resp->getStatus()); }
/** * Override the setPrivateKey method * * Override the parent method to store a binary representation of the private key as well. * * @param string $privateKey * @return Zend_Service_ReCaptcha_MailHide */ public function setPrivateKey($privateKey) { parent::setPrivateKey($privateKey); /* Pack the private key into a binary string */ $this->_privateKeyPacked = pack('H*', $this->_privateKey); return $this; }
public function spamAction() { // Get navigation $this->view->navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('core_admin_banning', array(), 'core_admin_banning_general'); // Get form $this->view->form = $form = new Core_Form_Admin_Settings_Spam(); // Get db $db = Engine_Db_Table::getDefaultAdapter(); // Populate some settings $settings = Engine_Api::_()->getApi('settings', 'core'); $config = (array) $settings->core_spam; // Load all IPs $bannedIpsTable = Engine_Api::_()->getDbtable('BannedIps', 'core'); $bannedIps = array(); foreach ($bannedIpsTable->getAddresses() as $bannedIp) { if (is_array($bannedIp)) { $bannedIps[] = join(' - ', $bannedIp); } else { if (is_string($bannedIp)) { $bannedIps[] = $bannedIp; } } } $config['bannedips'] = join("\n", $bannedIps); // Load all emails $bannedEmailsTable = Engine_Api::_()->getDbtable('BannedEmails', 'core'); $bannedEmails = $bannedEmailsTable->getEmails(); $config['bannedemails'] = join("\n", $bannedEmails); // Load all usernames $bannedUsernamesTable = Engine_Api::_()->getDbtable('BannedUsernames', 'core'); $bannedUsernames = $bannedUsernamesTable->getUsernames(); $config['bannedusernames'] = join("\n", $bannedUsernames); // Load all words $bannedWordsTable = Engine_Api::_()->getDbtable('BannedWords', 'core'); $bannedWords = $bannedWordsTable->getWords(); $config['bannedwords'] = join("\n", $bannedWords); // Populate if (_ENGINE_ADMIN_NEUTER) { $config['recaptchapublic'] = '**********'; $config['recaptchaprivate'] = '**********'; } $form->populate($config); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } // Process $db = Engine_Api::_()->getDbtable('settings', 'core')->getAdapter(); $db->beginTransaction(); $values = $form->getValues(); // Build banned IPs $bannedIpsNew = preg_split('/\\s*[,\\n]+\\s*/', $values['bannedips']); foreach ($bannedIpsNew as &$bannedIpNew) { if (false !== strpos($bannedIpNew, '-')) { $bannedIpNew = preg_split('/\\s*-\\s*/', $bannedIpNew, 2); } else { if (false != strpos($bannedIpNew, '*')) { $tmp = $bannedIpNew; if (false != strpos($tmp, ':')) { $bannedIpNew = array(str_replace('*', '0', $tmp), str_replace('*', 'ffff', $tmp)); } else { $bannedIpNew = array(str_replace('*', '0', $tmp), str_replace('*', '255', $tmp)); } } } } // Check if they are banning their own address if ($bannedIpsTable->isAddressBanned(Engine_IP::getRealRemoteAddress(), $bannedIpsTable->normalizeAddressArray($bannedIpsNew))) { return $form->addError('One of the IP addresses or IP address ranges you entered contains your own IP address.'); } if (!empty($values['recaptchapublic']) && !empty($values['recaptchaprivate'])) { $recaptcha = new Zend_Service_ReCaptcha($values['recaptchapublic'], $values['recaptchaprivate']); try { $resp = $recaptcha->verify('test', 'test'); // if( false === stripos($resp, 'error') ) { // return $form->addError('ReCaptcha Key Invalid: ' . $resp); // } if (in_array($err = $resp->getErrorCode(), array('invalid-site-private-key', 'invalid-site-public-key'))) { return $form->addError('ReCaptcha Error: ' . $err); } // Validate public key $httpClient = new Zend_Http_Client(); $httpClient->setUri('http://www.google.com/recaptcha/api/challenge'); $httpClient->setParameterGet('k', $values['recaptchapublic']); $resp = $httpClient->request('GET'); if (false !== stripos($resp->getBody(), 'Input error')) { return $form->addError('ReCaptcha Error: ' . str_replace(array("document.write('", "\\n');"), array('', ''), $resp->getBody())); } } catch (Exception $e) { return $form->addError('ReCaptcha Key Invalid: ' . $e->getMessage()); } $values['recaptchaenabled'] = true; } else { $values['recaptchaenabled'] = false; } try { if (!empty($bannedIpNew)) { // Save Banned IPs $bannedIpsTable->setAddresses($bannedIpsNew); unset($values['bannedips']); } // Save Banned Emails $bannedEmailsNew = preg_split('/\\s*[,\\n]+\\s*/', $values['bannedemails']); $bannedEmailsTable->setEmails($bannedEmailsNew); unset($values['bannedemails']); // Save Banned Usernames $bannedUsernamesNew = preg_split('/\\s*[,\\n]+\\s*/', $values['bannedusernames']); $bannedUsernamesTable->setUsernames($bannedUsernamesNew); unset($values['bannedusernames']); // Save Banned Words $bannedWordsNew = preg_split('/\\s*[,\\n]+\\s*/', $values['bannedwords']); $bannedWordsTable->setWords($bannedWordsNew); unset($values['bannedwords']); // Save other settings $settings->core_spam = $values; $db->commit(); $form->addNotice('Your changes have been saved.'); } catch (Exception $e) { $db->rollback(); throw $e; } }