diff --git a/systemvm/patches/debian/config/etc/init.d/cloud-early-config b/systemvm/patches/debian/config/etc/init.d/cloud-early-config index 0edd11ea05f..5b98a0cf982 100755 --- a/systemvm/patches/debian/config/etc/init.d/cloud-early-config +++ b/systemvm/patches/debian/config/etc/init.d/cloud-early-config @@ -1159,9 +1159,11 @@ setup_secstorage() { log_it "setting up apache2 for post upload of volume/template" a2enmod proxy a2enmod proxy_http + a2enmod headers SSL_FILE="/etc/apache2/sites-available/default-ssl" PATTERN="RewriteRule ^\/upload\/(.*)" + CORS_PATTERN="Header set Access-Control-Allow-Origin" if [ -f $SSL_FILE ]; then if grep -q "$PATTERN" $SSL_FILE ; then log_it "rewrite rules already exist in file $SSL_FILE" @@ -1172,6 +1174,14 @@ setup_secstorage() { sed -i -e "s/<\/VirtualHost>/RewriteCond %{REQUEST_METHOD} =POST \n&/" $SSL_FILE sed -i -e "s/<\/VirtualHost>/RewriteRule ^\/upload\/(.*) http:\/\/127.0.0.1:8210\/upload?uuid=\$1 [P,L] \n&/" $SSL_FILE fi + if grep -q "$CORS_PATTERN" $SSL_FILE ; then + log_it "cors rules already exist in file $SSL_FILE" + else + log_it "adding cors rules to file: $SSL_FILE" + sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Origin \"*\" \n&/" $SSL_FILE + sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Methods \"POST, OPTIONS\" \n&/" $SSL_FILE + sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Headers \"x-requested-with, Content-Type, origin, authorization, accept, client-security-token, x-signature, x-metadata, x-expires\" \n&/" $SSL_FILE + fi fi service apache2 restart diff --git a/systemvm/scripts/config_ssl.sh b/systemvm/scripts/config_ssl.sh index 8022b78d256..cd8059ce46b 100755 --- a/systemvm/scripts/config_ssl.sh +++ b/systemvm/scripts/config_ssl.sh @@ -61,6 +61,7 @@ config_apache2_conf() { SSL_FILE="/etc/apache2/sites-available/default-ssl" PATTERN="RewriteRule ^\/upload\/(.*)" + CORS_PATTERN="Header set Access-Control-Allow-Origin" if [ -f $SSL_FILE ]; then if grep -q "$PATTERN" $SSL_FILE ; then echo "rewrite rules already exist in file $SSL_FILE" @@ -71,6 +72,14 @@ config_apache2_conf() { sed -i -e "s/<\/VirtualHost>/RewriteCond %{REQUEST_METHOD} =POST \n&/" $SSL_FILE sed -i -e "s/<\/VirtualHost>/RewriteRule ^\/upload\/(.*) http:\/\/127.0.0.1:8210\/upload?uuid=\$1 [P,L] \n&/" $SSL_FILE fi + if grep -q "$CORS_PATTERN" $SSL_FILE ; then + echo "cors rules already exist in file $SSL_FILE" + else + echo "adding cors rules to file: $SSL_FILE" + sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Origin \"*\" \n&/" $SSL_FILE + sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Methods \"POST, OPTIONS\" \n&/" $SSL_FILE + sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Headers \"x-requested-with, Content-Type, origin, authorization, accept, client-security-token, x-signature, x-metadata, x-expires\" \n&/" $SSL_FILE + fi fi } diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js index 3ca19b313bd..68e3ec1bc88 100644 --- a/ui/scripts/storage.js +++ b/ui/scripts/storage.js @@ -454,28 +454,25 @@ args.response.success({ url: uploadparams.postURL, + ajaxPost: true, data: { - signature: uploadparams.signature, - expires: uploadparams.expires, - metadata: uploadparams.metadata + 'X-signature': uploadparams.signature, + 'X-expires': uploadparams.expires, + 'X-metadata': uploadparams.metadata } }); - - cloudStack.dialog.notice({ - message: "This volume file has been uploaded. Please check its status at Stroage menu > Volumes > " + args.data.name + " > Status field." - }); } }); }, postUpload: function(args) { - console.log("postUpload() is hit"); - // Called when upload is done to do - // verification checks; - // i.e., poll the server to verify successful upload - // - // success() will close the dialog and call standard action - // error() will keep dialog open if user wants to re-submit - args.response.success(); + if(args.error) { + args.response.error(args.errorMsg); + } else { + cloudStack.dialog.notice({ + message: "This volume file has been uploaded. Please check its status at Stroage menu > Volumes > " + args.data.name + " > Status field." + }); + args.response.success(); + } } }, fields: { diff --git a/ui/scripts/templates.js b/ui/scripts/templates.js index 4fe09442c5e..c060a0c844a 100644 --- a/ui/scripts/templates.js +++ b/ui/scripts/templates.js @@ -636,48 +636,30 @@ data: data, async: false, success: function(json) { - /* - { - "postuploadtemplateresponse": { - "getuploadparams": { - "id": "d5bdaf23-dcb9-4eef-9b94-81870490f457", - "postURL": "https://10.223.67.4/upload/d5bdaf23-dcb9-4eef-9b94-81870490f457", - "metadata": "7jCvmzKuMBStM/qEjx9HjSAISd+f3VAUqC9CkYmq92O+SznYov415LUndZ4KuLAtGNY37VeePs8X+0oyaVSj+cjD+KKoBJuynjBJViAQQYKT/amcOdrkloBA4DgNEAn16p32Z2qI4+Ky1ecDAtg1vkYNoz9ReaKbehM3n5MIFPonhnYBEmbVSZkCIbVbJeh+vmYs9Y3SHtcG+0gWiU06YQ4KGl7Wc03wp3wusAlj7+L+fEBha54Rx+C7aS6UPZgm8/+atUUric6xiGMsx603NUElcLWE+gQ7PTimsIr6ySvcmc3D0n6JK6A7bc72sfPrHEbnNPD+5+qXJsBcXPLtEAG2WwduarwZ", - "timeout": "2015-01-20T01:01:02.548Z", - "signature": "NLXv5YsNuUn7NKC+ZP5JtSM26MY=" - } - } - } - */ - - var uploadparams = json.postuploadtemplateresponse.getuploadparams; //son.postuploadtemplateresponse.getuploadparams is an object, not an array of object. + var uploadparams = json.postuploadtemplateresponse.getuploadparams; var templateId = uploadparams.id; args.response.success({ url: uploadparams.postURL, + ajaxPost: true, data: { - signature: uploadparams.signature, - expires: uploadparams.timeout, - metadata: uploadparams.metadata + 'X-signature': uploadparams.signature, + 'X-expires': uploadparams.expires, + 'X-metadata': uploadparams.metadata } }); - - cloudStack.dialog.notice({ - message: "This template file has been uploaded. Please check its status at Templates menu > " + args.data.name + " > Zones tab > click a zone > Status field and Ready field." - }); - } }); }, postUpload: function(args) { - console.log("postUpload() is hit"); - // Called when upload is done to do - // verification checks; - // i.e., poll the server to verify successful upload - // - // success() will close the dialog and call standard action - // error() will keep dialog open if user wants to re-submit - args.response.success(); + if(args.error) { + args.response.error(args.errorMsg); + } else { + cloudStack.dialog.notice({ + message: "This template file has been uploaded. Please check its status at Templates menu > " + args.data.name + " > Zones tab > click a zone > Status field and Ready field." + }); + args.response.success(); + } } }, fields: { diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js index 86703d5cd4b..38d248d4add 100644 --- a/ui/scripts/ui/dialog.js +++ b/ui/scripts/ui/dialog.js @@ -690,76 +690,103 @@ context: args.context, response: { success: function(successArgs) { - // - // Move file field into iframe; keep visible for consistency - // - var $uploadFrame = $('