Injection fix and log appname fix

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2016-11-10 16:16:33 +01:00 committed by Roeland Jago Douma
parent 2f5f1096ad
commit 3b62003c9c
No known key found for this signature in database
GPG Key ID: F941078878347C0C
4 changed files with 30 additions and 14 deletions

View File

@ -54,7 +54,7 @@ class CssController extends Controller {
}
/**
* @NoAdminRequired
* @PublicPage
* @NoCSRFRequired
*
* @param string $fileName css filename with extension
@ -76,8 +76,7 @@ class CssController extends Controller {
$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
$response->addHeader('Pragma', 'cache');
return $response;
} else {
return new NotFoundResponse();
}
return new NotFoundResponse();
}
}

View File

@ -27,7 +27,12 @@ namespace OC\Template;
class CSSResourceLocator extends ResourceLocator {
/** @var IAppData */
protected $appData;
/** @var \OCP\IURLGenerator */
protected $urlGenerator;
/** @var \OCP\Files\IConfig */
protected $systemConfig;
/**
* @param \OCP\ILogger $logger
@ -36,8 +41,11 @@ class CSSResourceLocator extends ResourceLocator {
* @param array $party_map
* @param IAppData $appData
*/
public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map, $appData) {
public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, $systemConfig) {
$this->appData = $appData;
$this->urlGenerator = $urlGenerator;
$this->systemConfig = $systemConfig;
parent::__construct($logger, $theme, $core_map, $party_map);
}
@ -47,8 +55,8 @@ class CSSResourceLocator extends ResourceLocator {
public function doFind($style) {
if (strpos($style, '3rdparty') === 0
&& $this->appendIfExist($this->thirdpartyroot, $style.'.css')
|| $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $this->appData)
|| $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss', $this->appData)
|| $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $this->appData, $this->urlGenerator, $this->systemConfig)
|| $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss', $this->appData, $this->urlGenerator, $this->systemConfig)
|| $this->appendIfExist($this->serverroot, $style.'.css')
|| $this->appendIfExist($this->serverroot, 'core/'.$style.'.css')
) {

View File

@ -115,19 +115,21 @@ abstract class ResourceLocator {
* @param string|null $webRoot base for path, default map $root to $webRoot
* @return bool True if the resource was found and cached, false otherwise
*/
protected function cacheAndAppendScssIfExist($root, $file, $appData, $webRoot = null) {
protected function cacheAndAppendScssIfExist($root, $file, $appData, $urlGenerator, $systemConfig, $webRoot = null) {
if (is_file($root.'/'.$file)) {
$scssCache = new \OC\Template\SCSSCacher(
$this->logger,
$root,
$file,
$appData);
$appData,
$urlGenerator,
$systemConfig);
if($scssCache->process()) {
$this->append($root, $scssCache->getCachedSCSS(), $webRoot, false);
return true;
} else {
$this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'server']);
$this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
return false;
}
}

View File

@ -40,6 +40,10 @@ class SCSSCacher {
protected $logger;
/** @var \OCP\Files\IAppData */
protected $appData;
/** @var \OCP\IURLGenerator */
protected $urlGenerator;
/** @var \OCP\Files\IConfig */
protected $systemConfig;
/**
* @param \OCP\ILogger $logger
@ -47,9 +51,12 @@ class SCSSCacher {
* @param string $file
* @param \OCP\Files\IAppData $appData
*/
public function __construct(\OCP\ILogger $logger, $root, $file, $appData) {
public function __construct(\OCP\ILogger $logger, $root, $file, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, $systemConfig) {
$this->logger = $logger;
$this->appData = $appData;
$this->urlGenerator = $urlGenerator;
$this->systemConfig = $systemConfig;
$this->root = $root;
$this->file = explode('/', $root.'/'.$file);
@ -110,7 +117,7 @@ class SCSSCacher {
private function cache() {
$scss = new Compiler();
$scss->setImportPaths($this->fileLoc);
if(\OC::$server->getSystemConfig()->getValue('debug')) {
if($this->systemConfig->getValue('debug')) {
// Debug mode
$scss->setFormatter('Leafo\ScssPhp\Formatter\Expanded');
$scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
@ -129,13 +136,13 @@ class SCSSCacher {
try {
$compiledScss = $scss->compile('@import "'.$this->fileNameSCSS.'";');
} catch(ParserException $e) {
$this->logger->error($e, ['app' => 'server']);
$this->logger->error($e, ['app' => 'core']);
return false;
}
try {
$cachedfile->putContent($this->rebaseUrls($compiledScss));
$this->logger->debug($this->rootCssLoc.'/'.$this->fileNameSCSS.' compiled and successfully cached', ['app' => 'server']);
$this->logger->debug($this->rootCssLoc.'/'.$this->fileNameSCSS.' compiled and successfully cached', ['app' => 'core']);
return true;
} catch(NotFoundException $e) {
return false;
@ -159,6 +166,6 @@ class SCSSCacher {
* @return string
*/
public function getCachedSCSS() {
return substr(\OC::$server->getURLGenerator()->linkToRoute('core.Css.getCss', array('fileName' => $this->fileNameCSS)), 1);
return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $this->fileNameCSS)), 1);
}
}