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 diff
     1.1 --- a/s4-funcs.sh	Thu Mar 14 12:48:07 2019 +0900
     1.2 +++ b/s4-funcs.sh	Thu Mar 14 15:38:08 2019 +0900
     1.3 @@ -29,7 +29,13 @@
     1.4  iconxy_M=400x400
     1.5  maximagexy=1600x1600
     1.6  ### maximagexy=400x400
     1.7 +filesize_max=$((5*1024*1024))
     1.8  file_accept='accept="image/*,text/*,audio/*,application/vnd.oasis.*,application/pdf,application/x-*"'
     1.9 +file_accept_egrep='^(text/|image/|audio/|application/(vnd.oasis|pdf|[xz]-))'
    1.10 +file_warn="
    1.11 +添付可能ファイル: 5MB以内のテキスト、画像、音声、動画、ODT、PDF、
    1.12 +圧縮ファイル、データベースファイル
    1.13 +[編集]リンクから修正してください。"
    1.14  blogreadflagrowid=0
    1.15  blogcutoffflagrowid=-1
    1.16  querylog=$tmpdir/query.log
    1.17 @@ -1242,6 +1248,7 @@
    1.18   # err k=$k v=$v
    1.19  	case "$k" in
    1.20  	  *:filename)
    1.21 +	    mimetype=`file --mime-type - < "$tmpd/$v"|cut -d' ' -f2`
    1.22  	    type='file'; k=${k%:filename}
    1.23  	    # DO NOT ALLOW Space and '|' in file names
    1.24  	    newv=`echo "$v"|sed 's/[ \|]/X/g'`
    1.25 @@ -1249,7 +1256,7 @@
    1.26  	      :
    1.27  	    fi
    1.28  # (echo k=$k v="[$v]"; ls -lF "$tmpd/$v"; file --mime-type "$tmpd/$v") 1>&3
    1.29 -	    case `file --mime-type - < "$tmpd/$v"|cut -d' ' -f2` in
    1.30 +	    case "$mimetype" in
    1.31  	      [Ii]mage/x-xcf)
    1.32  		bzip2 "$tmpd/$v"
    1.33  		v=${v}.bz2
    1.34 @@ -1259,6 +1266,15 @@
    1.35  		mogrify -resize $maximagexy'>' "$tmpd/$v"
    1.36  		;;
    1.37  	    esac
    1.38 +	    if ! echo "$mimetype" | egrep "$file_accept_egrep" >/dev/null 2>&1
    1.39 +	    then
    1.40 +	      replpar text string " *添付できない形式です($v)* $file_warn"
    1.41 +	      continue
    1.42 +	    elif [ `wc -c < "$tmpd/$v"` -gt "$filesize_max" ]; then
    1.43 +	      replpar text string \
    1.44 +		  " *添付ファイル($v)は${filesize_max}バイト以下にしてください* $file_warn"
    1.45 +	      continue
    1.46 +	    fi
    1.47  	    ;;
    1.48  	  *)
    1.49  	    type='string'