Source

lorea_production / elgg / mod / elggpg / raw.php

<?php
require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");

//require_once 'Crypt/GPG.php';

header("Content-type: text/plain");
if (!isloggedin()) {
  forward();
}

//$gpg = new Crypt_GPG(array('homedir' => elggpg_get_gpg_home()));
//echo $gpg->exportPublicKey($user->email);
putenv("GNUPGHOME=".elggpg_get_gpg_home());

$userids = get_input("keyid");
$accessid = get_input("accessid");
$akf = get_input("akf");
$url = get_input('url');

function getKeyList($users, $fullkey = false) {
	$gnupg = new gnupg();
	$list = array();
	foreach($users as $user) {
		if (!($user instanceof ElggUser)) {
			$user = get_entity($user);
		}
		$export = new stdClass;
		$export->userid = $user->guid;
		$export->uri = $user->url;
		$export->pubkey = $gnupg->export($user->email);
	 	$info = $gnupg->keyinfo($user->email);
	 	$export->keyid = $info[0]['subkeys'][0]['keyid'];
		$list[] = $export;
	}
	return $list;
}
error_log(" AKF " . $akf . "userids " . $userids . "ACCESSID " . $accessid);

if ($akf) {
	action_gatekeeper();
	$currentakf=get_metadata_byname($_SESSION['user']->guid,$_SERVER['HTTP_REFERER']);
	if ($currentakf) {
		$currentakf->value = $akf;
	} else { 
		create_metadata($_SESSION['user']->guid,$_SERVER['HTTP_REFERER'],$akf,'text',$_SESSION['user']->guid);
	}
	echo 'true';
} elseif ($userids) {
	$user_guids = explode(',', $_SESSION['user']->guid . ',' . $userids);
	$keyList = getKeyList($user_guids);
	echo json_encode($keyList);

} elseif ($accessid) {
	$members = get_members_of_access_collection($accessid);
	$keyList = getKeyList($members);
	echo json_encode($keyList);

} else {
	$user = get_entity(get_input('user'));
	$gnupg = new gnupg();
	echo $gnupg->export($user->email);
}
	

?>