Ejemplo n.º 1
0
	/**
	 * Test that a message can be written to a log file.
	 *
	 * @return \Core\Utilities\Logger\LogFile The log file created.
	 */
	public function testWrite(){
		$type = 'testphpunit';
		$msg  = \BaconIpsumGenerator::Make_a_Sentence();
		$code = '/test/' . Core::RandomHex(6);

		// First, I'll test the functional method.
		\Core\Utilities\Logger\append_to($type, $msg, $code);

		// Now a file should exist called testphpunit.log that contains the line above.
		$this->assertTrue(file_exists(ROOT_PDIR . 'logs/' . $type . '.log'));
		$contents = file_get_contents(ROOT_PDIR . 'logs/' . $type . '.log');
		$this->assertContains($msg, $contents);
		$this->assertContains($code, $contents);

		// And now the class method, (should be identical).
		$type = 'testphpunit';
		$msg  = \BaconIpsumGenerator::Make_a_Sentence();
		$code = '/test/' . Core::RandomHex(6);

		// First, I'll test the functional method.
		$log = new \Core\Utilities\Logger\LogFile($type);
		$log->write($msg, $code);

		// Now a file should exist called testphpunit.log that contains the line above.
		$this->assertTrue($log->exists());
		$contents = $log->getContents();
		$this->assertContains($msg, $contents);
		$this->assertContains($code, $contents);

		return $log;
	}
Ejemplo n.º 2
0
	/**
	 * Send the commands to a user to verify they have access to the provided GPG key.
	 *
	 * @param \UserModel $user
	 * @param string     $fingerprint
	 * @param boolean    $cli         Set to false to send non-CLI instructions.
	 *
	 * @return false|string
	 */
	public static function SendVerificationEmail(\UserModel $user, $fingerprint, $cli = true){
		$sentence = trim(\BaconIpsumGenerator::Make_a_Sentence());

		$nonce = \NonceModel::Generate(
			'30 minutes',
			null,
			[
				'sentence' => $sentence,
				'key' => $fingerprint,
				'user' => $user->get('id'),
			]
		);

		$key = $user->get('apikey');
		$url = \Core\resolve_link('/gpgauth/rawverify');
		if($cli){
			$cmd = <<<EOD
echo -n "{$sentence}" \\
| gpg -b -a --default-key $fingerprint \\
| curl --data-binary @- \\
--header "X-Core-Nonce-Key: $nonce" \\
$url

EOD;
		}
		else{
			$cmd = <<<EOD
echo -n "{$sentence}" | gpg -b -a
EOD;
		}


		$email = new \Email();
		$email->templatename = 'emails/user/gpgauth_key_verification.tpl';
		$email->setSubject('GPG Key Change Request');
		$email->assign('key', $fingerprint);
		$email->assign('sentence', $sentence);
		$email->assign('user', $user);
		$email->assign('cmd', $cmd);
		$email->to($user->get('email'));
		$email->setEncryption($fingerprint);

		\SystemLogModel::LogSecurityEvent('/user/gpg/submit', 'Verification requested for key ' . $fingerprint, null, $user->get('id'));

		if(!$email->send()){
			return false;
		}
		else{
			return $nonce;
		}
	}