upload.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. define('V_ROOT_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
  3. require_once V_ROOT_DIR . 'config/Config.class.php';
  4. require_once V_ROOT_DIR . 'core/utils/Utils.class.php';
  5. require_once V_ROOT_DIR . 'core/VestaSession.class.php';
  6. require_once V_ROOT_DIR . 'core/Vesta.class.php';
  7. require_once V_ROOT_DIR . 'core/exceptions/SystemException.class.php';
  8. require_once V_ROOT_DIR . 'core/exceptions/ProtectionException.class.php';
  9. require_once V_ROOT_DIR . 'core/utils/Message.class.php';
  10. require_once V_ROOT_DIR . 'core/Request.class.php';
  11. require_once V_ROOT_DIR . 'api/AjaxHandler.php';
  12. switch ($_GET['action']) {
  13. case 'show':
  14. if (!empty($_POST['process'])) {
  15. handleUpload();
  16. }
  17. else {
  18. show_form();
  19. }
  20. break;
  21. }
  22. function pass_contents($content)
  23. {
  24. if (trim($content) == '') {
  25. show_form(); print("<span id='msg' style='font-size:9px;color: red;'>Error occured. Please try to upload again</span>");
  26. return;
  27. }
  28. $type = $_GET['type'];
  29. print <<<JS
  30. <textarea id="result" style="display: none;">{$content}</textarea>
  31. <script type="text/javascript">parent.App.Pages.WEB_DOMAIN.setSSL('{$type}', this);</script>
  32. JS;
  33. }
  34. function handleUpload()
  35. {
  36. if ($_FILES["upload-ssl"]["size"] < 20000) {
  37. if ($_FILES["upload-ssl"]["error"] > 0) {
  38. show_form(); print("<span id='msg' style='font-size:9px;color: red;'>Error occured. Please try to upload again</span>");
  39. return;
  40. }
  41. else {
  42. $contents = file_get_contents($_FILES["upload-ssl"]['tmp_name']);
  43. return show_form().pass_contents($contents);
  44. }
  45. }
  46. else {
  47. show_form(); print("<span id='msg' style='font-size:9px;color: red;'>Filesize is too large. Please ensure you are uploading correct file</span>");
  48. return;
  49. }
  50. }
  51. //
  52. // functions
  53. function show_form()
  54. {
  55. $type = $_GET['type'];
  56. if (!in_array($type, array('key', 'cert'))) {
  57. exit;
  58. }
  59. print <<<HTML
  60. <script type="text/javascript">
  61. function upload()
  62. {
  63. var l_dot = '';
  64. document.getElementById('form-upl').style.display = 'none';
  65. try {
  66. document.getElementById('msg').style.display = 'none';
  67. } catch(e){};
  68. document.getElementById('form-loading').style.display = 'block';
  69. setInterval(function(){
  70. if (l_dot == '...') {
  71. l_dot = '';
  72. }
  73. l_dot += '.';
  74. document.getElementById('form-loading').innerHTML = 'Processing'+l_dot;
  75. }, 500);
  76. setTimeout(function() {
  77. document.forms[0].submit();
  78. }, 1000);
  79. }
  80. </script>
  81. <p id="form-loading" style="font-size:11px;color:#333;"></p>
  82. <form id="form-upl" action="" method="post" style="padding:0;margin:0" enctype="multipart/form-data"><input type="hidden" value="true" name="process"><input type="file" name="upload-ssl" onChange="upload();"/></form>
  83. HTML;
  84. }
  85. ?>