/trunk/includes/.htaccess |
---|
0,0 → 1,3 |
Order Deny,Allow |
Deny From All |
/trunk/includes/SecureMailer.class.php |
---|
0,0 → 1,132 |
<?php |
/* |
* Secure Mailer PHP Class |
* Copyright 2009-2013 Daniel Marschall, ViaThinkSoft |
* QB_SECURE_MAIL_PARAM (C) Erich Kachel |
* Version 2013-04-14 |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); |
* you may not use this file except in compliance with the License. |
* You may obtain a copy of the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* See the License for the specific language governing permissions and |
* limitations under the License. |
*/ |
// TODO: getHeaders() als single string , attachments , remove headers etc, headers als array in/out, Braucht man auch ein addRawHeader()? |
class SecureMailer { |
private $headers = ''; |
// TODO: sollte eher private sein, geht aber net |
const endl = "\n"; // GMX will kein CRLF! wtf?! (Unter Postfix in Linux) |
private function QB_SECURE_MAIL_PARAM($param_ = '', $level_ = 2) { |
// Verhindert Mail-Header-Injections |
// Quelle: http://www.erich-kachel.de/?p=26 |
/* replace until done */ |
while (!isset($filtered) || ($param_ != $filtered)) { |
if (isset($filtered)) { |
$param_ = $filtered; |
} |
$filtered = preg_replace("/(Content-Transfer-Encoding:|MIME-Version:|content-type:|Subject:|to:|cc:|bcc:|from:|reply-to:)/ims", '', $param_); |
} |
unset($filtered); |
if ($level_ >= 2) { |
/* replace until done */ |
while (!isset($filtered) || ($param_ != $filtered)) { |
if (isset($filtered)) { |
$param_ = $filtered; |
} |
$filtered = preg_replace("/(%0A|\\\\r|%0D|\\\\n|%00|\\\\0|%09|\\\\t|%01|%02|%03|%04|%05|%06|%07|%08|%09|%0B|%0C|%0E|%0F|%10|%11|%12|%13)/ims", '', $param_); |
} |
} |
return $param_; |
} |
private function getHeaders() { |
return $this->headers; |
} |
private static function mail_base64_encode($text) { |
// Why 72? Seen here: http://linux.dsplabs.com.au/munpack-mime-base64-multi-part-attachment-php-perl-decode-email-pdf-p82/ |
return wordwrap(base64_encode($text), 72, self::endl, true); |
} |
private function headerLine($name, $value) { |
// Change 2011-02-09 |
// LF is OK! CRLF does lead to CR+CRLF on some systems! |
// http://bugs.php.net/bug.php?id=15841 |
// The mail() function is not talking to an SMTP server, so RFC2822 does not apply here. mail() is talking to a command line program on the local system, and it is reasonable to expect that program to require system-native line breaks. |
return $this->QB_SECURE_MAIL_PARAM($name).': '.$this->QB_SECURE_MAIL_PARAM($value)."\n"; |
} |
public function addHeader($name, $value) { |
$this->headers .= $this->headerLine($name, $value); |
} |
public static function utf8Subject($subject) { |
return '=?UTF-8?B?'.base64_encode(utf8_encode($subject)).'?='; |
} |
private function _sendMail($recipient, $subject, $message, $add_headers='') { |
return @mail( |
$this->QB_SECURE_MAIL_PARAM($recipient), |
$this->QB_SECURE_MAIL_PARAM($subject), |
$this->QB_SECURE_MAIL_PARAM($message, 1), |
$this->getHeaders().$add_headers |
); |
} |
public function sendMail($recipient, $subject, $message) { |
return $this->_sendMail($recipient, $subject, $message, ''); |
} |
// TODO: plain aus html berechnen als optional? |
public function sendMailHTMLandPlainMultipart($to, $subject, $msg_html, $msg_plain) { |
$boundary = uniqid('np'); |
$msg_html = $this->QB_SECURE_MAIL_PARAM($msg_html, 1); |
$msg_plain = $this->QB_SECURE_MAIL_PARAM($msg_plain, 1); |
$add_headers = $this->headerLine('MIME-Version', '1.0'); |
$add_headers .= $this->headerLine('Content-Type', 'multipart/alternative; boundary="'.$boundary.'"'); |
$message = "This is a MIME encoded message."; |
$message .= self::endl; |
$message .= self::endl; |
$message .= "--" . $boundary . self::endl; |
$message .= "Content-type: text/plain; charset=utf-8".self::endl; |
$message .= "Content-Transfer-Encoding: base64".self::endl; |
$message .= self::endl; |
$message .= $this->mail_base64_encode($msg_plain); // better than wordwrap"ed-printable because of long lines (e.g. links) |
$message .= self::endl; |
$message .= self::endl; |
$message .= "--" . $boundary . self::endl; |
$message .= "Content-type: text/html; charset=utf-8".self::endl; |
$message .= "Content-Transfer-Encoding: base64".self::endl; |
$message .= self::endl; |
$message .= $this->mail_base64_encode($msg_html); |
$message .= self::endl; |
$message .= self::endl."--" . $boundary . "--"; |
return @mail( |
$this->QB_SECURE_MAIL_PARAM($to), |
$this->QB_SECURE_MAIL_PARAM($subject), |
$message, |
$this->getHeaders().$add_headers |
); |
} |
} |
/trunk/includes/SecureMailer_mastercopy.class.php |
---|
0,0 → 1,0 |
link /home/daniel-marschall/public_html/code/php/SecureMailer.class.phps |
Property changes: |
Added: svn:special |
+* |
\ No newline at end of property |
/trunk/includes/database.inc.php |
---|
0,0 → 1,25 |
<?php |
function verbinden() { |
global $mysql_database, $mysql_server, $mysql_pass, $mysql_user; |
global $link2; |
$link2 = mysql_connect($mysql_server, $mysql_user, $mysql_pass); |
if (!$link2) { |
die('<b>Verbindung zum MySQL-Server konnte nicht hergestellt werden! ('.mysql_error().')</b>'); |
} |
if (!mysql_select_db($mysql_database)) { |
die('<b>Verbindung zum MySQL-Server konnte nicht hergestellt werden! ('.mysql_error().')</b>'); |
} |
register_shutdown_function('trennen'); |
mysql_select_db($mysql_database); |
} |
function trennen() { |
global $link2; |
@mysql_close($link2); |
} |
?> |
/trunk/includes/download_recaptcha.sh |
---|
0,0 → 1,11 |
#!/bin/bash |
OLDDIR=$( pwd ) |
DIR=$( dirname "$0" ) |
cd "$DIR" |
git clone https://github.com/google/recaptcha.git |
cd "$OLDDIR" |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
Added: svn:mime-type |
+text/x-sh |
\ No newline at end of property |
/trunk/includes/ip_functions.inc.php |
---|
0,0 → 1,61 |
<?php |
/* |
* IP functions |
* Copyright 2015 Daniel Marschall, ViaThinkSoft |
* Version 2015-10-27 |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); |
* you may not use this file except in compliance with the License. |
* You may obtain a copy of the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* See the License for the specific language governing permissions and |
* limitations under the License. |
*/ |
function get_real_ip() { |
/* Eindeutige IP Adresse erhalten, auch bei Proxies und (neu:) von SSH connections im CLI modus */ |
// http://lists.phpbar.de/pipermail/php/Week-of-Mon-20040322/007749.html |
// Modificated by VTS |
// Version: 2015-10-27 |
// TODO: ipv6 |
if (isset($_SERVER['SSH_CLIENT'])) { $ary = explode(' ', $_SERVER['SSH_CLIENT']); return $ary[0]; } |
if (isset($_SERVER['SSH_CONNECTION'])) { $ary = explode(' ', $_SERVER['SSH_CONNECTION']); return $ary[0]; } |
$client_ip = (isset($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : ''; |
// It is not secure to use these, since they are not validated: http://www.thespanner.co.uk/2007/12/02/faking-the-unexpected/ |
// $x_forwarded_for = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : ''; |
$x_forwarded_for = ''; |
$remote_addr = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : ''; |
if (!empty($client_ip)) { |
$ip_expl = explode('.', $client_ip); |
$referer = explode('.', $remote_addr); |
if ($referer[0] != $ip_expl[0]) { |
$ip = array_reverse($ip_expl); |
$return = implode('.', $ip); |
} else { |
$return = $client_ip; |
} |
} else if (!empty($x_forwarded_for)) { |
if (strstr($x_forwarded_for, ',')) { |
$ip_expl = explode(',', $x_forwarded_for); |
$return = end($ip_expl); |
} else { |
$return = $x_forwarded_for; |
} |
} else { |
$return = $remote_addr; |
} |
unset ($client_ip, $x_forwarded_for, $remote_addr, $ip_expl); |
return $return; |
} |
/trunk/includes/ip_functions_mastercopy.inc.php |
---|
0,0 → 1,0 |
link /home/daniel-marschall/public_html/code/php/ip_functions.inc.phps |
Property changes: |
Added: svn:special |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/HEAD |
---|
0,0 → 1,0 |
ref: refs/heads/master |
/trunk/includes/recaptcha/.git/config |
---|
0,0 → 1,11 |
[core] |
repositoryformatversion = 0 |
filemode = true |
bare = false |
logallrefupdates = true |
[remote "origin"] |
url = https://github.com/google/recaptcha.git |
fetch = +refs/heads/*:refs/remotes/origin/* |
[branch "master"] |
remote = origin |
merge = refs/heads/master |
/trunk/includes/recaptcha/.git/description |
---|
0,0 → 1,0 |
Unnamed repository; edit this file 'description' to name the repository. |
/trunk/includes/recaptcha/.git/hooks/applypatch-msg.sample |
---|
0,0 → 1,15 |
#!/bin/sh |
# |
# An example hook script to check the commit log message taken by |
# applypatch from an e-mail message. |
# |
# The hook should exit with non-zero status after issuing an |
# appropriate message if it wants to stop the commit. The hook is |
# allowed to edit the commit message file. |
# |
# To enable this hook, rename this file to "applypatch-msg". |
. git-sh-setup |
commitmsg="$(git rev-parse --git-path hooks/commit-msg)" |
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} |
: |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/hooks/commit-msg.sample |
---|
0,0 → 1,24 |
#!/bin/sh |
# |
# An example hook script to check the commit log message. |
# Called by "git commit" with one argument, the name of the file |
# that has the commit message. The hook should exit with non-zero |
# status after issuing an appropriate message if it wants to stop the |
# commit. The hook is allowed to edit the commit message file. |
# |
# To enable this hook, rename this file to "commit-msg". |
# Uncomment the below to add a Signed-off-by line to the message. |
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg |
# hook is more suited to it. |
# |
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') |
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" |
# This example catches duplicate Signed-off-by lines. |
test "" = "$(grep '^Signed-off-by: ' "$1" | |
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { |
echo >&2 Duplicate Signed-off-by lines. |
exit 1 |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/hooks/post-update.sample |
---|
0,0 → 1,8 |
#!/bin/sh |
# |
# An example hook script to prepare a packed repository for use over |
# dumb transports. |
# |
# To enable this hook, rename this file to "post-update". |
exec git update-server-info |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/hooks/pre-applypatch.sample |
---|
0,0 → 1,14 |
#!/bin/sh |
# |
# An example hook script to verify what is about to be committed |
# by applypatch from an e-mail message. |
# |
# The hook should exit with non-zero status after issuing an |
# appropriate message if it wants to stop the commit. |
# |
# To enable this hook, rename this file to "pre-applypatch". |
. git-sh-setup |
precommit="$(git rev-parse --git-path hooks/pre-commit)" |
test -x "$precommit" && exec "$precommit" ${1+"$@"} |
: |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/hooks/pre-commit.sample |
---|
0,0 → 1,49 |
#!/bin/sh |
# |
# An example hook script to verify what is about to be committed. |
# Called by "git commit" with no arguments. The hook should |
# exit with non-zero status after issuing an appropriate message if |
# it wants to stop the commit. |
# |
# To enable this hook, rename this file to "pre-commit". |
if git rev-parse --verify HEAD >/dev/null 2>&1 |
then |
against=HEAD |
else |
# Initial commit: diff against an empty tree object |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
fi |
# If you want to allow non-ASCII filenames set this variable to true. |
allownonascii=$(git config --bool hooks.allownonascii) |
# Redirect output to stderr. |
exec 1>&2 |
# Cross platform projects tend to avoid non-ASCII filenames; prevent |
# them from being added to the repository. We exploit the fact that the |
# printable range starts at the space character and ends with tilde. |
if [ "$allownonascii" != "true" ] && |
# Note that the use of brackets around a tr range is ok here, (it's |
# even required, for portability to Solaris 10's /usr/bin/tr), since |
# the square bracket bytes happen to fall in the designated range. |
test $(git diff --cached --name-only --diff-filter=A -z $against | |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 |
then |
cat <<\EOF |
Error: Attempt to add a non-ASCII file name. |
This can cause problems if you want to work with people on other platforms. |
To be portable it is advisable to rename the file. |
If you know what you are doing you can disable this check using: |
git config hooks.allownonascii true |
EOF |
exit 1 |
fi |
# If there are whitespace errors, print the offending file names and fail. |
exec git diff-index --check --cached $against -- |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/hooks/pre-push.sample |
---|
0,0 → 1,53 |
#!/bin/sh |
# An example hook script to verify what is about to be pushed. Called by "git |
# push" after it has checked the remote status, but before anything has been |
# pushed. If this script exits with a non-zero status nothing will be pushed. |
# |
# This hook is called with the following parameters: |
# |
# $1 -- Name of the remote to which the push is being done |
# $2 -- URL to which the push is being done |
# |
# If pushing without using a named remote those arguments will be equal. |
# |
# Information about the commits which are being pushed is supplied as lines to |
# the standard input in the form: |
# |
# <local ref> <local sha1> <remote ref> <remote sha1> |
# |
# This sample shows how to prevent push of commits where the log message starts |
# with "WIP" (work in progress). |
remote="$1" |
url="$2" |
z40=0000000000000000000000000000000000000000 |
while read local_ref local_sha remote_ref remote_sha |
do |
if [ "$local_sha" = $z40 ] |
then |
# Handle delete |
: |
else |
if [ "$remote_sha" = $z40 ] |
then |
# New branch, examine all commits |
range="$local_sha" |
else |
# Update to existing branch, examine new commits |
range="$remote_sha..$local_sha" |
fi |
# Check for WIP commit |
commit=`git rev-list -n 1 --grep '^WIP' "$range"` |
if [ -n "$commit" ] |
then |
echo >&2 "Found WIP commit in $local_ref, not pushing" |
exit 1 |
fi |
fi |
done |
exit 0 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/hooks/pre-rebase.sample |
---|
0,0 → 1,169 |
#!/bin/sh |
# |
# Copyright (c) 2006, 2008 Junio C Hamano |
# |
# The "pre-rebase" hook is run just before "git rebase" starts doing |
# its job, and can prevent the command from running by exiting with |
# non-zero status. |
# |
# The hook is called with the following parameters: |
# |
# $1 -- the upstream the series was forked from. |
# $2 -- the branch being rebased (or empty when rebasing the current branch). |
# |
# This sample shows how to prevent topic branches that are already |
# merged to 'next' branch from getting rebased, because allowing it |
# would result in rebasing already published history. |
publish=next |
basebranch="$1" |
if test "$#" = 2 |
then |
topic="refs/heads/$2" |
else |
topic=`git symbolic-ref HEAD` || |
exit 0 ;# we do not interrupt rebasing detached HEAD |
fi |
case "$topic" in |
refs/heads/??/*) |
;; |
*) |
exit 0 ;# we do not interrupt others. |
;; |
esac |
# Now we are dealing with a topic branch being rebased |
# on top of master. Is it OK to rebase it? |
# Does the topic really exist? |
git show-ref -q "$topic" || { |
echo >&2 "No such branch $topic" |
exit 1 |
} |
# Is topic fully merged to master? |
not_in_master=`git rev-list --pretty=oneline ^master "$topic"` |
if test -z "$not_in_master" |
then |
echo >&2 "$topic is fully merged to master; better remove it." |
exit 1 ;# we could allow it, but there is no point. |
fi |
# Is topic ever merged to next? If so you should not be rebasing it. |
only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` |
only_next_2=`git rev-list ^master ${publish} | sort` |
if test "$only_next_1" = "$only_next_2" |
then |
not_in_topic=`git rev-list "^$topic" master` |
if test -z "$not_in_topic" |
then |
echo >&2 "$topic is already up-to-date with master" |
exit 1 ;# we could allow it, but there is no point. |
else |
exit 0 |
fi |
else |
not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` |
/usr/bin/perl -e ' |
my $topic = $ARGV[0]; |
my $msg = "* $topic has commits already merged to public branch:\n"; |
my (%not_in_next) = map { |
/^([0-9a-f]+) /; |
($1 => 1); |
} split(/\n/, $ARGV[1]); |
for my $elem (map { |
/^([0-9a-f]+) (.*)$/; |
[$1 => $2]; |
} split(/\n/, $ARGV[2])) { |
if (!exists $not_in_next{$elem->[0]}) { |
if ($msg) { |
print STDERR $msg; |
undef $msg; |
} |
print STDERR " $elem->[1]\n"; |
} |
} |
' "$topic" "$not_in_next" "$not_in_master" |
exit 1 |
fi |
<<\DOC_END |
This sample hook safeguards topic branches that have been |
published from being rewound. |
The workflow assumed here is: |
* Once a topic branch forks from "master", "master" is never |
merged into it again (either directly or indirectly). |
* Once a topic branch is fully cooked and merged into "master", |
it is deleted. If you need to build on top of it to correct |
earlier mistakes, a new topic branch is created by forking at |
the tip of the "master". This is not strictly necessary, but |
it makes it easier to keep your history simple. |
* Whenever you need to test or publish your changes to topic |
branches, merge them into "next" branch. |
The script, being an example, hardcodes the publish branch name |
to be "next", but it is trivial to make it configurable via |
$GIT_DIR/config mechanism. |
With this workflow, you would want to know: |
(1) ... if a topic branch has ever been merged to "next". Young |
topic branches can have stupid mistakes you would rather |
clean up before publishing, and things that have not been |
merged into other branches can be easily rebased without |
affecting other people. But once it is published, you would |
not want to rewind it. |
(2) ... if a topic branch has been fully merged to "master". |
Then you can delete it. More importantly, you should not |
build on top of it -- other people may already want to |
change things related to the topic as patches against your |
"master", so if you need further changes, it is better to |
fork the topic (perhaps with the same name) afresh from the |
tip of "master". |
Let's look at this example: |
o---o---o---o---o---o---o---o---o---o "next" |
/ / / / |
/ a---a---b A / / |
/ / / / |
/ / c---c---c---c B / |
/ / / \ / |
/ / / b---b C \ / |
/ / / / \ / |
---o---o---o---o---o---o---o---o---o---o---o "master" |
A, B and C are topic branches. |
* A has one fix since it was merged up to "next". |
* B has finished. It has been fully merged up to "master" and "next", |
and is ready to be deleted. |
* C has not merged to "next" at all. |
We would want to allow C to be rebased, refuse A, and encourage |
B to be deleted. |
To compute (1): |
git rev-list ^master ^topic next |
git rev-list ^master next |
if these match, topic has not merged in next at all. |
To compute (2): |
git rev-list master..topic |
if this is empty, it is fully merged to "master". |
DOC_END |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/hooks/pre-receive.sample |
---|
0,0 → 1,24 |
#!/bin/sh |
# |
# An example hook script to make use of push options. |
# The example simply echoes all push options that start with 'echoback=' |
# and rejects all pushes when the "reject" push option is used. |
# |
# To enable this hook, rename this file to "pre-receive". |
if test -n "$GIT_PUSH_OPTION_COUNT" |
then |
i=0 |
while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" |
do |
eval "value=\$GIT_PUSH_OPTION_$i" |
case "$value" in |
echoback=*) |
echo "echo from the pre-receive-hook: ${value#*=}" >&2 |
;; |
reject) |
exit 1 |
esac |
i=$((i + 1)) |
done |
fi |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/hooks/prepare-commit-msg.sample |
---|
0,0 → 1,36 |
#!/bin/sh |
# |
# An example hook script to prepare the commit log message. |
# Called by "git commit" with the name of the file that has the |
# commit message, followed by the description of the commit |
# message's source. The hook's purpose is to edit the commit |
# message file. If the hook fails with a non-zero status, |
# the commit is aborted. |
# |
# To enable this hook, rename this file to "prepare-commit-msg". |
# This hook includes three examples. The first comments out the |
# "Conflicts:" part of a merge commit. |
# |
# The second includes the output of "git diff --name-status -r" |
# into the message, just before the "git status" output. It is |
# commented because it doesn't cope with --amend or with squashed |
# commits. |
# |
# The third example adds a Signed-off-by line to the message, that can |
# still be edited. This is rarely a good idea. |
case "$2,$3" in |
merge,) |
/usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; |
# ,|template,) |
# /usr/bin/perl -i.bak -pe ' |
# print "\n" . `git diff --cached --name-status -r` |
# if /^#/ && $first++ == 0' "$1" ;; |
*) ;; |
esac |
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') |
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/hooks/update.sample |
---|
0,0 → 1,128 |
#!/bin/sh |
# |
# An example hook script to block unannotated tags from entering. |
# Called by "git receive-pack" with arguments: refname sha1-old sha1-new |
# |
# To enable this hook, rename this file to "update". |
# |
# Config |
# ------ |
# hooks.allowunannotated |
# This boolean sets whether unannotated tags will be allowed into the |
# repository. By default they won't be. |
# hooks.allowdeletetag |
# This boolean sets whether deleting tags will be allowed in the |
# repository. By default they won't be. |
# hooks.allowmodifytag |
# This boolean sets whether a tag may be modified after creation. By default |
# it won't be. |
# hooks.allowdeletebranch |
# This boolean sets whether deleting branches will be allowed in the |
# repository. By default they won't be. |
# hooks.denycreatebranch |
# This boolean sets whether remotely creating branches will be denied |
# in the repository. By default this is allowed. |
# |
# --- Command line |
refname="$1" |
oldrev="$2" |
newrev="$3" |
# --- Safety check |
if [ -z "$GIT_DIR" ]; then |
echo "Don't run this script from the command line." >&2 |
echo " (if you want, you could supply GIT_DIR then run" >&2 |
echo " $0 <ref> <oldrev> <newrev>)" >&2 |
exit 1 |
fi |
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then |
echo "usage: $0 <ref> <oldrev> <newrev>" >&2 |
exit 1 |
fi |
# --- Config |
allowunannotated=$(git config --bool hooks.allowunannotated) |
allowdeletebranch=$(git config --bool hooks.allowdeletebranch) |
denycreatebranch=$(git config --bool hooks.denycreatebranch) |
allowdeletetag=$(git config --bool hooks.allowdeletetag) |
allowmodifytag=$(git config --bool hooks.allowmodifytag) |
# check for no description |
projectdesc=$(sed -e '1q' "$GIT_DIR/description") |
case "$projectdesc" in |
"Unnamed repository"* | "") |
echo "*** Project description file hasn't been set" >&2 |
exit 1 |
;; |
esac |
# --- Check types |
# if $newrev is 0000...0000, it's a commit to delete a ref. |
zero="0000000000000000000000000000000000000000" |
if [ "$newrev" = "$zero" ]; then |
newrev_type=delete |
else |
newrev_type=$(git cat-file -t $newrev) |
fi |
case "$refname","$newrev_type" in |
refs/tags/*,commit) |
# un-annotated tag |
short_refname=${refname##refs/tags/} |
if [ "$allowunannotated" != "true" ]; then |
echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 |
echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 |
exit 1 |
fi |
;; |
refs/tags/*,delete) |
# delete tag |
if [ "$allowdeletetag" != "true" ]; then |
echo "*** Deleting a tag is not allowed in this repository" >&2 |
exit 1 |
fi |
;; |
refs/tags/*,tag) |
# annotated tag |
if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 |
then |
echo "*** Tag '$refname' already exists." >&2 |
echo "*** Modifying a tag is not allowed in this repository." >&2 |
exit 1 |
fi |
;; |
refs/heads/*,commit) |
# branch |
if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then |
echo "*** Creating a branch is not allowed in this repository" >&2 |
exit 1 |
fi |
;; |
refs/heads/*,delete) |
# delete branch |
if [ "$allowdeletebranch" != "true" ]; then |
echo "*** Deleting a branch is not allowed in this repository" >&2 |
exit 1 |
fi |
;; |
refs/remotes/*,commit) |
# tracking branch |
;; |
refs/remotes/*,delete) |
# delete tracking branch |
if [ "$allowdeletebranch" != "true" ]; then |
echo "*** Deleting a tracking branch is not allowed in this repository" >&2 |
exit 1 |
fi |
;; |
*) |
# Anything else (is there anything else?) |
echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 |
exit 1 |
;; |
esac |
# --- Finished |
exit 0 |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/index |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/info/exclude |
---|
0,0 → 1,6 |
# git ls-files --others --exclude-from=.git/info/exclude |
# Lines that start with '#' are comments. |
# For a project mostly in C, the following would be a good set of |
# exclude patterns (uncomment them if you want to use them): |
# *.[oa] |
# *~ |
/trunk/includes/recaptcha/.git/logs/HEAD |
---|
0,0 → 1,0 |
0000000000000000000000000000000000000000 6990961e664372ddbed7ebc1cd673da7077552e5 root <root@viathinksoft.de> 1503261208 +0200 clone: from https://github.com/google/recaptcha.git |
/trunk/includes/recaptcha/.git/logs/refs/heads/master |
---|
0,0 → 1,0 |
0000000000000000000000000000000000000000 6990961e664372ddbed7ebc1cd673da7077552e5 root <root@viathinksoft.de> 1503261208 +0200 clone: from https://github.com/google/recaptcha.git |
/trunk/includes/recaptcha/.git/logs/refs/remotes/origin/HEAD |
---|
0,0 → 1,0 |
0000000000000000000000000000000000000000 6990961e664372ddbed7ebc1cd673da7077552e5 root <root@viathinksoft.de> 1503261208 +0200 clone: from https://github.com/google/recaptcha.git |
/trunk/includes/recaptcha/.git/objects/pack/pack-6e721fbee4b0c02dc553c0dda0ecf7d62b0893eb.idx |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/objects/pack/pack-6e721fbee4b0c02dc553c0dda0ecf7d62b0893eb.pack |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/includes/recaptcha/.git/packed-refs |
---|
0,0 → 1,8 |
# pack-refs with: peeled fully-peeled |
6990961e664372ddbed7ebc1cd673da7077552e5 refs/remotes/origin/master |
3d3e42e31e2f0bd4798d3252c6c02af42004ee50 refs/tags/1.0.0 |
c800b38d17fdd932978e6c8a788d493810c01a76 refs/tags/1.1.0 |
090585935d95ebdf2d16dd071b10c9179a94da47 refs/tags/1.1.1 |
2b7e00566afca82a38a1d3adb8e42c118006296e refs/tags/1.1.2 |
727c57fb4d77e81f85f1ea69c2dd8549180e16db refs/tags/1.1.3 |
^5a56d15ca10a7b75158178752b2ad8f755eb4f78 |
/trunk/includes/recaptcha/.git/refs/heads/master |
---|
0,0 → 1,0 |
6990961e664372ddbed7ebc1cd673da7077552e5 |
/trunk/includes/recaptcha/.git/refs/remotes/origin/HEAD |
---|
0,0 → 1,0 |
ref: refs/remotes/origin/master |
/trunk/includes/recaptcha/.gitignore |
---|
0,0 → 1,3 |
/composer.lock |
/nbproject/private/ |
/vendor/ |
/trunk/includes/recaptcha/.travis.yml |
---|
0,0 → 1,19 |
language: php |
sudo: false |
php: |
- '5.5' |
- '5.6' |
- '7.0' |
- '7.1' |
- hhvm |
- nightly |
before_script: |
- composer install |
- phpenv version-name | grep ^5.[34] && echo "extension=apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true |
- phpenv version-name | grep ^5.[34] && echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true |
script: |
- vendor/bin/phpunit |
/trunk/includes/recaptcha/CONTRIBUTING.md |
---|
0,0 → 1,24 |
Want to contribute? Great! First, read this page (including the small print at the end). |
### Before you contribute |
Before we can use your code, you must sign the |
[Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1) |
(CLA), which you can do online. The CLA is necessary mainly because you own the |
copyright to your changes, even after your contribution becomes part of our |
codebase, so we need your permission to use and distribute your code. We also |
need to be sure of various other things—for instance that you'll tell us if you |
know that your code infringes on other people's patents. You don't have to sign |
the CLA until after you've submitted your code for review and a member has |
approved it, but you must do it before we can put your code into our codebase. |
Before you start working on a larger contribution, you should get in touch with |
us first through the issue tracker with your idea so that we can help out and |
possibly guide you. Coordinating up front makes it much easier to avoid |
frustration later on. |
### Code reviews |
All submissions, including submissions by project members, require review. We |
use GitHub pull requests for this purpose. |
### The small print |
Contributions made by corporations are covered by a different agreement than |
the one above, the Software Grant and Corporate Contributor License Agreement. |
Property changes: |
Added: svn:mime-type |
+text/markdown |
\ No newline at end of property |
/trunk/includes/recaptcha/LICENSE |
---|
0,0 → 1,29 |
Copyright 2014, Google Inc. |
All rights reserved. |
Redistribution and use in source and binary forms, with or without |
modification, are permitted provided that the following conditions are |
met: |
* Redistributions of source code must retain the above copyright |
notice, this list of conditions and the following disclaimer. |
* Redistributions in binary form must reproduce the above |
copyright notice, this list of conditions and the following disclaimer |
in the documentation and/or other materials provided with the |
distribution. |
* Neither the name of Google Inc. nor the names of its |
contributors may be used to endorse or promote products derived from |
this software without specific prior written permission. |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
/trunk/includes/recaptcha/README.md |
---|
0,0 → 1,115 |
# reCAPTCHA PHP client library |
[![Build Status](https://travis-ci.org/google/recaptcha.svg)](https://travis-ci.org/google/recaptcha) |
[![Latest Stable Version](https://poser.pugx.org/google/recaptcha/v/stable.svg)](https://packagist.org/packages/google/recaptcha) |
[![Total Downloads](https://poser.pugx.org/google/recaptcha/downloads.svg)](https://packagist.org/packages/google/recaptcha) |
* Project page: http://www.google.com/recaptcha/ |
* Repository: https://github.com/google/recaptcha |
* Version: 1.1.3 |
* License: BSD, see [LICENSE](LICENSE) |
## Description |
reCAPTCHA is a free CAPTCHA service that protect websites from spam and abuse. |
This is Google authored code that provides plugins for third-party integration |
with reCAPTCHA. |
## Installation |
### Composer (Recommended) |
[Composer](https://getcomposer.org/) is a widely used dependency manager for PHP |
packages. This reCAPTCHA client is available on Packagist as |
[`google/recaptcha`](https://packagist.org/packages/google/recaptcha) and can be |
installed either by running the `composer require` command or adding the library |
to your `composer.json`. To enable Composer for you project, refer to the |
project's [Getting Started](https://getcomposer.org/doc/00-intro.md) |
documentation. |
To add this dependency using the command, run the following from within your |
project directory: |
``` |
composer require google/recaptcha "~1.1" |
``` |
Alternatively, add the dependency directly to your `composer.json` file: |
```json |
"require": { |
"google/recaptcha": "~1.1" |
} |
``` |
### Direct download (no Composer) |
If you wish to install the library manually (i.e. without Composer), then you |
can use the links on the main project page to either clone the repo or download |
the [ZIP file](https://github.com/google/recaptcha/archive/master.zip). For |
convenience, an autoloader script is provided in `src/autoload.php` which you |
can require into your script instead of Composer's `vendor/autoload.php`. For |
example: |
```php |
require('/path/to/recaptcha/src/autoload.php'); |
$recaptcha = new \ReCaptcha\ReCaptcha($secret); |
``` |
The classes in the project are structured according to the |
[PSR-4](http://www.php-fig.org/psr/psr-4/) standard, so you may of course also |
use your own autoloader or require the needed files directly in your code. |
### Development install |
If you would like to contribute to this project or run the unit tests on within |
your own environment you will need to install the development dependencies, in |
this case that means [PHPUnit](https://phpunit.de/). If you clone the repo and |
run `composer install` from within the repo, this will also grab PHPUnit and all |
its dependencies for you. If you only need the autoloader installed, then you |
can always specify to Composer not to run in development mode, e.g. `composer |
install --no-dev`. |
*Note:* These dependencies are only required for development, there's no |
requirement for them to be included in your production code. |
## Usage |
First, register keys for your site at https://www.google.com/recaptcha/admin |
When your app receives a form submission containing the `g-recaptcha-response` |
field, you can verify it using: |
```php |
<?php |
$recaptcha = new \ReCaptcha\ReCaptcha($secret); |
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp); |
if ($resp->isSuccess()) { |
// verified! |
// if Domain Name Validation turned off don't forget to check hostname field |
// if($resp->getHostName() === $_SERVER['SERVER_NAME']) { } |
} else { |
$errors = $resp->getErrorCodes(); |
} |
``` |
You can see an end-to-end working example in |
[examples/example-captcha.php](examples/example-captcha.php) |
## Upgrading |
### From 1.0.0 |
The previous version of this client is still available on the `1.0.0` tag [in |
this repo](https://github.com/google/recaptcha/tree/1.0.0) but it is purely for |
reference and will not receive any updates. |
The major changes in 1.1.0 are: |
* installation now via Composer; |
* class loading also via Composer; |
* classes now namespaced; |
* old method call was `$rc->verifyResponse($remoteIp, $response)`, new call is |
`$rc->verify($response, $remoteIp)` |
## Contributing |
We accept contributions via GitHub Pull Requests, but all contributors need to |
be covered by the standard Google Contributor License Agreement. You can find |
instructions for this in [CONTRIBUTING](CONTRIBUTING.md) |
Property changes: |
Added: svn:mime-type |
+text/markdown |
\ No newline at end of property |
/trunk/includes/recaptcha/composer.json |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/json |
Property changes: |
Added: svn:mime-type |
+application/json |
\ No newline at end of property |
/trunk/includes/recaptcha/examples/example-captcha.php |
---|
0,0 → 1,130 |
<?php |
/** |
* Working sample code to accompany the library. The instructions here assume |
* you've just cloned the repo. If you've installed via composer, you will want |
* to adjust the path to the autoloader. |
* |
* 1. Run the server. For example, under Linux you can probably use: |
* /usr/bin/php -S "localhost:8000" "examples/example-captcha.php" |
* 2. Point your browser at http://localhost:8000 |
* 3. Follow the instructions |
* |
* @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. |
*/ |
// Initiate the autoloader. The file should be generated by Composer. |
// You will provide your own autoloader or require the files directly if you did |
// not install via Composer. |
require_once __DIR__ . '/../vendor/autoload.php'; |
// Register API keys at https://www.google.com/recaptcha/admin |
$siteKey = ''; |
$secret = ''; |
// reCAPTCHA supported 40+ languages listed here: https://developers.google.com/recaptcha/docs/language |
$lang = 'en'; |
?> |
<html> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
<title>reCAPTCHA Example</title> |
<link rel="shortcut icon" href="//www.gstatic.com/recaptcha/admin/favicon.ico" type="image/x-icon"/> |
<style type="text/css"> |
body { |
margin: 1em 5em 0 5em; |
font-family: sans-serif; |
} |
fieldset { |
display: inline; |
padding: 1em; |
} |
</style> |
</head> |
<body> |
<h1>reCAPTCHA Example</h1> |
<?php if ($siteKey === '' || $secret === ''): ?> |
<h2>Add your keys</h2> |
<p>If you do not have keys already then visit <kbd> |
<a href = "https://www.google.com/recaptcha/admin"> |
https://www.google.com/recaptcha/admin</a></kbd> to generate them. |
Edit this file and set the respective keys in <kbd>$siteKey</kbd> and |
<kbd>$secret</kbd>. Reload the page after this.</p> |
<?php |
elseif (isset($_POST['g-recaptcha-response'])): |
// The POST data here is unfiltered because this is an example. |
// In production, *always* sanitise and validate your input' |
?> |
<h2><kbd>POST</kbd> data</h2> |
<kbd><pre><?php var_export($_POST); ?></pre></kbd> |
<?php |
// If the form submission includes the "g-captcha-response" field |
// Create an instance of the service using your secret |
$recaptcha = new \ReCaptcha\ReCaptcha($secret); |
// If file_get_contents() is locked down on your PHP installation to disallow |
// its use with URLs, then you can use the alternative request method instead. |
// This makes use of fsockopen() instead. |
// $recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\SocketPost()); |
// Make the call to verify the response and also pass the user's IP address |
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); |
if ($resp->isSuccess()): |
// If the response is a success, that's it! |
?> |
<h2>Success!</h2> |
<p>That's it. Everything is working. Go integrate this into your real project.</p> |
<p><a href="/">Try again</a></p> |
<?php |
else: |
// If it's not successful, then one or more error codes will be returned. |
?> |
<h2>Something went wrong</h2> |
<p>The following error was returned: <?php |
foreach ($resp->getErrorCodes() as $code) { |
echo '<kbd>' , $code , '</kbd> '; |
} |
?></p> |
<p>Check the error code reference at <kbd><a href="https://developers.google.com/recaptcha/docs/verify#error-code-reference">https://developers.google.com/recaptcha/docs/verify#error-code-reference</a></kbd>. |
<p><strong>Note:</strong> Error code <kbd>missing-input-response</kbd> may mean the user just didn't complete the reCAPTCHA.</p> |
<p><a href="/">Try again</a></p> |
<?php |
endif; |
else: |
// Add the g-recaptcha tag to the form you want to include the reCAPTCHA element |
?> |
<p>Complete the reCAPTCHA then submit the form.</p> |
<form action="/" method="post"> |
<fieldset> |
<legend>An example form</legend> |
<p>Example input A: <input type="text" name="ex-a" value="foo"></p> |
<p>Example input B: <input type="text" name="ex-b" value="bar"></p> |
<div class="g-recaptcha" data-sitekey="<?php echo $siteKey; ?>"></div> |
<script type="text/javascript" |
src="https://www.google.com/recaptcha/api.js?hl=<?php echo $lang; ?>"> |
</script> |
<p><input type="submit" value="Submit" /></p> |
</fieldset> |
</form> |
<?php endif; ?> |
</body> |
</html> |
/trunk/includes/recaptcha/phpunit.xml.dist |
---|
0,0 → 1,17 |
<?xml version="1.0" encoding="UTF-8"?> |
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.4/phpunit.xsd" |
colors="true" |
verbose="true" |
bootstrap="src/autoload.php"> |
<testsuites> |
<testsuite name="reCAPTCHA Test Suite"> |
<directory>tests/ReCaptcha/</directory> |
</testsuite> |
</testsuites> |
<filter> |
<whitelist> |
<directory suffix=".php">src/ReCaptcha/</directory> |
</whitelist> |
</filter> |
</phpunit> |
/trunk/includes/recaptcha/src/ReCaptcha/ReCaptcha.php |
---|
0,0 → 1,98 |
<?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.3'; |
/** |
* Shared secret for the site. |
* @var 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. |
* @throws \RuntimeException if $secret is invalid |
*/ |
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); |
} |
} |
/trunk/includes/recaptcha/src/ReCaptcha/RequestMethod/Curl.php |
---|
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); |
} |
} |
/trunk/includes/recaptcha/src/ReCaptcha/RequestMethod/CurlPost.php |
---|
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; |
} |
} |
/trunk/includes/recaptcha/src/ReCaptcha/RequestMethod/Post.php |
---|
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); |
} |
} |
/trunk/includes/recaptcha/src/ReCaptcha/RequestMethod/Socket.php |
---|
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); |
} |
} |
/trunk/includes/recaptcha/src/ReCaptcha/RequestMethod/SocketPost.php |
---|
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_url_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]; |
} |
} |
/trunk/includes/recaptcha/src/ReCaptcha/RequestMethod.php |
---|
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); |
} |
/trunk/includes/recaptcha/src/ReCaptcha/RequestParameters.php |
---|
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(), '', '&'); |
} |
} |
/trunk/includes/recaptcha/src/ReCaptcha/Response.php |
---|
0,0 → 1,122 |
<?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 |
{ |
/** |
* Success or failure. |
* @var boolean |
*/ |
private $success = false; |
/** |
* Error code strings. |
* @var array |
*/ |
private $errorCodes = array(); |
/** |
* The hostname of the site where the reCAPTCHA was solved. |
* @var string |
*/ |
private $hostname; |
/** |
* 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')); |
} |
$hostname = isset($responseData['hostname']) ? $responseData['hostname'] : null; |
if (isset($responseData['success']) && $responseData['success'] == true) { |
return new Response(true, array(), $hostname); |
} |
if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { |
return new Response(false, $responseData['error-codes'], $hostname); |
} |
return new Response(false, array(), $hostname); |
} |
/** |
* Constructor. |
* |
* @param boolean $success |
* @param array $errorCodes |
* @param string $hostname |
*/ |
public function __construct($success, array $errorCodes = array(), $hostname = null) |
{ |
$this->success = $success; |
$this->errorCodes = $errorCodes; |
$this->hostname = $hostname; |
} |
/** |
* Is success? |
* |
* @return boolean |
*/ |
public function isSuccess() |
{ |
return $this->success; |
} |
/** |
* Get error codes. |
* |
* @return array |
*/ |
public function getErrorCodes() |
{ |
return $this->errorCodes; |
} |
/** |
* Get hostname. |
* |
* @return string |
*/ |
public function getHostname() |
{ |
return $this->hostname; |
} |
} |
/trunk/includes/recaptcha/src/autoload.php |
---|
0,0 → 1,38 |
<?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 = dirname(__FILE__).'/'.$class.'.php'; |
if (is_readable($path)) { |
require_once $path; |
} |
/* If we didn't find what we're looking for already, maybe it's |
* a test class? |
*/ |
$path = dirname(__FILE__).'/../tests/'.$class.'.php'; |
if (is_readable($path)) { |
require_once $path; |
} |
}); |
/trunk/includes/recaptcha/tests/ReCaptcha/ReCaptchaTest.php |
---|
0,0 → 1,75 |
<?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; |
class ReCaptchaTest extends \PHPUnit_Framework_TestCase |
{ |
/** |
* @expectedException \RuntimeException |
* @dataProvider invalidSecretProvider |
*/ |
public function testExceptionThrownOnInvalidSecret($invalid) |
{ |
$rc = new ReCaptcha($invalid); |
} |
public function invalidSecretProvider() |
{ |
return array( |
array(''), |
array(null), |
array(0), |
array(new \stdClass()), |
array(array()), |
); |
} |
public function testVerifyReturnsErrorOnMissingResponse() |
{ |
$rc = new ReCaptcha('secret'); |
$response = $rc->verify(''); |
$this->assertFalse($response->isSuccess()); |
$this->assertEquals(array('missing-input-response'), $response->getErrorCodes()); |
} |
public function testVerifyReturnsResponse() |
{ |
$method = $this->getMock('\\ReCaptcha\\RequestMethod', array('submit')); |
$method->expects($this->once()) |
->method('submit') |
->with($this->callback(function ($params) { |
return true; |
})) |
->will($this->returnValue('{"success": true}')); |
; |
$rc = new ReCaptcha('secret', $method); |
$response = $rc->verify('response'); |
$this->assertTrue($response->isSuccess()); |
} |
} |
/trunk/includes/recaptcha/tests/ReCaptcha/RequestMethod/CurlPostTest.php |
---|
0,0 → 1,63 |
<?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\RequestParameters; |
class CurlPostTest extends \PHPUnit_Framework_TestCase |
{ |
protected function setUp() |
{ |
if (!extension_loaded('curl')) { |
$this->markTestSkipped( |
'The cURL extension is not available.' |
); |
} |
} |
public function testSubmit() |
{ |
$curl = $this->getMock('\\ReCaptcha\\RequestMethod\\Curl', |
array('init', 'setoptArray', 'exec', 'close')); |
$curl->expects($this->once()) |
->method('init') |
->willReturn(new \stdClass); |
$curl->expects($this->once()) |
->method('setoptArray') |
->willReturn(true); |
$curl->expects($this->once()) |
->method('exec') |
->willReturn('RESPONSEBODY'); |
$curl->expects($this->once()) |
->method('close'); |
$pc = new CurlPost($curl); |
$response = $pc->submit(new RequestParameters("secret", "response")); |
$this->assertEquals('RESPONSEBODY', $response); |
} |
} |
/trunk/includes/recaptcha/tests/ReCaptcha/RequestMethod/PostTest.php |
---|
0,0 → 1,118 |
<?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\RequestParameters; |
class PostTest extends \PHPUnit_Framework_TestCase |
{ |
public static $assert = null; |
protected $parameters = null; |
protected $runcount = 0; |
public function setUp() |
{ |
$this->parameters = new RequestParameters("secret", "response", "remoteip", "version"); |
} |
public function tearDown() |
{ |
self::$assert = null; |
} |
public function testHTTPContextOptions() |
{ |
$req = new Post(); |
self::$assert = array($this, "httpContextOptionsCallback"); |
$req->submit($this->parameters); |
$this->assertEquals(1, $this->runcount, "The assertion was ran"); |
} |
public function testSSLContextOptions() |
{ |
$req = new Post(); |
self::$assert = array($this, "sslContextOptionsCallback"); |
$req->submit($this->parameters); |
$this->assertEquals(1, $this->runcount, "The assertion was ran"); |
} |
public function httpContextOptionsCallback(array $args) |
{ |
$this->runcount++; |
$this->assertCommonOptions($args); |
$options = stream_context_get_options($args[2]); |
$this->assertArrayHasKey('http', $options); |
$this->assertArrayHasKey('method', $options['http']); |
$this->assertEquals("POST", $options['http']['method']); |
$this->assertArrayHasKey('content', $options['http']); |
$this->assertEquals($this->parameters->toQueryString(), $options['http']['content']); |
$this->assertArrayHasKey('header', $options['http']); |
$headers = array( |
"Content-type: application/x-www-form-urlencoded", |
); |
foreach ($headers as $header) { |
$this->assertContains($header, $options['http']['header']); |
} |
} |
public function sslContextOptionsCallback(array $args) |
{ |
$this->runcount++; |
$this->assertCommonOptions($args); |
$options = stream_context_get_options($args[2]); |
$this->assertArrayHasKey('http', $options); |
$this->assertArrayHasKey('verify_peer', $options['http']); |
$this->assertTrue($options['http']['verify_peer']); |
$key = version_compare(PHP_VERSION, "5.6.0", "<") ? "CN_name" : "peer_name"; |
$this->assertArrayHasKey($key, $options['http']); |
$this->assertEquals("www.google.com", $options['http'][$key]); |
} |
protected function assertCommonOptions(array $args) |
{ |
$this->assertCount(3, $args); |
$this->assertStringStartsWith("https://www.google.com/", $args[0]); |
$this->assertFalse($args[1]); |
$this->assertTrue(is_resource($args[2]), "The context options should be a resource"); |
} |
} |
function file_get_contents() |
{ |
if (PostTest::$assert) { |
return call_user_func(PostTest::$assert, func_get_args()); |
} |
// Since we can't represent maxlen in userland... |
return call_user_func_array('file_get_contents', func_get_args()); |
} |
/trunk/includes/recaptcha/tests/ReCaptcha/RequestMethod/SocketPostTest.php |
---|
0,0 → 1,90 |
<?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\RequestParameters; |
class SocketPostTest extends \PHPUnit_Framework_TestCase |
{ |
public function testSubmitSuccess() |
{ |
$socket = $this->getMock('\\ReCaptcha\\RequestMethod\\Socket', array('fsockopen', 'fwrite', 'fgets', 'feof', 'fclose')); |
$socket->expects($this->once()) |
->method('fsockopen') |
->willReturn(true); |
$socket->expects($this->once()) |
->method('fwrite'); |
$socket->expects($this->once()) |
->method('fgets') |
->willReturn("HTTP/1.1 200 OK\n\nRESPONSEBODY"); |
$socket->expects($this->exactly(2)) |
->method('feof') |
->will($this->onConsecutiveCalls(false, true)); |
$socket->expects($this->once()) |
->method('fclose') |
->willReturn(true); |
$ps = new SocketPost($socket); |
$response = $ps->submit(new RequestParameters("secret", "response", "remoteip", "version")); |
$this->assertEquals('RESPONSEBODY', $response); |
} |
public function testSubmitBadResponse() |
{ |
$socket = $this->getMock('\\ReCaptcha\\RequestMethod\\Socket', array('fsockopen', 'fwrite', 'fgets', 'feof', 'fclose')); |
$socket->expects($this->once()) |
->method('fsockopen') |
->willReturn(true); |
$socket->expects($this->once()) |
->method('fwrite'); |
$socket->expects($this->once()) |
->method('fgets') |
->willReturn("HTTP/1.1 500 NOPEn\\nBOBBINS"); |
$socket->expects($this->exactly(2)) |
->method('feof') |
->will($this->onConsecutiveCalls(false, true)); |
$socket->expects($this->once()) |
->method('fclose') |
->willReturn(true); |
$ps = new SocketPost($socket); |
$response = $ps->submit(new RequestParameters("secret", "response", "remoteip", "version")); |
$this->assertEquals(SocketPost::BAD_RESPONSE, $response); |
} |
public function testSubmitBadRequest() |
{ |
$socket = $this->getMock('\\ReCaptcha\\RequestMethod\\Socket', array('fsockopen')); |
$socket->expects($this->once()) |
->method('fsockopen') |
->willReturn(false); |
$ps = new SocketPost($socket); |
$response = $ps->submit(new RequestParameters("secret", "response", "remoteip", "version")); |
$this->assertEquals(SocketPost::BAD_REQUEST, $response); |
} |
} |
/trunk/includes/recaptcha/tests/ReCaptcha/RequestParametersTest.php |
---|
0,0 → 1,61 |
<?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; |
class RequestParametersTest extends \PHPUnit_Framework_TestCase |
{ |
public function provideValidData() |
{ |
return array( |
array('SECRET', 'RESPONSE', 'REMOTEIP', 'VERSION', |
array('secret' => 'SECRET', 'response' => 'RESPONSE', 'remoteip' => 'REMOTEIP', 'version' => 'VERSION'), |
'secret=SECRET&response=RESPONSE&remoteip=REMOTEIP&version=VERSION'), |
array('SECRET', 'RESPONSE', null, null, |
array('secret' => 'SECRET', 'response' => 'RESPONSE'), |
'secret=SECRET&response=RESPONSE'), |
); |
} |
/** |
* @dataProvider provideValidData |
*/ |
public function testToArray($secret, $response, $remoteIp, $version, $expectedArray, $expectedQuery) |
{ |
$params = new RequestParameters($secret, $response, $remoteIp, $version); |
$this->assertEquals($params->toArray(), $expectedArray); |
} |
/** |
* @dataProvider provideValidData |
*/ |
public function testToQueryString($secret, $response, $remoteIp, $version, $expectedArray, $expectedQuery) |
{ |
$params = new RequestParameters($secret, $response, $remoteIp, $version); |
$this->assertEquals($params->toQueryString(), $expectedQuery); |
} |
} |
/trunk/includes/recaptcha/tests/ReCaptcha/ResponseTest.php |
---|
0,0 → 1,84 |
<?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; |
class ResponseTest extends \PHPUnit_Framework_TestCase |
{ |
/** |
* @dataProvider provideJson |
*/ |
public function testFromJson($json, $success, $errorCodes, $hostname) |
{ |
$response = Response::fromJson($json); |
$this->assertEquals($success, $response->isSuccess()); |
$this->assertEquals($errorCodes, $response->getErrorCodes()); |
$this->assertEquals($hostname, $response->getHostname()); |
} |
public function provideJson() |
{ |
return array( |
array('{"success": true}', true, array(), null), |
array('{"success": true, "hostname": "google.com"}', true, array(), 'google.com'), |
array('{"success": false, "error-codes": ["test"]}', false, array('test'), null), |
array('{"success": false, "error-codes": ["test"], "hostname": "google.com"}', false, array('test'), 'google.com'), |
array('{"success": true, "error-codes": ["test"]}', true, array(), null), |
array('{"success": true, "error-codes": ["test"], "hostname": "google.com"}', true, array(), 'google.com'), |
array('{"success": false}', false, array(), null), |
array('{"success": false, "hostname": "google.com"}', false, array(), 'google.com'), |
array('BAD JSON', false, array('invalid-json'), null), |
); |
} |
public function testIsSuccess() |
{ |
$response = new Response(true); |
$this->assertTrue($response->isSuccess()); |
$response = new Response(false); |
$this->assertFalse($response->isSuccess()); |
$response = new Response(true, array(), 'example.com'); |
$this->assertEquals('example.com', $response->getHostName()); |
} |
public function testGetErrorCodes() |
{ |
$errorCodes = array('test'); |
$response = new Response(true, $errorCodes); |
$this->assertEquals($errorCodes, $response->getErrorCodes()); |
} |
public function testGetHostname() |
{ |
$hostname = 'google.com'; |
$errorCodes = array(); |
$response = new Response(true, $errorCodes, $hostname); |
$this->assertEquals($hostname, $response->getHostname()); |
} |
} |