Verified Commit 8981a635 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(public-forms) Fix Captcha handling

The Captcha is now working. The HTML is now in the smarty template, and
 we use our own page instead of securimage_show.php and securimage_play.php.
We could remove the need of having to expose securimage and store its
 URI in the configuration if we use our own icons and pack their
 javascript, as these are the only things still obtained through the URI.

issue #6001
Showing with 74 additions and 4 deletions
+74 -4
...@@ -45,9 +45,13 @@ class publicFormsConfig extends simplePlugin ...@@ -45,9 +45,13 @@ class publicFormsConfig extends simplePlugin
'ou=forms' 'ou=forms'
), ),
new StringAttribute( new StringAttribute(
_('Securimage path'), _('If you wish to use captchas in your forms, you need to install securimage'), _('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 'fdPublicFormSecurimagePath', FALSE
), ),
new StringAttribute(
_('Securimage URI'), _('The base URI at which securimage is available'),
'fdPublicFormSecurimageURI', FALSE
),
] ]
], ],
]; ];
......
...@@ -17,9 +17,16 @@ attributetype ( 1.3.6.1.4.1.38414.68.1.2 NAME 'fdPublicFormSecurimagePath' ...@@ -17,9 +17,16 @@ attributetype ( 1.3.6.1.4.1.38414.68.1.2 NAME 'fdPublicFormSecurimagePath'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE) 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 # Object Class
objectclass ( 1.3.6.1.4.1.38414.68.2.1 NAME 'fdPublicFormsPluginConf' objectclass ( 1.3.6.1.4.1.38414.68.2.1 NAME 'fdPublicFormsPluginConf'
DESC 'FusionDirectory - Public forms plugin configuration' DESC 'FusionDirectory - Public forms plugin configuration'
SUP top AUXILIARY SUP top AUXILIARY
MUST ( cn ) MUST ( cn )
MAY ( fdPublicFormRDN $ fdPublicFormSecurimagePath ) ) MAY ( fdPublicFormRDN $ fdPublicFormSecurimagePath $ fdPublicFormSecurimageURI ) )
...@@ -36,7 +36,31 @@ ...@@ -36,7 +36,31 @@
<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> <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}
{if (!$done and $captcha)} {if (!$done and $captcha)}
{$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} {/if}
</div> </div>
{if !$done} {if !$done}
......
...@@ -325,6 +325,41 @@ class publicFormPage extends standAlonePage ...@@ -325,6 +325,41 @@ class publicFormPage extends standAlonePage
return; 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(); $this->save_object();
$smarty = get_smarty(); $smarty = get_smarty();
...@@ -338,7 +373,7 @@ class publicFormPage extends standAlonePage ...@@ -338,7 +373,7 @@ class publicFormPage extends standAlonePage
if (isset($this->form['fdPublicFormCaptcha']) && ($this->form['fdPublicFormCaptcha'] == 'TRUE')) { if (isset($this->form['fdPublicFormCaptcha']) && ($this->form['fdPublicFormCaptcha'] == 'TRUE')) {
require_once($config->get_cfg_value('PublicFormSecurimagePath')); require_once($config->get_cfg_value('PublicFormSecurimagePath'));
$smarty->assign('captcha', Securimage::getCaptchaHtml(['securimage_path' => 'securimage/'])); $smarty->assign('captcha', ['securimage_uri' => $config->get_cfg_value('PublicFormSecurimageURI', 'securimage/')]);
} }
} }
......
Supports Markdown
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