Improvements
This commit is contained in:
@ -9,6 +9,8 @@ class Hotfix
|
||||
|
||||
protected $signer;
|
||||
|
||||
protected $keyId;
|
||||
|
||||
protected $header;
|
||||
|
||||
protected $body;
|
||||
@ -16,7 +18,8 @@ class Hotfix
|
||||
public function __construct($hotfix, $signer)
|
||||
{
|
||||
$this->load($hotfix);
|
||||
$this->signer = $signer;
|
||||
$this->signer = $signer[0];
|
||||
$this->keyId = $signer[1];
|
||||
}
|
||||
|
||||
protected function load($hotfix)
|
||||
@ -31,6 +34,11 @@ class Hotfix
|
||||
$this->body = $body;
|
||||
}
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
if (!array_key_exists('lang', $this->header)) {
|
||||
@ -40,9 +48,12 @@ class Hotfix
|
||||
}
|
||||
|
||||
$script = null;
|
||||
$head = null;
|
||||
$foot = null;
|
||||
switch ($lang) {
|
||||
case 'bash':
|
||||
$exec = "/bin/bash";
|
||||
$head = file_get_contents(__DIR__."/../stubs/bash.stub");
|
||||
break;
|
||||
case 'php':
|
||||
$exec = "/usr/bin/env php";
|
||||
@ -53,7 +64,7 @@ class Hotfix
|
||||
}
|
||||
$tmpfile = sys_get_temp_dir()."/hotfix_".sha1($this->header['hotfix']);
|
||||
|
||||
file_put_contents($tmpfile, $this->body);
|
||||
file_put_contents($tmpfile, $head."\n".$this->body."\n".$foot);
|
||||
passthru($exec." ".$tmpfile);
|
||||
unlink($tmpfile);
|
||||
}
|
||||
@ -68,6 +79,11 @@ class Hotfix
|
||||
$this->signer['uids'][0]['email']
|
||||
);
|
||||
}
|
||||
|
||||
public function getKeyId()
|
||||
{
|
||||
return $this->keyId;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
|
@ -22,6 +22,11 @@ class Loader
|
||||
$this->loaders[] = $loader;
|
||||
}
|
||||
|
||||
public function getLoaders()
|
||||
{
|
||||
return $this->loaders;
|
||||
}
|
||||
|
||||
public function load($fix, $insecure=false)
|
||||
{
|
||||
foreach ($this->loaders as $loader) {
|
||||
@ -56,12 +61,22 @@ class Loader
|
||||
throw new \Exception("Hotfix signature is not valid!");
|
||||
}
|
||||
|
||||
$keyInfo = gnupg_keyinfo($gpg, $sigInfo[0]['fingerprint']);
|
||||
$fingerprint = $sigInfo[0]['fingerprint'];
|
||||
$keyInfo = gnupg_keyinfo($gpg, $fingerprint);
|
||||
|
||||
$subKeys = $keyInfo[0]['subkeys'];
|
||||
$keyId = null;
|
||||
foreach ($subKeys as $subKey) {
|
||||
if ($subKey['fingerprint'] == $fingerprint) {
|
||||
$keyId = $subKey['keyid'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($keyInfo)) {
|
||||
throw new \Exception("Unknown signer (key id {$sigInfo[0]['fingerprint']})");
|
||||
}
|
||||
|
||||
return $keyInfo[0];
|
||||
return [ $keyInfo[0], $keyId ];
|
||||
}
|
||||
}
|
||||
|
@ -15,4 +15,9 @@ class FileLoader implements LoaderInterface
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getInfo()
|
||||
{
|
||||
return "<info>filename</info> - Read a hotfix from a file";
|
||||
}
|
||||
}
|
||||
|
@ -15,4 +15,9 @@ class GistLoader implements LoaderInterface
|
||||
return file_get_contents($url);
|
||||
|
||||
}
|
||||
|
||||
public function getInfo()
|
||||
{
|
||||
return "gist:<info>user</info>/<info>gist-id</info> - Read hotfix from a Gist";
|
||||
}
|
||||
}
|
||||
|
@ -12,4 +12,9 @@ class HttpLoader implements LoaderInterface
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getInfo()
|
||||
{
|
||||
return "http(s)://<info>url</info> - Read hotfix from a URL";
|
||||
}
|
||||
}
|
||||
|
@ -20,4 +20,9 @@ class PastebinLoader implements LoaderInterface
|
||||
return $body;
|
||||
|
||||
}
|
||||
|
||||
public function getInfo()
|
||||
{
|
||||
return "pastebin:<info>paste-id</info> - Read hotfix from Pastebin";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user