Mercurial > hgrepos > hgweb.cgi > s4
changeset 511:f2dec8025291
Force restrict file type and file size
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Thu, 14 Mar 2019 15:38:08 +0900 |
parents | 2a70b6c7ffad |
children | 24a5010a131b |
files | s4-funcs.sh |
diffstat | 1 files changed, 17 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/s4-funcs.sh Thu Mar 14 12:48:07 2019 +0900 +++ b/s4-funcs.sh Thu Mar 14 15:38:08 2019 +0900 @@ -29,7 +29,13 @@ iconxy_M=400x400 maximagexy=1600x1600 ### maximagexy=400x400 +filesize_max=$((5*1024*1024)) file_accept='accept="image/*,text/*,audio/*,application/vnd.oasis.*,application/pdf,application/x-*"' +file_accept_egrep='^(text/|image/|audio/|application/(vnd.oasis|pdf|[xz]-))' +file_warn=" +添付可能ファイル: 5MB以内のテキスト、画像、音声、動画、ODT、PDF、 +圧縮ファイル、データベースファイル +[編集]リンクから修正してください。" blogreadflagrowid=0 blogcutoffflagrowid=-1 querylog=$tmpdir/query.log @@ -1242,6 +1248,7 @@ # err k=$k v=$v case "$k" in *:filename) + mimetype=`file --mime-type - < "$tmpd/$v"|cut -d' ' -f2` type='file'; k=${k%:filename} # DO NOT ALLOW Space and '|' in file names newv=`echo "$v"|sed 's/[ \|]/X/g'` @@ -1249,7 +1256,7 @@ : fi # (echo k=$k v="[$v]"; ls -lF "$tmpd/$v"; file --mime-type "$tmpd/$v") 1>&3 - case `file --mime-type - < "$tmpd/$v"|cut -d' ' -f2` in + case "$mimetype" in [Ii]mage/x-xcf) bzip2 "$tmpd/$v" v=${v}.bz2 @@ -1259,6 +1266,15 @@ mogrify -resize $maximagexy'>' "$tmpd/$v" ;; esac + if ! echo "$mimetype" | egrep "$file_accept_egrep" >/dev/null 2>&1 + then + replpar text string " *添付できない形式です($v)* $file_warn" + continue + elif [ `wc -c < "$tmpd/$v"` -gt "$filesize_max" ]; then + replpar text string \ + " *添付ファイル($v)は${filesize_max}バイト以下にしてください* $file_warn" + continue + fi ;; *) type='string'