Commit 5a6d5f58 authored by Côme Chilliet's avatar Côme Chilliet

Merge branch '6001-add-a-captcha-system-to-our-public-form-system' into '1.4-dev'

Resolve "Add a captcha system to our public form system"

See merge request fusiondirectory/fd-plugins!642
parents 298adf04 8981a635
......@@ -90,6 +90,11 @@ class publicForm extends simplePlugin
_('TOS URL'), _('Terms of service URL. If filled, this adds a mandatory checkbox to agree to the terms at this URL.'),
'fdPublicFormTosUrl', FALSE
),
new BooleanAttribute(
_('Captcha'), _('Add a captcha to the form'),
'fdPublicFormCaptcha', FALSE,
FALSE
),
]
],
];
......@@ -97,6 +102,8 @@ class publicForm extends simplePlugin
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE, $attributesInfo = NULL)
{
global $config;
if ($attributesInfo === NULL) {
$attributesInfo = $this->getAttributesInfo();
}
......@@ -111,6 +118,12 @@ class publicForm extends simplePlugin
$this->typeChanged();
$this->attributesAccess['fdPublicFormTemplateType']->setSubmitForm('typeChanged');
if ($config->get_cfg_value('PublicFormSecurimagePath', '') == '') {
$this->attributesAccess['fdPublicFormCaptcha']->setDisabled(TRUE);
$this->attributesAccess['fdPublicFormCaptcha']->setValue(FALSE);
$this->attributesAccess['fdPublicFormCaptcha']->setVisible(FALSE);
}
}
function typeChanged ()
......
......@@ -44,6 +44,14 @@ class publicFormsConfig extends simplePlugin
'fdPublicFormRDN', TRUE,
'ou=forms'
),
new StringAttribute(
_('Securimage path'), _('If you wish to use captchas in your forms, you need to install securimage. Specify here the path to the main class.'),
'fdPublicFormSecurimagePath', FALSE
),
new StringAttribute(
_('Securimage URI'), _('The base URI at which securimage is available'),
'fdPublicFormSecurimageURI', FALSE
),
]
],
];
......
......@@ -10,9 +10,23 @@ attributetype ( 1.3.6.1.4.1.38414.68.1.1 NAME 'fdPublicFormRDN'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE)
attributetype ( 1.3.6.1.4.1.38414.68.1.2 NAME 'fdPublicFormSecurimagePath'
DESC 'FusionDirectory - Public forms securimage path'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE)
attributetype ( 1.3.6.1.4.1.38414.68.1.3 NAME 'fdPublicFormSecurimageURI'
DESC 'FusionDirectory - Public forms securimage URI'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE)
# Object Class
objectclass ( 1.3.6.1.4.1.38414.68.2.1 NAME 'fdPublicFormsPluginConf'
DESC 'FusionDirectory - Public forms plugin configuration'
SUP top AUXILIARY
MUST ( cn )
MAY ( fdPublicFormRDN ) )
MAY ( fdPublicFormRDN $ fdPublicFormSecurimagePath $ fdPublicFormSecurimageURI ) )
......@@ -66,6 +66,12 @@ attributetype ( 1.3.6.1.4.1.38414.67.10.9 NAME 'fdPublicFormTosUrl'
SUBSTR caseExactSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
attributetype ( 1.3.6.1.4.1.38414.67.10.10 NAME 'fdPublicFormCaptcha'
DESC 'FusionDirectory - Whether this form should contain a captcha'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE )
# Objectclasses
objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm'
......@@ -75,4 +81,4 @@ objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm'
fdPublicFormTitle $ fdPublicFormText $
fdPublicFormTemplateType $ fdPublicFormTemplateDN $
fdPublicFormFinalText $ fdPublicFormPrivate $ fdPublicFormCreationBase $
fdPublicFormAlteredAttributes $ fdPublicFormTosUrl ) )
fdPublicFormAlteredAttributes $ fdPublicFormTosUrl $ fdPublicFormCaptcha ) )
......@@ -35,6 +35,33 @@
{if (!$done and $form.fdPublicFormTosUrl)}
<label for="tosCheckBox"><input type="checkbox" id="tosCheckBox" name="tosCheckBox"/> {t 1=$form.fdPublicFormTosUrl escape=no}I agree to the <a target="_blank" href="%1">terms of service</a>{/t}</label>
{/if}
{if (!$done and $captcha)}
<label for="captcha_code">
<div id="captcha_container" style="width:255px;margin:auto;">
<img id="captcha_image" style="float:left;" src="?captcha=show&amp;75aace5fbae3ff8717add401e4291cbb" alt="CAPTCHA Image" />
<div id="captcha_image_audio_div">
<audio id="captcha_image_audio" preload="none" style="display: none">
<source id="captcha_image_source_wav" src="?captcha=play&amp;id=5da816517fa90" type="audio/wav">
</audio>
</div>
<div id="captcha_image_audio_controls">
<a class="captcha_play_button" href="?captcha=play&amp;id=5da816517fad3" onclick="return false">
<img class="captcha_play_image" height="32" width="32" src="{$captcha.securimage_uri}/images/audio_icon.png" alt="Play CAPTCHA Audio"/>
<img class="captcha_loading_image rotating" height="32" width="32" src="{$captcha.securimage_uri}/images/loading.png" alt="Loading audio" style="display: none"/>
</a>
<noscript>Enable Javascript for audio controls</noscript>
</div>
<script type="text/javascript" src="{$captcha.securimage_uri}/securimage.js"></script>
<script type="text/javascript">captcha_image_audioObj = new SecurimageAudio({ audioElement: 'captcha_image_audio', controlsElement: 'captcha_image_audio_controls' });</script>
<a href="#" title="Refresh Image" onclick="if (typeof window.captcha_image_audioObj !== 'undefined') captcha_image_audioObj.refresh(); document.getElementById('captcha_image').src = '?captcha=show&amp;' + Math.random(); this.blur(); return false">
<img height="32" width="32" src="{$captcha.securimage_uri}/images/refresh.png" alt="Refresh Image" onclick="this.blur()"/>
</a>
<div style="clear: both"></div>
</div>
Type the text:
<input type="text" name="captcha_code" id="captcha_code" autocomplete="off"/>
</label>
{/if}
</div>
{if !$done}
<div id="window-footer" class="plugbottom">
......
......@@ -120,6 +120,7 @@ class publicFormPage extends standAlonePage
'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1,
'fdPublicFormTosUrl' => 1,
'fdPublicFormCaptcha' => 1,
'fdPublicFormAlteredAttributes' => '*',
],
$this->invitation['fdInvitationFormDN'],
......@@ -141,6 +142,7 @@ class publicFormPage extends standAlonePage
'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1,
'fdPublicFormTosUrl' => 1,
'fdPublicFormCaptcha' => 1,
'fdPublicFormAlteredAttributes' => '*',
],
NULL,
......@@ -219,6 +221,16 @@ class publicFormPage extends standAlonePage
{
global $config, $ui;
/* Check Captcha */
if (isset($this->form['fdPublicFormCaptcha']) && ($this->form['fdPublicFormCaptcha'] == 'TRUE')) {
require_once($config->get_cfg_value('PublicFormSecurimagePath'));
$securimage = new Securimage();
if (!$securimage->check($_POST['captcha_code'])) {
msg_dialog::display(_('Error'), _('Captcha code was wrong!'), ERROR_DIALOG);
return;
}
}
/* Check TOS checkbox */
if (isset($this->form['fdPublicFormTosUrl']) && !isset($_POST['tosCheckBox'])) {
msg_dialog::display(_('Error'), _('You need to accept the terms of service to continue!'), ERROR_DIALOG);
......@@ -307,10 +319,47 @@ class publicFormPage extends standAlonePage
function execute ()
{
global $config;
if (!$this->activated) {
return;
}
if (isset($_GET['captcha'])) {
/* We cannot use securimage_show.php and securimage_play.php because they cannot access our session
* So we use publicform.php?captcha=show and publicform.php?captcha=play instead */
require_once($config->get_cfg_value('PublicFormSecurimagePath'));
/* Showing or playing captcha */
switch ($_GET['captcha']) {
case 'show':
$img = new Securimage();
// set namespace if supplied to script via HTTP GET
if (!empty($_GET['namespace'])) {
$img->setNamespace($_GET['namespace']);
}
$img->show();
break;
case 'play':
$img = new Securimage();
// set namespace if supplied to script via HTTP GET
if (!empty($_GET['namespace'])) {
$img->setNamespace($_GET['namespace']);
}
// mp3 or wav format
$format = ((isset($_GET['format']) && strtolower($_GET['format']) == 'mp3') ? 'mp3' : NULL);
$img->outputAudioFile($format);
break;
default:
}
return;
}
$this->save_object();
$smarty = get_smarty();
......@@ -321,6 +370,11 @@ class publicFormPage extends standAlonePage
$templateOutput = $this->template->execute();
// TODO - Check that no dialogs are opened?
$smarty->assign('template_dialog', $templateOutput);
if (isset($this->form['fdPublicFormCaptcha']) && ($this->form['fdPublicFormCaptcha'] == 'TRUE')) {
require_once($config->get_cfg_value('PublicFormSecurimagePath'));
$smarty->assign('captcha', ['securimage_uri' => $config->get_cfg_value('PublicFormSecurimageURI', 'securimage/')]);
}
}
$smarty->assign('done', $this->done);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment