String name = "T" + System.currentTimeMillis();
String tmpdir = "/tmp/" + name;
Runtime.getRuntime().exec("mkdir -m 777 -p " + tmpdir).waitFor();
PrintWriter sume;
MultipartRequest multi =
new MultipartRequest(request, tmpdir, 100*1024*1024); // 100MB
out.println("<pre>");
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements()) {
String pname = (String) params.nextElement();
String pval = (String) multi.getParameter(pname);
out.println(pname + ": " + pval);
}
out.println("</pre>");
out.flush();
String action = multi.getParameter("action");
if (action.equals("createNewAdminApplication")) {
/*
Profile prof = sess.getUserProfile();
if (!prof.isAllowed("iwtAdmin-execute")) throw new AccessControlException("User " + uid + " does not have Admin privileges");
*/
createNewAdminApplication(multi, out);
} else {
String project = multi.getParameter("project");
if (project != null)
project.trim();
String app = multi.getParameter("app");
String export = multi.getParameter("export");
String filename = null;
Enumeration files = multi.getFileNames();
if (files.hasMoreElements()) {
filename = multi.getFilesystemName((String)files.nextElement());
monitor.log("MONITOR " + uid + "FileUpload as "+name+ " "+project+" using " + app );
Runtime.getRuntime().exec("/usr/bin/chmod 644 " + tmpdir + "/" + filename).waitFor();
//
// NOTE: enable other upload options here for multipart files
//
if (multi.getParameter("tar") != null) {
sume = new PrintWriter(new BufferedWriter(new FileWriter(new File(tmpdir, GEP_SU_SCRIPT))));
sume.println("cd " + tmpdir);
sume.println("gunzip -c " + filename + " | tar xf -");
sume.println("chmod -R 644 .");
sume.close();
Runtime.getRuntime().exec("/usr/bin/chmod 755 " + tmpdir + "/" + GEP_SU_SCRIPT).waitFor();
Process zip = Runtime.getRuntime().exec("su - " + submit_uid + " -c " + tmpdir + "/" + GEP_SU_SCRIPT);
}
}
if (action.equals("createNewProject")) {
createNewProject(uid, submit_uid, home, tmpdir,
filename, project, app, export, request, out);
} else if (action.equals("updateProject")) {
String id = multi.getParameter("id");
updateProject(uid, submit_uid, home, id, tmpdir,
filename, project, app, export, request, response);
} else {
unknownAction(uid, response);
}