uploadFiles.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. // include_once 'createCluster.php';
  3. include_once 'dbLib.php';
  4. //$requestData = file_get_contents('php://input');
  5. //error_log($requestdata, 3, "/tmp/rez.log");
  6. //$requestObj = json_decode($requestdata, true);
  7. $clusterName = $_GET['clusterName'];
  8. // Validate clusterName: TODO; FIXME
  9. // initCluster($clusterName);
  10. $identityFileDestination = getSshKeyFilePath($clusterName);
  11. $hostsFileDestination = getHostsFilePath($clusterName);
  12. // TODO: FIXME: Change echos to return error codes.
  13. //echo '<pre>';
  14. if (move_uploaded_file($_FILES['clusterDeployUserIdentityFile']['tmp_name'], $identityFileDestination)) {
  15. //echo "File is valid, and was successfully uploaded.\n";
  16. // Set the permissions
  17. chmod($identityFileDestination, 0400);// TODO: Error conditions
  18. } else {
  19. //echo "Possible file upload attack!\n";
  20. }
  21. if (move_uploaded_file($_FILES['clusterHostsFile']['tmp_name'], $hostsFileDestination)) {
  22. //echo "File is valid, and was successfully uploaded.\n";
  23. } else {
  24. //echo "Possible file upload attack!\n";
  25. }
  26. // TODO: FIXME: Check file lengths.
  27. $outjson = array(
  28. "errorCode"=> 0,
  29. // "clusterName" => $clusterName,
  30. // "finalDestination" => $identityFileDestination,
  31. // "fileToBeMoved" => $_FILES['clusterDeployUserIdentityFile']['tmp_name'],
  32. );
  33. header("Content-type: application/json");
  34. print (json_encode($outjson));
  35. ?>