upload.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. $type = $_GET['type'];
  25. print <<<JS
  26. <script type="text/javascript">parent.App.Pages.WEB_DOMAIN.setSSL('{$contents}', '{$type}');</script>
  27. JS;
  28. }
  29. function handleUpload()
  30. {
  31. if ($_FILES["upload-ssl"]["size"] < 20000) {
  32. if ($_FILES["upload-ssl"]["error"] > 0) {
  33. return show_form() . "Error occured. Please try to upload again";
  34. }
  35. else {
  36. /*echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  37. echo "Type: " . $_FILES["file"]["type"] . "<br />";
  38. echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  39. echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";*/
  40. $contents = file_get_contents($_FILES["upload-ssl"]['tmp_name']);
  41. return show_form().pass_contents($contents);
  42. /*if (file_exists("upload/" . $_FILES["file"]["name"])) {
  43. echo $_FILES["file"]["name"] . " already exists. ";
  44. }
  45. else {
  46. move_uploaded_file($_FILES["file"]["tmp_name"],
  47. "upload/" . $_FILES["file"]["name"]);
  48. echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  49. }*/
  50. }
  51. }
  52. else {
  53. return show_form() . "Filesize is too large. Please ensure you are uploading correct file";
  54. }
  55. }
  56. //
  57. // functions
  58. function show_form()
  59. {
  60. $type = $_GET['type'];
  61. if (!in_array($type, array('key', 'cert'))) {
  62. exit;
  63. }
  64. print <<<HTML
  65. <form action="" method="post" enctype="multipart/form-data"><input type="hidden" value="true" name="process"><input type="file" name="upload-ssl" onChange="document.forms[0].submit()"/></form>
  66. HTML;
  67. }
  68. ?>