コード例 #1
0
 /**
  * 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();
     }
 }
コード例 #2
0
ファイル: ReCaptcha.php プロジェクト: hahuunguyen/DTUI_201105
 /**
  * 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;
     }
 }
コード例 #3
0
 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";
         }
         //}
     }
 }
コード例 #4
0
 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;
     }
 }
コード例 #5
0
 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']);
         }
     }
 }
コード例 #6
0
ファイル: process_comments.php プロジェクト: colasad/code
<?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';
        }