Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reCAPTCHA v3, protection of BGP summary, and assorted bug fixes #46

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
5 changes: 5 additions & 0 deletions htdocs/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
lg_config.php
!lg_logo.gif
*.gif
*.jpg
*.jpeg
*.png
122 changes: 122 additions & 0 deletions htdocs/backend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

$_CONFIG = [];

if (file_exists('lg_config.php') AND is_readable('lg_config.php'))
{
require_once 'lg_config.php';
}

function curlCall($url, $headers, $action, $postdata = null){
if($action == "get"){
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, "3");
curl_setopt($ch, CURLOPT_TIMEOUT, "3");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$data = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if(curl_error($ch)){
return array(
"status" => 503,
"response" => json_decode(curl_error($ch), true)
);
}
curl_close($ch);
if(! empty($status)){
if($status < 400){
return array(
"status" => $status,
"response" => json_decode($data, true)
);
} else {
return array(
"status" => $status,
"response" => json_decode($data, true)
);
}
} else {
return array(
"status" => $status,
"response" => json_decode($data, true)
);
}
} elseif($action == "post"){
$encodedPostData = http_build_query($postdata);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encodedPostData);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, "3");
curl_setopt($ch, CURLOPT_TIMEOUT, "3");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$data = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if(curl_error($ch)){
return array(
"status" => 503,
"response" => json_decode(curl_error($ch), true)
);
}
curl_close($ch);
if(! empty($status)){
if($status < 400){
return array(
"status" => $status,
"response" => json_decode($data, true)
);
} else {
return array(
"status" => $status,
"response" => json_decode($data, true)
);
}
} else {
return array(
"status" => $status,
"response" => json_decode($data, true)
);
}
} else {
return array(
"status" => 400,
"response" => null
);
}
}

function verifyToken($token){
global $_CONFIG;
$url = $_CONFIG['recaptchaBackendVerifyURL'];
$headers = array(
"Content-Type: application/x-www-form-urlencoded"
);
return curlCall($url, $headers, "post", [
"secret" => $_CONFIG['recaptchaSiteSecret'],
"response" => $token
]);
}

$request = json_decode(file_get_contents('php://input'), true);
$token = "";

if(isset($request['token'])){
$token = $request['token'];
}

$response = verifyToken($token);

if($response){
echo json_encode($response, JSON_PRETTY_PRINT);
} else {
var_dump($response);
}



?>
17 changes: 17 additions & 0 deletions htdocs/forbidden.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
$urlProtocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
$url = $urlProtocol . "://" . $_SERVER['SERVER_NAME'] . "/";
?>
<html>
<head>
<Body>
<h1>403 Forbidden</h1>
<p>reCAPTCHA was unsuccessful or expired, redirecting...</p>
</Body>
</head>
<Script>
setTimeout(function () {
window.location.href = "<?php echo $url; ?>";
}, 2200);
</Script>
</html>
Loading