# HG changeset patch # User HIROSE Yuuji # Date 1552545488 -32400 # Node ID f2dec802529145648206229b64a5a14e741552c2 # Parent 2a70b6c7ffad91c21348a7343be4e0d3a90bc312 Force restrict file type and file size diff -r 2a70b6c7ffad -r f2dec8025291 s4-funcs.sh --- 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'