Search in sources :

Example 1 with AttachmentExtension

use of net.jforum.entities.AttachmentExtension in project jforum2 by rafaelsteil.

the class GenericAttachmentDAO method getExtension.

protected AttachmentExtension getExtension(ResultSet rs) throws SQLException {
    AttachmentExtension e = new AttachmentExtension();
    e.setAllow(rs.getInt("allow") == 1);
    e.setComment(rs.getString("description"));
    e.setExtension(rs.getString("extension"));
    e.setExtensionGroupId(rs.getInt("extension_group_id"));
    e.setId(rs.getInt("extension_id"));
    String icon = rs.getString("upload_icon");
    if (icon == null || icon.equals("")) {
        icon = rs.getString("group_icon");
    }
    e.setUploadIcon(icon);
    return e;
}
Also used : AttachmentExtension(net.jforum.entities.AttachmentExtension)

Example 2 with AttachmentExtension

use of net.jforum.entities.AttachmentExtension in project jforum2 by rafaelsteil.

the class AttachmentsAction method extensionsUpdate.

public void extensionsUpdate() {
    AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
    // Check for records to delete
    String[] delete = this.request.getParameterValues("delete");
    List deleteList = new ArrayList();
    if (delete != null) {
        deleteList = Arrays.asList(delete);
        am.removeExtensions(delete);
    }
    int total = this.request.getIntParameter("total_records");
    for (int i = 0; i < total; i++) {
        if (deleteList.contains(this.request.getParameter("id_" + i))) {
            continue;
        }
        AttachmentExtension e = new AttachmentExtension();
        e.setAllow(this.request.getParameter("allow_" + i) != null);
        e.setComment(this.request.getParameter("comment_" + i));
        e.setExtension(this.request.getParameter("extension_" + i));
        e.setExtensionGroupId(this.request.getIntParameter("extension_group_" + i));
        e.setId(this.request.getIntParameter("id_" + i));
        e.setUploadIcon(this.request.getParameter("upload_icon_" + i));
        am.updateExtension(e);
    }
    this.extensions();
}
Also used : AttachmentDAO(net.jforum.dao.AttachmentDAO) AttachmentExtension(net.jforum.entities.AttachmentExtension) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with AttachmentExtension

use of net.jforum.entities.AttachmentExtension in project jforum2 by rafaelsteil.

the class GenericAttachmentDAO method searchExtension.

private AttachmentExtension searchExtension(String paramName, Object paramValue) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        String sql = SystemGlobals.getSql("AttachmentModel.selectExtension");
        sql = sql.replaceAll("\\$field", paramName);
        p = JForumExecutionContext.getConnection().prepareStatement(sql);
        p.setObject(1, paramValue);
        AttachmentExtension e = new AttachmentExtension();
        rs = p.executeQuery();
        if (rs.next()) {
            e = this.getExtension(rs);
        } else {
            e.setUnknown(true);
        }
        return e;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) AttachmentExtension(net.jforum.entities.AttachmentExtension) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 4 with AttachmentExtension

use of net.jforum.entities.AttachmentExtension in project jforum2 by rafaelsteil.

the class AttachmentCommon method preProcess.

public void preProcess() {
    if (!this.canProceed) {
        return;
    }
    String t = this.request.getParameter("total_files");
    if (t == null || "".equals(t)) {
        return;
    }
    int total = Integer.parseInt(t);
    if (total < 1) {
        return;
    }
    if (total > SystemGlobals.getIntValue(ConfigKeys.ATTACHMENTS_MAX_POST)) {
        total = SystemGlobals.getIntValue(ConfigKeys.ATTACHMENTS_MAX_POST);
    }
    long totalSize = 0;
    int userId = SessionFacade.getUserSession().getUserId();
    Map extensions = this.am.extensionsForSecurity();
    for (int i = 0; i < total; i++) {
        FileItem item = (FileItem) this.request.getObjectParameter("file_" + i);
        if (item == null) {
            continue;
        }
        if (item.getName().indexOf('\000') > -1) {
            logger.warn("Possible bad attachment (null char): " + item.getName() + " - user_id: " + SessionFacade.getUserSession().getUserId());
            continue;
        }
        UploadUtils uploadUtils = new UploadUtils(item);
        // Check if the extension is allowed
        boolean containsExtension = extensions.containsKey(uploadUtils.getExtension());
        boolean denyAll = extensions.containsKey(DENY_ALL);
        boolean isAllowed = (!denyAll && !containsExtension) || (containsExtension && extensions.get(uploadUtils.getExtension()).equals(Boolean.TRUE));
        if (!isAllowed) {
            throw new BadExtensionException(I18n.getMessage("Attachments.badExtension", new String[] { uploadUtils.getExtension() }));
        }
        // Check comment length:
        String comment = this.request.getParameter("comment_" + i);
        if (comment.length() > 254) {
            throw new AttachmentException("Comment too long.");
        }
        Attachment a = new Attachment();
        a.setUserId(userId);
        AttachmentInfo info = new AttachmentInfo();
        info.setFilesize(item.getSize());
        info.setComment(comment);
        info.setMimetype(item.getContentType());
        // Get only the filename, without the path (IE does that)
        String realName = this.stripPath(item.getName());
        info.setRealFilename(realName);
        info.setUploadTimeInMillis(System.currentTimeMillis());
        AttachmentExtension ext = this.am.selectExtension(uploadUtils.getExtension().toLowerCase());
        if (ext.isUnknown()) {
            ext.setExtension(uploadUtils.getExtension());
        }
        info.setExtension(ext);
        String savePath = this.makeStoreFilename(info);
        info.setPhysicalFilename(savePath);
        a.setInfo(info);
        filesToSave.put(uploadUtils, a);
        totalSize += item.getSize();
    }
    // Check upload limits
    QuotaLimit ql = this.getQuotaLimit(userId);
    if (ql != null) {
        if (ql.exceedsQuota(totalSize)) {
            throw new AttachmentSizeTooBigException(I18n.getMessage("Attachments.tooBig", new Integer[] { new Integer(ql.getSizeInBytes() / 1024), new Integer((int) totalSize / 1024) }));
        }
    }
}
Also used : AttachmentInfo(net.jforum.entities.AttachmentInfo) Attachment(net.jforum.entities.Attachment) AttachmentException(net.jforum.exceptions.AttachmentException) FileItem(net.jforum.util.legacy.commons.fileupload.FileItem) AttachmentExtension(net.jforum.entities.AttachmentExtension) AttachmentSizeTooBigException(net.jforum.exceptions.AttachmentSizeTooBigException) QuotaLimit(net.jforum.entities.QuotaLimit) HashMap(java.util.HashMap) Map(java.util.Map) BadExtensionException(net.jforum.exceptions.BadExtensionException)

Example 5 with AttachmentExtension

use of net.jforum.entities.AttachmentExtension in project jforum2 by rafaelsteil.

the class AttachmentsAction method extensionsSave.

public void extensionsSave() {
    AttachmentExtension e = new AttachmentExtension();
    e.setAllow(this.request.getParameter("allow") != null);
    e.setComment(this.request.getParameter("comment"));
    e.setExtension(this.request.getParameter("extension"));
    e.setUploadIcon(this.request.getParameter("upload_icon"));
    e.setExtensionGroupId(this.request.getIntParameter("extension_group"));
    if (e.getExtension().startsWith(".")) {
        e.setExtension(e.getExtension().substring(1));
    }
    DataAccessDriver.getInstance().newAttachmentDAO().addExtension(e);
    this.extensions();
}
Also used : AttachmentExtension(net.jforum.entities.AttachmentExtension)

Aggregations

AttachmentExtension (net.jforum.entities.AttachmentExtension)5 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AttachmentDAO (net.jforum.dao.AttachmentDAO)1 Attachment (net.jforum.entities.Attachment)1 AttachmentInfo (net.jforum.entities.AttachmentInfo)1 QuotaLimit (net.jforum.entities.QuotaLimit)1 AttachmentException (net.jforum.exceptions.AttachmentException)1 AttachmentSizeTooBigException (net.jforum.exceptions.AttachmentSizeTooBigException)1 BadExtensionException (net.jforum.exceptions.BadExtensionException)1 DatabaseException (net.jforum.exceptions.DatabaseException)1 FileItem (net.jforum.util.legacy.commons.fileupload.FileItem)1