From e1011048bda24d6b72e7c652aca26dd91e05141f Mon Sep 17 00:00:00 2001 From: Dima Malishev Date: Sun, 11 Sep 2011 00:35:57 +0300 Subject: [PATCH] SSL files upload feature added --- web/js/helpers.js | 23 ++++++++++++++++++++ web/js/html.js | 6 +++++- web/js/pages.js | 8 +++++-- web/js/templates.js | 4 ++-- web/vesta/upload.php | 51 ++++++++++++++++++++++++++++---------------- 5 files changed, 69 insertions(+), 23 deletions(-) diff --git a/web/js/helpers.js b/web/js/helpers.js index f91a0ac3..601e080c 100644 --- a/web/js/helpers.js +++ b/web/js/helpers.js @@ -282,6 +282,29 @@ App.Helpers.closeInnerPopup = function(evt) $('#inner-popup').remove(); } +App.Helpers.getUploadUrl = function() +{ + var url_parts = location.href.split('#'); + if (url_parts.length > 1) { + var tab = url_parts[url_parts.length - 1]; + if ($.inArray(tab, App.Constants.TABS) != -1) { + App.Tmp.loadTAB = tab; + } + } + + var url_parts = location.href.split('?', 1); + var url = url_parts[0]; + url_parts = url.split('/'); + if (url_parts[url_parts.length -1] == 'index.html') { + url_parts[url_parts.length -1] = 'vesta/upload.php'; + } + else { + url_parts.push('vesta/upload.php'); + } + + return url_parts.join('/'); +} + App.Helpers.getBackendUrl = function() { var url_parts = location.href.split('#'); diff --git a/web/js/html.js b/web/js/html.js index a3761092..f01220d9 100644 --- a/web/js/html.js +++ b/web/js/html.js @@ -475,9 +475,13 @@ App.HTML.Build.dns_subrecord = function(record) App.HTML.Build.ssl_key_file = function() { - return ''; + return ''; } +App.HTML.Build.ssl_cert_file = function() +{ + return ''; +} App.HTML.Build.user_selects = function(tpl, options) { diff --git a/web/js/pages.js b/web/js/pages.js index ebca69f4..d1f700f2 100644 --- a/web/js/pages.js +++ b/web/js/pages.js @@ -71,10 +71,14 @@ App.Pages.WEB_DOMAIN.new_entry = function(evt) App.Helpers.updateScreen(); $('#'+form_id).find('.ns-entry, .additional-ns-add').addClass('hidden'); var ssl_key_upload = App.HTML.Build.ssl_key_file(); + var ssl_cert_upload = App.HTML.Build.ssl_cert_file(); $('#'+form_id).find('.ssl-key-input-dummy:first').replaceWith(ssl_key_upload); + $('#'+form_id).find('.ssl-cert-input-dummy:first').replaceWith(ssl_cert_upload); } -App.Pages.WEB_DOMAIN.setSSL = function(content, type) +App.Pages.WEB_DOMAIN.setSSL = function(type, frame) { - fb.warn(content); + var txt = App.Helpers.evalJSON(content); + var ref = frame.frameElement; + $(ref).next('textarea').val(frame.document.getElementById('result').value); } diff --git a/web/js/templates.js b/web/js/templates.js index 395507ac..b2d4dd02 100644 --- a/web/js/templates.js +++ b/web/js/templates.js @@ -567,12 +567,12 @@ App.Templates.html = {
\ \ ...\ - \ + \
\
\ \ ...\ - \ + \
\ \ \ diff --git a/web/vesta/upload.php b/web/vesta/upload.php index e1f67837..ecbd148e 100644 --- a/web/vesta/upload.php +++ b/web/vesta/upload.php @@ -25,9 +25,14 @@ switch ($_GET['action']) { function pass_contents($content) { + if (trim($content) == '') { + show_form(); print("Error occured. Please try to upload again"); + return; + } $type = $_GET['type']; print <<parent.App.Pages.WEB_DOMAIN.setSSL('{$contents}', '{$type}'); + + JS; } @@ -35,29 +40,17 @@ function handleUpload() { if ($_FILES["upload-ssl"]["size"] < 20000) { if ($_FILES["upload-ssl"]["error"] > 0) { - return show_form() . "Error occured. Please try to upload again"; + show_form(); print("Error occured. Please try to upload again"); + return; } else { - /*echo "Upload: " . $_FILES["file"]["name"] . "
"; - echo "Type: " . $_FILES["file"]["type"] . "
"; - echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; - echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
";*/ - $contents = file_get_contents($_FILES["upload-ssl"]['tmp_name']); return show_form().pass_contents($contents); - - /*if (file_exists("upload/" . $_FILES["file"]["name"])) { - echo $_FILES["file"]["name"] . " already exists. "; - } - else { - move_uploaded_file($_FILES["file"]["tmp_name"], - "upload/" . $_FILES["file"]["name"]); - echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; - }*/ } } else { - return show_form() . "Filesize is too large. Please ensure you are uploading correct file"; + show_form(); print("Filesize is too large. Please ensure you are uploading correct file"); + return; } } @@ -71,7 +64,29 @@ function show_form() } print << + +

+
HTML; }