aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Zfinger.php
blob: ce7117ad8da4ff3cf14e57f0414efb40960a40c5 (plain) (blame)
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
<?php
namespace Zotlabs\Module;

use Zotlabs\Web\HTTPSig;
use Zotlabs\Lib\Libzot;

class Zfinger extends \Zotlabs\Web\Controller {

	function init() {

		require_once('include/zot.php');
		require_once('include/crypto.php');

		$x = zotinfo($_REQUEST);

		if($x && $x['guid'] && $x['guid_sig']) {
			$chan_hash = make_xchan_hash($x['guid'],$x['guid_sig']);
			if($chan_hash) {
				$chan = channelx_by_hash($chan_hash);
			}
		}

		$headers = [];
		$headers['Content-Type'] = 'application/json' ;
		$ret = json_encode($x);

		if($chan) {
			$headers['Digest'] = HTTPSig::generate_digest_header($ret);
			$h = HTTPSig::create_sig($headers,$chan['channel_prvkey'], channel_url($chan));
			HTTPSig::set_headers($h);
		}
		else {
			foreach($headers as $k => $v) {
				header($k . ': ' . $v);
			}
		}

		echo $ret;
		killme();

	}

}