Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -11,9 +11,12 @@
namespace IPS\Helpers\Form\Captcha;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
@@ -28,12 +31,12 @@ interface CaptchaInterface
*
* @return string
*/
public function getHtml();
public function getHtml(): string;
/**
* Verify
*
* @return bool|null TRUE/FALSE indicate if the test passed or not. NULL indicates the test failed, but the captcha system will display an error so we don't have to.
*/
public function verify();
public function verify(): ?bool;
}
+27 -17
View File
@@ -11,36 +11,46 @@
namespace IPS\Helpers\Form\Captcha;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Http\Url;
use IPS\Output;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
use RuntimeException;
use function defined;
use function mb_strlen;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* hCaptcha
*/
class _Hcaptcha implements CaptchaInterface
class Hcaptcha implements CaptchaInterface
{
/**
* Does this CAPTCHA service support being added in a modal?
*/
public static $supportsModal = FALSE;
public static bool $supportsModal = FALSE;
/**
* @brief Error
*/
protected $error;
protected ?string $error;
/**
* Display
*
* @return string
*/
public function getHtml()
public function getHtml(): string
{
\IPS\Output::i()->jsFilesAsync[] = "https://js.hcaptcha.com/1/api.js";
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->hCaptcha( \IPS\Settings::i()->hcaptcha_sitekey );
Output::i()->jsFilesAsync[] = "https://js.hcaptcha.com/1/api.js";
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->hCaptcha( Settings::i()->hcaptcha_sitekey );
}
/**
@@ -48,20 +58,20 @@ class _Hcaptcha implements CaptchaInterface
*
* @return bool|null TRUE/FALSE indicate if the test passed or not. NULL indicates the test failed, but the captcha system will display an error so we don't have to.
*/
public function verify()
public function verify(): ?bool
{
try
{
$response = \IPS\Http\Url::external( 'https://hcaptcha.com/siteverify' )->request()->post( array(
'secret' => \IPS\Settings::i()->hcaptcha_secret,
'response' => trim( \IPS\Request::i()->__get('h-captcha-response') ),
'remoteip' => \IPS\Request::i()->ipAddress(),
) )->decodeJson( TRUE );
$response = Url::external( 'https://hcaptcha.com/siteverify' )->request()->post( array(
'secret' => Settings::i()->hcaptcha_secret,
'response' => trim( Request::i()->__get('h-captcha-response') ),
'remoteip' => Request::i()->ipAddress(),
) )->decodeJson();
$hostname = \IPS\Http\Url::internal('')->data[ \IPS\Http\Url::COMPONENT_HOST ];
return ( ( (bool) $response['success'] ) and ( $response['hostname'] === mb_substr( $hostname, \mb_strlen( $hostname ) - mb_strlen( $response['hostname'] ) ) ) );
$hostname = Url::internal('')->data[ Url::COMPONENT_HOST ];
return ( ( $response['success'] ) and ( $response['hostname'] === mb_substr( $hostname, mb_strlen( $hostname ) - mb_strlen( $response['hostname'] ) ) ) );
}
catch( \RuntimeException $e )
catch( RuntimeException $e )
{
if( $e->getMessage() == 'BAD_JSON' )
{
+26 -17
View File
@@ -11,35 +11,44 @@
namespace IPS\Helpers\Form\Captcha;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Http\Url;
use IPS\Member;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
use RuntimeException;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Invisible reCAPTCHA
*/
class _Invisible implements CaptchaInterface
class Invisible implements CaptchaInterface
{
/**
* Does this CAPTCHA service support being added in a modal?
*/
public static $supportsModal = TRUE;
public static bool $supportsModal = TRUE;
/**
* @brief Error
*/
protected $error;
protected ?string $error;
/**
* Display
*
* @return string
*/
public function getHtml()
public function getHtml(): string
{
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaInvisible( \IPS\Settings::i()->recaptcha2_public_key, preg_replace( '/^(.+?)\..*$/', '$1', \IPS\Member::loggedIn()->language()->short ) );
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaInvisible( Settings::i()->recaptcha2_public_key, preg_replace( '/^(.+?)\..*$/', '$1', Member::loggedIn()->language()->short ) );
}
/**
@@ -47,9 +56,9 @@ class _Invisible implements CaptchaInterface
*
* @return string
*/
public function rowHtml()
public function rowHtml(): string
{
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaInvisible( \IPS\Settings::i()->recaptcha2_public_key, preg_replace( '/^(.+?)\..*$/', '$1', \IPS\Member::loggedIn()->language()->short ), TRUE );
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaInvisible( Settings::i()->recaptcha2_public_key, preg_replace( '/^(.+?)\..*$/', '$1', Member::loggedIn()->language()->short ), TRUE );
}
/**
@@ -57,19 +66,19 @@ class _Invisible implements CaptchaInterface
*
* @return bool|null TRUE/FALSE indicate if the test passed or not. NULL indicates the test failed, but the captcha system will display an error so we don't have to.
*/
public function verify()
public function verify(): ?bool
{
try
{
$response = \IPS\Http\Url::external( 'https://www.google.com/recaptcha/api/siteverify' )->request()->post( array(
'secret' => \IPS\Settings::i()->recaptcha2_private_key,
'response' => trim( \IPS\Request::i()->__get('g-recaptcha-response') ),
'remoteip' => \IPS\Request::i()->ipAddress(),
) )->decodeJson( TRUE );
$response = Url::external( 'https://www.google.com/recaptcha/api/siteverify' )->request()->post( array(
'secret' => Settings::i()->recaptcha2_private_key,
'response' => trim( Request::i()->__get('g-recaptcha-response') ),
'remoteip' => Request::i()->ipAddress(),
) )->decodeJson();
return ( ( (bool) $response['success'] ) and ( $response['hostname'] === \IPS\Http\Url::internal('')->data[ \IPS\Http\Url::COMPONENT_HOST ] ) );
return ( ( $response['success'] ) and ( $response['hostname'] === Url::internal('')->data[ Url::COMPONENT_HOST ] ) );
}
catch( \RuntimeException $e )
catch( RuntimeException $e )
{
if( $e->getMessage() == 'BAD_JSON' )
{
+22 -14
View File
@@ -11,40 +11,48 @@
namespace IPS\Helpers\Form\Captcha;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Http\Url;
use IPS\Login;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* keyCAPTCHA
*/
class _Keycaptcha implements CaptchaInterface
class Keycaptcha implements CaptchaInterface
{
/**
* Does this CAPTCHA service support being added in a modal?
*/
public static $supportsModal = FALSE;
public static bool $supportsModal = FALSE;
/**
* @brief Error
*/
protected $error;
protected ?string $error;
/**
* Display
*
* @return string
*/
public function getHtml()
public function getHtml(): string
{
$explodedKey = explode( '0', \IPS\Settings::i()->keycaptcha_privatekey, 2 );
$explodedKey = explode( '0', Settings::i()->keycaptcha_privatekey, 2 );
$uniq = md5( mt_rand() );
$sign = md5( $uniq . \IPS\Request::i()->ipAddress . $explodedKey[0] );
$sign = md5( $uniq . Request::i()->ipAddress . $explodedKey[0] );
$sign2 = md5( $uniq . $explodedKey[0] );
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaKeycaptcha( $explodedKey[1], $uniq, $sign, $sign2 );
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaKeycaptcha( $explodedKey[1], $uniq, $sign, $sign2 );
}
/**
@@ -52,14 +60,14 @@ class _Keycaptcha implements CaptchaInterface
*
* @return bool|null TRUE/FALSE indicate if the test passed or not. NULL indicates the test failed, but the captcha system will display an error so we don't have to.
*/
public function verify()
public function verify(): ?bool
{
$explodedResponse = explode( '|', \IPS\Request::i()->keycaptcha );
$explodedKey = explode( '0', \IPS\Settings::i()->keycaptcha_privatekey );
$explodedResponse = explode( '|', Request::i()->keycaptcha );
$explodedKey = explode( '0', Settings::i()->keycaptcha_privatekey );
if( \IPS\Login::compareHashes( $explodedResponse[0], md5( 'accept' . $explodedResponse[1] . $explodedKey[0] . $explodedResponse[2] ) ) )
if( Login::compareHashes( $explodedResponse[0], md5( 'accept' . $explodedResponse[1] . $explodedKey[0] . $explodedResponse[2] ) ) )
{
if( (string) \IPS\Http\Url::external( $explodedResponse[2] )->request()->get() === '1' )
if( (string) Url::external( $explodedResponse[2] )->request()->get() === '1' )
{
return TRUE;
}
+28 -17
View File
@@ -11,35 +11,46 @@
namespace IPS\Helpers\Form\Captcha;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Http\Request\Exception;
use IPS\Http\Url;
use IPS\Log;
use IPS\Member;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
use RuntimeException;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* reCAPTCHA
*/
class _Recaptcha2 implements CaptchaInterface
class Recaptcha2 implements CaptchaInterface
{
/**
* Does this CAPTCHA service support being added in a modal?
*/
public static $supportsModal = TRUE;
public static bool $supportsModal = TRUE;
/**
* @brief Error
*/
protected $error;
protected ?string $error;
/**
* Display
*
* @return string
*/
public function getHtml()
public function getHtml(): string
{
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaRecaptcha2( \IPS\Settings::i()->recaptcha2_public_key, preg_replace( '/^(.+?)\..*$/', '$1', \IPS\Member::loggedIn()->language()->short ), \IPS\Theme::i()->settings['recaptcha2_theme'] );
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaRecaptcha2( Settings::i()->recaptcha2_public_key, preg_replace( '/^(.+?)\..*$/', '$1', Member::loggedIn()->language()->short ) );
}
/**
@@ -47,25 +58,25 @@ class _Recaptcha2 implements CaptchaInterface
*
* @return bool|null TRUE/FALSE indicate if the test passed or not. NULL indicates the test failed, but the captcha system will display an error so we don't have to.
*/
public function verify()
public function verify(): ?bool
{
try
{
$response = \IPS\Http\Url::external( 'https://www.google.com/recaptcha/api/siteverify' )->request()->post( array(
'secret' => \IPS\Settings::i()->recaptcha2_private_key,
'response' => trim( \IPS\Request::i()->__get('g-recaptcha-response') ),
'remoteip' => \IPS\Request::i()->ipAddress(),
) )->decodeJson( TRUE );
$response = Url::external( 'https://www.google.com/recaptcha/api/siteverify' )->request()->post( array(
'secret' => Settings::i()->recaptcha2_private_key,
'response' => trim( Request::i()->__get('g-recaptcha-response') ),
'remoteip' => Request::i()->ipAddress(),
) )->decodeJson();
return ( ( (bool) $response['success'] ) and ( $response['hostname'] === \IPS\Http\Url::internal('')->data[ \IPS\Http\Url::COMPONENT_HOST ] ) );
return ( ( $response['success'] ) and ( $response['hostname'] === Url::internal('')->data[ Url::COMPONENT_HOST ] ) );
}
catch( \IPS\Http\Request\Exception $e )
catch( Exception $e )
{
\IPS\Log::log( $e, 'recaptcha2_exception' );
Log::log( $e, 'recaptcha2_exception' );
return FALSE;
}
catch( \RuntimeException $e )
catch( RuntimeException $e )
{
if( $e->getMessage() == 'BAD_JSON' )
{
-103
View File
@@ -1,103 +0,0 @@
<?php
/**
* @brief Cloudflare Turnstile
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 13 June 2025
*/
namespace IPS\Helpers\Form\Captcha;
use IPS\Http\Request\Exception;
use IPS\Http\Url;
use IPS\Log;
use IPS\Member;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
use RuntimeException;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Cloudflare Turnstile
*/
class _Turnstile implements CaptchaInterface
{
/**
* Does this CAPTCHA service support being added in a modal?
*/
public static bool $supportsModal = TRUE;
/**
* @brief Error
*/
protected ?string $error;
/**
* Display
*
* @return string
*/
public function getHtml(): string
{
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->captchaTurnstile( $this->getTurnstileCredentials()['site_key'], preg_replace( '/^(.+?)\..*$/', '$1', Member::loggedIn()->language()->short ) );
}
/**
* Verify
*
* @return bool|null TRUE/FALSE indicate if the test passed or not. NULL indicates the test failed, but the captcha system will display an error so we don't have to.
*/
public function verify(): ?bool
{
try
{
$response = Url::external( 'https://challenges.cloudflare.com/turnstile/v0/siteverify' )->request(5)->post( [
'secret' => $this->getTurnstileCredentials()['secret_key'],
'response' => trim( Request::i()->__get('cf-turnstile-response') ),
'remoteip' => Request::i()->ipAddress(),
] )->decodeJson();
return ( ( $response['success'] ) and ( $response['hostname'] === Url::internal('')->data[ Url::COMPONENT_HOST ] ) );
}
catch( Exception $e )
{
Log::log( $e, 'turnstile_exception' );
return FALSE;
}
catch( RuntimeException $e )
{
if( $e->getMessage() == 'BAD_JSON' )
{
return FALSE;
}
else
{
throw $e;
}
}
}
/**
* Get Turnstile credentials
*
* @return array
*/
public function getTurnstileCredentials(): array
{
return [
'site_key' => Settings::i()->turnstile_site_key,
'secret_key' => Settings::i()->turnstile_secret_key
];
}
}