Skip to content
Snippets Groups Projects
Commit 5db36b5f authored by Rasmus Fuhse's avatar Rasmus Fuhse
Browse files

re #17 : add migration

parent cd8f531b
No related branches found
No related tags found
No related merge requests found
......@@ -153,6 +153,11 @@ class MypluginsController extends MarketController
if ($release_data['type'] === "zipfile") {
$this->release['repository_download_url'] = null;
}
if (!Request::get("use_secret")) {
$this->release['repository_secret'] = null;
} elseif(!$this->release['repository_secret']) {
$this->release['repository_secret'] = md5(uniqid());
}
$this->release->installFile();
$this->release->store();
......
......@@ -15,10 +15,29 @@ class UpdateController extends MarketController
die();
}
if ($release->getSecurityHash() === Request::get("s")) {
$release->installFile();
$this->render_text("OK");
if ($release['repository_secret']
&& !$this->verify_secret($release['repository_secret'])) {
$this->render_text("Incorrect payload.");
return;
} else {
$release->installFile();
$this->render_text("OK");
}
} else {
$this->render_text("Insecure request.");
}
}
protected function verify_secret($secret)
{
if (!isset($_SERVER['HTTP_X_HUB_SIGNATURE'])) {
return false;
}
$signatureHeader = $_SERVER['HTTP_X_HUB_SIGNATURE'];
$payload = file_get_contents('php://input');
list($algorithm, $hash) = explode('=', $signatureHeader, 2);
$calculatedHash = hash_hmac($algorithm, $payload, $secret);
return $calculatedHash === $hash;
}
}
\ No newline at end of file
<?php
class AddReleaseSecret extends Migration {
public function up() {
DBManager::get()->exec("
ALTER TABLE `pluginmarket_releases`
ADD `repository_secret` VARCHAR( 32 ) NULL
AFTER `repository_download_url` ;
");
}
}
\ No newline at end of file
......@@ -39,6 +39,10 @@
<?= _("Download-URL des Branches oder des Tags") ?>
<input type="text" name="release[repository_download_url]" value="<?= htmlReady($release['repository_download_url']) ?>">
</label>
<label>
<?= _("Automatisches Update absichern ber Sicherheitstoken (optional)") ?>
<input type="checkbox" name="use_secret"<? $release->isNew() || $release['repository_secret'] ? " checked" : "" ?> value="1">
</label>
<p class="info">
<?= _("Github.com und gitlab bieten zu jedem Branch und Tag den Download als ZIP-Datei an. Klicken Sie dort mit rechter Maustaste auf den Downloadbutton und kopieren Sie die URL, um sie hier einzufgen. Nach dem Speichern hier knnen Sie auf github bzw. gitlab Webhooks einrichten, damit der Marktplatz sich automatisch die neuste Version des Plugins vom Repository holt. Damit ist das Plugin auf dem Pluginmarktplatz immer brandaktuell.") ?>
</p>
......@@ -53,6 +57,13 @@
<?= _("Webhook-URL zum Einfgen in github oder gitlab:") ?>
<input type="text" readonly style="border: thin solid #cccccc; background-color: #eeeeee; width:100%;" value="<?= $controller->absolute_url_for('update/release/' . $release->getId(), array('s' => $release->getSecurityHash())) ?>">
</p>
<? if ($release['repository_secret']) : ?>
<label>
<?= _("Secret (optional)") ?>
<input type="text" readonly style="border: thin solid #cccccc; background-color: #eeeeee;" name="release[repository_secret]" value="<?= htmlReady($release['repository_secret']) ?>">
</label>
<? endif ?>
<? if ($domain_warning) : ?>
<p class="info"><?= htmlReady($domain_warning) ?></p>
<? endif ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment