-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoll.php
More file actions
111 lines (91 loc) · 2.6 KB
/
poll.php
File metadata and controls
111 lines (91 loc) · 2.6 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?
// Cryptoblog Connection Tracker
// Copyleft by Elemential 2015
// Licensed under LGPL 3.0
require_once("config.php");
require_once("verify.php");
require_once("message.php");
$return_value = [ "valid" => false ];
header("Content-type: application/json");
$con = CryptoblogConfig::getConnection();
$inputMessage = new CryptoblogMessage($_REQUEST['data'], $_REQUEST['peerid'], CryptoblogMessage::ENCRYPTED);
if( $inputMessage -> getValid() )
{
$data = $inputMessage -> getMessage();
$query = sprintf(
"UPDATE %1\$s
SET last = CURRENT_TIMESTAMP
WHERE id = %2\$d",
CryptoblogConfig::getTableName("peers"),
intval($_REQUEST['peerid']));
$result = $con -> query($query);
$return_data = [];
$query = sprintf(
"SELECT id,pubkey
FROM %1\$s
WHERE room = (
SELECT room
FROM %1\$s
WHERE id = %2\$d
LIMIT 1
)
AND id != %2\$d
AND UNIX_TIMESTAMP(last)>%3\$d",
CryptoblogConfig::getTableName("peers"),
$_REQUEST['peerid'],
time()-10);
$result = $con -> query($query);
$peers = [];
while($row = $result -> fetch_assoc())
{
$peers[] = [
"id" => $row["id"],
"key" => $row["pubkey"]
];
}
$return_data["peers"] = $peers;
$query = sprintf(
"SELECT name,link
FROM %1\$s
WHERE id = (
SELECT room
FROM %2\$s
WHERE id = %3\$d
LIMIT 1
)",
CryptoblogConfig::getTableName("rooms"),
CryptoblogConfig::getTableName("peers"),
$_REQUEST['peerid']
);
$result = $con -> query($query);
if($row = $result -> fetch_assoc())
{
$return_data["room"] = [
"name" => $row['name'],
"link" => $row['link']
];
}
$query = sprintf(
"SELECT id,sender,content
FROM %1\$s
WHERE recipient = %2\$s
AND seen = FALSE",
CryptoblogConfig::getTableName("negotiations"),
$_REQUEST['peerid']);
$result = $con -> query($query);
$negotiations = [];
while($row = $result -> fetch_assoc())
{
$negotiations[] = [
"id" => $row['id'],
"sender" => $row["sender"],
"content" => $row["content"]
];
}
$return_data["negotiations"] = $negotiations;
$message = new CryptoblogMessage($return_data, $_REQUEST['peerid'], CryptoblogMessage::DECRYPTED);
$return_value["data"] = $message -> getMessage();
$return_value["valid"] = $message -> getValid();
}
echo json_encode( $return_value );
?>