summaryrefslogtreecommitdiffstats
path: root/modules-available/rebootcontrol/hooks/config-tgz.inc.php
blob: c9ce1255b7ee08d4c96eeb90bd482cf63bb8e7aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

$pubkey = SSHKey::getPublicKey();
$tmpfile = '/tmp/bwlp-' . md5($pubkey) . '-2.tar';
if (!is_file($tmpfile) || !is_readable($tmpfile) || filemtime($tmpfile) + 86400 < time()) {
	if (file_exists($tmpfile)) {
		unlink($tmpfile);
	}
	try {
		$a = new PharData($tmpfile);
		$a->addFromString("/etc/ssh/mgmt/authorized_keys", $pubkey);
		$fi = $a->offsetGet("/etc/ssh/mgmt/authorized_keys");
		/** @var PharFileInfo $fi */
		$fi->chmod(0600);
		$file = $tmpfile;
	} catch (Exception $e) {
		EventLog::failure('Could not include ssh key for reboot-control in config.tgz', (string)$e);
	}
} elseif (is_file($tmpfile) && is_readable($tmpfile)) {
	$file = $tmpfile;
}