Exemple #1
0
	/**
	 * check if the matching key is available
	 */
	public function display_fingerprint_info() {

		if (!Login::$member->fingerprint) return;

		if (!$this->mail) {
			?><p class="problem"><?php 
echo _("Please confirm your email address and then reload this page!");
?>
</p><?
			return;
		}

		$gnupg = new_gnupg();

		$info = $gnupg->keyinfo($this->fingerprint());
		//var_dump($info);

		if ( !gnupg_keyinfo_matches_email($info, $this->mail) ) {
			?><p class="problem"><?php 
echo _("No key matching fingerprint and email address was found.");
?>
</p><?
			return;
		}

		if ($info[0]["disabled"]) {
			?><p class="problem"><?php 
echo _("This key is disabled.");
?>
</p><?
			return;
		}
		if ($info[0]["expired"]) {
			?><p class="problem"><?php 
echo _("This key is expired.");
?>
</p><?
			return;
		}
		if ($info[0]["revoked"]) {
			?><p class="problem"><?php 
echo _("This key is revoked.");
?>
</p><?
			return;
		}
		if ($info[0]["is_secret"]) {
			?><p class="problem"><?php 
echo _("This key is a secret key.");
?>
</p><?
			return;
		}
		if (!$info[0]["can_encrypt"]) {
			?><p class="problem"><?php 
echo _("This key can not encrypt.");
?>
</p><?
			return;
		}

		?><span class="fine" title="<?php 
echo _("The key was found and is usable.");
?>
">&#10003;</span><?

	}
			$import = $gnupg->import($_POST['key']);
			if (DEBUG) {
?>
<!--
<?php 
echo h(print_r($import, true));
?>
-->
<?
			}
			if ($import['imported'] + $import['unchanged'] + $import['newuserids'] + $import['newsubkeys'] > 1) {
				notice(sprintf(_("Multiple keys were uploaded at once. %d keys have been imported and %d keys are unchanged."), $import['imported'], $import['unchanged']));
			} elseif ($import['imported'] or $import['newuserids'] or $import['newuserids'] or $import['newsubkeys']) {
				if ($import['fingerprint'] != Login::$member->fingerprint()) {
					notice(_("The key has been imported, but does not match the fingerprint."));
				} elseif ( !gnupg_keyinfo_matches_email( $gnupg->keyinfo($import['fingerprint']), Login::$member->mail ) ) {
					notice(_("The key has been imported, but does not match the email address."));
				} else {
					success(_("The key has been imported."));
				}
			} elseif ($import['unchanged']) {
				notice(_("The key has already been imported."));
			} else {
				warning(_("The key could not be imported."));
			}
		}

		redirect();

	default:
		warning(_("Unknown action"));
/**
 * wrapper for mail()
 *
 * @param string  $to
 * @param string  $subject
 * @param string  $body
 * @param array   $headers     (optional)
 * @param string  $fingerprint (optional) encrypt mail with the public key with this fingerprint
 * @return bool
 */
function send_mail($to, $subject, $body, array $headers=array(), $fingerprint="") {

	$subject = mb_encode_mimeheader( limitstr(MAIL_SUBJECT_PREFIX.$subject, 125) );

	$headers[] = "Content-Type: text/plain; charset=UTF-8";
	$headers[] = "Content-Transfer-Encoding: 8bit";
	if (MAIL_FROM) $headers[] = "From: ".MAIL_FROM;

	$body = mb_wordwrap($body);

	if (GNUPG_SIGN_KEY) {
		$gnupg = new_gnupg();
		if ( $gnupg->addsignkey(GNUPG_SIGN_KEY) ) {
			if ($fingerprint) {
				if ( gnupg_keyinfo_matches_email($gnupg->keyinfo($fingerprint), $to) and $gnupg->addencryptkey($fingerprint) ) {
					$body = $gnupg->encryptsign($body);
				} else {
					$body .= "\n\n".mb_wordwrap(_("This email should be encrypted, but no available key matching your fingerprint and email address was found! Please check your settings:")." ".BASE_URL."settings_encryption.php");
					$body = $gnupg->sign($body);
				}
			} else {
				$body = $gnupg->sign($body);
			}
		} else {
			trigger_error("Gnupg sign key cound not be added", E_USER_WARNING);
		}
	}

	return mail($to, $subject, $body, join("\r\n", $headers));
}