Initial import of Din Beste Hjelper site

CodeIgniter 3 app for dinbestehjelper.no. Excludes vendor/, local backup
folders (new/, archive/, archived/) and DB dumps (*.sql) via .gitignore.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P16ttGUge8zj91dm6WrmEb
This commit is contained in:
Astral04
2026-08-04 12:52:43 +00:00
co-authored by Claude Opus 4.8
commit 4e1a69c8d4
542 changed files with 214158 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
<?php␍
/**␍
* This is a PHP library that handles calling reCAPTCHA.␍
*␍
* @copyright Copyright (c) 2015, Google Inc.␍
* @link http://www.google.com/recaptcha␍
*␍
* Permission is hereby granted, free of charge, to any person obtaining a copy␍
* of this software and associated documentation files (the "Software"), to deal␍
* in the Software without restriction, including without limitation the rights␍
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell␍
* copies of the Software, and to permit persons to whom the Software is␍
* furnished to do so, subject to the following conditions:␍
*␍
* The above copyright notice and this permission notice shall be included in␍
* all copies or substantial portions of the Software.␍
*␍
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR␍
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,␍
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE␍
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER␍
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,␍
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN␍
* THE SOFTWARE.␍
*/
namespace ReCaptcha;
/**␍
* reCAPTCHA client.␍
*/
class ReCaptcha␍
{
/**␍
* Version of this client library.␍
* @const string␍
*/
const VERSION = 'php_1.1.2';
/**␍
* Shared secret for the site.␍
* @var type string␍
*/
private $secret;
/**␍
* Method used to communicate with service. Defaults to POST request.␍
* @var RequestMethod␍
*/
private $requestMethod;
/**␍
* Create a configured instance to use the reCAPTCHA service.␍
*␍
* @param string $secret shared secret between site and reCAPTCHA server.␍
* @param RequestMethod $requestMethod method used to send the request. Defaults to POST.␍
*/
public function __construct($secret, RequestMethod $requestMethod = null)
{
if (empty($secret)) {
throw new \RuntimeException('No secret provided');
}
if (!is_string($secret)) {
throw new \RuntimeException('The provided secret must be a string');
}
$this->secret = $secret;
if (!is_null($requestMethod)) {
$this->requestMethod = $requestMethod;
} else {
$this->requestMethod = new RequestMethod\Post();
}
}
/**␍
* Calls the reCAPTCHA siteverify API to verify whether the user passes␍
* CAPTCHA test.␍
*␍
* @param string $response The value of 'g-recaptcha-response' in the submitted form.␍
* @param string $remoteIp The end user's IP address.␍
* @return Response Response from the service.␍
*/
public function verify($response, $remoteIp = null)
{
// Discard empty solution submissions␍
if (empty($response)) {
$recaptchaResponse = new Response(false, array('missing-input-response'));
return $recaptchaResponse;
}
$params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
$rawResponse = $this->requestMethod->submit($params);
return Response::fromJson($rawResponse);
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php␍
/**␍
* This is a PHP library that handles calling reCAPTCHA.␍
*␍
* @copyright Copyright (c) 2015, Google Inc.␍
* @link http://www.google.com/recaptcha␍
*␍
* Permission is hereby granted, free of charge, to any person obtaining a copy␍
* of this software and associated documentation files (the "Software"), to deal␍
* in the Software without restriction, including without limitation the rights␍
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell␍
* copies of the Software, and to permit persons to whom the Software is␍
* furnished to do so, subject to the following conditions:␍
*␍
* The above copyright notice and this permission notice shall be included in␍
* all copies or substantial portions of the Software.␍
*␍
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR␍
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,␍
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE␍
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER␍
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,␍
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN␍
* THE SOFTWARE.␍
*/
namespace ReCaptcha;
/**␍
* Method used to send the request to the service.␍
*/
interface RequestMethod␍
{
/**␍
* Submit the request with the specified parameters.␍
*␍
* @param RequestParameters $params Request parameters␍
* @return string Body of the reCAPTCHA response␍
*/
public function submit(RequestParameters $params);
}
+74
View File
@@ -0,0 +1,74 @@
<?php␍
/**␍
* This is a PHP library that handles calling reCAPTCHA.␍
*␍
* @copyright Copyright (c) 2015, Google Inc.␍
* @link http://www.google.com/recaptcha␍
*␍
* Permission is hereby granted, free of charge, to any person obtaining a copy␍
* of this software and associated documentation files (the "Software"), to deal␍
* in the Software without restriction, including without limitation the rights␍
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell␍
* copies of the Software, and to permit persons to whom the Software is␍
* furnished to do so, subject to the following conditions:␍
*␍
* The above copyright notice and this permission notice shall be included in␍
* all copies or substantial portions of the Software.␍
*␍
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR␍
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,␍
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE␍
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER␍
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,␍
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN␍
* THE SOFTWARE.␍
*/
namespace ReCaptcha\RequestMethod;
/**␍
* Convenience wrapper around the cURL functions to allow mocking.␍
*/
class Curl␍
{
/**␍
* @see http://php.net/curl_init␍
* @param string $url␍
* @return resource cURL handle␍
*/
public function init($url = null)
{
return curl_init($url);
}
/**␍
* @see http://php.net/curl_setopt_array␍
* @param resource $ch␍
* @param array $options␍
* @return bool␍
*/
public function setoptArray($ch, array $options)
{
return curl_setopt_array($ch, $options);
}
/**␍
* @see http://php.net/curl_exec␍
* @param resource $ch␍
* @return mixed␍
*/
public function exec($ch)
{
return curl_exec($ch);
}
/**␍
* @see http://php.net/curl_close␍
* @param resource $ch␍
*/
public function close($ch)
{
curl_close($ch);
}
}
+88
View File
@@ -0,0 +1,88 @@
<?php␍
/**␍
* This is a PHP library that handles calling reCAPTCHA.␍
*␍
* @copyright Copyright (c) 2015, Google Inc.␍
* @link http://www.google.com/recaptcha␍
*␍
* Permission is hereby granted, free of charge, to any person obtaining a copy␍
* of this software and associated documentation files (the "Software"), to deal␍
* in the Software without restriction, including without limitation the rights␍
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell␍
* copies of the Software, and to permit persons to whom the Software is␍
* furnished to do so, subject to the following conditions:␍
*␍
* The above copyright notice and this permission notice shall be included in␍
* all copies or substantial portions of the Software.␍
*␍
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR␍
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,␍
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE␍
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER␍
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,␍
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN␍
* THE SOFTWARE.␍
*/
namespace ReCaptcha\RequestMethod;
use ReCaptcha\RequestMethod;
use ReCaptcha\RequestParameters;
/**␍
* Sends cURL request to the reCAPTCHA service.␍
* Note: this requires the cURL extension to be enabled in PHP␍
* @see http://php.net/manual/en/book.curl.php␍
*/
class CurlPost implements RequestMethod␍
{
/**␍
* URL to which requests are sent via cURL.␍
* @const string␍
*/
const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
/**␍
* Curl connection to the reCAPTCHA service␍
* @var Curl␍
*/
private $curl;
public function __construct(Curl $curl = null)
{
if (!is_null($curl)) {
$this->curl = $curl;
} else {
$this->curl = new Curl();
}
}
/**␍
* Submit the cURL request with the specified parameters.␍
*␍
* @param RequestParameters $params Request parameters␍
* @return string Body of the reCAPTCHA response␍
*/
public function submit(RequestParameters $params)
{
$handle = $this->curl->init(self::SITE_VERIFY_URL);
$options = array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params->toQueryString(),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
),
CURLINFO_HEADER_OUT => false,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true
);
$this->curl->setoptArray($handle, $options);
$response = $this->curl->exec($handle);
$this->curl->close($handle);
return $response;
}
}
+70
View File
@@ -0,0 +1,70 @@
<?php␍
/**␍
* This is a PHP library that handles calling reCAPTCHA.␍
*␍
* @copyright Copyright (c) 2015, Google Inc.␍
* @link http://www.google.com/recaptcha␍
*␍
* Permission is hereby granted, free of charge, to any person obtaining a copy␍
* of this software and associated documentation files (the "Software"), to deal␍
* in the Software without restriction, including without limitation the rights␍
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell␍
* copies of the Software, and to permit persons to whom the Software is␍
* furnished to do so, subject to the following conditions:␍
*␍
* The above copyright notice and this permission notice shall be included in␍
* all copies or substantial portions of the Software.␍
*␍
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR␍
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,␍
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE␍
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER␍
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,␍
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN␍
* THE SOFTWARE.␍
*/
namespace ReCaptcha\RequestMethod;
use ReCaptcha\RequestMethod;
use ReCaptcha\RequestParameters;
/**␍
* Sends POST requests to the reCAPTCHA service.␍
*/
class Post implements RequestMethod␍
{
/**␍
* URL to which requests are POSTed.␍
* @const string␍
*/
const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
/**␍
* Submit the POST request with the specified parameters.␍
*␍
* @param RequestParameters $params Request parameters␍
* @return string Body of the reCAPTCHA response␍
*/
public function submit(RequestParameters $params)
{
/**␍
* PHP 5.6.0 changed the way you specify the peer name for SSL context options.␍
* Using "CN_name" will still work, but it will raise deprecated errors.␍
*/
$peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => $params->toQueryString(),
// Force the peer to validate (not needed in 5.6.0+, but still works␍
'verify_peer' => true,
// Force the peer validation to use www.google.com␍
$peer_key => 'www.google.com',
),
);
$context = stream_context_create($options);
return file_get_contents(self::SITE_VERIFY_URL, false, $context);
}
}
+104
View File
@@ -0,0 +1,104 @@
<?php␍
/**␍
* This is a PHP library that handles calling reCAPTCHA.␍
*␍
* @copyright Copyright (c) 2015, Google Inc.␍
* @link http://www.google.com/recaptcha␍
*␍
* Permission is hereby granted, free of charge, to any person obtaining a copy␍
* of this software and associated documentation files (the "Software"), to deal␍
* in the Software without restriction, including without limitation the rights␍
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell␍
* copies of the Software, and to permit persons to whom the Software is␍
* furnished to do so, subject to the following conditions:␍
*␍
* The above copyright notice and this permission notice shall be included in␍
* all copies or substantial portions of the Software.␍
*␍
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR␍
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,␍
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE␍
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER␍
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,␍
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN␍
* THE SOFTWARE.␍
*/
namespace ReCaptcha\RequestMethod;
/**␍
* Convenience wrapper around native socket and file functions to allow for␍
* mocking.␍
*/
class Socket␍
{
private $handle = null;
/**␍
* fsockopen␍
* ␍
* @see http://php.net/fsockopen␍
* @param string $hostname␍
* @param int $port␍
* @param int $errno␍
* @param string $errstr␍
* @param float $timeout␍
* @return resource␍
*/
public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null)
{
$this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout));
if ($this->handle != false && $errno === 0 && $errstr === '') {
return $this->handle;
}
return false;
}
/**␍
* fwrite␍
* ␍
* @see http://php.net/fwrite␍
* @param string $string␍
* @param int $length␍
* @return int | bool␍
*/
public function fwrite($string, $length = null)
{
return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length));
}
/**␍
* fgets␍
* ␍
* @see http://php.net/fgets␍
* @param int $length␍
* @return string␍
*/
public function fgets($length = null)
{
return fgets($this->handle, $length);
}
/**␍
* feof␍
* ␍
* @see http://php.net/feof␍
* @return bool␍
*/
public function feof()
{
return feof($this->handle);
}
/**␍
* fclose␍
* ␍
* @see http://php.net/fclose␍
* @return bool␍
*/
public function fclose()
{
return fclose($this->handle);
}
}
+121
View File
@@ -0,0 +1,121 @@
<?php␍
/**␍
* This is a PHP library that handles calling reCAPTCHA.␍
*␍
* @copyright Copyright (c) 2015, Google Inc.␍
* @link http://www.google.com/recaptcha␍
*␍
* Permission is hereby granted, free of charge, to any person obtaining a copy␍
* of this software and associated documentation files (the "Software"), to deal␍
* in the Software without restriction, including without limitation the rights␍
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell␍
* copies of the Software, and to permit persons to whom the Software is␍
* furnished to do so, subject to the following conditions:␍
*␍
* The above copyright notice and this permission notice shall be included in␍
* all copies or substantial portions of the Software.␍
*␍
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR␍
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,␍
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE␍
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER␍
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,␍
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN␍
* THE SOFTWARE.␍
*/
namespace ReCaptcha\RequestMethod;
use ReCaptcha\RequestMethod;
use ReCaptcha\RequestParameters;
/**␍
* Sends a POST request to the reCAPTCHA service, but makes use of fsockopen()␍
* instead of get_file_contents(). This is to account for people who may be on␍
* servers where allow_furl_open is disabled.␍
*/
class SocketPost implements RequestMethod␍
{
/**␍
* reCAPTCHA service host.␍
* @const string␍
*/
const RECAPTCHA_HOST = 'www.google.com';
/**␍
* @const string reCAPTCHA service path␍
*/
const SITE_VERIFY_PATH = '/recaptcha/api/siteverify';
/**␍
* @const string Bad request error␍
*/
const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}';
/**␍
* @const string Bad response error␍
*/
const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}';
/**␍
* Socket to the reCAPTCHA service␍
* @var Socket␍
*/
private $socket;
/**␍
* Constructor␍
*␍
* @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing␍
*/
public function __construct(Socket $socket = null)
{
if (!is_null($socket)) {
$this->socket = $socket;
} else {
$this->socket = new Socket();
}
}
/**␍
* Submit the POST request with the specified parameters.␍
*␍
* @param RequestParameters $params Request parameters␍
* @return string Body of the reCAPTCHA response␍
*/
public function submit(RequestParameters $params)
{
$errno = 0;
$errstr = '';
if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) {
return self::BAD_REQUEST;
}
$content = $params->toQueryString();
$request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n";
$request .= "Host: " . self::RECAPTCHA_HOST . "\r\n";
$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
$request .= "Content-length: " . strlen($content) . "\r\n";
$request .= "Connection: close\r\n\r\n";
$request .= $content . "\r\n\r\n";
$this->socket->fwrite($request);
$response = '';
while (!$this->socket->feof()) {
$response .= $this->socket->fgets(4096);
}
$this->socket->fclose();
if (0 !== strpos($response, 'HTTP/1.1 200 OK')) {
return self::BAD_RESPONSE;
}
$parts = preg_split("#\n\s*\n#Uis", $response);
return $parts[1];
}
}
+103
View File
@@ -0,0 +1,103 @@
<?php␍
/**␍
* This is a PHP library that handles calling reCAPTCHA.␍
*␍
* @copyright Copyright (c) 2015, Google Inc.␍
* @link http://www.google.com/recaptcha␍
*␍
* Permission is hereby granted, free of charge, to any person obtaining a copy␍
* of this software and associated documentation files (the "Software"), to deal␍
* in the Software without restriction, including without limitation the rights␍
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell␍
* copies of the Software, and to permit persons to whom the Software is␍
* furnished to do so, subject to the following conditions:␍
*␍
* The above copyright notice and this permission notice shall be included in␍
* all copies or substantial portions of the Software.␍
*␍
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR␍
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,␍
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE␍
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER␍
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,␍
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN␍
* THE SOFTWARE.␍
*/
namespace ReCaptcha;
/**␍
* Stores and formats the parameters for the request to the reCAPTCHA service.␍
*/
class RequestParameters␍
{
/**␍
* Site secret.␍
* @var string␍
*/
private $secret;
/**␍
* Form response.␍
* @var string␍
*/
private $response;
/**␍
* Remote user's IP address.␍
* @var string␍
*/
private $remoteIp;
/**␍
* Client version.␍
* @var string␍
*/
private $version;
/**␍
* Initialise parameters.␍
*␍
* @param string $secret Site secret.␍
* @param string $response Value from g-captcha-response form field.␍
* @param string $remoteIp User's IP address.␍
* @param string $version Version of this client library.␍
*/
public function __construct($secret, $response, $remoteIp = null, $version = null)
{
$this->secret = $secret;
$this->response = $response;
$this->remoteIp = $remoteIp;
$this->version = $version;
}
/**␍
* Array representation.␍
*␍
* @return array Array formatted parameters.␍
*/
public function toArray()
{
$params = array('secret' => $this->secret, 'response' => $this->response);
if (!is_null($this->remoteIp)) {
$params['remoteip'] = $this->remoteIp;
}
if (!is_null($this->version)) {
$params['version'] = $this->version;
}
return $params;
}
/**␍
* Query string representation for HTTP request.␍
*␍
* @return string Query string formatted parameters.␍
*/
public function toQueryString()
{
return http_build_query($this->toArray(), '', '&');
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php␍
/**␍
* This is a PHP library that handles calling reCAPTCHA.␍
*␍
* @copyright Copyright (c) 2015, Google Inc.␍
* @link http://www.google.com/recaptcha␍
*␍
* Permission is hereby granted, free of charge, to any person obtaining a copy␍
* of this software and associated documentation files (the "Software"), to deal␍
* in the Software without restriction, including without limitation the rights␍
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell␍
* copies of the Software, and to permit persons to whom the Software is␍
* furnished to do so, subject to the following conditions:␍
*␍
* The above copyright notice and this permission notice shall be included in␍
* all copies or substantial portions of the Software.␍
*␍
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR␍
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,␍
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE␍
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER␍
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,␍
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN␍
* THE SOFTWARE.␍
*/
namespace ReCaptcha;
/**␍
* The response returned from the service.␍
*/
class Response␍
{
/**␍
* Succes or failure.␍
* @var boolean␍
*/
private $success = false;
/**␍
* Error code strings.␍
* @var array␍
*/
private $errorCodes = array();
/**␍
* Build the response from the expected JSON returned by the service.␍
*␍
* @param string $json␍
* @return \ReCaptcha\Response␍
*/
public static function fromJson($json)
{
$responseData = json_decode($json, true);
if (!$responseData) {
return new Response(false, array('invalid-json'));
}
if (isset($responseData['success']) && $responseData['success'] == true) {
return new Response(true);
}
if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
return new Response(false, $responseData['error-codes']);
}
return new Response(false);
}
/**␍
* Constructor.␍
*␍
* @param boolean $success␍
* @param array $errorCodes␍
*/
public function __construct($success, array $errorCodes = array())
{
$this->success = $success;
$this->errorCodes = $errorCodes;
}
/**␍
* Is success?␍
*␍
* @return boolean␍
*/
public function isSuccess()
{
return $this->success;
}
/**␍
* Get error codes.␍
*␍
* @return array␍
*/
public function getErrorCodes()
{
return $this->errorCodes;
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php␍
/* An autoloader for ReCaptcha\Foo classes. This should be required()␍
* by the user before attempting to instantiate any of the ReCaptcha␍
* classes.␍
*/
spl_autoload_register(function ($class) {
if (substr($class, 0, 10) !== 'ReCaptcha\\') {
/* If the class does not lie under the "ReCaptcha" namespace,␍
* then we can exit immediately.␍
*/
return;
}
/* All of the classes have names like "ReCaptcha\Foo", so we need␍
* to replace the backslashes with frontslashes if we want the␍
* name to map directly to a location in the filesystem.␍
*/
$class = str_replace('\\', '/', $class);
/* First, check under the current directory. It is important that␍
* we look here first, so that we don't waste time searching for␍
* test classes in the common case.␍
*/
$path = $class.'.php';
if (is_readable($path)) {
require_once $path;
}
});
+49
View File
@@ -0,0 +1,49 @@
<?php␍
/**␍
* PHPMailer SPL autoloader.␍
* PHP Version 5␍
* @package PHPMailer␍
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project␍
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>␍
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>␍
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>␍
* @author Brent R. Matzelle (original founder)␍
* @copyright 2012 - 2014 Marcus Bointon␍
* @copyright 2010 - 2012 Jim Jagielski␍
* @copyright 2004 - 2009 Andy Prevost␍
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License␍
* @note This program is distributed in the hope that it will be useful - WITHOUT␍
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or␍
* FITNESS FOR A PARTICULAR PURPOSE.␍
*/
/**␍
* PHPMailer SPL autoloader.␍
* @param string $classname The name of the class to load␍
*/
function PHPMailerAutoload($classname)
{
//Can't use __DIR__ as it's only in PHP 5.3+␍
$filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
if (is_readable($filename)) {
require $filename;
}
}
if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
//SPL autoloading was introduced in PHP 5.1.2␍
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
spl_autoload_register('PHPMailerAutoload', true, true);
} else {
spl_autoload_register('PHPMailerAutoload');
}
} else {
/**␍
* Fall back to traditional autoload for old PHP versions␍
* @param string $classname The name of the class to load␍
*/
function __autoload($classname)
{
PHPMailerAutoload($classname);
}
}
File diff suppressed because it is too large Load Diff
+397
View File
@@ -0,0 +1,397 @@
<?php␍
/**␍
* PHPMailer POP-Before-SMTP Authentication Class.␍
* PHP Version 5␍
* @package PHPMailer␍
* @link https://github.com/PHPMailer/PHPMailer/␍
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>␍
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>␍
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>␍
* @author Brent R. Matzelle (original founder)␍
* @copyright 2012 - 2014 Marcus Bointon␍
* @copyright 2010 - 2012 Jim Jagielski␍
* @copyright 2004 - 2009 Andy Prevost␍
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License␍
* @note This program is distributed in the hope that it will be useful - WITHOUT␍
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or␍
* FITNESS FOR A PARTICULAR PURPOSE.␍
*/
/**␍
* PHPMailer POP-Before-SMTP Authentication Class.␍
* Specifically for PHPMailer to use for RFC1939 POP-before-SMTP authentication.␍
* Does not support APOP.␍
* @package PHPMailer␍
* @author Richard Davey (original author) <rich@corephp.co.uk>␍
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>␍
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>␍
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>␍
*/
class POP3␍
{
/**␍
* The POP3 PHPMailer Version number.␍
* @type string␍
* @access public␍
*/
public $Version = '5.2.9';
/**␍
* Default POP3 port number.␍
* @type integer␍
* @access public␍
*/
public $POP3_PORT = 110;
/**␍
* Default timeout in seconds.␍
* @type integer␍
* @access public␍
*/
public $POP3_TIMEOUT = 30;
/**␍
* POP3 Carriage Return + Line Feed.␍
* @type string␍
* @access public␍
* @deprecated Use the constant instead␍
*/
public $CRLF = "\r\n";
/**␍
* Debug display level.␍
* Options: 0 = no, 1+ = yes␍
* @type integer␍
* @access public␍
*/
public $do_debug = 0;
/**␍
* POP3 mail server hostname.␍
* @type string␍
* @access public␍
*/
public $host;
/**␍
* POP3 port number.␍
* @type integer␍
* @access public␍
*/
public $port;
/**␍
* POP3 Timeout Value in seconds.␍
* @type integer␍
* @access public␍
*/
public $tval;
/**␍
* POP3 username␍
* @type string␍
* @access public␍
*/
public $username;
/**␍
* POP3 password.␍
* @type string␍
* @access public␍
*/
public $password;
/**␍
* Resource handle for the POP3 connection socket.␍
* @type resource␍
* @access private␍
*/
private $pop_conn;
/**␍
* Are we connected?␍
* @type boolean␍
* @access private␍
*/
private $connected = false;
/**␍
* Error container.␍
* @type array␍
* @access private␍
*/
private $errors = array();
/**␍
* Line break constant␍
*/
const CRLF = "\r\n";
/**␍
* Simple static wrapper for all-in-one POP before SMTP␍
* @param $host␍
* @param boolean $port␍
* @param boolean $tval␍
* @param string $username␍
* @param string $password␍
* @param integer $debug_level␍
* @return boolean␍
*/
public static function popBeforeSmtp(
$host,
$port = false,
$tval = false,
$username = '',
$password = '',
$debug_level = 0
) {
$pop = new POP3;
return $pop->authorise($host, $port, $tval, $username, $password, $debug_level);
}
/**␍
* Authenticate with a POP3 server.␍
* A connect, login, disconnect sequence␍
* appropriate for POP-before SMTP authorisation.␍
* @access public␍
* @param string $host The hostname to connect to␍
* @param integer|boolean $port The port number to connect to␍
* @param integer|boolean $timeout The timeout value␍
* @param string $username␍
* @param string $password␍
* @param integer $debug_level␍
* @return boolean␍
*/
public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
{
$this->host = $host;
// If no port value provided, use default␍
if (false === $port) {
$this->port = $this->POP3_PORT;
} else {
$this->port = (integer)$port;
}
// If no timeout value provided, use default␍
if (false === $timeout) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = (integer)$timeout;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
// Reset the error log␍
$this->errors = array();
// connect␍
$result = $this->connect($this->host, $this->port, $this->tval);
if ($result) {
$login_result = $this->login($this->username, $this->password);
if ($login_result) {
$this->disconnect();
return true;
}
}
// We need to disconnect regardless of whether the login succeeded␍
$this->disconnect();
return false;
}
/**␍
* Connect to a POP3 server.␍
* @access public␍
* @param string $host␍
* @param integer|boolean $port␍
* @param integer $tval␍
* @return boolean␍
*/
public function connect($host, $port = false, $tval = 30)
{
// Are we already connected?␍
if ($this->connected) {
return true;
}
//On Windows this will raise a PHP Warning error if the hostname doesn't exist.␍
//Rather than suppress it with @fsockopen, capture it cleanly instead␍
set_error_handler(array($this, 'catchWarning'));
if (false === $port) {
$port = $this->POP3_PORT;
}
// connect to the POP3 server␍
$this->pop_conn = fsockopen(
$host, // POP3 Host␍
$port, // Port #␍
$errno, // Error Number␍
$errstr, // Error Message␍
$tval␍
); // Timeout (seconds)␍
// Restore the error handler␍
restore_error_handler();
// Did we connect?␍
if (false === $this->pop_conn) {
// It would appear not...␍
$this->setError(array(
'error' => "Failed to connect to server $host on port $port",
'errno' => $errno,
'errstr' => $errstr␍
));
return false;
}
// Increase the stream time-out␍
stream_set_timeout($this->pop_conn, $tval, 0);
// Get the POP3 server response␍
$pop3_response = $this->getResponse();
// Check for the +OK␍
if ($this->checkResponse($pop3_response)) {
// The connection is established and the POP3 server is talking␍
$this->connected = true;
return true;
}
return false;
}
/**␍
* Log in to the POP3 server.␍
* Does not support APOP (RFC 2828, 4949).␍
* @access public␍
* @param string $username␍
* @param string $password␍
* @return boolean␍
*/
public function login($username = '', $password = '')
{
if (!$this->connected) {
$this->setError('Not connected to POP3 server');
}
if (empty($username)) {
$username = $this->username;
}
if (empty($password)) {
$password = $this->password;
}
// Send the Username␍
$this->sendString("USER $username" . self::CRLF);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
// Send the Password␍
$this->sendString("PASS $password" . self::CRLF);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
return true;
}
}
return false;
}
/**␍
* Disconnect from the POP3 server.␍
* @access public␍
*/
public function disconnect()
{
$this->sendString('QUIT');
//The QUIT command may cause the daemon to exit, which will kill our connection␍
//So ignore errors here␍
try {
@fclose($this->pop_conn);
} catch (Exception $e) {
//Do nothing␍
};
}
/**␍
* Get a response from the POP3 server.␍
* $size is the maximum number of bytes to retrieve␍
* @param integer $size␍
* @return string␍
* @access private␍
*/
private function getResponse($size = 128)
{
$response = fgets($this->pop_conn, $size);
if ($this->do_debug >= 1) {
echo "Server -> Client: $response";
}
return $response;
}
/**␍
* Send raw data to the POP3 server.␍
* @param string $string␍
* @return integer␍
* @access private␍
*/
private function sendString($string)
{
if ($this->pop_conn) {
if ($this->do_debug >= 2) { //Show client messages when debug >= 2␍
echo "Client -> Server: $string";
}
return fwrite($this->pop_conn, $string, strlen($string));
}
return 0;
}
/**␍
* Checks the POP3 server response.␍
* Looks for for +OK or -ERR.␍
* @param string $string␍
* @return boolean␍
* @access private␍
*/
private function checkResponse($string)
{
if (substr($string, 0, 3) !== '+OK') {
$this->setError(array(
'error' => "Server reported an error: $string",
'errno' => 0,
'errstr' => ''
));
return false;
} else {
return true;
}
}
/**␍
* Add an error to the internal error store.␍
* Also display debug output if it's enabled.␍
* @param $error␍
*/
private function setError($error)
{
$this->errors[] = $error;
if ($this->do_debug >= 1) {
echo '<pre>';
foreach ($this->errors as $error) {
print_r($error);
}
echo '</pre>';
}
}
/**␍
* POP3 connection error handler.␍
* @param integer $errno␍
* @param string $errstr␍
* @param string $errfile␍
* @param integer $errline␍
* @access private␍
*/
private function catchWarning($errno, $errstr, $errfile, $errline)
{
$this->setError(array(
'error' => "Connecting to the POP3 server raised a PHP warning: ",
'errno' => $errno,
'errstr' => $errstr,
'errfile' => $errfile,
'errline' => $errline␍
));
}
}
File diff suppressed because it is too large Load Diff