]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_notify.php
mucho progress on notifier, email style dfrn url's
[friendica.git] / mod / dfrn_notify.php
1 <?php
2
3
4
5
6
7 function dfrn_notify_post(&$a) {
8
9         $dfrn_id = notags(trim($_POST['dfrn_id']));
10         $challenge = notags(trim($_POST['challenge']));
11         $data = $_POST['data'];
12
13         $r = q("SELECT * FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
14                 dbesc($dfrn_id),
15                 dbesc($challenge)
16         );
17         if(! count($r))
18                 xml_status(3);
19
20         $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
21                 dbesc($dfrn_id),
22                 dbesc($challenge)
23         );
24
25
26
27
28
29
30
31 }
32
33
34
35
36
37
38
39
40
41
42
43
44 function dfrn_notify_content(&$a) {
45
46         if(x($_GET,'dfrn_id')) {
47                 // initial communication from external contact
48                 $hash = random_string();
49
50                 $status = 0;
51
52                 $r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time()));
53
54                 $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` )
55                         VALUES( '%s', '%s', '%s') ",
56                         dbesc($hash),
57                         dbesc(notags(trim($_GET['dfrn_id']))),
58                         intval(time() + 60 )
59                 );
60
61                 $r = q("SELECT * FROM `contact` WHERE `issued-id` = '%s' AND `blocked` = 0 LIMIT 1",
62                         dbesc($_GET['dfrn_id']));
63                 if((! count($r)) || (! strlen($r[0]['prvkey'])))
64                         $status = 1;
65
66                 $challenge = '';
67
68                 openssl_private_encrypt($hash,$challenge,$r[0]['prvkey']);
69                 $challenge = bin2hex($challenge);
70                 echo '<?xml version="1.0" encoding="UTF-8"?><dfrn_notify><status>' .$status . '</status><dfrn_id>' . $_GET['dfrn_id'] . '</dfrn_id>'
71                         . '<challenge>' . $challenge . '</challenge></dfrn_notify>' . "\r\n" ;
72                 session_write_close();
73                 exit;
74                 
75         }
76
77 }