# HG changeset patch # User HIROSE Yuuji # Date 1333225161 -32376 # Node ID 904bbce89e7186daf39acd964f530efe29be927c # Parent 1ff30d4c58cead4bb12ff8e2c6b6d0574e0883f8 RCS-revision 1.18 date: 2012/04/01 05:18:57; author: yuuji; state: Exp; lines: +37 -36 Boring hack for ruby19 encoding issue Guidance message little bit informative diff -r 1ff30d4c58ce -r 904bbce89e71 after5.rb --- a/after5.rb Thu Sep 17 09:09:23 2009 +0859 +++ b/after5.rb Sun Apr 01 05:18:57 2012 +0859 @@ -1,14 +1,15 @@ -#!/usr/local/bin/ruby +#!/usr/local/bin/ruby19 # -*- coding: euc-jp -*- # # Associative Scheduling Table - after5 # (C)2003, 2004, 2006, 2008 by HIROSE Yuuji [yuuji@gentei.org] -# $Id: after5.rb,v 1.17 2009/09/17 09:09:23 yuuji Exp $ -# Last modified Thu Sep 17 18:08:23 2009 on spada +# $Id: after5.rb,v 1.18 2012/04/01 05:18:57 yuuji Exp $ +# Last modified Sun Apr 1 14:17:05 2012 on firestorm # See http://www.gentei.org/~yuuji/software/after5/ # このスクリプトはEUCで保存してください。 require 'kconv' +require 'nkf' $charset = 'EUC-JP' @@ -284,14 +285,14 @@ } u = newu map[u] = {} - d = File.join(@usermapdir, u) + d = File.join(@usermapdir, u).untaint next unless test(?d, d) Dir.foreach(d){|attr| next if /^\./ =~ attr attr.untaint if /^[A-Z_][-A-Z_0-9]*$/i =~ attr - file = File.join(@usermapdir, u, attr) + file = File.join(@usermapdir, u, attr).untaint next unless test(?s, file) && test(?r, file) - map[u][attr] = IO.readlines(file).join().strip + map[u][attr] = IO.readlines(file).join.toeuc.strip } } map @@ -374,19 +375,19 @@ g.split('').each{|c| gg << c[0].chr if c != '`'} g = gg map[gg] = {} - d = File.join(@groupmapdir, g) + d = File.join(@groupmapdir, g).untaint next unless test(?d, d) # get group name - gnf = File.join(d, 'name') + gnf = File.join(d, 'name').untaint if test(?r, gnf) && test(?s, gnf) - n = IO.readlines(gnf)[0].to_s.strip + n = IO.readlines(gnf)[0].to_s.toeuc.strip map[g]['name'] = if n > '' then n else g end else map[g]['name'] = g end # get administrators # - gad = File.join(d, 'admin') + gad = File.join(d, 'admin').untaint map[g]['admin'] = [] if test(?d, gad) Dir.foreach(gad){|a| @@ -397,7 +398,7 @@ end # collect members #map[g]['members'] = collectmembers(g) - memd = File.join(d, 'members') + memd = File.join(d, 'members').untaint map[g]['members'] = [] if test(?d, memd) Dir.foreach(memd){|a| @@ -419,8 +420,8 @@ return nil unless grp for u in users next unless account_exists(u) - mdir = File.join(@groupmapdir, grp, role) - file = File.join(mdir, u) + mdir = File.join(@groupmapdir, grp, role).untaint + file = File.join(mdir, u).untaint if remove @groupmap[grp][role].delete(u) File.unlink(file) if test(?e, file) @@ -435,8 +436,8 @@ end def setgroupname(grp, name) return nil unless @groupmap[grp] - mdir = File.join(@groupmapdir, grp) - nfile = File.join(mdir, 'name') + mdir = File.join(@groupmapdir, grp).untaint + nfile = File.join(mdir, 'name').untaint @groupmap[grp]['name'] = name if grp == name # remove the name file because it is default name @@ -582,7 +583,7 @@ sched[time][who] = {} file = File.join(dir, @schedulefile) if test(?s, file) && test(?r, file) && test(?s, file) - sched[time][who]['sched'] = IO.readlines(file).join().chomp! + sched[time][who]['sched'] = IO.readlines(file).join.toeuc.chomp! sched[time][who]['regtime'] = File.stat(file).mtime end sched[time][who]['pub'] = visible @@ -644,7 +645,7 @@ def getschedule(user, year, month, day, time) file = schedulefile(user, year, month, day, time) if test(?r, file) && test(?s, file) - return IO.readlines(file).join + return IO.readlines(file).join.toeuc end return nil end @@ -779,7 +780,7 @@ if test(?s, f) ntl[user][date] = {} ntl[user][date]['file'] = f - ntl[user][date]['text'] = IO.readlines(f) + ntl[user][date]['text'] = IO.readlines(f).toeuc else File.unlink(f) # symlink points to nonexistent file end @@ -967,7 +968,7 @@ @@holiday = {} return unless test(?f, file) && test(?s, file) IO.foreach(file){|line| - line.strip + line = line.toeuc.strip next if /^#/ =~ line date, what = line.scan(/(\S+)\s+(.*)/)[0] if %r,(\d+)/(\d+)/(\d+), =~ date @@ -1147,7 +1148,7 @@ 'nonpublic' => ['非', 'sec'], 'through' => ['〜', '=>'], 'yes' => ['はいな', 'yes'], - 'no' => ['やだ', 'nope'], + 'no' => ['やだ(非公開)', 'nope'], 'wnames' => [%w[日 月 火 水 木 金 土], %w[sun mon tue wed thu fri sat]], 'whichday' => ['(まとめ登録の場合)
期間中のどの日に?', @@ -1196,7 +1197,11 @@ 'user' => ['ユーザ', 'user'], 'group' => ['グループ', 'group'], 'personal' => ['個人で', 'personal'], - 'registas' => ['グループ予定として登録', 'Register as group'], + 'registas' => ['グループ予定として登録?', 'Register as group?'], + 'headsched' => ['下の枠内に予定を記入: 1行以内で短めに。 +長くなるときは2行目以降に詳細を。', +'Put shortest sentence as possible within 1 line. +Or, put short subject in the first line, details in latter lines.'], 'joinquit' => ['入退', 'joining/quiting'], 'of' => ['の', "'s"], 'id' => ['ID(ローマ字1単語空白なしで)', 'ID(without spaces)'], @@ -1308,8 +1313,7 @@ string.gsub!(/%(..)/){[$1.hex].pack("c")} end def decode(string) - string.gsub(/\+/, ' ') - string.gsub(/%(..)/){[$1.hex].pack("c")} + string.gsub(/\+/, ' ').gsub(/%(..)/){[$1.hex].pack("c")} end def gencookie(name, a, expire) @@ -1434,12 +1438,12 @@ cpy else string - end + end.untaint end def checkmail(mail) account, domain = mail.scan(/(.*)@(.*)/)[0] return false unless account != nil && domain != nil - return false unless /^[-0-9a-z_.]+$/oi =~ domain + return false unless /^[-0-9a-z_.]+$/oi =~ domain.toeuc domain = safecopy(domain) require 'socket' begin @@ -1485,13 +1489,9 @@ end def sendMail(to, subject, body) - body = Kconv::tojis(body) - subject = Kconv.tojis(subject) + body = NKF.nkf("-j", body) + subject = NKF.nkf("-jM", subject) to = safecopy(to) # cleanup tainted address - if /\e/ =~ subject # If contains JIS chars... - subject = subject.split(//,1).pack('m') - subject = "=?iso-2022-jp?B?#{subject}?=" - end subject.gsub!(/\n/, '') begin if (m=open("|-", "w")) @@ -1598,7 +1598,7 @@ if !checkauth return nil end - + month = day.month.to_s first = Time.mktime(day.year, day.month, 1) last = daysofmonth(day.year, day.month) @@ -2005,7 +2005,8 @@ @H.radio('editmode', 'remove', 'Delete?') + " / " + \ @H.radio('editmode', 'modify', 'Overwrite?') + " / " + \ @H.radio('editmode', 'append', 'Append?', true) + "
\n" + \ - @H.element("textarea", @schedulearea){} + "
\n" + \ + @H.element("p"){msg('headsched') + \ + @H.element("textarea", @schedulearea){}} + # textarea @H.submit_reset("GO") } #form end @@ -2226,7 +2227,7 @@ return nil end begin - (text = @params['schedule'].strip.gsub(/\r+\n/, $/)) << "\n" + (text = decode(@params['schedule']).strip.gsub(/\r+\n/, $/)) << "\n" text = purify(text) replace = (/modify/i =~ @params['editmode']) rc = @sc.register(registerer, y, m, d, timedir, text, replace) @@ -2239,7 +2240,7 @@ rescue outputError("Failed"+$!) end - text = decode(@sc.getschedule(registerer, y, m, d, timedir)) + text = @sc.getschedule(registerer, y, m, d, timedir) reg_notify(registerer, y, m, d, timedir, text) end @@ -3437,7 +3438,7 @@ end end -$KCODE='e' +$KCODE='e' if RUBY_VERSION < "1.9" After5.new.doit if __FILE__ == $0