-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-comment.php
76 lines (69 loc) · 2.85 KB
/
add-comment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
$config = include('../config.php');
header("Content-type: text/plain; charset=utf-8", true, 200); //Response body is text
if(isset($_POST['replyingto'])) {
$post = $_POST;
$message = trim($_POST['message']);
$name = trim($_POST['name']);
$email = md5(strtolower(trim( $_POST['email'])));
$emailorig = strtolower(trim( $_POST['email']));
$url = trim($_POST['url']);
$replyingto = trim($_POST['replyingto']);
$slug = $_POST['slug'];
$token = $_POST['token'];
$secretKey = $config['secretKey'];
// post request to server
$recaptchaurl = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) . '&response=' . urlencode($token);
$response = file_get_contents($recaptchaurl);
$responseKeys = json_decode($response,true);
// end post request
//check if the test was done OK, if the action name is correct
if ($responseKeys["success"] && $responseKeys["action"] == 'addcomment') {
$date = new DateTime();
$datetostring = $date->getTimestamp();
$myfilename = "entry$datetostring.yml";
$myfile = fopen($myfilename, "w") or die("Unable to open file!");
$txt = "_id: $datetostring\n";
fwrite($myfile, $txt);
$txt = "replying_to: '$replyingto'\n";
fwrite($myfile, $txt);
$txt = "message: \"$message\"\n";
fwrite($myfile, $txt);
$txt = "name: $name\n";
fwrite($myfile, $txt);
$txt = "email: $email\n";
fwrite($myfile, $txt);
$txt = "emailorig: $emailorig\n";
fwrite($myfile, $txt);
$txt = "url: $url\n";
fwrite($myfile, $txt);
$txt = "date: $datetostring\n";
fwrite($myfile, $txt);
$txt = "slug: $slug\n";
fwrite($myfile, $txt);
$responseKeysSuccess = $responseKeys["success"];
$txt = "reCaptchaSuccess: $responseKeysSuccess\n";
fwrite($myfile, $txt);
$responseKeysScore = $responseKeys["score"];
$txt = "reCaptchaScore: $responseKeysScore\n";
fwrite($myfile, $txt);
$responseKeysAction = $responseKeys["action"];
$txt = "reCaptchaAction: $responseKeysAction\n";
fwrite($myfile, $txt);
$responseKeysTS = $responseKeys["challenge_ts"];
$txt = "reCaptchaTimestamp: $responseKeysTS\n";
fwrite($myfile, $txt);
$responseKeysHost = $responseKeys["hostname"];
$txt = "reCaptchaHost: $responseKeysHost\n";
fwrite($myfile, $txt);
fclose($myfile);
exit("OK");
}
else {
exit("The only true wisdom is in knowing you know nothing.");
}
}
else {
exit("INVALID REQUEST.");
}
?>