Ejemplo n.º 1
0
 /**
  * Get Answer from given field out of Mail object
  *
  * @param \In2code\Powermail\Domain\Model\Field $field
  * @param \In2code\Powermail\Domain\Model\Mail $mail
  * @return \string Answer value
  */
 protected function getAnswerFromField($field, $mail)
 {
     foreach ($mail->getAnswers() as $answer) {
         if ($answer->getField()->getUid() == $field->getUid()) {
             return $answer->getValue();
         }
     }
     return '';
 }
Ejemplo n.º 2
0
 /**
  * Get Answer from given field out of Mail object
  *
  * @param Field $field
  * @param Mail $mail
  * @return string Answer value
  */
 protected function getAnswerFromField(Field $field, Mail $mail)
 {
     foreach ($mail->getAnswers() as $answer) {
         /** @var Answer $answer */
         if ($answer->getField() === $field) {
             return $answer->getValue();
         }
     }
     return '';
 }
 /**
  * Validation of given Params
  *
  * @param Mail $mail
  * @return bool
  */
 public function isValid($mail)
 {
     if (!$this->formHasPassword($mail->getForm()) || $this->ignoreValidationIfConfirmation()) {
         return true;
     }
     foreach ($mail->getAnswers() as $answer) {
         if ($answer->getField()->getType() !== 'password') {
             continue;
         }
         if ($answer->getValue() !== $this->getMirroredValueOfPasswordField($answer->getField())) {
             $this->setErrorAndMessage($answer->getField(), 'password');
         }
     }
     return $this->isValidState();
 }
Ejemplo n.º 4
0
 /**
  * @param \In2code\Powermail\Domain\Model\Mail $mail
  * @param \In2code\Powermail\Domain\Validator\CustomValidator $object
  */
 public function isValid($mail, $object)
 {
     $answers = $mail->getAnswers();
     $powermailVars = GeneralUtility::_GP('tx_powermail_pi1');
     /** @var \In2code\Powermail\Domain\Model\Answer $answer */
     foreach ($answers as $answer) {
         $field = $answer->getField();
         if ($field->getType() == 'recaptcha') {
             /*
              * Response will be token if valid, an empty string when not valid
              * When the previous step doesn't contain the recaptcha, NULL is
              * returned
              */
             $response = GeneralUtility::_GP('g-recaptcha-response');
             if ($response !== NULL) {
                 // Only check if a response is set
                 /** @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager configurationManager */
                 $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
                 $fullTs = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
                 $reCaptchaSettings = $fullTs['plugin.']['tx_powermail.']['settings.']['setup.']['reCAPTCHA.'];
                 if (isset($reCaptchaSettings) && is_array($reCaptchaSettings) && isset($reCaptchaSettings['secretKey']) && $reCaptchaSettings['secretKey']) {
                     $ch = curl_init();
                     $fields = array('secret' => $reCaptchaSettings['secretKey'], 'response' => $response);
                     //url-ify the data for the POST
                     $fieldsString = '';
                     foreach ($fields as $key => $value) {
                         $fieldsString .= $key . '=' . $value . '&';
                     }
                     rtrim($fieldsString, '&');
                     //set the url, number of POST vars, POST data
                     curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
                     curl_setopt($ch, CURLOPT_POST, count($fields));
                     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                     curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
                     //execute post
                     $result = json_decode(curl_exec($ch));
                     if (!(bool) $result->success) {
                         $object->setErrorAndMessage($field, LocalizationUtility::translate('validation.possible_robot', 'rhrecaptcha'));
                     }
                 } else {
                     throw new InvalidVariableException(LocalizationUtility::translate('error.no_secretKey', 'rhrecaptcha'), 1358349150);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Checks if two email-addresses are equal
  *
  * @param \In2code\Powermail\Domain\Model\Mail $mail
  * @param \In2code\Powermail\Domain\Validator\AbstractValidator $validator
  */
 public function checkEmails(\In2code\Powermail\Domain\Model\Mail $mail, \In2code\Powermail\Domain\Validator\AbstractValidator $validator)
 {
     $checkEmailEqualFirstId = '';
     $checkEmailEqualSecondId = '';
     if ($this->settings['checkEmailEqual'] && $this->settings['checkEmailEqualFirstId'] && $this->settings['checkEmailEqualSecondId']) {
         /** @var \In2code\Powermail\Domain\Model\Answer $answer */
         foreach ($mail->getAnswers() as $answer) {
             if ($answer->getField()->getUid() == $this->settings['checkEmailEqualFirstId']) {
                 $checkEmailEqualFirstId = $answer->getValue();
             } elseif ($answer->getField()->getUid() == $this->settings['checkEmailEqualSecondId']) {
                 $checkEmailEqualSecondId = $answer->getValue();
             }
         }
         if ($checkEmailEqualFirstId !== $checkEmailEqualSecondId) {
             $validator->setIsValid(false);
         }
     }
 }
 /**
  * Validation of given Params
  *
  * @param Mail $mail
  * @return bool
  */
 public function isValid($mail)
 {
     if ($this->formHasCaptcha($mail->getForm())) {
         foreach ($mail->getAnswers() as $answer) {
             /** @var Answer $answer */
             if ($answer->getField()->getType() === 'captcha') {
                 $this->setCaptchaArgument(true);
                 if (!$this->validCodePreflight($answer->getValue(), $answer->getField())) {
                     $this->setErrorAndMessage($answer->getField(), 'captcha');
                 }
             }
         }
         // if no captcha arguments given (maybe deleted from DOM)
         if (!$this->hasCaptchaArgument()) {
             $this->addError('captcha', 0);
             $this->setValidState(false);
         }
     }
     return $this->isValidState();
 }
 /**
  * Validation of given Mail Params
  *
  * @param \In2code\Powermail\Domain\Model\Mail $mail
  * @return bool
  */
 public function isValid($mail)
 {
     foreach ($mail->getAnswers() as $answer) {
         if ($answer->getValueType() === 3) {
             if (!is_array($answer->getValue())) {
                 continue;
             }
             foreach ($answer->getValue() as $value) {
                 if (!BasicFileUtility::checkExtension($value, $this->settings['misc.']['file.']['extension'])) {
                     $this->setErrorAndMessage($answer->getField(), 'upload_extension');
                     continue;
                 }
                 if (!BasicFileUtility::checkFilesize($value, $this->settings)) {
                     $this->setErrorAndMessage($answer->getField(), 'upload_size');
                     continue;
                 }
             }
         }
     }
     return $this->isValidState();
 }
Ejemplo n.º 8
0
 /**
  * Validation process
  *
  * @param Mail $mail
  * @return Result
  */
 public function validate($mail)
 {
     $this->emailFieldMarkerArray = GeneralUtility::trimExplode(',', $this->configuration['emailMarker'], true);
     $this->confirmEmailFieldMarkerArray = GeneralUtility::trimExplode(',', $this->configuration['emailConfirmMarker'], true);
     $result = new Result();
     foreach ($mail->getAnswers() as $answer) {
         if (in_array($answer->getField()->getMarker(), $this->emailFieldMarkerArray)) {
             $emailMarker = $answer->getField()->getMarker();
             $email = $answer->getValue();
         }
         if (in_array($answer->getField()->getMarker(), $this->confirmEmailFieldMarkerArray)) {
             $confirmEmailMarker = $answer->getField()->getMarker();
             $confirmEmail = $answer->getValue();
         }
     }
     if ($email && $confirmEmail && $emailMarker && $confirmEmailMarker && $email !== $confirmEmail) {
         $result->addError(new Error(LocalizationUtility::translate('validation_email_match', 't3ecom'), $confirmEmailMarker));
         $result->addError(new Error(LocalizationUtility::translate('validation_email_match', 't3ecom'), $emailMarker));
     }
     return $result;
 }
 /**
  * Validation of given Params
  *
  * @param Mail $mail
  * @return bool
  */
 public function isValid($mail)
 {
     if (empty($this->settings['validation.']['unique.'])) {
         return $this->isValidState();
     }
     foreach ($this->settings['validation.']['unique.'] as $marker => $amount) {
         if ((int) $amount === 0) {
             continue;
         }
         foreach ($mail->getAnswers() as $answer) {
             /** @var Answer $answer */
             if ($answer->getField()->getMarker() === $marker) {
                 $numberOfMails = $this->mailRepository->findByMarkerValueForm($marker, $answer->getValue(), $mail->getForm(), FrontendUtility::getStoragePage($this->getStoragePid()))->count();
                 if ($amount <= $numberOfMails) {
                     $this->setErrorAndMessage($answer->getField(), 'unique');
                 }
             }
         }
     }
     return $this->isValidState();
 }
Ejemplo n.º 10
0
 /**
  * Validation of given Params
  *
  * @param \In2code\Powermail\Domain\Model\Mail $mail
  * @return bool
  */
 public function isValid($mail)
 {
     if (!$this->formHasCaptcha($mail->getForm())) {
         return TRUE;
     }
     foreach ($mail->getAnswers() as $answer) {
         if ($answer->getField()->getType() !== 'captcha') {
             continue;
         }
         $this->captchaArgumentFound = TRUE;
         if (!$this->captchaEngine->validCode($answer->getValue(), $this->clearSession)) {
             $this->setErrorAndMessage($answer->getField(), 'captcha');
         }
     }
     // if no captcha arguments given (maybe deleted from DOM)
     if (!$this->captchaArgumentFound) {
         $this->addError('captcha', 0);
         $this->setIsValid(FALSE);
     }
     return $this->getIsValid();
 }
Ejemplo n.º 11
0
 /**
  * Add attachments from upload fields
  *
  * @param MailMessage $message
  * @return MailMessage
  */
 protected function addAttachmentsFromUploads(MailMessage $message)
 {
     if (empty($this->settings[$this->type]['attachment']) || empty($this->settings['misc']['file']['folder'])) {
         return $message;
     }
     /** @var Answer $answer */
     foreach ($this->mail->getAnswers() as $answer) {
         $values = $answer->getValue();
         if ($answer->getValueType() === 3 && is_array($values) && !empty($values)) {
             foreach ($values as $value) {
                 $file = GeneralUtility::getFileAbsFileName(BasicFileUtility::addTrailingSlash($this->settings['misc']['file']['folder']) . $value);
                 if (file_exists($file)) {
                     $message->attach(\Swift_Attachment::fromPath($file));
                 } else {
                     GeneralUtility::devLog('Error: File to attach does not exist', 'powermail', 2, $file);
                 }
             }
         }
     }
     return $message;
 }
Ejemplo n.º 12
0
 /**
  * Returns sendername from a couple of arguments
  *
  * @param Mail $mail Given Params
  * @param string|array $default String as default or cObject array
  * @param string $glue
  * @return string Sender Name
  */
 public function getSenderNameFromArguments(Mail $mail, $default = null, $glue = ' ')
 {
     $name = '';
     foreach ($mail->getAnswers() as $answer) {
         if (method_exists($answer->getField(), 'getUid') && $answer->getField()->getSenderName()) {
             if (!is_array($answer->getValue())) {
                 $value = $answer->getValue();
             } else {
                 $value = implode($glue, $answer->getValue());
             }
             $name .= $value . $glue;
         }
     }
     if (!trim($name) && $default) {
         if (!is_array($default)) {
             $name = $default;
         } else {
             /** @var ContentObjectRenderer $contentObject */
             $contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
             $name = $contentObject->cObjGetSingle($default[0][$default[1]], $default[0][$default[1] . '.']);
         }
     }
     if (empty($name) && !empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'])) {
         $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
     }
     if (!trim($name)) {
         $name = LocalizationUtility::translate('error_no_sender_name');
     }
     return trim($name);
 }
 /**
  * Blacklist String Check: Check if a blacklisted word is in given values
  *
  * @param Mail $mail
  * @param float $indication Indication if check fails
  * @return void
  */
 protected function blacklistStringCheck(Mail $mail, $indication = 1.0)
 {
     if (!$indication) {
         return;
     }
     $blacklist = GeneralUtility::trimExplode(',', $this->settings['spamshield.']['indicator.']['blacklistStringValues'], true);
     foreach ($mail->getAnswers() as $answer) {
         if (is_array($answer->getValue())) {
             continue;
         }
         foreach ((array) $blacklist as $blackword) {
             if ($this->findStringInString($answer->getValue(), $blackword)) {
                 $this->increaseSpamIndicator($indication);
                 $this->addMessage(__FUNCTION__ . ' failed');
                 return;
             }
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * Blacklist String Check: Check if a blacklisted word is in given values
  *
  * @param \In2code\Powermail\Domain\Model\Mail $mail
  * @param float $indication Indication if check fails
  * @return void
  */
 protected function blacklistStringCheck(\In2code\Powermail\Domain\Model\Mail $mail, $indication = 1.0)
 {
     if (!$indication) {
         return;
     }
     $blacklist = GeneralUtility::trimExplode(',', $this->settings['spamshield.']['indicator.']['blacklistStringValues'], TRUE);
     // if check failes
     foreach ($mail->getAnswers() as $answer) {
         if (is_array($answer->getValue())) {
             continue;
         }
         foreach ((array) $blacklist as $blackword) {
             if (stristr($answer->getValue(), $blackword)) {
                 $this->increaseSpamIndicator($indication);
                 $this->addMessage(__FUNCTION__ . ' failed');
                 return;
             }
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Returns sendername from a couple of arguments
  *
  * @param Mail $mail Given Params
  * @param string|array $default String as default or cObject array
  * @param string $glue
  * @return string Sender Name
  */
 public function getSenderNameFromArguments(Mail $mail, $default = null, $glue = ' ')
 {
     $name = '';
     foreach ($mail->getAnswers() as $answer) {
         /** @var Answer $answer */
         if (method_exists($answer->getField(), 'getUid') && $answer->getField()->isSenderName()) {
             if (!is_array($answer->getValue())) {
                 $value = $answer->getValue();
             } else {
                 $value = implode($glue, $answer->getValue());
             }
             $name .= $value . $glue;
         }
     }
     if (!trim($name) && $default) {
         if (!is_array($default)) {
             $name = $default;
         } else {
             /** @var ContentObjectRenderer $contentObject */
             $contentObject = GeneralUtility::makeInstance(ObjectManager::class)->get(ContentObjectRenderer::class);
             $name = $contentObject->cObjGetSingle($default[0][$default[1]], $default[0][$default[1] . '.']);
         }
     }
     if (empty($name) && !empty(ConfigurationUtility::getDefaultMailFromName())) {
         $name = ConfigurationUtility::getDefaultMailFromName();
     }
     if (!trim($name)) {
         $name = LocalizationUtility::translate('error_no_sender_name');
     }
     return trim($name);
 }
Ejemplo n.º 16
0
 /**
  * Get value for multi fieldtypes (checkbox, radio)
  *
  * @param \In2code\Powermail\Domain\Model\Field $field
  * @param \In2code\Powermail\Domain\Model\Mail $mail To prefill in Edit Action
  * @param \int $cycle Cycle Number (1,2,3...) - if filled checkbox or radiobutton
  * @return string
  */
 protected function getMultiValue(\In2code\Powermail\Domain\Model\Field $field, \In2code\Powermail\Domain\Model\Mail $mail = NULL, $cycle = 0)
 {
     $marker = $field->getMarker();
     $uid = $field->getUid();
     $selected = 0;
     $index = $cycle - 1;
     $options = $field->getModifiedSettings();
     // edit view
     if ($mail !== NULL && $mail->getAnswers()) {
         foreach ($mail->getAnswers() as $answer) {
             if ($answer->getField() === $field) {
                 $values = $answer->getValue();
                 foreach ((array) $values as $value) {
                     if ($value === $options[$index]['value'] || $value === $options[$index]['label']) {
                         $selected = 1;
                     }
                 }
             }
         }
     }
     // if GET/POST with marker (&tx_powermail_pi1[field][marker][index]=value)
     if (isset($this->piVars['field'][$marker]) && is_array($this->piVars['field'][$marker])) {
         foreach (array_keys($this->piVars['field'][$marker]) as $key) {
             if ($this->piVars['field'][$marker][$key] === $options[$index]['value'] || $this->piVars['field'][$marker][$key] === $options[$index]['label']) {
                 $selected = 1;
             }
         }
     } elseif (isset($this->piVars['field'][$marker])) {
         if ($this->piVars['field'][$marker] == $options[$index]['value'] || $this->piVars['field'][$marker] == $options[$index]['label']) {
             $selected = 1;
         }
     } elseif (isset($this->piVars[$marker]) && is_array($this->piVars[$marker])) {
         foreach (array_keys($this->piVars[$marker]) as $key) {
             if ($this->piVars[$marker][$key] === $options[$index]['value'] || $this->piVars[$marker][$key] === $options[$index]['label']) {
                 $selected = 1;
             }
         }
     } elseif (isset($this->piVars[$marker])) {
         if ($this->piVars[$marker] == $options[$index]['value'] || $this->piVars[$marker] == $options[$index]['label']) {
             $selected = 1;
         }
     } elseif (isset($this->piVars['field'][$uid])) {
         if (is_array($this->piVars['field'][$uid])) {
             foreach ($this->piVars['field'][$uid] as $key => $value) {
                 $value = NULL;
                 if ($this->piVars['field'][$uid][$key] == $options[$index]['value'] || $this->piVars['field'][$uid][$key] == $options[$index]['label']) {
                     $selected = 1;
                 }
             }
         } else {
             if ($this->piVars['field'][$uid] == $options[$index]['value'] || $this->piVars['field'][$uid] == $options[$index]['label']) {
                 $selected = 1;
             }
         }
     } elseif (isset($this->piVars['uid' . $uid])) {
         if ($this->piVars['uid' . $uid] == $options[$index]['value'] || $this->piVars['uid' . $uid] == $options[$index]['label']) {
             $selected = 1;
         }
     } elseif ($field->getFeuserValue() && intval($GLOBALS['TSFE']->fe_user->user['uid']) !== 0) {
         // if fe_user is logged in
         if ($GLOBALS['TSFE']->fe_user->user[$field->getFeuserValue()] == $options[$index]['value'] || $GLOBALS['TSFE']->fe_user->user[$field->getFeuserValue()] == $options[$index]['label']) {
             $selected = 1;
         }
     } elseif ($options[$index]['selected']) {
         $selected = 1;
     } elseif (isset($this->settings['prefill.'][$marker]) || isset($this->settings['prefill.'][$marker . '.'])) {
         if (isset($this->settings['prefill.'][$marker . '.']) && is_array($this->settings['prefill.'][$marker . '.'])) {
             $data = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettableProperties($field);
             $this->cObj->start($data);
             if (isset($this->settings['prefill.'][$marker . '.']['0'])) {
                 /**
                  * plugin.tx_powermail.settings.setup.prefill.marker.0 = TEXT
                  * plugin.tx_powermail.settings.setup.prefill.marker.0.value = red
                  */
                 foreach (array_keys($this->settings['prefill.'][$marker . '.']) as $key) {
                     if (stristr($key, '.')) {
                         continue;
                     }
                     $prefill = $this->cObj->cObjGetSingle($this->settings['prefill.'][$marker . '.'][$key], $this->settings['prefill.'][$marker . '.'][$key . '.']);
                     if ($prefill == $options[$index]['value'] || $prefill == $options[$index]['label']) {
                         $selected = 1;
                     }
                 }
             } else {
                 /**
                  * plugin.tx_powermail.settings.setup.prefill.marker = TEXT
                  * plugin.tx_powermail.settings.setup.prefill.marker.value = red
                  */
                 $prefill = $this->cObj->cObjGetSingle($this->settings['prefill.'][$marker], $this->settings['prefill.'][$marker . '.']);
                 if ($prefill == $options[$index]['value'] || $prefill == $options[$index]['label']) {
                     $selected = 1;
                 }
             }
         } else {
             /**
              * plugin.tx_powermail.settings.setup.prefill.marker = red
              */
             if ($this->settings['prefill.'][$marker] == $options[$index]['value'] || $this->settings['prefill.'][$marker] == $options[$index]['label']) {
                 $selected = 1;
             }
         }
     }
     return $selected;
 }
Ejemplo n.º 17
0
Archivo: Div.php Proyecto: advOpk/pwm
 /**
  * Generate a new array their labels and respect FE language
  *        Your Firstname: => value
  *
  * @param \In2code\Powermail\Domain\Model\Mail $mail
  * @return array new array
  */
 public function getVariablesWithLabels(\In2code\Powermail\Domain\Model\Mail $mail)
 {
     $variables = array();
     foreach ($mail->getAnswers() as $answer) {
         if (!method_exists($answer->getField(), 'getUid')) {
             continue;
         }
         $variables[] = array('label' => $answer->getField()->getTitle(), 'value' => $answer->getValue(), 'uid' => $answer->getField()->getUid());
     }
     return $variables;
 }