tokens for multipart data upload.
This commit is contained in:
parent
5c69eda010
commit
feff7f4343
|
@ -24,15 +24,33 @@ class PluploadController extends Zend_Controller_Action
|
||||||
$this->view->headScript()->appendFile($baseUrl.'js/plupload/i18n/'.$locale.'.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
$this->view->headScript()->appendFile($baseUrl.'js/plupload/i18n/'.$locale.'.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
||||||
|
|
||||||
$this->view->headLink()->appendStylesheet($baseUrl.'css/plupload.queue.css?'.$CC_CONFIG['airtime_version']);
|
$this->view->headLink()->appendStylesheet($baseUrl.'css/plupload.queue.css?'.$CC_CONFIG['airtime_version']);
|
||||||
|
|
||||||
|
$csrf_namespace = new Zend_Session_Namespace('csrf_namespace');
|
||||||
|
$csrf_namespace->setExpirationSeconds(900);
|
||||||
|
$csrf_namespace->authtoken = sha1(uniqid(rand(),1));
|
||||||
|
|
||||||
|
$csrf_element = new Zend_Form_Element_Hidden('csrf');
|
||||||
|
$csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label');
|
||||||
|
$csrf_form = new Zend_Form();
|
||||||
|
$csrf_form->addElement($csrf_element);
|
||||||
|
$this->view->form = $csrf_form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function uploadAction()
|
public function uploadAction()
|
||||||
{
|
{
|
||||||
|
$current_namespace = new Zend_Session_Namespace('csrf_namespace');
|
||||||
|
$observed_csrf_token = $this->_getParam('csrf_token');
|
||||||
|
$expected_csrf_token = $current_namespace->authtoken;
|
||||||
|
|
||||||
|
if($observed_csrf_token == $expected_csrf_token){
|
||||||
$upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
|
$upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
|
||||||
$tempFilePath = Application_Model_StoredFile::uploadFile($upload_dir);
|
$tempFilePath = Application_Model_StoredFile::uploadFile($upload_dir);
|
||||||
$tempFileName = basename($tempFilePath);
|
$tempFileName = basename($tempFilePath);
|
||||||
|
|
||||||
$this->_helper->json->sendJson(array("jsonrpc" => "2.0", "tempfilepath" => $tempFileName));
|
$this->_helper->json->sendJson(array("jsonrpc" => "2.0", "tempfilepath" => $tempFileName));
|
||||||
|
}else{
|
||||||
|
$this->_helper->json->sendJson(array("jsonrpc" => "2.0", "valid" => false, "error" => "CSRF token did not match."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function copyfileAction()
|
public function copyfileAction()
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<form id="plupload_form">
|
<form id="plupload_form">
|
||||||
|
<?php echo $this->form->getElement('csrf') ?>
|
||||||
<div id="plupload_files"></div>
|
<div id="plupload_files"></div>
|
||||||
</form>
|
</form>
|
||||||
<div id="plupload_error">
|
<div id="plupload_error">
|
||||||
|
|
|
@ -11,7 +11,10 @@ $(document).ready(function() {
|
||||||
multiple_queues : 'true',
|
multiple_queues : 'true',
|
||||||
filters : [
|
filters : [
|
||||||
{title: "Audio Files", extensions: "ogg,mp3,oga,flac,wav,m4a,mp4,opus"}
|
{title: "Audio Files", extensions: "ogg,mp3,oga,flac,wav,m4a,mp4,opus"}
|
||||||
]
|
],
|
||||||
|
multipart_params : {
|
||||||
|
"csrf_token" : $("#csrf").attr('value'),
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
uploader = $("#plupload_files").pluploadQueue();
|
uploader = $("#plupload_files").pluploadQueue();
|
||||||
|
|
Loading…
Reference in New Issue