Merge branch 'cc-5709-airtime-analyzer' into saas-file-sanitization
Conflicts: airtime_mvc/application/controllers/LibraryController.php airtime_mvc/application/modules/rest/controllers/MediaController.php
This commit is contained in:
commit
9098e204e5
|
@ -1,9 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: sourcefabric
|
|
||||||
* Date: 17/02/15
|
|
||||||
*/
|
|
||||||
|
|
||||||
class FileDataHelper {
|
class FileDataHelper {
|
||||||
|
|
||||||
|
@ -12,9 +7,16 @@ class FileDataHelper {
|
||||||
* at all costs, so check the data and sanitize it if necessary
|
* at all costs, so check the data and sanitize it if necessary
|
||||||
* @param array $data array containing new file metadata
|
* @param array $data array containing new file metadata
|
||||||
*/
|
*/
|
||||||
public static function sanitizeData(&$data) {
|
public static function sanitizeData(&$data)
|
||||||
// If the track number isn't numeric, this will return 0
|
{
|
||||||
$data["track_number"] = intval($data["track_number"]);
|
if (array_key_exists("track_number", $data)) {
|
||||||
|
// If the track number isn't numeric, this will return 0
|
||||||
|
$data["track_number"] = intval($data["track_number"]);
|
||||||
|
}
|
||||||
|
if (array_key_exists("year", $data)) {
|
||||||
|
// If the track number isn't numeric, this will return 0
|
||||||
|
$data["year"] = intval($data["year"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -441,12 +441,11 @@ class LibraryController extends Zend_Controller_Action
|
||||||
$serialized[$j["name"]] = $j["value"];
|
$serialized[$j["name"]] = $j["value"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($form->isValid($serialized)) {
|
// Sanitize any wildly incorrect metadata before it goes to be validated.
|
||||||
// Sanitize any incorrect metadata that slipped past validation
|
FileDataHelper::sanitizeData($serialized);
|
||||||
FileDataHelper::sanitizeData($serialized);
|
|
||||||
$file->setDbColMetadata($serialized);
|
|
||||||
|
|
||||||
$this->_redirect('Library');
|
if ($form->isValid($serialized)) {
|
||||||
|
$file->setDbColMetadata($serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,9 +119,6 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
$file->save();
|
$file->save();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// Sanitize any incorrect metadata that slipped past validation
|
|
||||||
FileDataHelper::sanitizeData($whiteList);
|
|
||||||
|
|
||||||
/* If full_path is set, the post request came from ftp.
|
/* If full_path is set, the post request came from ftp.
|
||||||
* Users are allowed to upload folders via ftp. If this is the case
|
* Users are allowed to upload folders via ftp. If this is the case
|
||||||
* we need to include the folder name with the file name, otherwise
|
* we need to include the folder name with the file name, otherwise
|
||||||
|
@ -175,8 +172,6 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
$file->save();
|
$file->save();
|
||||||
return;
|
return;
|
||||||
} else if ($file && isset($requestData["resource_id"])) {
|
} else if ($file && isset($requestData["resource_id"])) {
|
||||||
// Sanitize any incorrect metadata that slipped past validation
|
|
||||||
FileDataHelper::sanitizeData($whiteList);
|
|
||||||
|
|
||||||
$file->fromArray($whiteList, BasePeer::TYPE_FIELDNAME);
|
$file->fromArray($whiteList, BasePeer::TYPE_FIELDNAME);
|
||||||
|
|
||||||
|
@ -206,8 +201,6 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
->setHttpResponseCode(200)
|
->setHttpResponseCode(200)
|
||||||
->appendBody(json_encode(CcFiles::sanitizeResponse($file)));
|
->appendBody(json_encode(CcFiles::sanitizeResponse($file)));
|
||||||
} else if ($file) {
|
} else if ($file) {
|
||||||
// Sanitize any incorrect metadata that slipped past validation
|
|
||||||
FileDataHelper::sanitizeData($whiteList);
|
|
||||||
|
|
||||||
//local file storage
|
//local file storage
|
||||||
$file->setDbDirectory(self::MUSIC_DIRS_STOR_PK);
|
$file->setDbDirectory(self::MUSIC_DIRS_STOR_PK);
|
||||||
|
@ -304,6 +297,9 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
|
|
||||||
private function validateRequestData($file, &$whiteList)
|
private function validateRequestData($file, &$whiteList)
|
||||||
{
|
{
|
||||||
|
// Sanitize any wildly incorrect metadata before it goes to be validated
|
||||||
|
FileDataHelper::sanitizeData($whiteList);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// EditAudioMD form is used here for validation
|
// EditAudioMD form is used here for validation
|
||||||
$fileForm = new Application_Form_EditAudioMD();
|
$fileForm = new Application_Form_EditAudioMD();
|
||||||
|
|
Loading…
Reference in New Issue