use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class Admin method _fillSecData.
private void _fillSecData(SecurityManager sm) throws PageException {
Struct sct = new StructImpl();
pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
sct.set("cfx_setting", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_CFX_SETTING) == SecurityManager.VALUE_YES));
sct.set("cfx_usage", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_CFX_USAGE) == SecurityManager.VALUE_YES));
sct.set("custom_tag", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_CUSTOM_TAG) == SecurityManager.VALUE_YES));
sct.set(KeyConstants._datasource, _fillSecDataDS(sm.getAccess(SecurityManager.TYPE_DATASOURCE)));
sct.set("debugging", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_DEBUGGING) == SecurityManager.VALUE_YES));
sct.set("direct_java_access", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_DIRECT_JAVA_ACCESS) == SecurityManager.VALUE_YES));
sct.set("mail", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_MAIL) == SecurityManager.VALUE_YES));
sct.set(KeyConstants._mapping, Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_MAPPING) == SecurityManager.VALUE_YES));
sct.set("remote", Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_REMOTE) == SecurityManager.VALUE_YES));
sct.set("setting", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_SETTING) == SecurityManager.VALUE_YES));
sct.set("search", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_SEARCH) == SecurityManager.VALUE_YES));
sct.set("scheduled_task", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_SCHEDULED_TASK) == SecurityManager.VALUE_YES));
sct.set(KeyConstants._cache, Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_CACHE) == SecurityManager.VALUE_YES));
sct.set("gateway", Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_GATEWAY) == SecurityManager.VALUE_YES));
sct.set(KeyConstants._orm, Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_ORM) == SecurityManager.VALUE_YES));
sct.set("tag_execute", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_EXECUTE) == SecurityManager.VALUE_YES));
sct.set("tag_import", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_IMPORT) == SecurityManager.VALUE_YES));
sct.set("tag_object", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_OBJECT) == SecurityManager.VALUE_YES));
sct.set("tag_registry", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_REGISTRY) == SecurityManager.VALUE_YES));
sct.set("access_read", SecurityManagerImpl.toStringAccessRWValue(sm.getAccess(SecurityManager.TYPE_ACCESS_READ)));
sct.set("access_write", SecurityManagerImpl.toStringAccessRWValue(sm.getAccess(SecurityManager.TYPE_ACCESS_WRITE)));
short accessFile = sm.getAccess(SecurityManager.TYPE_FILE);
String str = SecurityManagerImpl.toStringAccessValue(accessFile);
if (str.equals("yes"))
str = "all";
sct.set(KeyConstants._file, str);
Array arr = new ArrayImpl();
if (accessFile != SecurityManager.VALUE_ALL) {
Resource[] reses = ((SecurityManagerImpl) sm).getCustomFileAccess();
for (int i = 0; i < reses.length; i++) {
arr.appendEL(reses[i].getAbsolutePath());
}
}
sct.set("file_access", arr);
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class Collection method setPath.
/**
* set the value path
*
* @param path value to set
* @throws PageException
*/
public void setPath(String strPath) throws PageException {
if (strPath == null)
return;
this.path = ResourceUtil.toResourceNotExisting(pageContext, strPath.trim());
// this.path=new File(path.toLowerCase().trim());
pageContext.getConfig().getSecurityManager().checkFileLocation(this.path);
if (!this.path.exists()) {
Resource parent = this.path.getParentResource();
if (parent != null && parent.exists())
this.path.mkdirs();
else {
throw new ApplicationException("attribute path of the tag collection must be a existing directory");
}
} else if (!this.path.isDirectory())
throw new ApplicationException("attribute path of the tag collection must be a existing directory");
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class Range method _doStartTag.
private int _doStartTag() throws PageException {
// check the file before doing anyrhing else
Resource file = null;
if (content == null && !StringUtil.isEmpty(strFile))
file = ResourceUtil.toResourceExisting(pageContext, strFile);
// get response object
HttpServletResponse rsp = pageContext.getHttpServletResponse();
// check committed
if (rsp.isCommitted())
throw new ApplicationException("content is already flushed", "you can't rewrite head of response after part of the page is flushed");
// set type
if (!StringUtil.isEmpty(type, true)) {
type = type.trim();
ReqRspUtil.setContentType(rsp, type);
// TODO more dynamic implementation, configuration in admin?
if (!HTTPUtil.isTextMimeType(type)) {
((PageContextImpl) pageContext).getRootOut().setAllowCompression(false);
}
}
Range[] ranges = getRanges();
boolean hasRanges = ranges != null && ranges.length > 0;
if (_range == RANGE_YES || hasRanges) {
rsp.setHeader("Accept-Ranges", "bytes");
} else if (_range == RANGE_NO) {
rsp.setHeader("Accept-Ranges", "none");
hasRanges = false;
}
// set content
if (this.content != null || file != null) {
pageContext.clear();
InputStream is = null;
OutputStream os = null;
long totalLength, contentLength;
try {
os = getOutputStream();
if (content != null) {
// ReqRspUtil.setContentLength(rsp,content.length);
contentLength = content.length;
totalLength = content.length;
is = new BufferedInputStream(new ByteArrayInputStream(content));
} else {
// ReqRspUtil.setContentLength(rsp,file.length());
pageContext.getConfig().getSecurityManager().checkFileLocation(file);
contentLength = totalLength = file.length();
is = IOUtil.toBufferedInputStream(file.getInputStream());
}
// write
if (!hasRanges)
IOUtil.copy(is, os, false, false);
else {
contentLength = 0;
long off, len, to;
for (int i = 0; i < ranges.length; i++) {
off = ranges[i].from;
if (ranges[i].to == -1) {
len = -1;
to = totalLength - 1;
} else {
to = ranges[i].to;
if (to >= totalLength)
to = totalLength - 1;
len = to - ranges[i].from + 1;
}
rsp.addHeader("Content-Range", "bytes " + off + "-" + to + "/" + Caster.toString(totalLength));
rsp.setStatus(206);
// print.e("Content-Range: bytes "+off+"-"+to+"/"+Caster.toString(totalLength));
contentLength += to - off + 1L;
// ReqRspUtil.setContentLength(rsp,len);
IOUtil.copy(is, os, off, len);
}
}
if (!(os instanceof GZIPOutputStream))
ReqRspUtil.setContentLength(rsp, contentLength);
} catch (IOException ioe) {
} finally {
IOUtil.flushEL(os);
IOUtil.closeEL(is, os);
if (deletefile && file != null)
ResourceUtil.removeEL(file, true);
((PageContextImpl) pageContext).getRootOut().setClosed(true);
}
throw new PostContentAbort();
} else // clear current content
if (reset)
pageContext.clear();
// EVAL_PAGE;
return EVAL_BODY_INCLUDE;
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class Directory method actionRename.
/**
* rename a directory to a new Name
* @throws PageException
*/
public static void actionRename(PageContext pc, Resource directory, String strNewdirectory, String serverPassword, boolean createPath, Object acl, String storage) throws PageException {
// check directory
SecurityManager securityManager = pc.getConfig().getSecurityManager();
securityManager.checkFileLocation(pc.getConfig(), directory, serverPassword);
if (!directory.exists())
throw new ApplicationException("the directory [" + directory.toString() + "] doesn't exist");
if (!directory.isDirectory())
throw new ApplicationException("the file [" + directory.toString() + "] exists, but it isn't a directory");
if (!directory.canRead())
throw new ApplicationException("no access to read directory [" + directory.toString() + "]");
if (strNewdirectory == null)
throw new ApplicationException("the attribute [newDirectory] is not defined");
// real to source
Resource newdirectory = toDestination(pc, strNewdirectory, directory);
securityManager.checkFileLocation(pc.getConfig(), newdirectory, serverPassword);
if (newdirectory.exists())
throw new ApplicationException("new directory [" + newdirectory.toString() + "] already exists");
if (createPath) {
newdirectory.getParentResource().mkdirs();
}
try {
directory.moveTo(newdirectory);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw Caster.toPageException(t);
}
// set S3 stuff
setS3Attrs(pc, directory, acl, storage);
}
use of lucee.commons.io.res.Resource in project Lucee by lucee.
the class Directory method actionCopy.
public static void actionCopy(PageContext pc, Resource directory, String strDestination, String serverPassword, boolean createPath, Object acl, String storage, final ResourceFilter filter, boolean recurse, int nameconflict) throws PageException {
// check directory
SecurityManager securityManager = pc.getConfig().getSecurityManager();
securityManager.checkFileLocation(pc.getConfig(), directory, serverPassword);
if (!directory.exists())
throw new ApplicationException("directory [" + directory.toString() + "] doesn't exist");
if (!directory.isDirectory())
throw new ApplicationException("file [" + directory.toString() + "] exists, but isn't a directory");
if (!directory.canRead())
throw new ApplicationException("no access to read directory [" + directory.toString() + "]");
if (StringUtil.isEmpty(strDestination))
throw new ApplicationException("attribute destination is not defined");
// real to source
Resource newdirectory = toDestination(pc, strDestination, directory);
if (nameconflict == NAMECONFLICT_ERROR && newdirectory.exists())
throw new ApplicationException("new directory [" + newdirectory.toString() + "] already exist");
securityManager.checkFileLocation(pc.getConfig(), newdirectory, serverPassword);
try {
boolean clearEmpty = false;
// has already a filter
ResourceFilter f = null;
if (filter != null) {
if (!recurse) {
f = new AndResourceFilter(new ResourceFilter[] { filter, new NotResourceFilter(DirectoryResourceFilter.FILTER) });
} else {
clearEmpty = true;
f = new OrResourceFilter(new ResourceFilter[] { filter, DirectoryResourceFilter.FILTER });
}
} else {
if (!recurse)
f = new NotResourceFilter(DirectoryResourceFilter.FILTER);
}
if (!createPath) {
Resource p = newdirectory.getParentResource();
if (p != null && !p.exists())
throw new ApplicationException("parent directory for [" + newdirectory + "] doesn't exist");
}
ResourceUtil.copyRecursive(directory, newdirectory, f);
if (clearEmpty)
ResourceUtil.removeEmptyFolders(newdirectory, f == null ? null : new NotResourceFilter(filter));
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw new ApplicationException(t.getMessage());
}
// set S3 stuff
setS3Attrs(pc, directory, acl, storage);
}
Aggregations