2018-02-23 04:16:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HarbormasterBuildLogView extends AphrontView {
|
|
|
|
|
|
|
|
private $log;
|
2018-02-23 04:35:13 +01:00
|
|
|
private $highlightedLineRange;
|
2018-02-23 04:16:45 +01:00
|
|
|
|
|
|
|
public function setBuildLog(HarbormasterBuildLog $log) {
|
|
|
|
$this->log = $log;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBuildLog() {
|
|
|
|
return $this->log;
|
|
|
|
}
|
|
|
|
|
2018-02-23 04:35:13 +01:00
|
|
|
public function setHighlightedLineRange($range) {
|
|
|
|
$this->highlightedLineRange = $range;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHighlightedLineRange() {
|
|
|
|
return $this->highlightedLineRange;
|
|
|
|
}
|
|
|
|
|
2018-02-23 04:16:45 +01:00
|
|
|
public function render() {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$log = $this->getBuildLog();
|
|
|
|
$id = $log->getID();
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->setHeader(pht('Build Log %d', $id));
|
|
|
|
|
|
|
|
$download_uri = "/harbormaster/log/download/{$id}/";
|
|
|
|
|
Never generate file download forms which point to the CDN domain, tighten "form-action" CSP
Summary:
Depends on D19155. Ref T13094. Ref T4340.
We can't currently implement a strict `form-action 'self'` content security policy because some file downloads rely on a `<form />` which sometimes POSTs to the CDN domain.
Broadly, stop generating these forms. We just redirect instead, and show an interstitial confirm dialog if no CDN domain is configured. This makes the UX for installs with no CDN domain a little worse and the UX for everyone else better.
Then, implement the stricter Content-Security-Policy.
This also removes extra confirm dialogs for downloading Harbormaster build logs and data exports.
Test Plan:
- Went through the plain data export, data export with bulk jobs, ssh key generation, calendar ICS download, Diffusion data, Paste data, Harbormaster log data, and normal file data download workflows with a CDN domain.
- Went through all those workflows again without a CDN domain.
- Grepped for affected symbols (`getCDNURI()`, `getDownloadURI()`).
- Added an evil form to a page, tried to submit it, was rejected.
- Went through the ReCaptcha and Stripe flows again to see if they're submitting any forms.
Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam
Maniphest Tasks: T13094, T4340
Differential Revision: https://secure.phabricator.com/D19156
2018-03-01 00:22:10 +01:00
|
|
|
$can_download = (bool)$log->getFilePHID();
|
|
|
|
|
2018-02-23 04:16:45 +01:00
|
|
|
$download_button = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setHref($download_uri)
|
|
|
|
->setIcon('fa-download')
|
Never generate file download forms which point to the CDN domain, tighten "form-action" CSP
Summary:
Depends on D19155. Ref T13094. Ref T4340.
We can't currently implement a strict `form-action 'self'` content security policy because some file downloads rely on a `<form />` which sometimes POSTs to the CDN domain.
Broadly, stop generating these forms. We just redirect instead, and show an interstitial confirm dialog if no CDN domain is configured. This makes the UX for installs with no CDN domain a little worse and the UX for everyone else better.
Then, implement the stricter Content-Security-Policy.
This also removes extra confirm dialogs for downloading Harbormaster build logs and data exports.
Test Plan:
- Went through the plain data export, data export with bulk jobs, ssh key generation, calendar ICS download, Diffusion data, Paste data, Harbormaster log data, and normal file data download workflows with a CDN domain.
- Went through all those workflows again without a CDN domain.
- Grepped for affected symbols (`getCDNURI()`, `getDownloadURI()`).
- Added an evil form to a page, tried to submit it, was rejected.
- Went through the ReCaptcha and Stripe flows again to see if they're submitting any forms.
Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam
Maniphest Tasks: T13094, T4340
Differential Revision: https://secure.phabricator.com/D19156
2018-03-01 00:22:10 +01:00
|
|
|
->setDisabled(!$can_download)
|
|
|
|
->setWorkflow(!$can_download)
|
2018-02-23 04:16:45 +01:00
|
|
|
->setText(pht('Download Log'));
|
|
|
|
|
|
|
|
$header->addActionLink($download_button);
|
|
|
|
|
|
|
|
$box_view = id(new PHUIObjectBoxView())
|
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
2018-02-28 15:39:30 +01:00
|
|
|
->setHeader($header);
|
|
|
|
|
|
|
|
$has_linemap = $log->getLineMap();
|
|
|
|
if ($has_linemap) {
|
|
|
|
$content_id = celerity_generate_unique_node_id();
|
|
|
|
$content_div = javelin_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'id' => $content_id,
|
|
|
|
'class' => 'harbormaster-log-view-loading',
|
|
|
|
),
|
|
|
|
pht('Loading...'));
|
|
|
|
|
|
|
|
require_celerity_resource('harbormaster-css');
|
|
|
|
|
|
|
|
Javelin::initBehavior(
|
|
|
|
'harbormaster-log',
|
|
|
|
array(
|
|
|
|
'contentNodeID' => $content_id,
|
|
|
|
'renderURI' => $log->getRenderURI($this->getHighlightedLineRange()),
|
|
|
|
));
|
|
|
|
|
|
|
|
$box_view->appendChild($content_div);
|
|
|
|
} else {
|
|
|
|
$box_view->setFormErrors(
|
|
|
|
array(
|
|
|
|
pht(
|
|
|
|
'This older log is missing required rendering data. To rebuild '.
|
|
|
|
'rendering data, run: %s',
|
|
|
|
phutil_tag(
|
|
|
|
'tt',
|
|
|
|
array(),
|
|
|
|
'$ bin/harbormaster rebuild-log --force --id '.$log->getID())),
|
|
|
|
));
|
|
|
|
}
|
2018-02-23 04:16:45 +01:00
|
|
|
|
|
|
|
return $box_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|