Search in sources :

Example 6 with QuotaLimit

use of net.jforum.entities.QuotaLimit 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 7 with QuotaLimit

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

the class PostAction method insert.

public void insert() {
    int forumId;
    // If we have a topic_id, then it should be a reply
    if (this.request.getParameter("topic_id") != null) {
        int topicId = this.request.getIntParameter("topic_id");
        Topic t = TopicRepository.getTopic(new Topic(topicId));
        if (t == null) {
            t = DataAccessDriver.getInstance().newTopicDAO().selectRaw(topicId);
            if (t == null) {
                throw new ForumException("Could not find a topic with id #" + topicId);
            }
        }
        forumId = t.getForumId();
        if (!TopicsCommon.isTopicAccessible(t.getForumId())) {
            return;
        }
        if (t.getStatus() == Topic.STATUS_LOCKED) {
            this.topicLocked();
            return;
        }
        this.context.put("topic", t);
        this.context.put("setType", false);
        this.context.put("pageTitle", I18n.getMessage("PostForm.reply") + " " + t.getTitle());
    } else {
        forumId = this.request.getIntParameter("forum_id");
        if (this.isReplyOnly(forumId)) {
            this.replyOnly();
            return;
        }
        this.context.put("setType", true);
        this.context.put("pageTitle", I18n.getMessage("PostForm.title"));
    }
    Forum forum = ForumRepository.getForum(forumId);
    if (forum == null) {
        throw new ForumException("Could not find a forum with id #" + forumId);
    }
    if (!TopicsCommon.isTopicAccessible(forumId)) {
        return;
    }
    if (!this.anonymousPost(forumId) || this.isForumReadonly(forumId, this.request.getParameter("topic_id") != null)) {
        return;
    }
    int userId = SessionFacade.getUserSession().getUserId();
    this.setTemplateName(TemplateKeys.POSTS_INSERT);
    // Attachments
    boolean attachmentsEnabled = SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(forumId));
    if (attachmentsEnabled && !SessionFacade.isLogged() && !SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_ANONYMOUS)) {
        attachmentsEnabled = false;
    }
    this.context.put("attachmentsEnabled", attachmentsEnabled);
    if (attachmentsEnabled) {
        QuotaLimit ql = new AttachmentCommon(this.request, forumId).getQuotaLimit(userId);
        this.context.put("maxAttachmentsSize", new Long(ql != null ? ql.getSizeInBytes() : 1));
        this.context.put("maxAttachments", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
    }
    boolean needCaptcha = SystemGlobals.getBoolValue(ConfigKeys.CAPTCHA_POSTS);
    this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
    this.context.put("smilies", SmiliesRepository.getSmilies());
    this.context.put("forum", forum);
    this.context.put("action", "insertSave");
    this.context.put("start", this.request.getParameter("start"));
    this.context.put("isNewPost", true);
    this.context.put("needCaptcha", needCaptcha);
    this.context.put("htmlAllowed", SecurityRepository.canAccess(SecurityConstants.PERM_HTML_DISABLED, Integer.toString(forumId)));
    this.context.put("canCreateStickyOrAnnouncementTopics", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_STICKY_ANNOUNCEMENT_TOPICS));
    this.context.put("canCreatePolls", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_POLL));
    User user = DataAccessDriver.getInstance().newUserDAO().selectById(userId);
    ViewCommon.prepareUserSignature(user);
    if (this.request.getParameter("preview") != null) {
        user.setNotifyOnMessagesEnabled(this.request.getParameter("notify") != null);
    }
    this.context.put("user", user);
}
Also used : ForumException(net.jforum.exceptions.ForumException) User(net.jforum.entities.User) Topic(net.jforum.entities.Topic) QuotaLimit(net.jforum.entities.QuotaLimit) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon) Forum(net.jforum.entities.Forum)

Example 8 with QuotaLimit

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

the class PostAction method quote.

public void quote() {
    PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
    Post p = pm.selectById(this.request.getIntParameter("post_id"));
    if (p.getId() == 0) {
        this.postNotFound();
        return;
    }
    if (p.isModerationNeeded()) {
        this.notModeratedYet();
        return;
    }
    if (!this.anonymousPost(p.getForumId())) {
        return;
    }
    Topic topic = TopicRepository.getTopic(new Topic(p.getTopicId()));
    if (topic == null) {
        topic = DataAccessDriver.getInstance().newTopicDAO().selectRaw(p.getTopicId());
    }
    if (!TopicsCommon.isTopicAccessible(topic.getForumId())) {
        return;
    }
    if (topic.getStatus() == Topic.STATUS_LOCKED) {
        this.topicLocked();
        return;
    }
    this.setTemplateName(TemplateKeys.POSTS_QUOTE);
    this.context.put("forum", ForumRepository.getForum(p.getForumId()));
    this.context.put("action", "insertSave");
    this.context.put("post", p);
    UserDAO um = DataAccessDriver.getInstance().newUserDAO();
    User u = um.selectById(p.getUserId());
    int userId = SessionFacade.getUserSession().getUserId();
    this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(topic.getForumId())));
    QuotaLimit ql = new AttachmentCommon(this.request, topic.getForumId()).getQuotaLimit(userId);
    this.context.put("maxAttachmentsSize", new Long(ql != null ? ql.getSizeInBytes() : 1));
    this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
    this.context.put("maxAttachments", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
    this.context.put("isNewPost", true);
    this.context.put("topic", topic);
    this.context.put("quote", "true");
    this.context.put("quoteUser", u.getUsername());
    this.context.put("setType", false);
    this.context.put("htmlAllowed", SecurityRepository.canAccess(SecurityConstants.PERM_HTML_DISABLED, Integer.toString(topic.getForumId())));
    this.context.put("start", this.request.getParameter("start"));
    this.context.put("user", DataAccessDriver.getInstance().newUserDAO().selectById(userId));
    this.context.put("pageTitle", I18n.getMessage("PostForm.reply") + " " + topic.getTitle());
    this.context.put("smilies", SmiliesRepository.getSmilies());
    boolean needCaptcha = SystemGlobals.getBoolValue(ConfigKeys.CAPTCHA_POSTS);
    if (needCaptcha) {
        SessionFacade.getUserSession().createNewCaptcha();
    }
    this.context.put("needCaptcha", needCaptcha);
}
Also used : User(net.jforum.entities.User) PostDAO(net.jforum.dao.PostDAO) UserDAO(net.jforum.dao.UserDAO) Post(net.jforum.entities.Post) Topic(net.jforum.entities.Topic) QuotaLimit(net.jforum.entities.QuotaLimit) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 9 with QuotaLimit

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

the class AttachmentsAction method quotaLimitSave.

public void quotaLimitSave() {
    QuotaLimit ql = new QuotaLimit();
    ql.setDescription(this.request.getParameter("quota_description"));
    ql.setSize(this.request.getIntParameter("max_filesize"));
    ql.setType(this.request.getIntParameter("type"));
    DataAccessDriver.getInstance().newAttachmentDAO().addQuotaLimit(ql);
    this.quotaLimit();
}
Also used : QuotaLimit(net.jforum.entities.QuotaLimit)

Aggregations

QuotaLimit (net.jforum.entities.QuotaLimit)9 User (net.jforum.entities.User)4 Topic (net.jforum.entities.Topic)3 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)3 PostDAO (net.jforum.dao.PostDAO)2 UserDAO (net.jforum.dao.UserDAO)2 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 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 AttachmentDAO (net.jforum.dao.AttachmentDAO)1 PollDAO (net.jforum.dao.PollDAO)1 Attachment (net.jforum.entities.Attachment)1 AttachmentExtension (net.jforum.entities.AttachmentExtension)1 AttachmentInfo (net.jforum.entities.AttachmentInfo)1 Forum (net.jforum.entities.Forum)1