# HG changeset patch # User HIROSE Yuuji # Date 1074194908 -32378 # Node ID 51440ee77ae40a870c99ab00d82442d382994100 # Parent f4b10ab5479fd667cd91c53d29c3786491205472 RCS-revision 1.8 date: 2004/01/16 04:28:06; author: yuuji; state: Exp; lines: +35 -14 Separate cookie values into account information and prefefences. diff -r f4b10ab5479f -r 51440ee77ae4 after5.rb --- a/after5.rb Sat Jan 10 06:57:44 2004 +0859 +++ b/after5.rb Fri Jan 16 04:28:06 2004 +0859 @@ -2,8 +2,8 @@ # # Associative Scheduling Table - after5 # (C)2003, 2004 by HIROSE Yuuji [yuuji@gentei.org] -# $Id: after5.rb,v 1.7 2004/01/10 06:57:44 yuuji Exp $ -# Last modified Sat Jan 10 15:48:17 2004 on firestorm +# $Id: after5.rb,v 1.8 2004/01/16 04:28:06 yuuji Exp $ +# Last modified Fri Jan 16 13:10:10 2004 on firestorm # See http://www.gentei.org/~yuuji/software/after5/ # このスクリプトはEUCで保存してください。 @@ -474,12 +474,13 @@ visible = false #next unless /@/ =~ who # user must be as user@do.ma.in next unless account_exists(who) - next if personalonly && who != user + ## next if personalonly && who != user #2004/1/16 who.untaint dir = File.join(t, who) next unless test(?d, dir) && test(?x, dir) pub = File.join(dir, 'pub') - if test(?f, pub) && test(?r, pub) && test(?s, pub) + if test(?f, pub) && test(?r, pub) && test(?s, pub) && + !personalonly # unneccessary if personal mode if IO.readlines(pub)[0].to_i > 0 visible = true end @@ -921,7 +922,7 @@ @schedulearea = {'rows'=>'4', 'cols'=>'60', 'name'=>'schedule'} @oldagent = (%r,Mozilla/4, =~ ENV['HTTP_USER_AGENT']) @lang = 0 - @savecookieregexp = /^(user$|passwd$|display(mode|days)$|nt|headline)/ + @saveprefsregexp = /^(display(mode|days)$|nt|headline)/ @opt = { 'conf' => @mybase+".cf", 'css' => @mybase+".css", @@ -1156,16 +1157,26 @@ end def importcookie() - @cookie.keys.grep(@savecookieregexp){|v| + @cookie.keys.grep(@saveprefsregexp){|v| @params[v] = @params[v] || @cookie[v] } + for v in %w[user passwd] + @params[v] = @params[v] || @cookie[v] + end end def setcookie() + a = {} + a['user'] = @params['user'] if @params['user'] + a['passwd'] = @params['passwd'] if @params['passwd'] + ac = gencookie("value", a, 3600*6*1) + printf "Set-Cookie: %s\n", ac if ac p = {} - @params.keys.grep(@savecookieregexp){|v| + @params.keys.grep(@saveprefsregexp){|v| p[v] = @params[v].to_s.strip if @params[v] && @params[v] > '' } - c = gencookie(p, 3600*6*1) + c = gencookie("prefs", p, 3600*24*7) + str = [ac, c].select{|x|x}.join("; ") + # printf "Set-Cookie: %s\n", str if str>'' printf "Set-Cookie: %s\n", c if c end @@ -1179,7 +1190,7 @@ string.gsub!(/%(..)/){[$1.hex].pack("c")} end - def gencookie(a, expire) + def gencookie(name, a, expire) x = a.collect{|k, v| sprintf("%s=%s", k, encode(v)) if v } @@ -1187,7 +1198,7 @@ return nil if x.empty? str = x.join('&') ex = (Time.new+expire).to_s - sprintf "value=%s; expires=%s", encode(str), ex + sprintf "%s=%s; expires=%s", name, encode(str), ex end def login() @@ -1254,6 +1265,7 @@ newp = pm.setnewpasswd(user, @opt['pswdlen']) sendMail(email, "#{@mybase} password", "(#{ENV['REMOTE_ADDR']} からのアクセスによる送信)\n" + + @opt['url'] + "\n" + "#{@mybase} 用の #{user} さんのパスワードは\n" + (newp || "未定義") + "\nです。\n") @O.print @H.p("#{email} 宛に送信しておきました") @@ -1262,16 +1274,20 @@ outputError(msg('pswderror')) throw :auth, nil end - else + elsif passwd == '' newp = pm.setnewpasswd(user, @opt['pswdlen']) @sc.createuser(user, user) sendMail(email, "#{@mybase} new account", sprintf(msg('accessfrom'), ENV['REMOTE_ADDR']) + + sprintf(@opt['url']) + "\n" + sprintf(msg('newpassword'), user, newp) + sprintf(msg('mischief'))) @O.print @H.p(sprintf(msg('newaccount'), user)) @O.print @H.p(@H.a(@myname, msg('login'))) throw :auth, nil + else + outputError(msg('pswderror')) + throw :auth, nil end } if auth @@ -1518,7 +1534,8 @@ topic = sprintf "%s%s", time == @opt['alldaydir'] ? '' : time+":", if personal - text.split("\n") ##[0] + (@params['user'] == who ? "" : who+"=") + + text ## .split("\n") ##[0] else nickname(who) + \ if headline == 'whole' @@ -2701,7 +2718,7 @@ } @O.print @H.p(deleteuser(user) ? msg("done") : msg("failure")) - @O.print footer() + @O.print @H.p(@H.a(@myname, msg('login'))) end def admgroupsub() @@ -2993,9 +3010,13 @@ end def getcookie() cookie = {} - if /value=(.*)/ =~ ENV['HTTP_COOKIE'] + return cookie unless ENV['HTTP_COOKIE'] + #if /value=(.*)/ =~ ENV['HTTP_COOKIE'] + for cv in ENV['HTTP_COOKIE'].split(/[\; ]+/).grep(/(value|prefs)=(.*)/) # value=$1.gsub!(/%(..)/){[$1.hex].pack("c")} + next unless /\w+=(.*)/ =~ cv value=decode!($1) + next unless value for line in value.split("&") if /(\w+)=(.*)/ =~ line key, value = $1, $2