<%@page import="com.google.gson.Gson"%> <%@page import="com.en.fs.enums.ParentDirType"%> <%@page import="java.util.ArrayList"%> <%@page import="java.util.List"%> <%@page import="java.util.Date"%> <%@page import="java.io.File"%> <%@ page import="com.en.fs.pm.ProjectsFileManager" %> <%@ page import="com.en.fs.util.*" %> <%@ page import="com.en.fs.core.CommandResultSet" %> <%@ page import="com.en.fs.pm.Config" %> <%@ page import="com.en.fs.pm.entity.WebsiteFS" %> <%@ page import="com.en.fs.enums.ParentDirType" %> <%@ page import="com.en.fs.pm.GCPFileManager" %> <%@ page import="com.en.gcp.storage.client.api.domain.StorageFile" %> <%@ page import="java.util.Iterator" %> <%@ page import="com.en.dashboard.WebsiteProjectInfoManager" %> <%@ page contentType="text/html; charset=utf-8" language="java"%> <% JSPUtils ju = new JSPUtils(pageContext); String websiteID = ju.s("websiteID", ""); String pdir = ju.s("pdir", "active"); String dir = ju.s("dir"); String dirJS = ProjectsFileManager.gson.toJson(dir); String fn = ju.s("fn"); //System.out.println("websiteID:"+websiteID+", pdir:"+pdir+", dir:"+dir+", dirJS:"+dirJS+", fn:"+fn); /*if fn is delete and dir is not trash than move to trash */ if("delete".equalsIgnoreCase(fn) && !dir.toLowerCase().startsWith("trash")){ fn = "moveToTrash"; } //boolean isSafeLink = ("active".equalsIgnoreCase(pdir) && dir.toLowerCase().startsWith("photos")) ||("active".equalsIgnoreCase(pdir) && dir.toLowerCase().startsWith("videos")) ; //System.out.println("isSafeLink:"+isSafeLink); //referral validation all the directory except 'photos' and 'video'. boolean isValidAccess = false; boolean isValidReferral = PMUtils.isValidReferral(request.getHeader("referer")); if(isValidReferral){ //if referral is true than set cookie for the next request within the page Cookie ck = new Cookie("fileServer","valid"); response.addCookie(ck); } isValidAccess = isValidReferral || (JSPUtils.getCookie(request, "fileServer") != null && "valid".equals(JSPUtils.getCookie(request, "fileServer"))); //System.out.println("isValidReferral:"+isValidReferral); boolean isSafeLink = PMUtils.isSafeAccessDirectory(pdir, dir); if( !isSafeLink ){ if( !isValidAccess){ out.print("Security error : Permission denied"); return; } } /**validation**/ if ("".equals(websiteID)){ out.print("Security error : Website not found."); return; }; if (!"active".equals(pdir) && !"attic".equals(pdir)){ out.print("Security error : Invalid Directory."); return; }; //disabled below code because project management system changes /** get networkpath from db table and create folder structure if website is new and show the content */ /* WebsiteFS info = ProjectsFileManager.getFileServerData(websiteID); if(info == null){ out.println("ERROR Incorrect website info."); return; } String schoolName = info.getWebsiteName(); String networkPath = info.getFsPath(); int fsREC_ID = info.getFsREC_ID(); int websiteStatus = info.getWebsiteStatus(); */ //START enabled below code due to project management system changes WebsiteFS info = ProjectsFileManager.getFileServerData(websiteID); if(info == null){ //if info is null means it's not exist in website table, so it's a website-project info = ProjectsFileManager.getProjectFileServerDataFromDb(websiteID, ju.I("websiteREC_ID", 0)); if(info == null){ out.println("ERROR Website project record not exist."); return; } /*info = new WebsiteFS(); info.setWebsiteName(websiteID); info.setFsREC_ID(3); info.setWebsiteStatus(2); if(PMUtils.isDevServer()){ //below is only for testing in local-its not required if we create a soft link pmfiles --> actual pmfiles path info.setFsPath("/Volumes/edunet/data/pmfiles"); }else{ info.setFsPath("/pmfiles"); } int websiteREC_ID = ju.I("websiteREC_ID", 0); if(websiteREC_ID != 0){ String websiteName = ProjectsFileManager.getWebsiteName(websiteREC_ID); if(!StringUtils.isEmptyOrWhitespaceOnly(websiteName)){ info.setWebsiteName(websiteName); } }*/ } String schoolName = info.getWebsiteName() + (StringUtils.isEmptyOrWhitespaceOnly(info.getWebsiteProjectName()) ? "" : " - "+info.getWebsiteProjectName()); String networkPath = info.getFsPath(); int fsREC_ID = info.getFsREC_ID(); if(fsREC_ID == 0 && StringUtils.isEmptyOrWhitespaceOnly(networkPath)){ //Once we do full archive then we update fsREC_ID to 0 and delete the website directory completely. So show error message. out.print("Security error : This website is fully archived."); return; } int websiteStatus = info.getWebsiteStatus(); //END enabled below code due to project management system changes boolean isParentDirsExist = false; boolean isWebDirsExist = false; File activeDir = new File(networkPath + File.separator + ParentDirType.ACTIVE.getValue()); //File archivedDir = new File(networkPath + File.separator + ParentDirType.ARCHIVED.getValue()); File atticDir = new File(networkPath + File.separator + ParentDirType.ATTIC.getValue()); //we can create Active and Attic directory while statring the pmfiles server just like Archieved directory if(!activeDir.exists()){ if (!activeDir.mkdir()) { out.println("ERROR Could not create the new Active directory."); return; } } if(!atticDir.exists()){ if (!atticDir.mkdirs()) { out.println("ERROR Could not create the new Attic directory."); return; } } //Create Active website and its sub directory if not exist File activeWebDir = new File(activeDir, websiteID); //File archiveWebDir = new File(archivedDir, websiteID); File atticWebDir = new File(atticDir, websiteID); if(!activeWebDir.exists()){ //If website dir is not exist in parent dir(Active) then check if it exists in GCP archived bucket. GCPFileManager gcpFm = new GCPFileManager(websiteID, networkPath, ""); Iterable isf = gcpFm.getList(); Iterator iterator = isf.iterator(); boolean websiteDirExitInGCPAcrhived = iterator.hasNext(); if(websiteDirExitInGCPAcrhived){ String archiveUrl = "archive.jsp?websiteID=" + websiteID; out.print("Security error: This website's files are fully archived. " + "Please visit the archived version."); return; } if(websiteStatus != 2){ out.println("ERROR: Website directory does not exist and we can not create the initial website and sub directory structure because its not a UC project. "); return; } if (!activeWebDir.mkdir()) { out.println("ERROR Could not create the new " +websiteID+ " directory inside Active directory."); return; } if(activeWebDir.exists()){ File src = new File(Config.getSampleDirPath()); if (!src.exists()) { out.println("ERROR: Can not find the sample directory to copy."); return; } try { if(activeWebDir.listFiles().length <= 0){ DirectoryCopyUtils.copyDir(src.toString(), activeWebDir.toString()); } } catch (Exception e) { %> ERROR: Could not copy the sample directory.
Source: <%= src %>
Destination: <%= activeWebDir.toString() %>, <%= atticWebDir.toString() %>
Exception: <%= e %>
<% return; } } } //Create Attic website directory if not exist /* if(!atticWebDir.exists()){ if (!atticWebDir.mkdir()) { out.println("ERROR Could not create the new " +websiteID+ " directory inside Attic directory."); return; } } */ //Create trash folder File trash = new File(activeWebDir, "Trash"); if(!trash.exists()){ trash.mkdir(); } ProjectsFileManager fm = null; if("active".equals(pdir)){ File folder = new File(activeWebDir, dir); if(!folder.exists()){ out.println(""+folder.getPath()+" folder does not exist"); return; } fm = new ProjectsFileManager(activeWebDir.toString(), true); }else{ File folder = new File(atticWebDir, dir); if(!folder.exists()){ out.println(""+folder.getPath()+" folder does not exist"); return; } fm = new ProjectsFileManager(atticWebDir.toString(), true); } CommandResultSet crs = null; ParentDirType pdirType = !"active".equals(pdir) ? ParentDirType.ATTIC : ParentDirType.ACTIVE; String fileBaseURL = "pmfiles-" + fsREC_ID + "/" + pdirType.getValue() + "/" + websiteID + (StringUtils.isEmptyOrWhitespaceOnly(dir) ? "" : "/" + dir); %> Educational Networks File Manager
<%if (ju.s("fn").equals("createDirectory")) { %> <%crs = fm.createDirectoryCrs(dir, ju.s("filename")); %> <% if (crs.isSuccessful()) { %>
× Success! ${param.filename} has been created successfully.
<% } else { %>
× Failed! Could not create ${param.filename}
<%=crs.getErrorMsg() %>
<% } %> <% } else if("moveToTrash".equals(fn)){ %> <% File src = new File(activeWebDir,ju.s("file")); File dst = new File(activeWebDir+"/Trash",src.getName()); %> <% if(fm.moveToTrash(src, dst, activeWebDir)) { %>
× Success! ${param.file} has been deleted successfully.
<% } else { %>
× Failed! Could not delete ${param.file}.
<% } %> <% } else if(ju.s("fn").equals("delete")){ %> <%/*delete functionality file param is required else it will delete everything*/ if("".equals(ju.s("file"))){ %>
× Warning! No file selected to delete.
<%} else if (fm.deleteFile(ju.s("file"))) { %>
× Success! ${param.file} has been deleted successfully.
<%if(!StringUtils.isEmptyOrWhitespaceOnly(websiteID)){ WebsiteProjectInfoManager.updateWebsiteProjectAttribute(websiteID); }%> <% } else { %>
× Failed! Could not delete ${param.file}.
<% }%> <%} else if(ju.s("fn").equals("rename")){ %> <% crs = fm.renameCrs(ju.s("dir"), ju.s("src"), ju.s("dst"));%> <% if (crs.isSuccessful()) { %>
× Success! ${param.src} has been renamed to ${param.dst} successfully.
<% } else { %>
× Failed! Could not rename ${param.src} to ${param.dst}. <%=crs.getErrorMsg() %>
<% } %> <%} else if(ju.s("fn").equals("upload")){ %>
<% if(fm.uploadFiles(dir, request, true).length == 0) { %> There has been a problem uploading your file. Please try again!
<% } else { %> Your file has been uploaded successfully!
<% } %>
<%} else if(ju.s("fn").equals("emptyTrash")){ %> <% if(FileUtils.deleteDirectoryContents(new File(activeWebDir, "Trash"))) { %>
× Success!
<% } else { %>
× Failed! Please try again.
<% } %> <%} else if(ju.s("fn").equals("move")){ File src = new File(ju.s("src")); File dst = new File(ju.s("dst")); crs = fm.move(src, dst); %> <% if (crs.isSuccessful()) { %>
× Success! file has been moved successfully.
<% } else { %>
× Failed! Could not move the file. <%=crs.getErrorMsg() %>
<% } %> <%}else if("moveToAttic".equals(fn)){ File src = new File(ju.s("src")); File dst = new File(ju.s("dst")); crs = fm.moveToAttic(src, dst); %> <% if (crs.isSuccessful()) { %>
× Success! file has been moved to attic successfully.
<% } else { %>
× Failed! Could not move the file. <%=crs.getErrorMsg() %>
<% } %> <%} else if("deleteMulti".equalsIgnoreCase(fn)){ String[] files = request.getParameterValues("imageFiles"); crs = fm.moveToTrashMultipleFiles(files, activeWebDir); %> <% if (crs.isSuccessful()) { %>
× <%=crs.getProgressReport("progressReport") %>
<% } %> <%} %>
<% File root = new File(networkPath); long totalSpace = root.getTotalSpace(); long freeSpace = root.getFreeSpace(); long usedSpace = totalSpace-freeSpace; if(freeSpace/(1024l*1024l*1024l) < 50){ %>
×

Warning! Running Low on Storage Space. Know More
Please contact your administrator or email.

<% } %> <% File files[] = fm.getFiles(dir); List dirList = new ArrayList(); List fileList = new ArrayList(); List imageList = new ArrayList(); List videoList = new ArrayList(); for(File f : files){ //Don't want to show os realted files //such as : .DS_Store, .svn, .gitkeep etc. if(ProjectsFileManager.FS_DISUSE_FILES.contains(f.getName())){ continue; } if(f.isDirectory() && !f.getName().equalsIgnoreCase("trash")){ dirList.add(f); } if(f.isFile()){ if(fm.getExtension(f).equalsIgnoreCase("MOV") || fm.getExtension(f).equalsIgnoreCase("MP4")){ if(f.getName().indexOf("_output.MP4") == -1) videoList.add(f); } else if( (fm.getExtension(f).equalsIgnoreCase("PNG") || fm.getExtension(f).equalsIgnoreCase("IMG") || fm.getExtension(f).equalsIgnoreCase("JPEG") || fm.getExtension(f).equalsIgnoreCase("JPG") || fm.getExtension(f).equalsIgnoreCase("GIF") ) ){ if(!f.getName().contains("_thumb") ) imageList.add(f); }else{ fileList.add(f); } } } %> <% //fn is complete i.e. upload complete and there is image than trigger generate thumbnails //and if there is video than trigger encode video if("uploaded".equalsIgnoreCase(fn)){ boolean thumbsExist = true; boolean encodedExist = true; for(File file : imageList){ File thumbImg = new File(file.getParent() + StringUtils.FS + ProjectsFileManager.getFileName(file) + "_thumb.jpg"); if(!thumbImg.exists()){ thumbsExist = false; break; } } for(File file : videoList){ File encodedVideo = new File(file.getPath()+"_output.MP4"); if(!encodedVideo.exists()){ encodedExist = false; break; } } if(!thumbsExist){ %> <% } if(!encodedExist){ %> <% } %> <% } %>
<% String pdirDisplay = "attic".equalsIgnoreCase(pdir) ? "Attic" : ( "active".equalsIgnoreCase(pdir) && !dir.startsWith("Trash") ? "Main" : "");%> <% if(isValidAccess){ %> <%=pdirDisplay %> <% }else{ %> <%=pdirDisplay %> <% } %> <% if(!dir.startsWith("Trash")){%>»<%} %> <%File history[] = fm.getHistory(dir); for (int i = 0; i < history.length; i++) { File f = history[i]; if (!f.isFile()) { %> <%= f.getName().length()>40 ? f.getName().substring(0, 37)+"..." : f.getName() %> » <% } %> <% } %>
<% if("active".equalsIgnoreCase(pdir) && !dir.startsWith("Trash")){ %>

<%if( isSafeLink ){ %>   <%} %>     <%if(videoList.size() != 0){ %> <%} %> <% if( "active".equalsIgnoreCase(pdir) && dir.toLowerCase().startsWith("photo") && fileList.size() > 0 ){ %>   <%} %>

<% } if(dir.startsWith("Trash") && new File(activeWebDir,"Trash").list().length !=0){ %>

<% } %>
<%if( isSafeLink ){ %> <% } %> <% if(dirList.size()+fileList.size()+videoList.size()+imageList.size() == 0){ %>

There is nothing in this directory.

<%} else { %> <% if("active".equalsIgnoreCase(pdir) && ( dir.toLowerCase().startsWith("photos") || dir.toLowerCase().startsWith("mockups") ) ){ %> <%if(dirList.size()!=0 || fileList.size()!=0 || videoList.size()!=0){ %>
<%for (int i = 0; i < dirList.size(); i++) { File file = dirList.get(i); %> <%} %> <%for (int i = 0; i < fileList.size(); i++) { File file = fileList.get(i); %> <%} %> <%for (int i = 0; i < videoList.size(); i++) { File file = videoList.get(i); File playFile = new File(file.getParent(), file.getName()+"_output.MP4"); %> <%} %>
Name Date Modified Size Action
 <%=file.getName().length()>50 ? file.getName().substring(0, 47)+"..." : file.getName() %> <%=Misc.getDisplayDateTimeFormat().format(file.lastModified()) %> <%//=StringUtils.getFormattedSize(org.apache.commons.io.FileUtils.sizeOfDirectory(file)) %>
 <%=file.getName().length()>50 ? file.getName().substring(0, 47)+"..." : file.getName() %> <%=Misc.getDisplayDateTimeFormat().format(file.lastModified()) %> <%=StringUtils.getFormattedSize(file.length()) %>
 <%=file.getName().length()>50 ? file.getName().substring(0, 47)+"..." : file.getName() %> <%if(playFile.exists()){ %> <% } else{ %> <% } %>   <%if(!playFile.exists()){ %>(Encoded version is not available. Retry)<%} %> <%=Misc.getDisplayDateTimeFormat().format(file.lastModified()) %> <%=StringUtils.getFormattedSize(file.length()) %>
<% } %> <% if(imageList.size()!=0){ %>
Select  All  None 

<% if(pdir.equalsIgnoreCase("active") && !dir.startsWith("Trash")){ %> Download Originals <% } %>

<%for (int i = 0; i < imageList.size(); i++) { File file = imageList.get(i); %> <% if(i%4 == 0){ %>
<% } %>
<% String fileExt = ProjectsFileManager.getFileExtension(file); File thumbFile = new File(file.getParent(), ProjectsFileManager.getFileName(file)+"_thumb.jpg"); File thumb1File = new File(file.getParent(), ProjectsFileManager.getFileName(file)+"_thumb1.jpg"); if(thumbFile.exists()){ %> &ofe=<%=fileExt %>" target="_blank"> <%=file.getName() %> <% }else{ %> &ofe=<%=fileExt %>" target="_blank"> <%=file.getName() %> <%} %>

<%= file.getName() %>  (<%=StringUtils.getFormattedSize(file.length()) %>)

<% if(i%4 == 3 || i==imageList.size()-1){ %>

<% } %> <% } %>
<% } %> <% } //if(!dir.startsWith("photos") && !dir.startsWith("mockups") ) else { %> <%if(dirList.size()!=0 || fileList.size()!=0 || imageList.size()!=0 || videoList.size()!=0){ %>
<%for (int i = 0; i < dirList.size(); i++) { File file = dirList.get(i); %> <%} %> <%for (int i = 0; i < fileList.size(); i++) { File file = fileList.get(i); %> <%} %> <%for (int i = 0; i < videoList.size(); i++) { File file = videoList.get(i); File playFile = new File(file.getParent(), file.getName()+"_output.MP4"); %> <%} %> <%for (int i = 0; i < imageList.size(); i++) { File file = imageList.get(i); File thumbFile = new File(file.getParent(), ProjectsFileManager.getFileName(file)+"_thumb.jpg"); %> <% } %>
Name Date Modified Size Action
 <%=file.getName().length()>50 ? file.getName().substring(0, 47)+"..." : file.getName() %> <%=Misc.getDisplayDateTimeFormat().format(file.lastModified()) %> <%=StringUtils.getFormattedSize(org.apache.commons.io.FileUtils.sizeOfDirectory(file)) %>
 <%= file.getName().length()>50 ? file.getName().substring(0, 47)+"..." : file.getName() %> <%=Misc.getDisplayDateTimeFormat().format(file.lastModified()) %> <%=StringUtils.getFormattedSize(file.length()) %>
 <%=file.getName().length()>50 ? file.getName().substring(0, 47)+"..." : file.getName() %> <%if("active".equalsIgnoreCase(pdir)){ %> <%if(playFile.exists()){ %> <% } else{ %> <% } %>    <%if(!playFile.exists()){ %>(Encoded version is not available. Retry)<%} %> <% } %> <%=Misc.getDisplayDateTimeFormat().format(file.lastModified()) %> <%=StringUtils.getFormattedSize(file.length()) %>
 <%=file.getName().length()>50 ? file.getName().substring(0, 47)+"..." : file.getName() %> <%if(!thumbFile.exists() && "active".equalsIgnoreCase(pdir)){%> (Thumbnail is not available.)<%} %> <%=Misc.getDisplayDateTimeFormat().format(file.lastModified()) %> <%=StringUtils.getFormattedSize(file.length()) %>
<% } %> <% if(imageList.size()!=0 && "active".equalsIgnoreCase(pdir)){ %>
 

<% if(pdir.equalsIgnoreCase("active") && !dir.startsWith("Trash")){ %> <% if(!StringUtils.isEmptyOrWhitespaceOnly(dir) && dir.toLowerCase().startsWith("design")){ %> <% } %> <% } %>

<%for (int i = 0; i < imageList.size(); i++) { File file = imageList.get(i); %> <% if(i%6 == 0){ %>
<% } %>
<% File thumbFile = new File(file.getParent(), ProjectsFileManager.getFileName(file)+"_thumb.jpg"); if(thumbFile.exists()){ %> <%=file.getName() %> <% } else { %> <%=file.getName() %> <%} %>

<%= file.getName() %>  (<%=StringUtils.getFormattedSize(file.length()) %>)

<% if(i%6 == 5 || i==imageList.size()-1){ %>

<% } %> <% } %>
<% } %> <% } //else %> <% } //else block of if(dirList.size()+fileList.size()+videoList.size()+imageList.size() == 0) %>