changeset 8:3db7524d3dea

Add default images
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 20 Jul 2015 11:30:39 +0900
parents 67a1bb482ce1
children c2776f0f1d36
files mpsplit.rb y4-blog.sh y4-funcs.sh y4-init.sh y4.cgi
diffstat 5 files changed, 53 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/mpsplit.rb	Sun Jul 19 17:02:46 2015 +0900
+++ b/mpsplit.rb	Mon Jul 20 11:30:39 2015 +0900
@@ -5,8 +5,9 @@
 Encoding.default_internal = Encoding::BINARY
 
 boundary="--"+ARGV[0] # +"\r\n"
-tmpdir=(ARGV[1] || "tmp")
-test(?d, tmpdir) || Dir.mkdir("tmp")
+tmpdir=(ARGV[1] || "tmp").dup
+tmpdir.untaint
+test(?d, tmpdir) or Dir.mkdir(tmpdir)
 stream=STDIN.readlines.join
 stream.split(boundary)[1..-2].each do |x|
   header = x.sub(/\r\n\r\n.*/, "")
@@ -15,7 +16,8 @@
 STDERR.printf("body[%s]=[%s]\n", name, body.length)
   if /filename=(['\"]?)(.*?)\1/ =~ header && $2 > ""
     fn = $2
-    open(File.expand_path(fn, tmpdir), "w") do |out|
+    fn.untaint if File.dirname(fn)=="."
+    open(File.expand_path(fn, tmpdir).untaint, "w") do |out|
       out.write body
     end
     printf("%s:filename=%s\n", name, fn)
--- a/y4-blog.sh	Sun Jul 19 17:02:46 2015 +0900
+++ b/y4-blog.sh	Mon Jul 20 11:30:39 2015 +0900
@@ -252,7 +252,7 @@
 	  dir=`printf $bd/%03d $i`
 	  mkdir $dir
 	  query "select quote(bin) from article_m where rowid=$rowid;" \
-	      | xxd -r -p > $dir/$filename
+	      | unhexize > $dir/$filename
 	done
   if [ ! -d $bd/001 ]; then
     contenttype; echo
--- a/y4-funcs.sh	Sun Jul 19 17:02:46 2015 +0900
+++ b/y4-funcs.sh	Mon Jul 20 11:30:39 2015 +0900
@@ -6,7 +6,7 @@
 myargs="$@"
 #bindir=`(cd $mydir/bin; pwd)`
 # :$bindir
-PATH=/usr/local/sqlite3/bin:/usr/local/vim7/bin:/usr/local/ImageMagick/bin:$PATH
+PATH=/usr/local/sqlite3/bin:/usr/local/vim7/bin:/usr/iekei/ImageMagick/bin:/usr/local/ImageMagick/bin:$PATH
 tmpdir=${TMPDIR:-tmp}
 dbdir=${DBDIR:-db}
 tmpfiles=""
@@ -517,7 +517,7 @@
 		 #file=$td/$val
 		 file=$td/`query "select val from $cond $slice;"`
 ####tmp		 [ -s $file -a -s $td/$fn.rowid ] && continue
-		 sq $db<<EOF | xxd -r -p > $file
+		 sq $db<<EOF | unhexize > $file
 .output $td/$fn.rowid
 select rowid from $cond $slice;
 .output $td/$fn
@@ -559,7 +559,7 @@
 		       if [ ! -s $file ]; then
 			## sq $db "select quote(bin) from $cond and val=\"$fn\"" \
 			 query "select quote(bin) from $cond and val=\"$fn\";" \
-			     | xxd -r -p > $file
+			     | unhexize > $file
 			 echo ${type#file:} > $file.content-type
 # err TTTTTTTTTTTTTTTT: $type
 			 case $type in
@@ -631,11 +631,31 @@
     if type xxd >/dev/null 2>&1; then
       hexize="xxd -p"
     else
-      hexize="hexdump -ve '1/1 \"%.2x\"'"
+      hexize_hd() {
+	hexdump -ve '1/1 "%.2x"'
+      }
+      hexize="hexize_hd"
     fi
   fi
   cat $1 | $hexize | tr -d '\n'
 }
+unhexize() {
+  if [ -z "$unhex" ]; then
+    if type xxd >/dev/null 2>&1; then
+      unhex="xxd -p -r"
+    elif type perl >/dev/null 2>&1; then
+      cat >$tmpd/unhex.pl<<EOF
+s/([0-9a-f]{2})/print chr hex \$1/gie
+EOF
+      # Perl refuses -e in setuid circumstances, which can be absurdly
+      # avoided by creating scripts in a file where its parent directory is
+      # world writable...:)
+      unhex="perl -n $tmpd/unhex.pl"
+    fi
+  fi
+  cat $1 | $unhex
+#  cat $1 | tee /tmp/uh.in| $unhex | tee /tmp/uh.out
+}
 percenthex() {
   hexize $1 | sed 's/\(..\)/%\1/g'
 }
@@ -1400,6 +1420,7 @@
   # $1=definition-file
   # Using $user and $session
   rowid=`getpar rowid`
+err ...........rowid=$rowid
   if [ ! -e $1 ]; then
     echo "<p>テーブル定義ファイルが見付かりません</p>"
     exit 1
@@ -1785,7 +1806,7 @@
  <table class="b $2">
 $forms
  </table>$hiddens
- ${rowid:+<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">}
+ ${rowid:+<input type="hidden" name="rowid" value="$rowid">}
 EOF
   if [ -z $GF_VIEWONLY ]; then
     cat<<EOF
--- a/y4-init.sh	Sun Jul 19 17:02:46 2015 +0900
+++ b/y4-init.sh	Mon Jul 20 11:30:39 2015 +0900
@@ -42,12 +42,12 @@
 	 case $keytype in
 	   *p*|*f*)
 	     addcol=$col
-	     pkey="$pkey${pkey:+, }$col"
 	     case $keytype in
 	       *pf*|*fp*)
 		 fkey="${fkey}, foreign key($col) references $objtype on delete cascade on update cascade"
 		 fkey2="${fkey2}, foreign key($col) references $objtype on delete cascade on update cascade" ;;
 	       *p*)
+		 pkey="$pkey${pkey:+, }$col"
 		 fkey2="${fkey2}, foreign key($col) references $tmain($col) on delete cascade on update cascade" ;; 
 	     esac
 	     ;;
--- a/y4.cgi	Sun Jul 19 17:02:46 2015 +0900
+++ b/y4.cgi	Mon Jul 20 11:30:39 2015 +0900
@@ -26,31 +26,32 @@
 stage=`getpar stage`
 stage=${stage:-$1}
 case ${stage} in
-  "")
-    contenttype; echo
-    m4 -D_SITE_="S System" $layout/welcome.m4.html
-    # echo "<pre>"; gencookie "user=$user" "skey=$skey"; echo "</pre>"
-    # echo "<pre>`env|sort -u`</pre>"
-    ;;
-  "diary")
+  # "")
+  #   contenttype; echo
+  #   m4 -D_SITE_="S System" $layout/welcome.m4.html
+  #   # echo "<pre>"; gencookie "user=$user" "skey=$skey"; echo "</pre>"
+  #   # echo "<pre>`env|sort -u`</pre>"
+  #   ;;
+  "home"|"")
     contenttype; echo
-    title=`getpar title` #diary=`getpar diary` wday=`getpar wday`
-    [ -n "$title" ] && par2table $formdir/diary.def
-    m4 -D_TITLE_="$title" -D_DIARY_="$diary" \
-       -D_FORM_="`genform templ/form/diary.def`" \
-       -D_FORM2_="syscmd(\`genform templ/form/diary.def')" \
-       -D_DUMPTABLE_="`dumptable html diary title,wday,diary`" \
-       $layout/html.m4.html $layout/diary.m4.html
+err HOME: just in rowid=`getpar rowid`
+    [ -n "`getpar rowid`" ] && par2table $formdir/user.def
+    showhome ${2:-$user}
     ;;
+  # "diary")
+  #   contenttype; echo
+  #   title=`getpar title` #diary=`getpar diary` wday=`getpar wday`
+  #   [ -n "$title" ] && par2table $formdir/diary.def
+  #   m4 -D_TITLE_="$title" -D_DIARY_="$diary" \
+  #      -D_FORM_="`genform templ/form/diary.def`" \
+  #      -D_FORM2_="syscmd(\`genform templ/form/diary.def')" \
+  #      -D_DUMPTABLE_="`dumptable html diary title,wday,diary`" \
+  #      $layout/html.m4.html $layout/diary.m4.html
+  #   ;;
   "invite")
     contenttype; echo
     invite
     ;;
-  "home")
-    contenttype; echo
-    [ -n "`getpar rowid`" ] && par2table $formdir/user.def
-    showhome ${2:-$user}
-    ;;
   "groupman")
     contenttype; echo
     gname=`getpar gname`

yatex.org