first commit

This commit is contained in:
Your Name
2021-04-20 11:13:47 +05:30
parent b76859a3f1
commit 0a18b88eba
408 changed files with 47723 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CAPTCHA Module for OpenConf</title>
<style type="text/css">
body { font-family: arial, helvetica, sans-serif; font-size: 80%; }
</style>
</head>
<body>
<h1>CAPTCHA Module for OpenConf</h1>
<p>This module adds a <a href="https://en.wikipedia.org/wiki/CAPTCHA" title="Wikipedia definition page" target="_blank">CAPTCHA</a> verification to the submission and contact forms so as to ensure they are submitted by a person.</p>
<h3>Requirements and Configuration</h3>
<p>If running OpenConf on your own server, sign up for an <a href="https://www.hcaptcha.com/" target="_blank">hCaptcha</a> or a <a href="https://www.google.com/recaptcha" target="_blank">Google reCAPTCHA</a> account and enter your account API keys into this module's settings. <b>Note:</b> PHP must be configured so that allow_url_fopen is enabled.</p>
<p>The <i>OpenConf Hosting Service</i> already has this module pre-configured and no configuration is necessary &ndash; simply install and activate the module.</p>
<h3>Usage &ndash; Authors</h3>
<p>Follow the instructions provided with the CAPTCHA field on the form.</p>
<hr />
<p>Version 3.0.0<br />
- Added hCaptcha
</p>
<p>Version 2.1.0<br />
- Removed deprecated reCAPTCHA 1.0
</p>
<p>Version 2.0.0<br />
- Added support for reCAPTCHA 2.0
</p>
<p>Version 1.3.0<br />
- Added settings import/export
</p>
<p>Version 1.2.2<br />
- Updated recaptchalib.php
</p>
<p>Version 1.2.1<br />
- Fixed PHP_SELF reference in init.inc
</p>
<p>Version 1.2.0<br />
- Changed to use new submission form fieldset<br />
- Split out author and concact fields
</p>
<p>Version 1.1.1<br />
- Added token check for settings.inc
</p>
<p>Version 1.1.0<br />
- Changed author-validate to check for existence of POST variables
- Changed author-fields to not display blank table row for contact form, and included field label
</p>
<p>Version 1.0.0<br />
- Initial Release</p>
</body>
</html>
+23
View File
@@ -0,0 +1,23 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
print '
<fieldset>
<legend>' . oc_('CAPTCHA') . '</legend>
<br /><span class="err">';
require_once('captcha-include.inc');
mod_captcha_displayCAPTCHA();
print '</span>
</fieldset>';
+16
View File
@@ -0,0 +1,16 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
require_once('captcha-include.inc');
if ($mod_captcha_err = mod_captcha_verifyCAPTCHA()) {
$err .= '<li>' . $mod_captcha_err . '</li>';
}
+76
View File
@@ -0,0 +1,76 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
// display CAPTCHA
function mod_captcha_displayCAPTCHA() {
if (OC_CAPTCHA_service == 'hCaptcha') {
print '
<script src="https://www.hCaptcha.com/1/api.js?hl=' . urlencode($GLOBALS['OC_locale']) . '" async defer></script>
<div class="h-captcha" data-sitekey="' . safeHTMLstr(OC_CAPTCHA_public_key) . '"></div>
';
} elseif (OC_CAPTCHA_service == 'reCAPTCHA') {
print '
<script src="https://www.google.com/recaptcha/api.js?hl=' . $GLOBALS['OC_locale'] . '" async defer></script>
<div class="g-recaptcha" data-sitekey="' . safeHTMLstr(OC_CAPTCHA_public_key) . '"></div>
<noscript>
<div style="width: 302px; height: 352px;">
<div style="width: 302px; height: 352px; position: relative;">
<div style="width: 302px; height: 352px; position: absolute;">
<iframe src="https://www.google.com/recaptcha/api/fallback?k=' . safeHTMLstr(OC_CAPTCHA_public_key) . '" frameborder="0" scrolling="no" style="width: 302px; height:352px; border-style: none;" title="CAPTCHA">
</iframe>
</div>
<div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;">
<textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 80px; border: 1px solid #c1c1c1; margin: 0px; padding: 0px; resize: none;" value="">
</textarea>
</div>
</div>
</div>
</noscript>
';
}
}
// verify CAPTCH - returns false if verifies OK, otherwise error string
function mod_captcha_verifyCAPTCHA() {
if (OC_CAPTCHA_service == 'hCaptcha') {
$mod_captcha_var = 'h-captcha-response';
$mod_catpcha_url = 'https://hcaptcha.com/siteverify';
} elseif (OC_CAPTCHA_service == 'reCAPTCHA') {
$mod_captch_var = 'g-captcha-response';
$mod_catpcha_url = 'https://www.google.com/recaptcha/api/siteverify';
} else {
err('invalid CAPTCHA');
}
if (isset($_POST[$mod_captcha_var]) && !empty($_POST[$mod_captcha_var])) {
$mod_catpcha_url .= '?secret=' . urlencode(OC_CAPTCHA_private_key) . '&response=' . urlencode($_POST['h-captcha-response']) . '&remoteip=' . urlencode($_SERVER['REMOTE_ADDR']);
if ($response = file_get_contents($mod_catpcha_url)) {
if ($responseAR = json_decode($response, true)) {
if (trim($responseAR['success']) == true) {
return(false); // OK
} elseif (isset($responseAR['error-codes'])) {
$mod_captcha_err = (is_array($responseAR['error-codes']) ? implode(',', $responseAR['error-codes']) : $responseAR['error-codes']);
} else {
$mod_captcha_err = 3;
}
} else {
$mod_captcha_err = 4;
}
} else {
$mod_captcha_err = 5;
}
}
return(
oc_('CAPTCHA verification failed') .
(empty($mod_captcha_err) ? '' : (' (' . $mod_captcha_err . ')'))
);
}
+24
View File
@@ -0,0 +1,24 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
print '
<tr>
<td class="item" valign="top"><label for="recaptcha_response_field">' . oc_('CAPTCHA Check') . ':</label></td>
<td colspan=2>
<span class="err">
';
require_once('captcha-include.inc');
mod_captcha_displayCAPTCHA();
print '</span></td></tr>';
+16
View File
@@ -0,0 +1,16 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
require_once('captcha-include.inc');
if ($mod_captcha_err = mod_captcha_verifyCAPTCHA()) {
$err .= '<li>' . $mod_captcha_err . '</li>';
}
View File
View File
+42
View File
@@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
// Check at least one CAPTCHA service keys configured and setup constants
if (!defined('OC_CAPTCHA_service')) {
if (!empty($OC_configAR['MOD_CAPTCHA_hcaptcha_public_key']) && !empty($OC_configAR['MOD_CAPTCHA_hcaptcha_private_key'])) {
define('OC_CAPTCHA_service', 'hCaptcha');
define('OC_CAPTCHA_public_key', $OC_configAR['MOD_CAPTCHA_hcaptcha_public_key']);
define('OC_CAPTCHA_private_key', $OC_configAR['MOD_CAPTCHA_hcaptcha_private_key']);
} elseif (!empty($OC_configAR['OC_CAPTCHA_public_key']) && !empty($OC_configAR['MOD_CAPTCHA_private_key'])) {
define('OC_CAPTCHA_service', 'reCAPTCHA');
define('OC_CAPTCHA_public_key', $OC_configAR['OC_CAPTCHA_public_key']);
define('OC_CAPTCHA_private_key', $OC_configAR['MOD_CAPTCHA_private_key']);
}
// Register chair settings hook
oc_addHook('chair-menu-settings-modules', array($OC_modulesAR[$moduleId]['name'], '<a href="../modules/request.php?module=captcha&action=settings.inc">CAPTCHA</a>'));
// Register settings export/import hooks
oc_addHook('settings-export-options', '../modules/captcha/settings-export-options.inc');
oc_addHook('settings-export-prep', '../modules/captcha/settings-export-prep.inc');
}
// Register form hooks
if (defined('OC_CAPTCHA_service')) {
if (preg_match("/submit\.php/", $_SERVER['PHP_SELF'])) { // new subs only
oc_addHook('author-submit-fields', '../modules/captcha/author-fields.inc');
oc_addHook('author-submission-validate', '../modules/captcha/author-validate.inc');
}
oc_addHook('author-contact-fields', '../modules/captcha/contact-fields.inc');
oc_addHook('author-contact-validate', '../modules/captcha/contact-validate.inc');
}
+21
View File
@@ -0,0 +1,21 @@
## +----------------------------------------------------------------------+
## | OpenConf |
## +----------------------------------------------------------------------+
## | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
## +----------------------------------------------------------------------+
## | This source file is subject to the OpenConf License, available on |
## | the OpenConf web site: www.OpenConf.com |
## +----------------------------------------------------------------------+
## NOTE: This file cannot contain a semi-colon (;) except at the end of a
## SQL statement.
# --------------------------------------------------------
INSERT INTO `config` (`module`, `setting`, `value`, `name`, `description`, `parse`) VALUES ('captcha', 'MOD_CAPTCHA_private_key', '', 'reCAPTCHA Private Key', 'obtain from google.com/recaptcha', 0);
INSERT INTO `config` (`module`, `setting`, `value`, `name`, `description`, `parse`) VALUES ('captcha', 'MOD_CAPTCHA_public_key', '', 'reCAPTCHA Public Key', 'obtain from google.com/recaptcha', 0);
INSERT INTO `config` (`module`, `setting`, `value`, `name`, `description`, `parse`) VALUES ('captcha', 'MOD_CAPTCHA_hcaptcha_private_key', '', 'hCaptcha Private Key', 'obtain from hcaptcha.com', 0);
INSERT INTO `config` (`module`, `setting`, `value`, `name`, `description`, `parse`) VALUES ('captcha', 'MOD_CAPTCHA_hcaptcha_public_key', '', 'hCaptcha Public Key', 'obtain from hcaptcha.com', 0);
+22
View File
@@ -0,0 +1,22 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
// Module ID - needs to match directory name
$moduleId = 'captcha';
// Module info
$OC_modulesAR[$moduleId] = array(
'name' => 'CAPTCHA',
'description' => 'Checks that submissions are being made by a human',
'version' => '3.0.0',
'dependencies' => array(),
'developer' => 'OpenConf'
);
@@ -0,0 +1,16 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
print '
<br />
<label><input type="checkbox" name="settings[]" value="captcha" /> CAPTCHA - Configuration</label><br />
';
+14
View File
@@ -0,0 +1,14 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
if (in_array('captcha', $_POST['settings'])) {
$settings['modules']['captcha'] = $OC_modulesAR['captcha']['name'];
}
+81
View File
@@ -0,0 +1,81 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
$MOD_CAPTCHA_configVars = array('MOD_CAPTCHA_hcaptcha_public_key', 'MOD_CAPTCHA_hcaptcha_private_key', 'MOD_CAPTCHA_private_key', 'MOD_CAPTCHA_public_key');
if (isset($_POST['submit']) && ($_POST['submit'] == 'Save Settings')) {
// Check for valid submission
if (!validToken('chair')) {
warn('Invalid submission');
}
// Validate settings
$err = array();
if (!ini_get('allow_url_fopen')) {
$err[] = 'PHP must be configured to have allow_url_fopen enabled';
}
// Errors?
if (!empty($err)) {
print '<div class="warn"><p>Please re-enter your settings, noting the following:</p><ul><li>' . implode('</li><li>', $err) . '</li></ul></div><br /><hr /><br />';
} else { // Update settings
updateAllConfigSettings($MOD_CAPTCHA_configVars, $_POST, OCC_MODULE_ID);
// notify user
print '<p style="text-align: center" class="note">Settings Saved</p>';
}
}
print '
<form method="post" action="' . OCC_SELF . '" class="ocform">
<input type="hidden" name="token" value="' . $_SESSION[OCC_SESSION_VAR_NAME]['chairtoken'] . '" />
<p>OpenConf supports the <a href="https://hcaptcha.com" target="_blank" rel="noopener noreferrer">hCaptcha</a> and <a href="https://www.google.com/recaptcha" target="_blank" rel="noopener noreferrer">Google reCAPTCHA</a> services. Sign up for an account with either service and enter the public/private keys below. If credentials are filled in for both services, hCAPTCHA will be used by default.</p>
<fieldset id="oc_fs_mod_captcha_hcaptcha">
<legend onclick="oc_fsToggle(this)">hCpatcha</span></legend>
<div class="fieldsetnote note">In order to use hCaptcha, first sign up for an account at <a href="https://hcaptcha.com" target="_blank" rel="noopener noreferrer">https://hcaptcha.com</a></div>
<div id="oc_fs_mod_captcha_hcaptcha_div">
<div class="field">
<label for="MOD_CAPTCHA_hcaptcha_public_key">Public (Site) key:</label>
<input name="MOD_CAPTCHA_hcaptcha_public_key" id="MOD_CAPTCHA_hcaptcha_public_key" value="' . safeHTMLstr($OC_configAR['MOD_CAPTCHA_hcaptcha_public_key']) . '" size="60" />
</div>
<div class="field">
<label for="MOD_CAPTCHA_hcaptcha_private_key">Private (Secret) key:</label>
<input name="MOD_CAPTCHA_hcaptcha_private_key" id="MOD_CAPTCHA_hcaptcha_private_key" value="' . safeHTMLstr($OC_configAR['MOD_CAPTCHA_hcaptcha_private_key']) . '" size="60" />
</div>
</div>
</fieldset>
<fieldset id="oc_fs_mod_captcha_recaptcha">
<legend onclick="oc_fsToggle(this)">Google reCAPTCHA v2</span></legend>
<div class="fieldsetnote note">In order to use reCAPTCHA, first sign up for an account at <a href="https://google.com/recaptcha" target="_blank" rel="noopener noreferrer">https://google.com/recaptcha</a></div>
<div id="oc_fs_mod_captcha_recaptcha_div">
<div class="field">
<label for="MOD_CAPTCHA_public_key">Public key:</label>
<input name="MOD_CAPTCHA_public_key" id="MOD_CAPTCHA_public_key" value="' . safeHTMLstr($OC_configAR['MOD_CAPTCHA_public_key']) . '" size="60" />
</div>
<div class="field">
<label for="MOD_CAPTCHA_private_key">Private key:</label>
<input name="MOD_CAPTCHA_private_key" id="MOD_CAPTCHA_private_key" value="' . safeHTMLstr($OC_configAR['MOD_CAPTCHA_private_key']) . '" size="60" />
</div>
</div>
</fieldset>
<p><input type="submit" name="submit" value="Save Settings" class="submit" /></p>
</form>
';
+15
View File
@@ -0,0 +1,15 @@
## +----------------------------------------------------------------------+
## | OpenConf |
## +----------------------------------------------------------------------+
## | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
## +----------------------------------------------------------------------+
## | This source file is subject to the OpenConf License, available on |
## | the OpenConf web site: www.OpenConf.com |
## +----------------------------------------------------------------------+
## NOTE: This file cannot contain a semi-colon (;) except at the end of a
## SQL statement.
# --------------------------------------------------------
DELETE FROM `config` WHERE `module`='captcha';
View File
View File
@@ -0,0 +1,13 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
ocsql_query("INSERT INTO `" . OCC_TABLE_CONFIG . "` (`module`, `setting`, `value`, `name`, `description`, `parse`) VALUES ('captcha', 'MOD_CAPTCHA_version', '1.0', 'Version Number', 'reCAPTCHA API version number', 0)");
@@ -0,0 +1,13 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
ocsql_query("DELETE FROM `" . OCC_TABLE_CONFIG . "` WHERE `module`='captcha' AND `setting`='MOD_CAPTCHA_version' LIMIT 1");
@@ -0,0 +1,14 @@
<?php
// +----------------------------------------------------------------------+
// | OpenConf |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2020 Zakon Group LLC. All Rights Reserved. |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on |
// | the OpenConf web site: www.OpenConf.com |
// +----------------------------------------------------------------------+
ocsql_query("INSERT INTO `" . OCC_TABLE_CONFIG . "` (`module`, `setting`, `value`, `name`, `description`, `parse`) VALUES ('captcha', 'MOD_CAPTCHA_hcaptcha_private_key', '', 'hCaptcha Private (Secret) Key', 'obtain from hcaptcha.com', 0)");
ocsql_query("INSERT INTO `" . OCC_TABLE_CONFIG . "` (`module`, `setting`, `value`, `name`, `description`, `parse`) VALUES ('captcha', 'MOD_CAPTCHA_hcaptcha_public_key', '', 'hCaptcha Public (Site) Key', 'obtain from hcaptcha.com', 0)");