Mercurial > hgrepos > hgweb.cgi > after5
annotate after5.rb @ 29:e7a01e561e28 draft
Message 'no' should contain only 'no'.
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Tue, 03 Apr 2012 15:06:33 +0900 |
parents | ff684484b12a |
children | af3f2175eddf |
rev | line source |
---|---|
17 | 1 #!/usr/local/bin/ruby19 |
16 | 2 # -*- coding: euc-jp -*- |
0 | 3 # |
4 # Associative Scheduling Table - after5 | |
22
8803e5d52611
Show guidance when wrong password entered.
HIROSE Yuuji <yuuji@gentei.org>
parents:
18
diff
changeset
|
5 # (C)2003, 2004, 2006, 2008, 2012 by HIROSE Yuuji [yuuji<at>gentei.org] |
26 | 6 # $Id: after5.rb,v 1.19 2012/04/01 11:52:25 yuuji Exp yuuji $ |
18 | 7 # $HGid$ |
29
e7a01e561e28
Message 'no' should contain only 'no'.
HIROSE Yuuji <yuuji@gentei.org>
parents:
28
diff
changeset
|
8 # Last modified Tue Apr 3 15:05:40 2012 on firestorm |
0 | 9 # See http://www.gentei.org/~yuuji/software/after5/ |
10 # このスクリプトはEUCで保存してください。 | |
11 | |
12 require 'kconv' | |
17 | 13 require 'nkf' |
0 | 14 |
15 $charset = 'EUC-JP' | |
16 | |
17 class HTMLout | |
18 def contenttype(type = "text/html", charset = $charset) | |
19 sprintf "Content-type: %s; charset=%s\n\n", type, charset | |
20 end | |
21 def initialize(title = "Document") | |
22 @title = title | |
23 @eltstack = [] | |
24 end | |
25 def resetstack() | |
26 @eltstack = [] | |
27 end | |
28 def head(title = @title, css = "style.css") | |
29 sprintf <<__EOS__, title, css | |
30 <html> | |
31 <head> | |
32 <title>%s</title> | |
33 <link rel="stylesheet" type="text/css" href="%s"> | |
34 </head> | |
35 __EOS__ | |
36 end | |
37 | |
38 def startelement(elt, attrs = {}, nl = true) | |
39 attr = "" | |
40 if attrs.is_a?(Hash) | |
41 for k in attrs.keys | |
42 attr += " %s=\"%s\"" % [k, attrs[k]] | |
43 end | |
44 end | |
45 @eltstack.push(elt) | |
46 sprintf "<%s%s>%s", elt, attr, nl ? "\n" : "" | |
47 end | |
48 def endelement(elt = nil, nl = true) | |
49 if elt | |
50 x = elt | |
51 @eltstack.pop | |
52 else | |
53 x = @eltstack.pop | |
54 end | |
55 sprintf "</%s>%s", x, nl ? "\n" : "" | |
56 end | |
57 def element(elt, attrs = nil, nl = nil) | |
58 attr = "" | |
59 lf = nl ? "\n" : "" | |
60 if attrs.is_a?(Hash) | |
61 for k in attrs.keys | |
62 attr += " %s=\"%s\"" % [k, attrs[k]] | |
63 end | |
64 end | |
65 body = yield | |
66 sprintf "<%s%s>%s%s%s</%s>%s", elt, attr, lf, body, lf, elt, lf | |
67 end | |
68 def elementln(elt, attr=nil) | |
69 body = yield | |
70 element(elt, attr, true){body} | |
71 end | |
72 def a(href, anchor = nil, attrs = {}) | |
73 attr = attrs | |
74 attr['href'] = href | |
75 element("a", attr){ | |
76 anchor or href | |
77 } | |
78 end | |
79 def p(msg, attrs=nil) | |
80 element("p", attrs){msg} | |
81 end | |
82 def text(name, value='', size=nil, maxlength=nil) | |
83 sprintf "<input type=\"text\" name=\"%s\" value=\"%s\"%s%s>", | |
84 name, value, | |
85 size ? " size=\"%s\""%size.to_s : '', | |
86 maxlength ? " maxlength=\"%s\""%maxlength.to_s : '' | |
87 end | |
88 def hidden(name, value='') | |
89 sprintf "<input type=\"hidden\" name=\"%s\" value=\"%s\">", name, value | |
90 end | |
91 def radio(name, value, text='', checked=nil) | |
92 sprintf "<input type=\"radio\" name=\"%s\" value=\"%s\"%s>%s", | |
93 name, value, checked ? " checked" : "", text | |
94 end | |
95 def checkbox(name, value, text='', checked=nil) | |
96 sprintf "<input type=\"checkbox\" name=\"%s\" value=\"%s\"%s>%s", | |
97 name, value, checked ? " checked" : "", text | |
98 end | |
99 def submit(name, value, text='') | |
100 sprintf "<input type=\"submit\" name=\"%s\" value=\"%s\">%s\n", | |
101 name, value, text | |
102 end | |
103 def reset(name, value, text='') | |
104 sprintf "<input type=\"reset\" name=\"%s\" value=\"%s\">\n", | |
105 name, value, text | |
106 end | |
107 def submit_reset(name) | |
108 submit(name, "GO")+reset(name, "Reset") | |
109 end | |
110 | |
2 | 111 def select(name, range, selected=nil) |
112 #start = (b<e ? b : e) | |
113 #last = (b>e ? b : e) | |
114 c=0 | |
0 | 115 "<select name=\"#{name}\">\n" + \ |
2 | 116 range.collect{|i| |
3 | 117 value = (i.is_a?(Array) ? i[1] : i).to_s |
118 sprintf "<option%s%s>%s%s</option>", | |
119 (selected.to_s==value.to_s) ? " selected" : "", | |
120 i.is_a?(Array) ? " value=\"%s\"" % value : '', | |
121 i.is_a?(Array) ? i[0] : i.to_s, | |
2 | 122 (c+=1)%6==0 ? "\n" : '' |
0 | 123 }.join + \ |
124 "\n</select>\n" | |
125 end | |
126 end | |
14 | 127 class TEXTout |
128 def isBlock(elt) | |
129 /\b(tr|[udo]l|p|div)\b/i =~ elt | |
130 end | |
131 def isEOC(elt) | |
132 /\bt[dh]\b/i =~ elt | |
133 end | |
134 def eoelem(elt) | |
135 r = "" | |
136 r << "\n" if isBlock(elt) | |
137 r << " " if isEOC(elt) | |
138 r | |
139 end | |
140 def contenttype(type = "text/plain", charset = $charset) | |
141 ### sprintf "Content-type: %s; charset=%s\n\n", type, charset | |
142 "" | |
143 end | |
144 def initialize(title = "Document") | |
145 @title = title | |
146 @eltstack = [] | |
147 end | |
148 def resetstack() | |
149 @eltstack = [] | |
150 end | |
151 def head(title = @title, css = "style.css") | |
152 sprintf <<__EOS__, title, css | |
153 ===== [[[ %s ]]] ===== | |
154 __EOS__ | |
155 end | |
156 | |
157 def startelement(elt, attrs = {}, nl = true) | |
158 attr = "" | |
159 x = sprintf "%s", " "*@eltstack.length | |
160 @eltstack.push(elt) | |
161 x | |
162 end | |
163 def endelement(elt = nil, nl = true) | |
164 if elt | |
165 x = elt | |
166 @eltstack.pop | |
167 else | |
168 x = @eltstack.pop | |
169 end | |
170 eoelem(x) | |
171 end | |
172 def element(elt, attrs = nil, nl = nil) | |
173 attr = "" | |
174 lf = nl ? "\n" : "" | |
175 body = yield | |
176 #sprintf "<%s%s>%s%s%s</%s>%s", elt, attr, lf, body, lf, elt, lf | |
177 sprintf "%s%s", body, eoelem(elt) | |
178 end | |
179 def elementln(elt, attr=nil) | |
180 body = yield | |
181 sprintf "%s\n", body | |
182 end | |
183 def a(href, anchor = nil, attrs = {}) | |
184 attr = attrs | |
185 attr['href'] = href | |
186 # sprintf "%s\n", href | |
187 anchor | |
188 end | |
189 def p(msg, attrs=nil) | |
190 element("p", attrs){msg} | |
191 end | |
192 def text(name, value='', size=nil, maxlength=nil) | |
193 "" | |
194 end | |
195 def hidden(name, value='') | |
196 "" | |
197 end | |
198 def radio(name, value, text='', checked=nil) | |
199 "" | |
200 end | |
201 def checkbox(name, value, text='', checked=nil) | |
202 "" | |
203 end | |
204 def submit(name, value, text='') | |
205 "" | |
206 end | |
207 def reset(name, value, text='') | |
208 "" | |
209 end | |
210 def submit_reset(name) | |
211 "" | |
212 end | |
213 def select(name, range, selected=nil) | |
214 "" | |
215 end | |
216 end | |
0 | 217 |
218 class PasswdMgr | |
219 def initialize(name, mode=0640) | |
220 require 'dbm' | |
221 @pdb = DBM.open(name, mode) | |
222 end | |
223 def checkpasswd(user, passwd) | |
224 if @pdb[user] then | |
225 @pdb[user] == passwd.crypt(@pdb[user]) | |
226 end | |
227 end | |
228 def setpasswd(user, passwd) | |
229 salt = [rand(64),rand(64)].pack("C*").tr("\x00-\x3f","A-Za-z0-9./") | |
230 @pdb[user] = passwd.crypt(salt) | |
231 end | |
232 def userexist?(user) | |
233 @pdb[user] ? true : false | |
234 end | |
235 def getpasswd(user) | |
236 @pdb[user] | |
237 end | |
238 def delete(user) | |
239 @pdb.delete(user) | |
240 end | |
241 def close() | |
242 @pdb.close() | |
243 end | |
244 def newpasswd(length) | |
245 srand(Time.now.to_i) | |
246 left = "qazxswedcvfrtgb12345" | |
247 right = "yhnmjuik.lop;/67890-" | |
248 array = [left, right] | |
249 (1..length).collect{|i| | |
250 a = array[i%array.length] | |
251 a[rand(a.length), 1] | |
252 }.join('') | |
253 end | |
254 def users() | |
255 @pdb.keys | |
256 end | |
257 private :newpasswd | |
258 def setnewpasswd(user, length=8) | |
259 newp = newpasswd(length) | |
260 setpasswd(user, newp) | |
261 newp | |
262 end | |
263 end | |
264 | |
265 class ScheduleDir | |
266 def initialize(dir = "s") | |
267 @dir = dir | |
268 @schedulefile = "sched" | |
269 @usermapdir = File.join(@dir, "usermap") | |
270 @usermap = mkusermap() | |
271 @groupmapdir = File.join(@dir, "groupmap") | |
272 @groupmap = mkgroupmap() | |
273 @crondir = File.join(@dir, "crondir") | |
274 | |
275 end | |
276 def mkusermap() | |
277 map = {} | |
278 unless test(?d, @usermapdir) | |
279 mkdir_p(@usermapdir) | |
280 end | |
281 Dir.foreach(@usermapdir){|u| | |
282 next if /^\./ =~ u | |
283 newu = '' | |
284 u.split('').each{|c| # for security wrapping | |
12 | 285 newu << c[0].chr if %r,[-A-Z0-9/+_.@],i =~ c |
0 | 286 } |
287 u = newu | |
288 map[u] = {} | |
17 | 289 d = File.join(@usermapdir, u).untaint |
0 | 290 next unless test(?d, d) |
291 Dir.foreach(d){|attr| | |
292 next if /^\./ =~ attr | |
12 | 293 attr.untaint if /^[A-Z_][-A-Z_0-9]*$/i =~ attr |
17 | 294 file = File.join(@usermapdir, u, attr).untaint |
0 | 295 next unless test(?s, file) && test(?r, file) |
17 | 296 map[u][attr] = IO.readlines(file).join.toeuc.strip |
0 | 297 } |
298 } | |
299 map | |
300 end | |
301 def putuserattr(user, attr, text) | |
302 # if text==nil, remove it | |
303 d = File.join(@usermapdir, user) | |
304 Dir.mkdir(d) unless test(?d, d) | |
305 file = File.join(d, attr) | |
306 begin | |
2 | 307 unless @usermap[user] |
308 @usermap[user] = {} | |
309 mkdir_p(d) unless test(?d, d) | |
310 end | |
0 | 311 @usermap[user][attr] = text |
312 if text==nil | |
313 File.unlink(file) | |
314 else | |
315 open(file, "w"){|w| w.puts @usermap[user][attr]} | |
316 end | |
317 rescue | |
318 return nil | |
319 end | |
320 return {attr => text} | |
321 end | |
322 def getuserattr(user, attr) | |
323 # Should we distinguish between attribute is nil and "" ? | |
324 if @usermap.has_key?(user) && @usermap[user][attr].is_a?(String) && | |
325 @usermap[user][attr] > '' | |
326 return @usermap[user][attr] | |
327 else | |
328 return nil | |
329 end | |
330 end | |
331 | |
332 def nickname(user) | |
333 if @usermap.has_key?(user) && @usermap[user]['name'].is_a?(String) && | |
334 @usermap[user]['name'] > '' | |
335 return @usermap[user]['name'] | |
336 else | |
337 return user.sub(/@.*/, '') | |
338 end | |
339 end | |
340 def setnickname(user, nickname) | |
341 putuserattr(user, 'name', nickname) | |
342 end | |
343 | |
344 # | |
345 # make group map | |
346 def collectmembers(gname) | |
347 @visitedgroup=[] unless @visitedgroup | |
348 return [] unless @visitedgroup.grep(gname).empty? | |
349 @visitedgroup.push(gname) | |
350 mdir = File.join(@groupmapdir, gname, 'members') | |
351 return [] unless test(?d, mdir) | |
352 members = [] | |
353 Dir.foreach(mdir){|item| | |
354 next if /^\./ =~ item | |
355 item.untaint | |
356 next unless test(?f, File.join(mdir, item)) | |
357 if /.+@.+/ =~ item | |
358 members << item | |
359 else | |
360 members += collectmembers(item) | |
361 end | |
362 } | |
363 @visitedgroup.pop | |
364 members | |
365 end | |
366 def mkgroupmap() | |
367 map = {} | |
368 return map unless test(?d, @groupmapdir) | |
369 @visitedgroup = [] | |
370 Dir.foreach(@groupmapdir){|g| | |
371 next if /^\./ =~ g | |
372 newg = '' | |
373 next unless /^[-a-z0-9_.]+$/i =~ g | |
374 #g.untaint ## untaintじゃだめだ。map{g} のkeyがtaintedになっちゃうよ | |
375 gg = '' # for security wrapping | |
376 g.split('').each{|c| gg << c[0].chr if c != '`'} | |
377 g = gg | |
378 map[gg] = {} | |
17 | 379 d = File.join(@groupmapdir, g).untaint |
0 | 380 next unless test(?d, d) |
381 # get group name | |
17 | 382 gnf = File.join(d, 'name').untaint |
0 | 383 if test(?r, gnf) && test(?s, gnf) |
17 | 384 n = IO.readlines(gnf)[0].to_s.toeuc.strip |
0 | 385 map[g]['name'] = if n > '' then n else g end |
386 else | |
387 map[g]['name'] = g | |
388 end | |
389 # get administrators | |
390 # | |
17 | 391 gad = File.join(d, 'admin').untaint |
0 | 392 map[g]['admin'] = [] |
393 if test(?d, gad) | |
394 Dir.foreach(gad){|a| | |
395 # administrator should be a person (not group) | |
396 next unless /@/ =~ a | |
397 map[g]['admin'] << a | |
398 } | |
399 end | |
400 # collect members | |
401 #map[g]['members'] = collectmembers(g) | |
17 | 402 memd = File.join(d, 'members').untaint |
0 | 403 map[g]['members'] = [] |
404 if test(?d, memd) | |
405 Dir.foreach(memd){|a| | |
406 next if /^\./ =~ a | |
407 map[g]['members'] << a | |
408 } | |
409 end | |
410 } | |
411 map | |
412 end | |
413 def groupmap() | |
414 @groupmap | |
415 end | |
416 def groups() | |
417 @groupmap.keys | |
418 end | |
2 | 419 def addgroup(group, users, remove=nil, role='members') |
420 grp = groups.grep(group)[0] # group may be tainted, using kept name | |
421 return nil unless grp | |
0 | 422 for u in users |
423 next unless account_exists(u) | |
17 | 424 mdir = File.join(@groupmapdir, grp, role).untaint |
425 file = File.join(mdir, u).untaint | |
0 | 426 if remove |
427 @groupmap[grp][role].delete(u) | |
428 File.unlink(file) if test(?e, file) | |
429 else | |
430 @groupmap[grp][role] << u | |
431 @groupmap[grp][role].uniq | |
432 Dir.mkdir(file) unless test(?d, mdir) | |
433 open(file, "w"){|x|} # Touch it | |
434 end | |
435 end | |
436 grp | |
437 end | |
438 def setgroupname(grp, name) | |
439 return nil unless @groupmap[grp] | |
17 | 440 mdir = File.join(@groupmapdir, grp).untaint |
441 nfile = File.join(mdir, 'name').untaint | |
0 | 442 @groupmap[grp]['name'] = name |
443 if grp == name | |
444 # remove the name file because it is default name | |
445 File.unlink(nfile) if test(?e, nfile) | |
446 else | |
447 Dir.mkdir(mdir) unless test(?d, mdir) | |
448 open(nfile, "w"){|n| n.puts name.to_s.strip} | |
449 end | |
450 name | |
451 end | |
452 def creategroup(grp, grpname="", admin=[]) | |
2 | 453 grpptnOK = /^[-A-Z0-9._:!$%,]+$/i |
454 return nil unless grpptnOK =~ grp | |
455 gg = '' | |
456 grp.split('').each{|c| gg << c[0].chr if c =~ grpptnOK} | |
457 grp = gg | |
0 | 458 gdir = File.join(@groupmapdir, grp) |
459 mkdir_p(gdir) # Should not care errors here | |
460 Dir.mkdir(File.join(gdir, "admin")) | |
461 Dir.mkdir(File.join(gdir, "members")) | |
462 @groupmap[grp] = {} | |
463 if grpname == '' | |
464 @groupmap[grp]['name'] = grp | |
465 else | |
466 setgroupname(grp, grpname) | |
467 end | |
468 @groupmap[grp]['members'] = [] | |
469 @groupmap[grp]['admin'] = [] | |
470 addgroup(grp, admin) | |
471 addgroup(grp, admin, nil, 'admin') | |
472 return @groupmap[grp] | |
473 end | |
474 def createuser(user, email = nil) | |
475 return nil unless /@/ =~ user | |
476 return nil if %r@[\/()\;|,$\%^!\#&\'\"]@ =~ user | |
477 email = email || user | |
478 @usermap[user] = {} | |
479 Dir.mkdir(File.join(@usermapdir, user)) | |
480 putuserattr(user, 'email', email) | |
481 end | |
482 def deleteuser(user) | |
483 return nil unless @usermap[user] | |
484 begin | |
485 @usermap[user] # return value | |
486 ensure | |
487 @usermap.delete(user) | |
488 rm_rf(File.join(@usermapdir, user)) | |
489 rm_rf(File.join(@groupmapdir, "*/members/#{user}")) | |
490 rm_rf(File.join(@crondir, "[1-9]*-*-*/#{user}")) | |
491 rm_rf(File.join(@dir, "[1-9]*/[0-9][0-9]/[0-9][0-9]/[0-9]???/#{user}")) | |
492 end | |
493 end | |
494 def destroygroup(grp) | |
495 return nil unless @groupmap[grp] | |
496 begin | |
497 @groupmap[grp] # return value | |
498 ensure | |
499 @groupmap.delete(grp) | |
500 rm_rf(File.join(@groupmapdir, grp)) | |
501 rm_rf(File.join(@groupmapdir, "*/members/#{grp}")) | |
502 rm_rf(File.join(@crondir, "[1-9]*-*-*/#{grp}")) | |
503 rm_rf(File.join(@dir, "[1-9]*/[0-9][0-9]/[0-9][0-9]/[0-9]???/#{grp}")) | |
504 end | |
505 end | |
506 def rm_rf(path) | |
6 | 507 path.untaint |
0 | 508 if (list = Dir.glob(path))[0] |
509 for p in list | |
2 | 510 p.untaint |
0 | 511 system "/bin/rm -rf \"#{p}\"" |
512 end | |
513 cleanup_files(list[0]) | |
514 end | |
515 end | |
516 def account_exists(instance) | |
517 if /@/ =~ instance | |
518 true | |
519 else | |
520 ! @groupmap.select{|k, v| k==instance}.empty? | |
521 end | |
522 end | |
523 def ismember(user, grouporuser) | |
524 return true if user==grouporuser | |
525 if @groupmap[grouporuser] | |
526 @groupmap[grouporuser]['members'].grep(user)[0] | |
527 end | |
528 end | |
2 | 529 def isuser(user) |
530 @usermap[user] && @usermap.keys.grep(user)[0] | |
531 end | |
0 | 532 def isgroup(grp) |
533 @groupmap[grp] | |
534 end | |
535 def isadmin(user, group) | |
536 @groupmap[group] and @groupmap[group]['admin'].grep(user)[0] | |
537 end | |
538 def members(grp) | |
539 @groupmap[grp] and ####################@groupmap[grp]['members'] | |
540 collectmembers(grp) | |
541 end | |
542 def admins(grp) | |
543 @groupmap[grp] and @groupmap[grp]['admin'] | |
544 end | |
545 def groupname(grp) | |
546 @groupmap[grp] && @groupmap[grp]['name'] | |
547 end | |
2 | 548 def name2group(name) |
549 @groupmap.find{|g, v| v.is_a?(Hash) && v['name']==name} | |
550 end | |
551 def day_all(d, user=nil, personalonly = nil) | |
0 | 552 y, m, d = d.scan(%r,(\d\d\d\d+)/(\d+)/(\d+),)[0] |
553 #daydir = File.join(@dir, "%04d"%y.to_i, "%02d"%m.to_i, "%02d"%d.to_i) | |
554 daydir = File.join("s", "%04d"%y.to_i, "%02d"%m.to_i, "%02d"%d.to_i) | |
555 sched = {} | |
556 return sched unless test(?d, daydir) | |
557 Dir.foreach(daydir) {|time| | |
558 next if /^\./ =~ time | |
559 next unless /^\d\d\d\d$/ =~ time | |
560 time.untaint | |
561 t = File.join(daydir, time) | |
562 next unless test(?d, t) | |
563 sched[time] = {} | |
564 Dir.foreach(t){|who| | |
565 next if /^\./ =~ who | |
566 | |
567 visible = false | |
568 #next unless /@/ =~ who # user must be as user@do.ma.in | |
569 next unless account_exists(who) | |
7 | 570 ## next if personalonly && who != user #2004/1/16 |
0 | 571 who.untaint |
572 dir = File.join(t, who) | |
573 next unless test(?d, dir) && test(?x, dir) | |
574 pub = File.join(dir, 'pub') | |
7 | 575 if test(?f, pub) && test(?r, pub) && test(?s, pub) && |
576 !personalonly # unneccessary if personal mode | |
0 | 577 if IO.readlines(pub)[0].to_i > 0 |
578 visible = true | |
579 end | |
580 end | |
581 | |
582 | |
583 if ismember(user, who) || visible | |
584 sched[time][who] = {} | |
585 file = File.join(dir, @schedulefile) | |
586 if test(?s, file) && test(?r, file) && test(?s, file) | |
17 | 587 sched[time][who]['sched'] = IO.readlines(file).join.toeuc.chomp! |
6 | 588 sched[time][who]['regtime'] = File.stat(file).mtime |
0 | 589 end |
590 sched[time][who]['pub'] = visible | |
591 end | |
592 } #|who| | |
593 sched.delete(time) if sched[time].empty? | |
594 } | |
595 sched | |
596 end | |
597 | |
598 def scheduledir(user, y, m, d, time) | |
599 sprintf("%s/%04d/%02d/%02d/%04d/%s", | |
600 @dir, y.to_i, m.to_i, d.to_i, time.to_i, user) | |
601 end | |
602 def schedulefile(user, y, m, d, time) | |
603 File.join(scheduledir(user, y, m, d, time), @schedulefile) | |
604 end | |
605 def mkdir_p(path, mode=0777) | |
606 # Do not mkdir `path' for | |
607 # absolute paths | |
608 # those paths which contains `../' | |
609 # for the sake of security reason | |
610 return false if %r,\.\./|^/, =~ path | |
611 p = 0 | |
612 i=0 | |
613 while p=path.index("/", p) | |
614 dir = path[0..p].chop | |
615 p += 1 | |
616 break if i > 10 # overprotecting | |
617 next if test(?d, dir) | |
618 Dir.mkdir(dir, mode) | |
619 i += 1 | |
620 end | |
621 Dir.mkdir(path, mode) unless test(?d, path) | |
622 end | |
623 | |
624 # | |
625 # register schedule for user | |
626 # | |
627 def register(user, year, month, day, time, text, replace=nil) | |
628 # return code: 0 = succesfull new registration | |
629 # 1 = succesfull appending registration | |
630 dir = scheduledir(user, year, month, day, time) | |
631 file = schedulefile(user, year, month, day, time) | |
632 ret = 0 | |
633 um = File.umask(027) | |
634 begin | |
635 if !replace && test(?s, file) | |
636 ret = 1 | |
637 else | |
638 mkdir_p(dir, 0777) | |
639 end | |
640 ensure | |
641 File.umask(um) | |
642 end | |
643 open(file, replace ? "w" : "a"){|out|out.print text} | |
644 return ret | |
645 end | |
646 def getschedule(user, year, month, day, time) | |
647 file = schedulefile(user, year, month, day, time) | |
648 if test(?r, file) && test(?s, file) | |
17 | 649 return IO.readlines(file).join.toeuc |
0 | 650 end |
651 return nil | |
652 end | |
653 def remove(user, year, month, day, time) | |
654 file = schedulefile(user, year, month, day, time) | |
655 dir = File.dirname(file) | |
656 if test(?r, file) && test(?s, file) | |
657 File.unlink(file) | |
658 end | |
659 for f in Dir.glob(File.join(dir, "*")) | |
660 f.untaint | |
661 File.unlink(f) | |
662 end | |
663 Dir.rmdir(dir) if test(?d, dir) | |
664 begin | |
665 Dir.rmdir(File.dirname(dir)) | |
666 rescue | |
667 end | |
668 end | |
669 # | |
670 # register file | |
671 # | |
672 def putfile(user, year, month, day, time, file, contents) | |
673 scback = @schedulefile | |
674 begin | |
675 @schedulefile = File.basename(file) | |
676 register(user, year, month, day, time, contents, true) | |
677 ensure | |
678 @schedulefile = scback | |
679 end | |
680 end | |
681 def getfile(user, year, month, day, time, file) | |
682 scback = @schedulefile | |
683 begin | |
684 @schedulefile = File.basename(file) | |
685 getschedule(user, year, month, day, time) | |
686 ensure | |
687 @schedulefile = scback | |
688 end | |
689 end | |
690 def removefile(user, year, month, day, time, file) | |
691 dir = scheduledir(user, year, month, day, time) | |
692 file = File.join(dir, file) | |
693 if test(?e, file) | |
694 File.unlink(file) | |
695 end | |
696 end | |
697 # | |
698 # registration to crondir | |
699 # | |
700 def cronlink_file(nt_time, user, y, m, d, time) | |
701 subdir = nt_time.strftime("%Y-%m-%d-%H%M/#{user}") | |
702 cdir = File.join(@crondir, subdir) | |
703 File.join(cdir, sprintf("%04d-%02d-%02d-%04d", y, m, d, time)) | |
704 end | |
705 def register_crondir(nt_time, user, y, m, d, time) | |
706 linkfile = cronlink_file(nt_time, user, y, m, d, time) | |
707 mkdir_p(File.dirname(linkfile)) | |
708 scfile = schedulefile(user, y, m, d, time) | |
709 if test(?s, scfile) | |
710 sclink = File.join("../../..", scfile.sub!(Regexp.quote(@dir+'/'), '')) | |
711 File.symlink(sclink, linkfile) unless test(?e, linkfile) | |
712 return linkfile | |
713 end | |
714 return false | |
715 end | |
716 def remove_crondir(nt_time, user, y, m, d, time) | |
717 linkfile = cronlink_file(nt_time, user, y, m, d, time) | |
718 scfile = schedulefile(user, y, m, d, time) | |
719 if test(?e, linkfile) | |
720 File.unlink(linkfile) | |
721 begin | |
722 dir = linkfile | |
723 2.times {|x| | |
724 dir = File.dirname(dir) | |
725 if Dir.open(dir).collect.length <= 2 # is empty dir | |
726 Dir.rmdir(dir) | |
727 else | |
728 break | |
729 end | |
730 } | |
731 rescue | |
732 end | |
733 return linkfile | |
734 end | |
735 return false | |
736 end | |
737 | |
738 # | |
739 # return the Hash of crondir {user => files} | |
740 def notify_list(asof) | |
741 slack = 5*60 | |
742 gomifiles = [] | |
743 ntl = {} | |
744 return ntl unless test(?d, @crondir) | |
745 Dir.foreach(@crondir){|datedir| | |
2 | 746 next unless /(\d\d\d\d+)-(\d+)-(\d+)-(\d\d\d\d)/ =~ datedir |
10 | 747 ##datedir = sprintf("%04d-%02d-%02d-%04d", |
748 ## $1.to_i, $2.to_i, $3.to_i, $4.to_i) | |
749 datedir.untaint | |
0 | 750 dd = File.join(@crondir, datedir) |
751 next unless test(?d, dd) | |
752 y, m, d, hm = $1.to_i, $2.to_i, $3.to_i, $4.to_i | |
753 hh = hm/100 % 60 | |
754 mm = (hm%100) % 60 | |
755 t = Time.mktime(y, m, d, hh, mm) | |
756 next if t-slack > asof | |
757 # | |
758 # collect them | |
759 Dir.foreach(dd){|user| | |
2 | 760 # next unless /@/ =~ user || isgroup(user) |
761 next if /^\./ =~ user | |
762 if isgroup(user) | |
763 user = @groupmap.keys.grep(user)[0] | |
764 else | |
765 user = @usermap.keys.grep(user)[0] | |
766 end | |
767 next unless user | |
0 | 768 ud = File.join(dd, user) |
769 next unless test(?d, ud) | |
770 ntl[user] = {} | |
771 Dir.foreach(ud){|date| | |
772 next if /^\./ =~ date | |
773 unless /(\d\d\d\d+)-(\d+)-(\d+)-(\d\d\d\d)/ =~ date | |
774 gomifiles << File.join(ud, date) | |
775 next | |
776 end | |
13 | 777 #date = sprintf("%04d-%02d-%02d-%04d", |
778 # $1.to_i, $2.to_i, $3.to_i, $4.to_i) | |
779 date.untaint | |
0 | 780 f = File.join(ud, date) |
781 if test(?s, f) | |
782 ntl[user][date] = {} | |
783 ntl[user][date]['file'] = f | |
17 | 784 ntl[user][date]['text'] = IO.readlines(f).toeuc |
0 | 785 else |
786 File.unlink(f) # symlink points to nonexistent file | |
787 end | |
788 } | |
789 if ntl[user].empty? | |
790 # if ud does not contain valid cron symlinks, | |
791 # ud had been left badly. Remove it. | |
792 ntl.delete(user) | |
793 cleanup_files(gomifiles) | |
794 end | |
795 } | |
796 } | |
797 ntl | |
798 end | |
799 # | |
800 # cleanup file and directories | |
801 def cleanup_crondir(time) | |
802 Dir.foreach(@crnondir){|datedir| | |
803 dd = File.join(@crondir, datedir) | |
804 next unless test(?d, dd) | |
805 next unless /(\d\d\d\d+)-(\d+)-(\d+)-(\d\d\d\d)/ =~ dd | |
806 y, m, d, hm = $1.to_i, $2.to_i, $3.to_i, $4.to_i | |
807 hh = hm/100 % 60 | |
808 mm = (hm%100) % 60 | |
809 t = Time.mktime(y, m, d, hh, mm) | |
810 if t < time | |
811 system "rm -rf #{dd}" | |
812 end | |
813 } | |
814 end | |
815 # | |
816 # remove files in FILES, and remove parent directory if possible | |
817 def cleanup_files(files) | |
818 sentinel = File.stat(@dir).ino | |
16 | 819 me = $0.dup.untaint |
820 scriptsuid = File.stat(me).uid | |
0 | 821 for f in files |
2 | 822 if $SAFE > 0 |
823 f.untaint | |
824 if test(?e, f) && File.stat(f).uid != scriptsuid | |
825 f.taint | |
826 end | |
827 end | |
828 printf "Removing %s\n", f if $DEBUG | |
0 | 829 File.unlink(f) if test(?e, f) |
830 d = f | |
831 loop { | |
832 d = File.dirname(d) | |
833 break if d.length < 2 | |
834 break if File.stat(d).ino == sentinel | |
835 begin | |
836 puts "rmdir #{d}" if $DEBUG | |
837 Dir.rmdir(d) | |
838 rescue | |
839 break | |
840 end | |
841 } | |
842 end | |
843 end | |
844 end | |
845 | |
846 class StringIO<IO | |
847 def initialize() | |
848 @str="" | |
849 end | |
850 def foo=(str) | |
851 @str = str | |
852 end | |
2 | 853 def append(str) |
854 @str = str+@str | |
855 end | |
0 | 856 def print(str) |
857 @str << str | |
858 end | |
859 def puts(str) | |
860 @str << str+"\n" | |
861 end | |
862 def printf(*args) | |
863 @str << sprintf(*args) | |
864 end | |
865 def write(bytes) | |
866 print(bytes) | |
867 end | |
868 def gets() | |
869 return nil if @str == '' | |
870 p = @str.index(?\n) | |
871 if p | |
872 r = @str[0..p] | |
873 @str=@str[p+1..-1] | |
874 else | |
875 r = @str | |
876 end | |
877 return r | |
878 end | |
879 def readline() | |
880 this.gets() | |
881 end | |
882 def readlines() | |
883 r = @str | |
884 @str='' | |
885 r | |
886 end | |
887 | |
888 def p(*obj) | |
889 STDOUT.p(*obj) | |
890 end | |
891 end | |
892 | |
893 class CMDTimeout < Exception | |
894 def initialize() | |
895 @pw = IO.pipe | |
896 @pr = IO.pipe | |
897 @pe = IO.pipe | |
898 @timeout = false | |
899 end | |
900 def start(cmd, timeout, mixstderr=false) | |
901 if @pid=fork | |
902 @pw[0].close | |
903 @pr[1].close | |
904 @pe[1].close | |
905 # puts "parent!" | |
906 if @tk=fork | |
907 # main | |
908 else | |
909 @pw[1].close | |
910 @pr[0].close | |
911 @pe[0].close | |
912 trap(:INT){exit 0} | |
913 sleep timeout | |
914 begin | |
915 @timeout = true | |
916 STDERR.puts "TIMEOUT" | |
917 Process.kill :INT, @pid | |
918 rescue | |
919 #puts "Already done" | |
920 end | |
921 exit 0 | |
922 end | |
923 else | |
924 # Running this block with pid=@pid | |
925 trap(:INT){@timeout = true; exit 0} | |
926 @pw[1].close | |
927 STDIN.reopen(@pw[0]) | |
928 @pw[0].close | |
929 | |
930 @pr[0].close | |
931 STDOUT.reopen(@pr[1]) | |
932 if mixstderr | |
933 STDERR.reopen(@pr[1]) | |
934 else | |
935 STDERR.reopen(@pe[1]) | |
936 end | |
937 @pr[1].close | |
938 @pe[0].close | |
939 @pe[1].close | |
940 | |
15 | 941 exec(*cmd) |
0 | 942 exit 0 |
943 end | |
944 return [@pw[1], @pr[0], @pe[0]] | |
945 end | |
946 def wait() | |
947 Process.waitpid(@pid, nil) | |
948 end | |
949 def close() | |
950 @pr.each{|p| p.close unless p.closed?} | |
951 @pw.each{|p| p.close unless p.closed?} | |
952 @pe.each{|p| p.close unless p.closed?} | |
953 begin | |
954 Process.kill :INT, @tk | |
955 rescue | |
956 end | |
957 end | |
958 def timeout() | |
959 @timeout | |
960 end | |
961 end | |
962 | |
963 class Holiday | |
964 def initialize(dir = ".") | |
965 @@dir = dir | |
966 defined?(@@holiday) || setupHoliday | |
967 end | |
968 def setupHoliday(file = "holiday") | |
969 @@holiday = {} | |
970 return unless test(?f, file) && test(?s, file) | |
971 IO.foreach(file){|line| | |
17 | 972 line = line.toeuc.strip |
0 | 973 next if /^#/ =~ line |
974 date, what = line.scan(/(\S+)\s+(.*)/)[0] | |
975 if %r,(\d+)/(\d+)/(\d+), =~ date | |
976 cdate = sprintf("%d/%d/%d", $1.to_i, $2.to_i, $3.to_i) | |
977 @@holiday[cdate] || @@holiday[cdate] = [] | |
978 @@holiday[cdate] << what | |
979 elsif %r,(\d+)/(\d+), =~ date | |
980 cdate = sprintf("%d/%d", $1.to_i, $2.to_i) | |
981 @@holiday[cdate] || @@holiday[cdate] = [] | |
982 @@holiday[cdate] << what | |
983 elsif %r,(\d+)/(\w+), =~ date | |
984 cdate = sprintf("%d/%s", $1.to_i, $2.downcase) | |
985 @@holiday[cdate] || @@holiday[cdate] = [] | |
986 @@holiday[cdate] << what | |
987 end | |
988 } | |
989 end | |
990 def isHoliday(y, m, d, wday=nil) | |
991 y, m, d = y.to_i, m.to_i, d.to_i | |
992 wname = %w[sun mon tue wed thu fri sat] | |
993 holiday = @@holiday[sprintf("%d/%d/%d", y, m, d)] || | |
994 @@holiday[sprintf("%d/%d", m, d)] | |
995 unless holiday | |
996 wday = wname[wday || Time.mktime(y, m, d).wday] | |
997 nthweek = (d-1)/7+1 | |
998 holiday = @@holiday[sprintf("%d/w%d%s", m, nthweek, wday)] | |
999 end | |
1000 holiday | |
1001 end | |
1002 def holidays() | |
1003 @@holiday | |
1004 end | |
1005 end | |
1006 | |
1007 class After5 | |
1008 def initialize() | |
1009 @me = File.expand_path($0) | |
1010 @mydir, @myname = File.dirname(@me), File.basename(@me) | |
1 | 1011 @mybase = @myname.sub(/\.\w+$/, '') |
0 | 1012 @mydir.untaint |
1 | 1013 @mybase.untaint |
0 | 1014 Dir.chdir @mydir |
1 | 1015 @myname='a5.cgi' if test(?f, "a5.cgi") |
0 | 1016 @conf = nil |
1017 @schedulearea = {'rows'=>'4', 'cols'=>'60', 'name'=>'schedule'} | |
1018 @oldagent = (%r,Mozilla/4, =~ ENV['HTTP_USER_AGENT']) | |
2 | 1019 @lang = 0 |
14 | 1020 @mailmode = nil |
7 | 1021 @saveprefsregexp = /^(display(mode|days)$|nt|headline)/ |
0 | 1022 @opt = { |
1023 'conf' => @mybase+".cf", | |
1024 'css' => @mybase+".css", | |
13 | 1025 'logfile' => 's/'+@mybase+".log", |
0 | 1026 "sendmail" => "/usr/sbin/sendmail", |
1027 'hostcmd' => '/usr/bin/host', | |
1028 'nslookup' => '/usr/sbin/nsookup', | |
1029 'bg' => 'ivory', | |
8 | 1030 'name' => nil, |
0 | 1031 'at_bsd' => '%H:%M %b %d %Y', |
1032 'at_solaris' => '%H:%M %b %d,%Y', | |
1033 'schedir' => 's', | |
1034 'tdskip' => '<br>', | |
1035 'forgot' => 'wasureta', | |
1036 'size' => @oldagent ? '15' : '40', | |
1037 'morning' => '6', | |
1038 'night' => '22', | |
1039 'alldaydir' => '3000', | |
1040 'pswdlen' => 4, | |
6 | 1041 'pswddb' => 's/a5pswd', |
2 | 1042 'lang' => 'j', |
6 | 1043 'notifymail' => true, |
0 | 1044 } |
1045 @ntlist = [ | |
1046 ['nt10m', "10"+msg('minutes', 'before')], | |
1047 ['nt30m', "30"+msg('minutes', 'before')], | |
1048 ['nt60m', "60"+msg('minutes', 'before')], | |
1049 ['nttoday', msg('theday')], | |
1050 ['nt1d', "1"+msg('days', 'before')], | |
1051 ['nt2d', "2"+msg('days', 'before')], | |
1052 ['nt3d', "3"+msg('days', 'before')], | |
1053 ['nt7d', "7"+msg('days', 'before')], | |
1054 ['nt30d', "30"+msg('days', 'before')], | |
1055 ] | |
1056 ##@job = "today" | |
3 | 1057 @wnames = %w[sun mon tue wed thu fri sat] |
0 | 1058 @job = "login" |
1059 @sc = ScheduleDir.new | |
1060 @O = StringIO.new | |
1061 @H = HTMLout.new() | |
1062 @umback = File.umask | |
1063 @author = 'yuuji@gentei.org' | |
1064 @after5url = 'http://www.gentei.org/~yuuji/software/after5/' | |
1065 File.umask(007) | |
1066 end | |
1067 def doit() | |
1068 @params = getarg() | |
1069 @cookie = getcookie() | |
3 | 1070 importcookie() |
2 | 1071 @lang = (/^j/i =~ @opt['lang'] ? 0 : 1) |
0 | 1072 p @cookie if $DEBUG |
1073 p @params if $DEBUG | |
1074 | |
3 | 1075 ### @params['displaymode'] = @params['displaymode'] || @cookie['displaymode'] |
2 | 1076 personal = /personal/i =~ @params['displaymode'] |
1077 bodyclass = if personal then {'class'=>'personal'} end | |
0 | 1078 |
1079 ## x = {"align"=>'center'} | |
1080 ## @H.element("p", x, "hoge", nil) | |
1081 ## @H.element("p", nil, "buha", nil) | |
1082 | |
3 | 1083 if nil |
0 | 1084 if !@params['passwd'] && @cookie['passwd'] |
1085 @params['passwd'] = @cookie['passwd'] | |
1086 end | |
1087 if !@params['user'] && @cookie['user'] | |
1088 @params['user'] = @cookie['user'] | |
1089 end | |
3 | 1090 end |
0 | 1091 @params['user'] = safecopy(@params['user']) |
2 | 1092 |
15 | 1093 ######eval @job |
8 | 1094 a5name = if @opt['name'] && @opt['name'] > '' |
1095 sprintf("(%s)", @opt['name']) | |
1096 else | |
1097 "" | |
1098 end | |
2 | 1099 @O.append(@H.contenttype() + |
8 | 1100 @H.head(a5name+"After 5"+@job.sub(/\s*/, ' '), @opt['css'])) |
2 | 1101 @O.print @H.startelement("body", bodyclass, true) |
15 | 1102 # @job should be here because its output shoud go after <body>. |
1103 eval @job | |
0 | 1104 @O.print @H.endelement(nil, true) # body |
14 | 1105 @O.print @H.endelement("html", true) # html |
0 | 1106 setcookie() |
1107 | |
1108 print @O.readlines | |
1109 end | |
1110 def msg(*keyword) | |
1111 unless defined?(@msg) | |
1112 @msg = { | |
3 | 1113 'title' => ['みんなの予定表 <img src="after5.png" alt="「アフター5」">', 'Schedule table for us all <img src="after5.png" alt="After 5">'], |
0 | 1114 'login' => ['ログイン', 'Login'], |
1115 'loginfirst' => ['最初にログインすべし', 'Login first'], | |
1116 'autherror' => ['認証エラーがあったと管理者に伝えてくれっす', | |
1117 'Unexpected authentication error. Please tell this to the administrator'], | |
1118 'yourmail' => ['あなたのメイルアドレス', 'Your email address'], | |
1119 'passwd' => ['パスワード<br>(初回時は空欄)', | |
1120 'Passowrd<br>Left blank, first time'], | |
1121 'error' => ['エラー:', 'Error: '], | |
1122 'mailerror' => ['メイルアドレスが違います', 'Invalid email address'], | |
1123 'pswderror' => ['パスワードが違います', 'Password incorrect'], | |
22
8803e5d52611
Show guidance when wrong password entered.
HIROSE Yuuji <yuuji@gentei.org>
parents:
18
diff
changeset
|
1124 'forgotguide' => ['忘れた場合は %s と入力するよろし', |
8803e5d52611
Show guidance when wrong password entered.
HIROSE Yuuji <yuuji@gentei.org>
parents:
18
diff
changeset
|
1125 "Put \`%s' when you forgot password."], |
8 | 1126 'fmtdaysschedule'=> ['%s〜の予定', 'Schedule from %s'], |
18 | 1127 'schedtable' => ['予定表', 'Schedule Table'], |
0 | 1128 'noplan' => ['登録されている予定はありません', 'No plans'], |
1129 'allday' => ['全日', 'whole day'], | |
1130 'addsched' => ['新規予定項目の登録', 'Register new schedule'], | |
1131 'defthisday' => ['デフォルトの日付はこの日になってま', ''], | |
1132 '24hour' => ['24時間制4桁でね<br>(0000〜2359)<br>%sは時刻指定なし', 'in 24-hour<br>(0000-2359)<br>%s for whole day'], | |
14 | 1133 '24hourtxt' => ['24時間制4桁でね(0000〜2359), %sは時刻指定なし', 'in 24-hour(0000-2359), %s for whole day'], |
0 | 1134 'reqnotify' => ['通知メイルいるけ?', 'Previous notification'], |
1135 'rightnow' => ['登録時にすぐ', 'Right now on registration'], | |
1136 'immediatenote' => ['に以下の予定を登録しました', | |
1137 ", Your schedule has been registered as follows;"], | |
1138 'registerer_is' => ['登録名義: ', 'Register as '], | |
1139 'registerer' => ['登録者: ', 'registerer: '], | |
1140 'about' => ['約', 'about'], | |
1141 'minutes' => ['分', 'minutes'], | |
1142 'hours' => ['時間', 'hour(s)'], | |
1143 'days' => ['日', 'day(s)'], | |
2 | 1144 'daystodisplay' => ['日分表示', 'days to display'], |
0 | 1145 'before' => ['前', 'before'], |
2 | 1146 'precedingday' => ['前日', 'Preceding day'], |
0 | 1147 'theday' => ['当日朝', "the day's morning"], |
1148 'night' => ['(夜)', '(night)'], | |
1149 'publicok' => ['メンバーに<br>見せてもええね?', | |
1150 'visible from other members?'], | |
1151 'public' => ['公', 'pub'], | |
1152 'nonpublic' => ['非', 'sec'], | |
2 | 1153 'through' => ['〜', '=>'], |
0 | 1154 'yes' => ['はいな', 'yes'], |
29
e7a01e561e28
Message 'no' should contain only 'no'.
HIROSE Yuuji <yuuji@gentei.org>
parents:
28
diff
changeset
|
1155 'no' => ['やだ', 'nope'], |
2 | 1156 'wnames' => [%w[日 月 火 水 木 金 土], |
1157 %w[sun mon tue wed thu fri sat]], | |
1158 'whichday' => ['<small>(まとめ登録の場合)</small><br>期間中のどの日に?', | |
1159 '<small>(On multiple registration)</small><br>Which days in the term?'], | |
1160 'singleday' => ['一日分だけ登録', '1day regist'], | |
1161 'everyday' => ['毎日', 'everyday'], | |
0 | 1162 'invaliddate' => ['日付指定が変みたい', 'Invalid time string'], |
1163 'past' => ['それはもう過去の話ね', 'It had Pasted'], | |
1164 'putsomething' => ['何か書こうや', 'Write some message please'], | |
1165 'appended' => ['既存の予定に追加しました', 'Appended'], | |
1166 'append' => ['追加', 'append'], | |
1167 'join' => ['参加', 'join'], | |
1168 'regist' => ['登録', 'register'], | |
1169 'remove' => ['削除', 'remove'], | |
14 | 1170 'move' => ['移動', 'move'], |
1171 'newdate' => ['移動先時刻', 'New date'], | |
0 | 1172 'deletion' => ['完全消去', 'deletion'], |
1173 'deletionwarn' => ['OK押したら即消去。確認とらないぞ', | |
1174 'Hitting OK immediately delets this group, be carefully!'], | |
1175 'deluser' => ['%s ユーザ消してええかの?', "Delete the user `%s'"], | |
1176 'delgroup' => ['%s グループ消してええかの?', "Delete the group `%s'"], | |
1177 'really?' => ['ほんまにええけ?', 'Really?'], | |
1178 'chicken' => ['ふっ、腰抜けめ', 'Hey, chicken boy'], | |
1179 'modify' => ['修正', 'modify'], | |
1180 'done' => ['完了', 'done'], | |
1181 'success' => ['成功', 'success'], | |
1182 'failure' => ['失敗', 'failure'], | |
1183 'tomonthlist' => ['%s の一覧', 'all %s table'], | |
1184 'notifysubj' => @mybase+"'s reminder for your plan", | |
1185 'introduce' => ['はいこんにちは、'+@mybase+'ですよ〜。', | |
1186 "Hi, this is #{@mybase}'s notification."], | |
1187 'notifymail' => ['こんな予定がありまっせ。', | |
1188 "You have some eschedule below;"], | |
1189 'notification' => ['の通知', 'notification'], | |
1190 'newaccount' => ["新しいアカウントを作りました。\n"+ | |
1191 "パスワードは %s さん宛に送信しておきました。\n", | |
1192 "You got new account for #{@mybase}\n" + | |
1193 "Password was sent to %s.\nThank you.\n"], | |
1194 'accessfrom' => ["%s からのアクセスによる送信\n", | |
1195 "This mail was sent by the access from %s\n"], | |
1196 'newpassword' => ["%s さんのパスワードは %s です。\n", | |
1197 "The password of %s is %s\n"], | |
1198 'mischief' => ["身に覚えのない場合はいたずらです。どうしましょ。", | |
1199 'If you have no idea for getting this message, '+ | |
1200 'it is mischief by someone else'], | |
1201 'user' => ['ユーザ', 'user'], | |
1202 'group' => ['グループ', 'group'], | |
1203 'personal' => ['個人で', 'personal'], | |
17 | 1204 'registas' => ['グループ予定として登録?', 'Register as group?'], |
1205 'headsched' => ['下の枠内に予定を記入: 1行以内で短めに。 | |
1206 長くなるときは2行目以降に詳細を。', | |
1207 'Put shortest sentence as possible within 1 line. | |
1208 Or, put short subject in the first line, details in latter lines.'], | |
0 | 1209 'joinquit' => ['入退', 'joining/quiting'], |
1210 'of' => ['の', "'s"], | |
1211 'id' => ['ID(ローマ字1単語空白なしで)', 'ID(without spaces)'], | |
1212 'name' => ['名前', 'name'], | |
1213 'anystring' => ['(日本語OK)', '(any length, any characters)'], | |
1214 'setto' => ['を設定 → ', 'set to '], | |
2 | 1215 'dupname' => ['あー、%sってグループ名は既にあるん素。別のにして.', |
1216 "Group name `%s' already exists, choose another name."], | |
0 | 1217 'management' => ['管理', 'management'], |
1218 'administrator' => ['管理者', 'Administrator'], | |
1219 'newgroup' => ['新規グループ作成', 'Create new group'], | |
1220 'adminop' => ['管理<br>操作', "Administrative<br>operation"], | |
1221 'member' => ['メンバー', 'Member'], | |
2 | 1222 'personalmode' => ['自分のだけ表示モード', 'Display Personal Only'], |
1223 'normalmode' => ['全員分表示モード', "Display Everyone's"], | |
3 | 1224 'display' => ['予定表示行: ', 'Display schedule of: '], |
1225 'nameonly' => ['名前のみ', 'Name Only'], | |
1226 'head5char' => ['先頭5文字', 'Head 5 chars'], | |
1227 'headline' => ['先頭1行', 'Headline only'], | |
1228 'whole' => ['長くても全部', 'Whole text'], | |
6 | 1229 'hldays' => ['最新X日分強調', 'Hilight Recent X-days'], |
0 | 1230 'addedtogroup' => ['をグループに追加 →', 'added to the group:'], |
1231 'removedfromgp' => ['をグループから削除:', 'removed from the group:'], | |
1232 'soleadmin' => ['%s は %s の唯一の管理者なのでやめられないのだ', | |
1233 "%s is sole administrator of %s. Cannot retire."], | |
1234 'recursewarn' => ['個人では加入してないが、別の加入グループがこのグループに入っているので実質参加していることになっている。', | |
1235 'Though this member does not join to this group, it is assumed to be joining this group because other group where one joins is joined to this group.'], | |
1236 'regaddress' => ['登録アカウント名', 'Account id'], | |
1237 'existent' => ['既にあるんすよ → ', 'Already exists: '], | |
1238 'mailaddress' => ['通知送付先アドレス', 'Notification email address'], | |
1239 'weburl' => ['ゲストブックとかURL<br><small>(予定への反応を書いて欲しい場所)</small>', 'Your guest book URL'], | |
1240 'usermodwarn' => ['いちいち yes/no とか確認取らないから押したら最後、気いつけて。', | |
1241 'This is the final decision. Make sure and sure.'], | |
1242 'joinmyself' => ['自分自身が既存のグループに対して入る(IN)か出る(OUT)かを決めるのがここ。自分管理のグループに誰かを足すなら「管理操作」、新たにグループを作るなら', | |
1243 'In this page, you can decide put yourself IN or OUT of the existing groups. If you want to manage the member of your own group, go to'], | |
1244 'groupwarn' => ['自分が参加してないグループAに、自分が参加しているグループBが含まれている場合、グループAにも加入していると見なされるので気をつけよう。管理者はグループのニックネームを変えられるよ。', | |
1245 'Though you are not member of group A, you are treated as a member of A, if you join to the group B, which is a member of A. Think the nesting of groups carefully, please. Group administrator can change the group nickname.'], | |
1246 'wholemembers' => ['グループ内グループを考慮した上で、現在グループ %s への通知は以下のメンバーに送られる。', | |
1247 "Consiering the groups registered in another group, notification to the group `%s' is send to members as follows."], | |
1248 'noadmingroup' => ['管理できるグループはないっす', | |
1249 "'There's no groups under your administration."], | |
1250 'multiplemail' => ['複数の宛先に通知したいなら..', | |
1251 'Wanna send notify to multiple address...'], | |
1252 'nickname' => ['ニックネーム', 'nickname'], | |
1253 'shortnameplz' => ['表が崩れるほど長すぎるニックネームは嫌われるよ。短めにね。', | |
1254 'Because nickname is displayed many times in table, shorter name is prefered.'], | |
1255 'nicknamenote' => ['ニックネームを消去するとデフォルト名になりんす.', | |
1256 'Default name is displayed if you remove nickname.'], | |
1257 'nothingtodo' => ['って何もやることあらへんかったで', | |
14 | 1258 'Nothing to do for this transaction.'], |
1259 'schedlist' => [' and %d days Schedule list', | |
1260 'から%d日間の予定一覧'], | |
1261 'nothing' => ['なんもないす', 'Nothing'], | |
1262 'sessionpswd' => ['セッションパスワード(これはいじらないでね)', | |
1263 'Session Password(Do not modify this)'], | |
1264 'date' => ['日付', 'Date'], | |
1265 'time' => ['時刻指定', 'Time'], | |
1266 'publicp' => ['公開=yes、非公開=no', 'Public?'], | |
1267 'neednotify' => ['通知メイル(要らないのは消してね)', | |
1268 'Leave lines for notification timing'], | |
1269 'schedulehere' => ['以下登録内容', 'Your Schedule below'] | |
0 | 1270 } |
1271 end | |
1272 keyword.collect{|k| | |
1273 if @msg[k].is_a?(Array) | |
2 | 1274 @msg[k][@lang] |
0 | 1275 elsif @msg[k].is_a?(String) |
1276 @msg[k] | |
1277 else | |
1278 '' | |
1279 end | |
2 | 1280 }.join(['', ' '][@lang]) |
0 | 1281 end |
1282 | |
3 | 1283 def importcookie() |
7 | 1284 @cookie.keys.grep(@saveprefsregexp){|v| |
3 | 1285 @params[v] = @params[v] || @cookie[v] |
1286 } | |
7 | 1287 for v in %w[user passwd] |
1288 @params[v] = @params[v] || @cookie[v] | |
1289 end | |
3 | 1290 end |
0 | 1291 def setcookie() |
7 | 1292 a = {} |
1293 a['user'] = @params['user'] if @params['user'] | |
1294 a['passwd'] = @params['passwd'] if @params['passwd'] | |
1295 ac = gencookie("value", a, 3600*6*1) | |
1296 printf "Set-Cookie: %s\n", ac if ac | |
0 | 1297 p = {} |
7 | 1298 @params.keys.grep(@saveprefsregexp){|v| |
6 | 1299 p[v] = @params[v].to_s.strip if @params[v] && @params[v] > '' |
0 | 1300 } |
7 | 1301 c = gencookie("prefs", p, 3600*24*7) |
1302 str = [ac, c].select{|x|x}.join("; ") | |
1303 # printf "Set-Cookie: %s\n", str if str>'' | |
0 | 1304 printf "Set-Cookie: %s\n", c if c |
1305 end | |
1306 | |
1307 def encode(string) # borrowed from cgi.rb | |
1308 string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do | |
1309 '%' + $1.unpack('H2' * $1.size).join('%').upcase | |
1310 end.tr(' ', '+') | |
1311 end | |
14 | 1312 def purify(string) |
1313 string.gsub(/[\040-\177]/) {encode($&)} | |
1314 end | |
0 | 1315 def decode!(string) |
1316 string.gsub!(/\+/, ' ') | |
1317 string.gsub!(/%(..)/){[$1.hex].pack("c")} | |
1318 end | |
14 | 1319 def decode(string) |
17 | 1320 string.gsub(/\+/, ' ').gsub(/%(..)/){[$1.hex].pack("c")} |
14 | 1321 end |
0 | 1322 |
7 | 1323 def gencookie(name, a, expire) |
0 | 1324 x = a.collect{|k, v| |
1325 sprintf("%s=%s", k, encode(v)) if v | |
1326 } | |
1327 x.delete(nil) | |
1328 return nil if x.empty? | |
1329 str = x.join('&') | |
1330 ex = (Time.new+expire).to_s | |
7 | 1331 sprintf "%s=%s; expires=%s", name, encode(str), ex |
0 | 1332 end |
1333 | |
1334 def login() | |
1335 @O.print @H.elementln("h1", nil){msg('title')} | |
1336 @O.print @H.elementln("h2", nil){msg('login')} | |
1337 format = {'method'=>'POST', 'action'=>@myname+"?-today"} | |
1338 @O.print @H.elementln("form", format){ | |
1339 @H.elementln("table", nil){ | |
1340 @H.elementln("tr", nil){ | |
1341 @H.element("td", nil){msg('yourmail')} + \ | |
1342 @H.element("td", nil){ | |
1343 sprintf '<input type="text" size="%s" name="user">', @opt['size'] | |
1344 } | |
1345 } + \ | |
1346 @H.elementln("tr", nil){ | |
1347 @H.element("td", nil){msg('passwd')} + \ | |
1348 @H.element("td", nil){ | |
1349 sprintf '<input type="password" size="%s" name="passwd">', @opt['size'] | |
1350 } | |
1351 } | |
1352 } + '<input type="submit" value="LOGIN">' | |
1353 } | |
1354 @O.print footer2() | |
1355 end | |
1356 def open_pm() | |
1357 begin | |
1358 PasswdMgr.new(@opt['pswddb']) | |
1359 rescue | |
1360 STDERR.printf "Cannot open pswd file [%s]\n", @opt['pswddb'] | |
1361 STDERR.printf "euid=#{Process.euid}, uid=#{Process.uid}\n", @opt['pswddb'] | |
1362 nil | |
1363 end | |
1364 end | |
1365 def outputError(*msg) | |
1366 @O.print @H.p(msg('error')+sprintf(*msg)) | |
1367 end | |
1368 def mailaddress(user) | |
1369 email = @sc.getuserattr(user, "email") | |
1370 email || user | |
1371 end | |
1372 def webpage(user) | |
1373 @sc.getuserattr(user, "webpage") | |
1374 end | |
14 | 1375 def checkauth_mail() |
1376 return true # temporary | |
1377 end | |
0 | 1378 def checkauth() |
14 | 1379 if @mailmode && @params['sessionpw'] |
1380 return checkauth_mail | |
1381 end | |
1382 auth = catch(:auth) { | |
0 | 1383 unless @params['user'] |
1384 outputError(@H.a(@myname, msg('loginfirst'))) | |
1385 throw :auth, nil | |
1386 end | |
1387 unless pm=open_pm() | |
1388 outputError(msg('autherror')) | |
1389 throw :auth, nil | |
1390 end | |
1391 user, passwd = @params['user'], @params['passwd'] | |
1392 email = mailaddress(user) | |
1393 if !checkmail(user) | |
1394 outputError(msg('mailerror')) | |
1395 throw :auth, nil | |
1396 end | |
1397 if pm.userexist?(user) | |
1398 if pm.checkpasswd(user, passwd) | |
1399 throw :auth, true | |
1400 elsif passwd == @opt['forgot'] | |
1401 newp = pm.setnewpasswd(user, @opt['pswdlen']) | |
1402 sendMail(email, "#{@mybase} password", | |
1403 "(#{ENV['REMOTE_ADDR']} からのアクセスによる送信)\n" + | |
7 | 1404 @opt['url'] + "\n" + |
0 | 1405 "#{@mybase} 用の #{user} さんのパスワードは\n" + |
1406 (newp || "未定義") + "\nです。\n") | |
1407 @O.print @H.p("#{email} 宛に送信しておきました") | |
1408 throw :auth, nil | |
1409 else | |
1410 outputError(msg('pswderror')) | |
22
8803e5d52611
Show guidance when wrong password entered.
HIROSE Yuuji <yuuji@gentei.org>
parents:
18
diff
changeset
|
1411 @O.print @H.p(sprintf(msg('forgotguide'), @opt['forgot'])) |
0 | 1412 throw :auth, nil |
1413 end | |
7 | 1414 elsif passwd == '' |
0 | 1415 newp = pm.setnewpasswd(user, @opt['pswdlen']) |
1416 @sc.createuser(user, user) | |
1417 sendMail(email, "#{@mybase} new account", | |
1418 sprintf(msg('accessfrom'), ENV['REMOTE_ADDR']) + | |
7 | 1419 sprintf(@opt['url']) + "\n" + |
0 | 1420 sprintf(msg('newpassword'), user, newp) + |
1421 sprintf(msg('mischief'))) | |
1422 @O.print @H.p(sprintf(msg('newaccount'), user)) | |
1423 @O.print @H.p(@H.a(@myname, msg('login'))) | |
1424 throw :auth, nil | |
7 | 1425 else |
1426 outputError(msg('pswderror')) | |
1427 throw :auth, nil | |
0 | 1428 end |
1429 } | |
1430 if auth | |
1431 return true | |
1432 else | |
1433 return false | |
1434 end | |
1435 end | |
1436 def safecopy(string) | |
1437 return nil unless string | |
1438 if $SAFE > 0 | |
1439 cpy='' | |
1440 string.split('').each{|c| | |
1441 cpy << c[0].chr if c[0] != ?` # ` | |
1442 } | |
28 | 1443 cpy.untaint |
0 | 1444 else |
1445 string | |
28 | 1446 end |
0 | 1447 end |
1448 def checkmail(mail) | |
1449 account, domain = mail.scan(/(.*)@(.*)/)[0] | |
1450 return false unless account != nil && domain != nil | |
17 | 1451 return false unless /^[-0-9a-z_.]+$/oi =~ domain.toeuc |
0 | 1452 domain = safecopy(domain) |
1453 require 'socket' | |
1454 begin | |
1455 TCPSocket.gethostbyname(domain) | |
1456 return true | |
1457 rescue | |
1458 if test(?x, @opt["hostcmd"]) | |
1459 open("| #{@opt['hostcmd']} -t mx #{domain}.", "r") {|ns| | |
1460 #p ns.readlines.grep(/\d,\s*mail exchanger/) | |
1461 return ! ns.readlines.grep(/is handled .*(by |=)\d+/).empty? | |
1462 } | |
1463 elsif test(?x, @opt["nslookup"]) | |
1464 open("| #{@opt['nslookup']} -type=mx #{domain}.", "r") {|ns| | |
1465 #p ns.readlines.grep(/\d,\s*mail exchanger/) | |
1466 return ! ns.readlines.grep(/\d,\s*mail exchanger/).empty? | |
1467 } | |
1468 end | |
1469 return false | |
1470 end | |
1471 end # checkmail | |
1472 | |
1473 # Logging | |
1474 # | |
1475 def putLog(msg) | |
1476 msg += "\n" unless /\n/ =~ msg | |
1477 open(@opt["logfile"], "a+") {|lp| | |
1478 lp.print Time.now.to_s + " " + msg | |
1479 } | |
1480 end | |
1481 | |
1482 def sendnotify(whom, subj, body) | |
1483 users = users() | |
1484 if grepgroup(whom) | |
1485 recipients = @sc.members(whom) | |
1486 else | |
1487 recipients=[whom] | |
1488 end | |
1489 for u in recipients | |
1490 if users.grep(u)[0] | |
1491 sendMail(mailaddress(u), subj, body) | |
1492 end | |
1493 end | |
1494 end | |
1495 | |
1496 def sendMail(to, subject, body) | |
17 | 1497 body = NKF.nkf("-j", body) |
1498 subject = NKF.nkf("-jM", subject) | |
0 | 1499 to = safecopy(to) # cleanup tainted address |
1500 subject.gsub!(/\n/, '') | |
1501 begin | |
1502 if (m=open("|-", "w")) | |
1503 m.print "To: #{to}\n" | |
1504 m.print "Subject: #{subject}\n" | |
1505 m.print "Mime-Version: 1.0 | |
1506 Content-Transfer-Encoding: 7bit | |
1507 Content-Type: Text/Plain; charset=iso-2022-jp | |
1508 | |
1509 " | |
1510 m.print body, "\n" | |
1511 m.close | |
1512 else | |
1513 # exec(@attr['mail'], "-s", subject, to) | |
1514 exec(@opt['sendmail'], to) | |
1515 exit 0; | |
1516 end | |
1517 putLog("Sent '#{subject}' to #{to}\n") | |
1518 return true | |
1519 rescue | |
1520 putLog("FAILED! - Sent '#{subject}' to #{to}\n") | |
1521 return nil | |
1522 end | |
1523 end # sendMail | |
1524 | |
1525 def today() | |
1526 today = Time.now | |
1527 showtable(today) | |
1528 end | |
1529 def isleap?(y) | |
1530 if y%400 == 0 | |
1531 true | |
1532 elsif y%100 == 0 || y%4 != 0 | |
1533 false | |
1534 else | |
1535 true | |
1536 end | |
1537 end | |
1538 def daysofmonth(year, month) | |
1539 dl = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
1540 if month != 2 || !isleap?(year) | |
1541 dl[month-1] | |
1542 else | |
1543 29 | |
1544 end | |
1545 end | |
1546 # | |
1547 # Return the Time object at the last day of last month | |
1548 def lastmonth(today) | |
1549 Time.at(Time.mktime(today.year, today.month)-3600*24) | |
1550 end | |
1551 # | |
1552 # Return the Time object at the first day of next month | |
1553 def nextmonth(today) | |
1554 y, m = today.year, today.month | |
1555 Time.at(Time.mktime(y, m, daysofmonth(y, m))+3600*24) | |
1556 end | |
1557 | |
1558 def month(month) | |
1559 y, m = month.scan(%r,(\d\d\d\d+)/(\d+),)[0] | |
1560 if y && m | |
1561 showtable(Time.mktime(y, m, 1)) | |
1562 else | |
1563 outputError "%s %s", msg('invaliddate'), month | |
1564 return nil | |
1565 end | |
1566 end | |
1567 def footer1() | |
1568 "<br>" + \ | |
1569 @H.element("p"){ | |
1570 me = @myname+"?-"; delim = " / " | |
1571 @H.a(me+'userman', msg('user', 'management')) + delim + \ | |
2 | 1572 @H.a(me+'groupman', msg('group', 'management')) + delim + \ |
1573 if /personal/i =~ @params['displaymode'] | |
1574 @H.a(me+'today_n', msg('normalmode')) | |
1575 else | |
1576 @H.a(me+'today_p', msg('personalmode')) | |
1577 end | |
0 | 1578 } |
1579 end | |
1580 | |
1581 def footer2() | |
1582 "<hr>" + \ | |
1583 @H.element("code") { | |
1584 "This " + \ | |
1585 @H.a(@after5url, "After5") + \ | |
1586 " board is maintained by " + \ | |
1587 @opt['maintainer'].sub('@', "@") + "." | |
1588 } | |
1589 end | |
1590 def footer() | |
1591 footer1+footer2 | |
1592 end | |
1593 def nickname(userORgroup) | |
1594 if grepgroup(userORgroup) | |
1595 @sc.groupname(userORgroup) | |
1596 else | |
1597 @sc.nickname(userORgroup) | |
1598 end | |
1599 end | |
1600 # | |
1601 # show specified month's calendar | |
1602 def showtable(day) | |
1603 if !checkauth | |
1604 return nil | |
1605 end | |
17 | 1606 |
0 | 1607 month = day.month.to_s |
1608 first = Time.mktime(day.year, day.month, 1) | |
1609 last = daysofmonth(day.year, day.month) | |
1610 wday1 = first.wday | |
1611 start = 1-wday1 | |
3 | 1612 wname = @wnames |
0 | 1613 today = Time.now |
8 | 1614 todayy = today.year |
0 | 1615 todaym = today.month |
1616 todayd = today.day | |
1617 tdclass = {} | |
1618 tdclass["width"] = "64px" if @oldagent # workaround for NN4 | |
2 | 1619 personal = /personal/ =~ @params['displaymode'] |
3 | 1620 headline = @params['headline'] |
6 | 1621 headlinehl = @params['headlinehl'] |
1622 hldays = headlinehl.to_i * 3600*24 | |
1623 recent = {'class'=>'recent'} | |
3 | 1624 monthstr = sprintf "%d/%d", day.year, day.month |
1625 | |
0 | 1626 holiday = Holiday.new |
1627 # create dayofweek header | |
3 | 1628 @O.print @H.elementln("h1", nil){monthstr} |
2 | 1629 # which mode? |
1630 @O.print @H.p(msg(personal ? 'personalmode' : 'normalmode')) | |
1631 # | |
1632 # display table | |
0 | 1633 @O.print @H.startelement("table", {'border'=>"1", 'class'=>'main'}) |
1634 | |
1635 # day of week | |
1636 @O.print @H.startelement("tr") | |
1637 for w in wname | |
1638 @O.print @H.element("th", {'class'=>w}){w.capitalize} | |
1639 end | |
1640 @O.print "\n"+@H.endelement(nil, true) | |
1641 | |
1642 # create day table | |
1643 column = start | |
1644 ## p day, last | |
1645 while column <= last | |
1646 @O.print @H.elementln("tr", nil){ | |
1647 (column..column+6).collect{|d| | |
8 | 1648 todayp = (day.year==todayy && day.month==todaym && d==todayd) |
0 | 1649 wd=d-column |
1650 hd = holiday.isHoliday(day.year, day.month, d, wd) | |
1651 tdclass['class'] = (hd ? 'holiday' : wname[wd]) | |
1652 @H.element("td", tdclass){ | |
13 | 1653 if d>0 |
1654 thisday = first+(d-1)*3600*24 | |
1655 #date = "%d/%d/%d"%[day.year, day.month, d] | |
1656 date = "%d/%d/%d"%[thisday.year, thisday.month, thisday.day] | |
0 | 1657 @H.element("p", {'class'=>todayp ? 'todayline' : 'dayline'}){ |
13 | 1658 ##@H.a(@myname+"?-show+"+date, "%4d"%d) |
1659 @H.a(@myname+"?-show+"+date, "%4d"%thisday.day) | |
0 | 1660 } + \ |
1661 # isHoliday? | |
1662 if hd | |
1663 @H.element("small"){hd.join("<br>")} | |
1664 end.to_s + \ | |
1665 @H.element("p", {'class'=>'topic'}){ | |
2 | 1666 s = @sc.day_all(date, @params['user'], personal) |
0 | 1667 if !s.empty? |
1668 s.keys.sort.collect{|time| | |
1669 s[time].keys.sort.collect{|who| | |
14 | 1670 text = decode(s[time][who]['sched']) |
6 | 1671 topic = sprintf "%s%s", |
3 | 1672 time == @opt['alldaydir'] ? '' : time+":", |
2 | 1673 if personal |
9 | 1674 (@params['user'] == who ? "" : nickname(who)+"=") + |
7 | 1675 text ## .split("\n") ##[0] |
2 | 1676 else |
5 | 1677 nickname(who) + \ |
3 | 1678 if headline == 'whole' |
5 | 1679 '=' + text |
3 | 1680 elsif headline == 'head5char' |
5 | 1681 '=' + text.gsub(/\n/, '').sub(/(.{5}).*/, '\1') |
3 | 1682 elsif headline == 'headline' |
5 | 1683 '=' + text.split("\n")[0] |
3 | 1684 end.to_s |
2 | 1685 end |
6 | 1686 if hldays > 0 && |
1687 (today - s[time][who]['regtime']) < hldays | |
1688 topic = @H.element("span", recent){topic} | |
1689 end | |
1690 topic | |
3 | 1691 }.join("<br>") |
1692 }.join("<br>\n") | |
0 | 1693 else |
1694 @opt['tdskip'] | |
1695 end | |
1696 } | |
1697 else | |
1698 @opt['tdskip'] | |
1699 end | |
1700 } | |
1701 }.join | |
1702 } | |
1703 column += 7 | |
1704 end | |
1705 | |
1706 # month-link | |
1707 @O.print @H.elementln("tr", {'class'=>'monthlink'}){ | |
1708 lm1 = lastmonth(day) | |
1709 lm2 = lastmonth(lm1) | |
1710 lm3 = lastmonth(lm2) | |
1711 nm1 = nextmonth(day) | |
1712 nm2 = nextmonth(nm1) | |
1713 nm3 = nextmonth(nm2) | |
1714 [lm3, lm2, lm1, nil, nm1, nm2, nm3].collect{|t| | |
1715 @H.element("td"){ | |
1716 if t.is_a?(Time) | |
1717 ym = sprintf("%d/%d", t.year, t.month) | |
1718 @H.a(sprintf("%s?-month+%s", @myname, ym), ym) | |
1719 else | |
1720 sprintf "%d/%d", day.year, day.month | |
1721 end | |
1722 } | |
1723 }.join("\n") | |
1724 } | |
1725 @O.print "\n"+@H.endelement(nil, true) | |
1726 | |
1727 @O.print "showtable" if @params['user'] == @author | |
3 | 1728 @O.print @H.elementln("form", {'action'=>@myname+"?-month+#{monthstr}", 'method'=>'POST'}){ |
1729 choice = [ | |
1730 [msg('nameonly'), 'name'], | |
1731 [msg('head5char'), 'head5char'], | |
1732 [msg('headline'), 'headline'], | |
1733 [msg('whole'), 'whole']] | |
1734 msg('display') + \ | |
6 | 1735 @H.select('headline', choice, headline) + "/" + \ |
1736 msg('hldays') + \ | |
1737 @H.select('headlinehl', 0..30, headlinehl) + \ | |
3 | 1738 @H.submit("GO", "GO") |
1739 } | |
0 | 1740 @O.print footer |
1741 ##schedule.day_all("2003/12/22") | |
1742 # @O.print @H.endelement() | |
1743 end | |
1744 | |
1745 # | |
1746 # Put carrying values | |
1747 def hiddenvalues() | |
2 | 1748 h = %w[user displaymode].collect{|v| |
0 | 1749 if @params[v] |
1750 sprintf "<input type=\"hidden\" name=\"%s\" value=\"%s\">\n", | |
1751 v, @params[v] | |
1752 end | |
1753 } | |
1754 h.delete(nil) | |
1755 h.join | |
1756 end | |
2 | 1757 def date2ymd(date) |
1758 %r,(\d\d\d\d+)/(\d\d?)/(\d\d?), =~ date and | |
1759 [$1.to_i, $2.to_i, $3.to_i] | |
1760 end | |
0 | 1761 # |
1762 # Return the string of table | |
2 | 1763 def dayTableString(user, datestr, range, personal = nil) |
1764 #s = @sc.day_all(date, user, personal) | |
1765 #return '' if s.empty? | |
0 | 1766 r = '' |
2 | 1767 header = @H.startelement("table", {'border'=>'1'}, true) |
1768 | |
1769 day = Time.mktime(*date2ymd(datestr)) | |
1770 i = -1 | |
1771 while (i+=1) < range | |
1772 d = Time.at(day+i*3600*24) | |
1773 date = sprintf("%04d/%02d/%02d", d.year, d.month, d.day) | |
3 | 1774 datewn = @H.element("span", {'class'=>@wnames[d.wday]}){ |
1775 sprintf("%s(%s)", date, @msg['wnames'][@lang][d.wday]) | |
1776 } | |
2 | 1777 s = @sc.day_all(date, user, personal) |
1778 next if s.empty? | |
1779 | |
1780 r << @H.element("tr", nil){ | |
1781 @H.element("th", {'class'=>'time'}){'TIME'} + \ | |
3 | 1782 @H.element("th", nil){'Who - '+datewn+' - What'} |
2 | 1783 } |
6 | 1784 for time in s.keys.sort |
2 | 1785 tstr = case time |
1786 when @opt['alldaydir'] | |
1787 msg('allday') | |
1788 else | |
1789 sprintf "%02d:%02d", time.to_i/100, time.to_i%100 | |
1790 end | |
1791 r << @H.startelement("tr", nil, true) | |
1792 r << @H.element("th", {'class'=>'time'}){tstr} | |
1793 r << @H.element("td"){ | |
1794 @H.elementln("table"){ | |
1795 s[time].keys.collect{|who| | |
1796 editable = (user==who || @sc.ismember(user, who)) | |
1797 groupp = grepgroup(who) | |
1798 @H.element("tr"){ | |
1799 @H.element("td", {'class'=>groupp ? 'group' : 'who'}){ | |
1800 if !groupp && webpage(who) | |
1801 @H.a(webpage(who), nickname(who)) | |
1802 else | |
1803 nickname(who) | |
1804 end | |
1805 } + \ | |
1806 @H.element("td"){ | |
1807 if editable | |
1808 s[time][who]['pub'] ? msg('public') : | |
1809 msg('nonpublic') | |
1810 else | |
1811 @opt['tdskip'] | |
1812 end | |
1813 } + \ | |
1814 @H.element("td"){ | |
1815 if editable | |
1816 @H.a(@myname+"?-modify+#{date}/#{time}/#{who}", | |
1817 msg('modify')) | |
1818 else | |
1819 @opt['tdskip'] | |
1820 end | |
1821 } + \ | |
1822 @H.element("td"){ | |
1823 if editable | |
1824 @H.a(@myname+"?-remove+#{date}/#{time}/#{who}", | |
1825 msg('remove')) | |
1826 else | |
1827 @opt['tdskip'] | |
1828 end | |
1829 } + \ | |
14 | 1830 @H.element("td"){ |
1831 if editable | |
1832 @H.a(@myname+"?-move+#{date}/#{time}/#{who}", | |
1833 msg('move')) | |
1834 else | |
1835 @opt['tdskip'] | |
1836 end | |
1837 } + \ | |
15 | 1838 @H.element("td"){decode(s[time][who]['sched'])} |
2 | 1839 } |
1840 }.join("\n") | |
1841 } | |
0 | 1842 } |
2 | 1843 r << @H.endelement() |
1844 end | |
0 | 1845 end |
2 | 1846 footer = @H.endelement() |
1847 if r > '' | |
1848 header + r + footer | |
1849 else | |
1850 '' | |
1851 end | |
0 | 1852 end |
14 | 1853 def dayTextString(user, datestr, range, personal = nil) |
1854 r = '' | |
1855 cols = 20 | |
1856 header = "-" * cols + "\n" | |
1857 | |
1858 day = Time.mktime(*date2ymd(datestr)) | |
1859 i = -1 | |
1860 while (i+=1) < range | |
1861 d = Time.at(day+i*3600*24) | |
1862 date = sprintf("%04d/%02d/%02d", d.year, d.month, d.day) | |
1863 datewn = sprintf("%s(%s)", date, @msg['wnames'][@lang][d.wday]) | |
1864 s = @sc.day_all(date, user, personal) | |
1865 next if s.empty? | |
1866 | |
1867 r << sprintf("TIME Who %s - What\n", datewn) | |
1868 | |
1869 for time in s.keys.sort | |
1870 tstr = case time | |
1871 when @opt['alldaydir'] | |
1872 msg('allday') | |
1873 else | |
1874 sprintf "%02d:%02d", time.to_i/100, time.to_i%100 | |
1875 end | |
1876 r << s[time].keys.collect{|who| | |
1877 editable = (user==who || @sc.ismember(user, who)) | |
1878 groupp = grepgroup(who) | |
1879 sprintf("%-5s %-10s %s", tstr, nickname(who), s[time][who]['sched']) | |
1880 }.join("\n") + "\n" | |
1881 end | |
1882 r << "-" * cols + "\n" | |
1883 end | |
1884 footer = "That's all\n" | |
1885 if r > '' | |
1886 header + r + footer | |
1887 else | |
1888 '' | |
1889 end | |
1890 | |
1891 end | |
0 | 1892 # |
2 | 1893 # new form |
1894 def displayRegistForm(date, multiple = true) | |
0 | 1895 # |
1896 # Link button to add new plan | |
1897 #now = Time.now+3600*24 | |
2 | 1898 thisyear, thismonth, thisday = date.scan(%r,(\d\d\d\d+)/(\d+)/(\d+),)[0] |
1899 user = @params['user'] | |
0 | 1900 now = Time.mktime(thisyear, thismonth, thisday.to_i, Time.now.hour) |
1901 y, m, d, h, min = now.year, now.month, now.day, now.hour, now.min | |
2 | 1902 nextweek = Time.at(now+3600*24*7) |
1903 ey, em, ed = nextweek.year, nextweek.month, nextweek.day | |
1904 rcsp = (multiple ? {'colspan'=>'2'} : nil) | |
1905 wnames = @msg['wnames'][@lang] | |
1906 wnames << @msg['everyday'][@lang] | |
1907 | |
0 | 1908 @O.print @H.element('h2', nil, true){msg('addsched')} |
1909 @O.print @H.element('p', nil){msg('defthisday')} | |
2 | 1910 |
0 | 1911 @O.print @H.element("form", {'action'=>@myname+"?-addsched", 'method'=>'POST'}){ |
2 | 1912 border1 = {'border'=>'1'} |
1913 border1c = {'border'=>'1', 'class'=>'c'} | |
1914 mygroup = @sc.groups().select{|g|@sc.ismember(user, g)} | |
0 | 1915 @H.elementln('table', border1){ |
1916 @H.elementln('tr'){ | |
1917 @H.element('th'){'Name'} + \ | |
2 | 1918 @H.element('td', rcsp){ |
0 | 1919 hiddenvalues() + @sc.nickname(user) |
1920 } | |
1921 } + \ | |
1922 @H.elementln('tr'){ | |
1923 @H.element('th'){'Year'} + \ | |
2 | 1924 @H.element('td'){@H.select("year", y..y+5, y)} + \ |
1925 if multiple | |
1926 @H.element('td'){ | |
1927 d1 = msg('singleday') | |
1928 msg('through')+@H.select("endyear", [d1]+(y..y+5).to_a, d1) | |
1929 } | |
1930 end | |
0 | 1931 } + \ |
1932 @H.elementln('tr'){ | |
1933 @H.element('th'){'Month'} + \ | |
2 | 1934 @H.element('td'){@H.select("month", 1..12, m)} + \ |
1935 if multiple | |
1936 @H.element('td'){ | |
1937 msg('through')+@H.select("endmonth", 1..12, em) | |
1938 } | |
1939 end | |
0 | 1940 } + \ |
1941 @H.elementln('tr'){ | |
1942 @H.element('th'){'Day'} + \ | |
2 | 1943 @H.element('td'){@H.select("day", 1..31, d)} + \ |
1944 if multiple | |
1945 @H.element('td'){ | |
1946 msg('through')+@H.select("endday", 1..31, ed) | |
1947 } | |
1948 end | |
0 | 1949 } + \ |
2 | 1950 if multiple |
1951 @H.elementln('tr'){ | |
1952 @H.element('th'){ | |
1953 msg('whichday') | |
1954 } + \ | |
1955 @H.element('td', rcsp){ | |
1956 @H.elementln('table', border1c){ | |
1957 @H.element('tr'){ | |
1958 i=-1 | |
1959 wnames.collect{|w| | |
1960 @H.element('td'){ | |
1961 i+=1 | |
1962 @H.radio('whichday', i.to_s, '', i==wnames.length-1) | |
1963 } | |
1964 }.join("\n") | |
1965 } + \ | |
1966 @H.element('tr'){ | |
1967 i=-1 | |
1968 wnames.collect{|w| | |
1969 @H.element('td'){w} | |
1970 }.join | |
1971 } | |
1972 } | |
1973 } | |
1974 } | |
1975 end + \ | |
0 | 1976 @H.elementln('tr'){ |
1977 @H.element('th'){'Time<br>'+ \ | |
1978 sprintf(msg('24hour'), @opt['alldaydir'])} + \ | |
2 | 1979 @H.element('td', rcsp){ |
0 | 1980 '<input type=text name="time" value="3000" size=8 maxlength="4">' |
1981 } | |
1982 } + \ | |
1983 @H.elementln('tr'){ | |
1984 @H.element('th'){msg('publicok')} + \ | |
2 | 1985 @H.element('td', rcsp){ |
0 | 1986 @H.radio('pub', 'yes', msg('yes')+'<br>', true) + \ |
1987 @H.radio('pub', 'no', msg('no')) | |
1988 } | |
1989 } | |
1990 ## table | |
1991 } + \ | |
1992 @H.elementln("p"){ # put notify mail checkbox | |
1993 msg('reqnotify') + '<br>' + \ | |
1994 @ntlist.collect{|n, v| | |
8 | 1995 # Actual variables of notifylist for submitting is "sub_"+n |
1996 @H.checkbox("sub_"+n, 'yes', v, @params[n]) | |
0 | 1997 }.join("\n") + \ |
1998 " " + @H.checkbox('rightnow', 'yes', msg('rightnow'), true) + \ | |
1999 "\n" | |
2000 } + \ | |
2001 if mygroup[0] | |
2002 @H.elementln("p"){ # put "register as" | |
2003 msg('registas') + "<br>\n" + \ | |
2004 mygroup.collect{|g| | |
2005 @H.radio('registas', g, @sc.groupname(g)) | |
2006 }.join(' ') + "\n/ " + \ | |
2007 @H.radio('registas', 'no', msg('personal')) | |
2008 } | |
2009 end.to_s + "\n" + \ | |
2 | 2010 @H.radio('editmode', 'remove', 'Delete?') + " / " + \ |
2011 @H.radio('editmode', 'modify', 'Overwrite?') + " / " + \ | |
2012 @H.radio('editmode', 'append', 'Append?', true) + "<br>\n" + \ | |
17 | 2013 @H.element("p"){msg('headsched') + \ |
2014 @H.element("textarea", @schedulearea){}} + # textarea | |
0 | 2015 @H.submit_reset("GO") |
2016 } #form | |
2 | 2017 end |
2018 # | |
2019 # show the schedule list of specified date | |
2020 # | |
2021 def show(date) | |
2022 if !checkauth | |
2023 return nil | |
2024 end | |
2025 user = safecopy(@params['user']) | |
2026 personal = (/personal/i =~ @params['displaymode']) | |
2027 @params['displaydays'] = @params['displaydays'] || @cookie['displaydays'] | |
3 | 2028 days = @params['displaydays'].to_i |
18 | 2029 days = (days > 0 ? days : 3) |
2 | 2030 |
2031 # str = @sc.day_all(date, user, personal) | |
2032 outstr = dayTableString(user, date, days, personal) | |
2033 | |
2034 @O.print @H.element("h1", nil){ | |
2035 sprintf msg('fmtdaysschedule'), date | |
2036 } | |
18 | 2037 @O.print @H.element("h2"){msg('schedtable')} |
2 | 2038 ## @O.print @H.p() |
2039 @O.print @H.elementln("form", {'action'=>@myname+"?-show+#{date}", 'method'=>'POST'}){ | |
2040 @H.elementln("p"){ | |
6 | 2041 msg(personal ? 'personalmode' : 'normalmode') + "<br>" + \ |
2 | 2042 @H.select("displaydays", 1..30, days) + msg('daystodisplay') + \ |
2043 @H.submit("GO", "GO") | |
2044 } | |
2045 } | |
2046 if outstr > '' | |
2047 @O.print outstr | |
2048 else | |
2049 @O.print @H.p(msg('noplan')) | |
2050 end #is_empty? | |
2051 thisyear, thismonth, thisday = date.scan(%r,(\d\d\d\d+)/(\d+)/(\d+),)[0] | |
2052 mstr = sprintf "%04d/%02d", thisyear.to_i, thismonth.to_i | |
2053 @O.print @H.a(@myname+"?-month+"+mstr, | |
2054 sprintf(msg('tomonthlist'), mstr)) | |
2055 | |
2056 | |
2057 # | |
2058 # Display registration form | |
2059 displayRegistForm(date) | |
0 | 2060 @O.print "show" if user == @author |
2061 end | |
2062 | |
2063 # | |
2064 # call process | |
2065 def call_process(cmd, input=nil, timeout=10) | |
2066 prc = CMDTimeout.new | |
2067 fds = prc.start(cmd, timeout, true) | |
2068 if input | |
2069 Thread.start { | |
2070 fds[0].sync = true | |
2071 fds[0].print.input | |
2072 fds[0] | |
2073 } | |
2074 end | |
2075 begin | |
2076 fds[1].readlines | |
2077 ensure | |
2078 prc.close() | |
2079 end | |
2080 end | |
2081 # | |
2082 # notification registerer | |
2083 def notify_time(year, month, day, time, symbol) | |
2084 if (t = time.to_i) > 2359 | |
2085 hh = mm = 0 | |
2086 else | |
2087 hh, mm = t/100, t%100 | |
2088 end | |
2089 base = Time.mktime(year.to_i, month.to_i, day.to_i, hh, mm) | |
2090 if /nt(\d+)([mh])$/ =~ symbol | |
2091 return nil if t > 2359 | |
2092 num, unit = $1.to_i, $2.downcase | |
2093 rate = {'h'=>3600, 'm'=>60}[unit] || 3600 | |
2094 return Time.at(base-rate*num) | |
2095 elsif /nt(\d+)d/ =~ symbol | |
2096 seconds = $1.to_i*3600*24 | |
14 | 2097 tday= Time.at(base-seconds) |
2098 target = [tday.year, tday.month, tday.day, @opt['night'].to_i] | |
2099 targetnight = Time.mktime(*target) | |
0 | 2100 elsif "nttoday" == symbol |
2101 Time.mktime(year.to_i, month.to_i, day.to_i, @opt['morning']) | |
2102 end | |
2103 end | |
2104 def reg_notify(user, year, month, day, time, text, cancelall = nil) | |
6 | 2105 return nil unless @opt['notifymail'] |
0 | 2106 threshold = 5*60 # Omit notifycation within 30min future |
2107 | |
2108 y, m, d, t, = year.to_i, month.to_i, day.to_i, time.to_i | |
2109 if t > 2359 | |
2110 hh = mm = 0 | |
2111 else | |
2112 hh = t/100 | |
2113 mm = t%100 | |
2114 end | |
2115 now = Time.now | |
2116 | |
2117 filearg = [user, year, month, day, t] | |
2118 @ntlist.each{|k, v| | |
8 | 2119 # @params[k]s are always defined in cookies, so we use @params["sub_"+k] |
2120 @params[k] = @params["sub_"+k] | |
0 | 2121 nt_time = notify_time(year, month, day, t, k) |
2122 if !nt_time | |
2123 # do nothing for allday schedule's notification before some minutes | |
2124 elsif cancelall || nt_time < now+threshold || | |
2125 /yes|on|true|1/ !~ @params[k] || !@params[k] | |
2126 # cancel | |
2127 uf = @sc.remove_crondir(nt_time, user, year, month, day, t) | |
2128 @sc.removefile(*(filearg+[k])) | |
2129 else | |
2130 # register | |
2131 lf = @sc.register_crondir(nt_time, user, year, month, day, t) | |
2132 @sc.putfile(*(filearg+[k, lf])) | |
2133 end | |
2134 } | |
2135 end | |
2136 def cancel_notify(user, year, month, day, time) | |
2137 reg_notify(user, year, month, day, time, 'dummy', true) | |
2138 end | |
2 | 2139 |
2140 def commit_schedule(who, y, m, d, timedir, text, repl, pub) | |
2141 | |
2142 end | |
2143 | |
14 | 2144 def regulate_time(y, m, d, tm) |
2145 if tm > 2399 | |
2146 sh, smin = 23, 59 | |
2147 timedir=@opt['alldaydir'] | |
2148 tmstr = msg('allday') | |
2149 else | |
2150 sh = (tm/100).to_i | |
2151 smin = (tm%100).to_i | |
2152 timedir = sprintf("%04d", tm) | |
2153 tmstr = sprintf("%d:%02d", sh, smin) | |
2154 end | |
2155 time = nil | |
2156 begin | |
2157 time = Time.mktime(y, m, d, sh, smin) | |
2158 rescue | |
2159 outputError "%s<br>\nyear=%s<br>month=%s<br>day=%s<br>time=%s\n", | |
2160 msg('invaliddate'), | |
2161 @params['year'], @params['month'], @params['day'], @params['time'] | |
2162 return nil | |
2163 end | |
2164 [time, timedir, tmstr] | |
2165 end | |
2166 | |
0 | 2167 # |
2168 # add or remove a schedule | |
2169 # | |
2170 def add_remove(remove = nil) | |
2171 if !checkauth | |
2172 return nil | |
2173 end | |
2174 user = registerer = @params['user'] | |
2175 as = @params['registas'] | |
2176 if as && as > '' && /^no$/ !~ as && @sc.ismember(user, as) | |
3 | 2177 if (gr=grepgroup(as)) |
2178 registerer = gr | |
2179 end | |
0 | 2180 end |
2181 now = Time.now | |
2 | 2182 #y, m, d, h, min = now.year, now.month, now.day, now.hour, now.min |
0 | 2183 |
2184 $KCODE='e' if $DEBUG | |
2185 @O.print @params.inspect if $DEBUG | |
2186 # | |
2187 # Check the validity of specified time | |
2188 sy = @params['year'].to_i | |
2189 sm = @params['month'].to_i | |
2190 sd = @params['day'].to_i | |
2191 tm = @params['time'].to_i | |
14 | 2192 |
2193 time, timedir, tmstr = regulate_time(sy, sm, sd, tm) | |
2 | 2194 |
2195 # | |
2196 # Check continuous schedule registration | |
2197 wwday = @params['whichday'].to_i | |
2198 if @params['endyear'] && @params['endmonth'] && @params['endday'] && | |
2199 (ey=@params['endyear'].to_i) > 0 && | |
2200 (em=@params['endmonth'].to_i) > 0 && | |
2201 (ed=@params['endday'].to_i) > 0 | |
2202 daylist = [] | |
2203 endtime = Time.mktime(ey, em, ed, 23, 59) | |
2204 ti = time | |
2205 begin | |
2206 if wwday==7 || wwday==ti.wday | |
2207 daylist << [ti.year, ti.month, ti.day] | |
2208 end | |
9 | 2209 end while (ti=Time.at(ti+3600*24)) <= endtime |
2 | 2210 else |
2211 daylist = [[sy, sm, sd]] | |
2212 end | |
2213 | |
2214 if !remove && !(@params['schedule'] && @params['schedule'].strip > '') | |
0 | 2215 outputError msg('putsomething') |
2216 return nil | |
2217 end | |
2218 | |
2 | 2219 |
2220 for y, m, d in daylist | |
2221 # do remove or addition | |
2222 if remove | |
2223 cancel_notify(registerer, y, m, d, timedir) | |
2224 begin | |
2225 @sc.remove(registerer, y, m, d, timedir) | |
2226 #########@O.print @H.p(msg('remove')+msg('done')) | |
2227 rescue | |
2228 outputError("Failed"+$!) | |
2229 end | |
2230 else | |
2231 if time < now | |
2232 outputError(msg('past')) | |
2233 return nil | |
2234 end | |
2235 begin | |
17 | 2236 (text = decode(@params['schedule']).strip.gsub(/\r+\n/, $/)) << "\n" |
14 | 2237 text = purify(text) |
2 | 2238 replace = (/modify/i =~ @params['editmode']) |
2239 rc = @sc.register(registerer, y, m, d, timedir, text, replace) | |
2240 if @params['pub'] && /yes/ =~ @params['pub'] | |
2241 @sc.putfile(registerer, y, m, d, timedir, 'pub', "1\n") | |
2242 else | |
2243 @sc.removefile(registerer, y, m, d, timedir, 'pub') | |
2244 end | |
2245 ######## @O.print @H.p(msg('appended')) if rc == 1 | |
2246 rescue | |
2247 outputError("Failed"+$!) | |
2248 end | |
17 | 2249 text = @sc.getschedule(registerer, y, m, d, timedir) |
2 | 2250 reg_notify(registerer, y, m, d, timedir, text) |
2251 | |
0 | 2252 end |
2 | 2253 |
2254 end | |
2255 | |
2256 if !remove && @params['rightnow'] && /yes/i =~ @params['rightnow'] | |
2257 header = sprintf("%s\n%s/%s/%s%s %s %s\n%s%s%s\n%s\n", | |
2258 @opt['url'], | |
2259 sy, sm, sd, | |
2260 if daylist.length > 1 | |
2261 "-%s/%s/%s" % daylist[-1] | |
2262 end, | |
2263 tmstr, msg('immediatenote'), | |
2264 msg('registerer_is'), nickname(registerer), | |
2265 if user!=registerer | |
2266 sprintf(" (%s%s)", | |
2267 msg('registerer'), nickname(user)) | |
2268 else | |
2269 "" | |
2270 end, | |
2271 "-"*70) | |
2272 sendnotify(registerer, "Registration completed", header+text) | |
0 | 2273 end |
14 | 2274 unless @mailmode |
2275 show(sprintf("%04d/%02d/%02d", sy, sm, sd)) | |
2276 @O.print "add_remove" if user == @author | |
2277 end | |
0 | 2278 end |
2279 | |
2280 # add | |
2281 def addsched() | |
14 | 2282 if "move" == @params['editmode'] |
2283 add_remove(:remove) | |
2284 for p in %w(year month day time) do | |
2285 @params[p] = @params["new"+p] | |
2286 end | |
2287 end | |
2288 add_remove(/^remove/i =~ @params['editmode']) | |
0 | 2289 end |
2290 | |
2291 # | |
2292 # Display remove or modify screen | |
14 | 2293 def remove_modify(datetime, editmode) |
0 | 2294 if !checkauth |
2295 return nil | |
2296 end | |
2297 | |
2298 user = @params['user'] | |
2299 y, m, d, time, dummy, as = | |
2300 datetime.scan(%r,(\d\d\d\d+)/(\d+)/(\d+)/(\d+)(/(.+))?,)[0] | |
2301 # datetime always contains trailing slash generated by parsedate | |
2302 # but if the trailing part is a user(not a group), it is removed | |
2303 # because it filtered out by grepgroup() function | |
2304 if ! (y && m && d && time) | |
2305 outputError "Invalid time specification" | |
2306 return nil | |
2307 elsif as && as > '' | |
2308 unless @sc.ismember(user, as) | |
2309 outputError "You have no permission to edit group %s's schedule", as | |
2310 return nil | |
2311 end | |
2312 user = as | |
2313 end | |
2314 unless text=@sc.getschedule(user, y, m, d, time) | |
2315 outputError "%s %s", datetime, msg('noplan') | |
2316 return nil | |
2317 end | |
15 | 2318 text = decode(text) |
0 | 2319 @O.print @H.elementln("h1"){ |
14 | 2320 sprintf "%s %s", datetime, msg(editmode) |
0 | 2321 } |
2322 @O.print @H.elementln("form", {'action'=>@myname+"?-addsched", 'method'=>'POST'}){ | |
2323 pubp=(@sc.getfile(user, y, m, d, time, 'pub').to_i > 0) | |
2324 if as | |
2325 @H.hidden("registas", as) | |
2326 end.to_s + \ | |
2327 "<input type=\"hidden\" name=\"year\" value=\"%04d\">\n" % y.to_i + \ | |
2328 "<input type=\"hidden\" name=\"month\" value=\"%02d\">\n" % m.to_i + \ | |
2329 "<input type=\"hidden\" name=\"day\" value=\"%02d\">\n" % d.to_i + \ | |
2330 "<input type=\"hidden\" name=\"time\" value=\"%04d\">\n" % time.to_i + \ | |
14 | 2331 if editmode=="move" |
2332 @H.elementln("table") { | |
2333 @H.elementln("tr", {"colspan" => "2"}) {msg('newdate')} + \ | |
2334 @H.elementln("tr") { | |
2335 @H.element("th"){"Year"} + \ | |
2336 @H.element("td"){@H.select("newyear", y.to_i..y.to_i+5, y)} | |
2337 } + \ | |
2338 @H.elementln("tr") { | |
2339 @H.element("th"){"Month"} + \ | |
2340 @H.element("td"){@H.select("newmonth", 1..12, m)} | |
2341 } + \ | |
2342 @H.elementln("tr") { | |
2343 @H.element("th"){"Day"} + \ | |
2344 @H.element("td"){@H.select("newday", 1..31, d)} | |
2345 } + \ | |
2346 @H.elementln("tr") { | |
2347 @H.element("th"){"Time"} + \ | |
2348 @H.element("td"){ | |
2349 "<input type=text name=\"newtime\" value=\"#{time}\" " + \ | |
2350 "size=\"8\" maxlength=\"4\">" | |
2351 } | |
2352 } | |
2353 } | |
2354 end.to_s + \ | |
2355 @H.elementln("div", {"style" => | |
2356 "visibility: " + | |
2357 (editmode=="move" ? "hidden" : "show") + "\""}) { | |
2358 msg('reqnotify') + "<br>\n" + \ | |
2359 @ntlist.collect{|nt, v| | |
2360 cronp = @sc.getfile(user, y, m, d, time, nt) | |
2361 sprintf "<input type=\"checkbox\" name=\"%s\"%s>%s \n", | |
2362 nt, (cronp ? " checked" : ""), v | |
2363 }.join + "<br>" | |
2364 } + \ | |
0 | 2365 @H.element("textarea", @schedulearea) {text} + "<br>" + \ |
2366 @H.radio("editmode", "append", msg('append')) + ' / ' + \ | |
14 | 2367 @H.radio("editmode", "modify", msg('modify'), editmode=="modify")+' / '+\ |
2368 @H.radio("editmode", "remove", msg('remove'), editmode=="remove")+' / '+\ | |
2369 @H.radio("editmode", "move", msg('move'), editmode=="move") + ' / ' + \ | |
0 | 2370 "<br>\n" + \ |
2371 msg('publicok') + \ | |
2372 @H.radio("pub", "yes", msg('yes'), pubp) + \ | |
2373 @H.radio("pub", "no", msg('no'), !pubp) + \ | |
2374 '<br>' + \ | |
2375 @H.submit_reset("GO") | |
2376 } | |
2377 @O.print "remove_modify" if user == @author | |
2378 end | |
2379 def remove(datetime) | |
14 | 2380 remove_modify(datetime, "remove") |
0 | 2381 end |
2382 def modify(datetime) | |
14 | 2383 remove_modify(datetime, "modify") |
2384 end | |
2385 def move(datetime) | |
2386 remove_modify(datetime, "move") | |
0 | 2387 end |
2388 | |
2389 def prohibitviahttp() | |
2390 %w[REMOTE_ADDR REMOTE_HOST SERVER_NAME].each{|v| | |
2391 if ENV[v] | |
2392 print "Content-type: text/plain\n\n" | |
2393 print "Do not call this via CGI" | |
2394 exit 0 | |
2395 end | |
2396 } | |
2397 end | |
2398 # | |
2399 # notify: call via cron | |
2400 def notify() | |
2401 prohibitviahttp() | |
2402 unless @opt['maintainer'] | |
2403 STDERR.printf "Set maintainer(email-address) in %s\n", @opt['conf'] | |
2404 STDERR.print "(ex) maintainer=yuuji@gentei.org\n" | |
2405 exit 0 | |
2406 end | |
2407 Dir.chdir @mydir | |
2408 line = "-"*25 | |
2409 indent = " " | |
2410 now = Time.now | |
2411 p "notifylist", @sc.notify_list(now) if $DEBUG | |
2412 @sc.notify_list(now).each{|u, datehash| | |
2413 dellist = [] | |
2414 content = datehash.sort.collect{|date, filehash| | |
2415 next unless /(\d\d\d\d+)-(\d+)-(\d+)-(\d\d\d\d)/ =~ date | |
2416 y, m, d, t = $1.to_i, $2.to_i, $3.to_i, $4.to_i | |
11 | 2417 ddiff=(Time.mktime(y, m, d) \ |
2418 - Time.mktime(now.year, now.month, now.day))/3600/24 | |
0 | 2419 if t > 2359 |
2420 hhmm = msg('allday') | |
11 | 2421 if ddiff > 1 |
2422 comment = "%d%s" % [ddiff, msg('days', 'before')] | |
2423 else | |
2424 comment = msg(now.hour > 18 ? 'precedingday' : 'theday') | |
2425 end | |
0 | 2426 else |
2427 hhmm = sprintf "%02d:%02d", t/100, t%100 | |
2 | 2428 diff = Time.mktime(y, m, d, t/100, t%100) - now |
0 | 2429 if diff < 7200 |
2430 comment = "%d%s" % [diff/60, msg('minutes', 'before')] | |
11 | 2431 elsif (ddiff == 0) |
0 | 2432 comment = "%s%d%s" % |
2433 [msg('about'), diff/3600, msg('hours', 'before')] | |
2434 else | |
2435 comment = "%d%s" % [ddiff, msg('days', 'before')] | |
2436 end | |
2437 end | |
2438 dellist << filehash['file'] | |
2439 sprintf("%s[[[%d/%d/%d %s]]]%s\n", line, y, m, d, hhmm, line) + \ | |
2440 sprintf("(%s %s)\n", comment, msg('notification')) + \ | |
15 | 2441 indent+decode(filehash['text'].join(indent)) + "\n\n" |
0 | 2442 } |
2443 # content.delete(nil) | |
2444 if content | |
2445 if $DEBUG | |
2446 print content | |
2447 else | |
2448 content.unshift(msg('introduce')+"\n"+msg('notifymail')+"\n") | |
2449 content.unshift(@opt['url'].to_s+"\n") | |
2450 if sendnotify(u, msg('notifysubj'), content.join) | |
2451 # send mail completed | |
2452 begin | |
2453 @sc.cleanup_files(dellist) | |
2454 rescue | |
2455 end | |
2456 end | |
2457 end | |
2458 end | |
2459 } | |
2460 if !(list=@sc.notify_list(now)).empty? | |
2461 subj = @mybase+": Undeleted old cron files detected" | |
2462 files = list.collect{|who, whash| | |
2463 whash.sort.collect{|date, fhash| fhash['file']}.join("\n") | |
2464 }.join("\n") | |
2465 sendMail(@opt['maintainer'], subj, | |
2466 "This is `#{@mybase}' in #{@mydir}\n" + | |
2467 "You'd better check and remove these files.\n\n"+files) | |
2468 end | |
2469 | |
2470 exit 0 | |
2471 end | |
2472 | |
2473 # | |
2474 # user management | |
2475 def userman() | |
2476 if !checkauth | |
2477 return nil | |
2478 end | |
2479 user=@params['user'] | |
2480 nickname = @sc.nickname(user) | |
2481 tdclass = {} | |
2482 tdclass["width"] = "80px" if @oldagent # workaround for NN4 | |
2483 | |
2484 @O.print @H.elementln("h1"){ | |
2485 @mybase+' '+msg('user', 'management') | |
2486 } | |
2487 @O.print @H.p(@sc.mkusermap.inspect) if $DEBUG | |
2488 @O.print @H.p(msg('usermodwarn')) | |
2489 @O.print \ | |
2490 @H.elementln("form", {'action'=>@myname+"?-usermod", 'method'=>'POST'}){ | |
2491 @H.elementln("table"){ | |
2492 @H.elementln("tr"){ | |
2493 @H.element("td", tdclass) {msg('regaddress')} + \ | |
2494 @H.element("td") { | |
2495 @H.element("code"){user} | |
2496 } | |
2497 } + \ | |
2498 @H.elementln("tr"){ | |
2499 @H.element("td", tdclass) {msg('mailaddress')} + \ | |
2500 @H.element("td") { | |
2501 @H.text("newmail", mailaddress(user), @opt['size'], 80) | |
2502 } | |
2503 } + \ | |
2504 @H.elementln("tr"){ | |
2505 @H.element("td", tdclass) {msg('weburl')} + \ | |
2506 @H.element("td") { | |
2507 @H.text("webpage", webpage(user), @opt['size'], 80) | |
2508 } | |
2509 } + \ | |
2510 @H.elementln("tr"){ | |
2511 @H.element("td") {msg('nickname')} + \ | |
2512 @H.element("td") { | |
2513 @H.text("nickname", nickname, @opt['size'], 10) | |
2514 } | |
2515 } | |
2516 } + \ | |
2517 @H.elementln("p"){ | |
2518 msg('shortnameplz') + "<br>\n" + \ | |
2519 @H.a(@after5url+"multiplenotify.html", msg('multiplemail')) | |
2520 } + \ | |
2521 '<br>' + \ | |
2522 @H.submit_reset("GO") | |
2523 } # form | |
2524 | |
2525 # | |
2526 # Next section, REMOVE USER! | |
2527 @O.print @H.elementln("h2"){ | |
2528 sprintf "%s %s %s", msg('user'), user, msg('deletion') | |
2529 } | |
2530 @O.print @H.p(msg('deletionwarn'))+"\n" | |
2531 @O.print @H.elementln("form", {'action'=>@myname+"?-delusersub+#{user}", 'method'=>'POST'}){ | |
2532 @H.hidden("user", user) + "\n" + \ | |
2533 @H.elementln("table"){ | |
2534 @H.elementln("tr"){ | |
2535 @H.elementln("td"){ | |
2536 sprintf msg('deluser'), user | |
2537 } + \ | |
2538 @H.elementln("td"){ | |
2539 @H.radio("delete", "yes", msg('yes')) + ' ' + \ | |
2540 @H.radio("delete", "no", msg('no'), true) | |
2541 } | |
2542 } + \ | |
2543 @H.elementln("tr"){ | |
2544 @H.elementln("td"){ | |
2545 sprintf msg('really?'), user | |
2546 } + \ | |
2547 @H.elementln("td"){ | |
2548 @H.radio("delete2", "yes", msg('yes')) + ' ' + \ | |
2549 @H.radio("delete2", "no", msg('no'), true) | |
2550 } | |
2551 } | |
2552 } + \ | |
2553 "<br>\n" + @H.submit_reset("GO") | |
2554 } | |
2555 | |
2556 | |
2557 end | |
2558 def usermod() | |
2559 if !checkauth | |
2560 return nil | |
2561 end | |
2562 @O.print @H.elementln("h1"){ | |
2563 msg('user', 'management')+" "+msg('done') | |
2564 } | |
2565 user=@params['user'] | |
2566 email = mailaddress(user) | |
2567 newmail = @params['newmail'] | |
2568 nickname = @sc.nickname(user) | |
2569 newnn = @params['nickname'].to_s.strip | |
2570 webpage = webpage(user) | |
2571 newweb = @params['webpage'] | |
2572 if email != newmail | |
2573 # change user's address | |
2574 if newmail == user | |
2575 newvalue = nil | |
2576 elsif checkmail(newmail) | |
2577 newvalue = newmail | |
2578 else | |
2579 @O.print @H.elementln("pre"){"Invalid mail address"} | |
2580 end | |
2581 @O.print @H.elementln("pre"){ | |
2582 if @sc.putuserattr(user, 'email', newvalue) | |
2583 sprintf "new mail address=\"%s\"", mailaddress(user) | |
2584 else | |
2585 sprintf "Setting new mail address to \"%s\" failed", newvalue | |
2586 end | |
2587 } | |
2588 end | |
2589 if nickname != newnn | |
2590 if @sc.setnickname(user, newnn) | |
2591 @O.print @H.p(msg('success')) | |
2592 @O.print @H.elementln("pre"){ | |
2593 sprintf "user=\"%s\"\nnickname=\"%s\"", user, @sc.nickname(user) | |
2594 } | |
2595 @O.print @H.p(msg('nicknamenote')) if newnn == '' | |
2596 else | |
2597 @O.print @H.p(msg('failure')) | |
2598 end | |
2599 end | |
2600 if newweb > '' && webpage != newweb | |
2601 if @sc.putuserattr(user, "webpage", newweb) | |
2602 @O.print @H.p(msg('success')) | |
2603 @O.print @H.elementln("pre"){ | |
2604 sprintf "user=\"%s\"\nwebpage=\"%s\"", user, webpage(user) | |
2605 } | |
2606 else | |
2607 @O.print @H.p("Update webpage"+msg('failure')) | |
2608 end | |
2609 end | |
2610 end | |
2611 # | |
2612 # Display form of group management | |
2613 def groupman() | |
2614 if !checkauth | |
2615 return nil | |
2616 end | |
2617 user=@params['user'] | |
2618 nickname = @sc.nickname(user) | |
2619 tdclass = {} | |
2620 tdclass["width"] = "80px" if @oldagent # workaround for NN4 | |
2621 admclass = {'class'=>'admin'} | |
2622 grmap = @sc.groupmap | |
2623 | |
2624 @O.print @H.elementln("h1"){ | |
2625 @mybase+' '+msg('group', 'management') | |
2626 } | |
2627 $KCODE='e' if $DEBUG | |
2628 @O.print grmap.inspect if $DEBUG | |
2629 @O.print @H.p(msg('joinmyself')+ | |
2630 @H.a(@myname+"?-newgroup", msg('newgroup'))) | |
2631 @O.print @H.p(msg('usermodwarn')) | |
2632 @O.print \ | |
2633 @H.elementln("form", {'action'=>@myname+"?-groupmod", 'method'=>'POST'}){ | |
2634 @H.elementln("table", {'border'=>'1', 'vertical-align'=>'top'}){ | |
2635 grmap.collect{|g, ghash| | |
2636 @H.elementln("tr"){ | |
2637 @H.element("td", @sc.isadmin(user, g) ? admclass : nil){ | |
2638 g | |
2639 } + \ | |
2640 @H.element("td"){ | |
2641 @H.element("div", {'class'=>'c'}) { | |
2642 if @sc.isadmin(user, g) | |
2643 @H.a(@myname+"?-admgroup+#{g}", msg('adminop')) | |
2644 else | |
2645 '--' | |
2646 end | |
2647 } | |
2648 } + \ | |
2649 @H.element("td"){ | |
2650 memberp = @sc.ismember(user, g) | |
2651 if ghash['admin'].grep(user)[0] | |
2652 @H.text("groupname-#{g}", ghash['name'], nil, 20) | |
2653 else | |
2654 ghash['name'] | |
2655 end + '<br>' + \ | |
2656 @H.radio("groupadd-#{g}", "yes", "IN", memberp) + " / " + \ | |
2657 @H.radio("groupadd-#{g}", "no", "OUT", !memberp) | |
2658 } + \ | |
2659 @H.element("td"){ | |
2660 ghash['members'].collect{|u| | |
2661 @sc.nickname(u) | |
2662 }.join(", ") | |
2663 } | |
2664 } | |
27 | 2665 }.join("\n") |
0 | 2666 } + \ |
2667 '' + \ | |
2668 @H.p(msg('groupwarn', 'shortnameplz')) + \ | |
2669 @H.submit_reset("GO") | |
2670 } # form | |
2671 end | |
2 | 2672 def groupnamesString() |
2673 @H.elementln("p", {'class'=>'listup'}){ | |
2674 @sc.groups().collect{|g|@sc.groupname(g)}.join(", ") | |
2675 } | |
2676 end | |
0 | 2677 def groupmod() |
2678 if !checkauth | |
2679 return nil | |
2680 end | |
2681 @O.print @H.elementln("h1"){ | |
2682 msg('group', 'management')+" "+msg('done') | |
2683 } | |
2684 user=@params['user'] | |
2685 @O.print @params.inspect if $DEBUG | |
2686 | |
2687 for grp in @sc.groups() | |
2688 # | |
2689 # as a member, participate or retire | |
2690 key = "groupadd-#{grp}" | |
2691 removep = (/no/i =~ @params[key]) | |
2692 memberp = @sc.ismember(user, grp) | |
2693 if @params[key] | |
2694 if (!removep) ^ memberp | |
2695 @sc.addgroup(grp, [user], removep) | |
2696 @O.print @H.elementln("p"){ | |
2697 sprintf "%s [%s] %s %s", msg('user'), user, | |
2698 removep ? msg('removedfromgp') : msg('addedtogroup'), grp | |
2699 } | |
2700 end | |
2701 end | |
2702 # | |
2703 # as a owner, change the name of group | |
2704 if @sc.isadmin(user, grp) && | |
2705 (newname = @params["groupname-#{grp}"]) && | |
2706 @sc.groupname(grp) != newname | |
2 | 2707 @O.printf "@sc.name2group=%s<br>\n", @sc.name2group(newname) |
2708 if dupl=@sc.name2group(newname) | |
2709 @O.print @H.p(sprintf(msg('dupname'), newname)) | |
2710 @O.print groupnamesString() | |
2711 | |
2712 else | |
2713 @sc.setgroupname(grp, newname) | |
2714 @O.print @H.elementln("p"){ | |
2715 sprintf "%s %s%s %s", | |
2716 msg('group'), grp, msg('of', 'name', 'setto'), newname | |
2717 } | |
2718 end | |
0 | 2719 end |
2720 end | |
2721 end | |
2722 def users() | |
2723 unless pm=open_pm() | |
2724 outputError(msg('autherror')) | |
2725 return nil | |
2726 end | |
2727 pm.users | |
2728 end | |
2729 def grepgroup(gname) | |
2730 gr = @sc.groups.grep(gname)[0] | |
2731 end | |
2732 def admgroup(group = nil) | |
2733 # if group==nil, create new | |
2734 if !checkauth | |
2735 return nil | |
2736 end | |
2737 @O.print @H.elementln("h1"){ | |
2738 msg('group', 'management') | |
2739 } | |
2740 user=@params['user'] | |
2741 | |
2742 # Check the existent group's validity | |
2743 if group | |
2744 unless (gr=grepgroup(group)) | |
2745 @O.print @H.p("No such group #{group}") | |
2746 return nil | |
2747 end | |
2748 group = gr | |
2749 unless @sc.isadmin(user, group) | |
2750 @O.print @H.p("You are not administrator of #{group}.") | |
2751 return nil | |
2752 end | |
2753 @O.print @H.elementln("h2"){ | |
2754 msg('group')+" #{group}" + | |
2755 if group != @sc.groupname(group) | |
2756 " (#{@sc.groupname(group)})" | |
2757 end.to_s | |
2758 } | |
2759 actionmethod={'action'=>@myname+"?-admgroupsub", 'method'=>'POST'} | |
2760 else | |
2761 # New group creation | |
2762 @O.print @H.elementln("h2"){ | |
2763 msg('newgroup') | |
2764 } | |
2765 actionmethod={'action'=>@myname+"?-newgroupsub", 'method'=>'POST'} | |
2766 end | |
2767 | |
2768 userlist = ([user] + users()).uniq | |
2769 myselfclass = {'class'=>'admin'} | |
2770 colspan2 = {'colspan'=>'2'} | |
2771 warnclass = {'class'=>'warn'} | |
2772 warnp = nil | |
2773 | |
2774 @O.print @H.elementln("form", actionmethod){ | |
2775 @H.hidden('group', group) + "\n" + \ | |
2776 if group | |
2777 "" | |
2778 else | |
2779 # new group creation | |
2780 grps = @sc.groups() | |
2781 i=1 | |
2782 defname = "group%03d"%i | |
2783 while grps.grep(defname)[0] | |
2784 defname = "group%03d"%(i+=1) | |
2785 end | |
2786 @H.element("pre"){ | |
2787 msg('group', 'of', 'id')+"\n"+@H.text("group", defname) + "\n" + \ | |
2788 msg('group', 'of', 'name', 'anystring')+"\n"+ \ | |
2789 @H.text("gname", '') + "\n" | |
2790 } | |
2791 end + \ | |
2792 @H.elementln("table", {'border'=>'1'}){ | |
2793 @H.elementln("tr"){ | |
2794 @H.element("th"){msg('join')} + \ | |
2795 @H.element("th"){msg('administrator')} + \ | |
2796 @H.element("th"){msg('member')} | |
2797 } + \ | |
2798 userlist.collect{|u| | |
2799 recursememp = nil | |
2800 if group | |
2801 memberp = (@sc.ismember(u, group) && true) | |
2802 adminp = (@sc.isadmin(u, group) && true) | |
2803 if !memberp && @sc.members(group).grep(u)[0] | |
2804 recursememp = true | |
2805 end | |
2806 else | |
2807 memberp = adminp = (u == user) | |
2808 end | |
2809 @H.elementln("tr", (u==user ? myselfclass : nil)){ | |
2810 @H.element("td"){ | |
2811 @H.radio('mem-'+u, 'yes', 'YES / ', memberp) + \ | |
2812 @H.radio('mem-'+u, 'no', 'NO', !memberp) | |
2813 } + \ | |
2814 @H.element("td"){ | |
2815 @H.radio('adm-'+u, 'yes', 'YES / ', adminp) + \ | |
2816 @H.radio('adm-'+u, 'no', 'NO', !adminp) | |
2817 } + \ | |
2818 @H.element("td"){ | |
2819 @sc.nickname(u) + \ | |
2820 if recursememp | |
2821 warnp = true | |
2822 @H.element("span", warnclass){"(*)"} | |
2823 end.to_s | |
2824 } | |
2825 } | |
2826 }.join + \ | |
2827 # group names | |
2828 @H.elementln("tr"){ | |
2829 @H.element("th", colspan2){msg('join')} + \ | |
2830 @H.element("th"){msg('group')} | |
2831 } + \ | |
2832 @sc.groups().collect{|g| | |
2833 next if group == g | |
2834 memberp = @sc.ismember(g, group) | |
2835 @H.element("tr"){ | |
2836 @H.element("td", colspan2){ | |
2837 @H.radio('mem-'+g, 'yes', 'YES / ', memberp) + \ | |
2838 @H.radio('mem-'+g, 'no', 'NO', !memberp) | |
2839 } + \ | |
2840 @H.element("td"){ | |
2841 if @sc.isadmin(user, g) | |
2842 @H.a(@myname+"?-admgroup+#{g}", @sc.groupname(g)) | |
2843 else | |
2844 @sc.groupname(g) | |
2845 end | |
2846 } | |
2847 } | |
2848 }.join | |
2849 } + "<br>\n" + \ | |
2850 @H.submit_reset("GO") | |
2851 } # form | |
2852 @O.print @H.p(@H.element("span", warnclass){"(*)"}+ | |
2853 msg('recursewarn')) if warnp | |
2 | 2854 if group && (members = @sc.members(group))[0] |
0 | 2855 @O.print @H.p(sprintf(msg('wholemembers'), group)) |
2856 @O.print @H.elementln("p", {'class'=>'listup'}){ | |
2 | 2857 members.collect{|u|@sc.nickname(u)}.join(", ")} |
0 | 2858 end |
2859 | |
2860 # | |
2861 # Next section, REMOVE GROUP! | |
2862 return nil unless group | |
2863 @O.print @H.elementln("h2"){ | |
2864 sprintf "%s %s %s", msg('group'), group, msg('deletion') | |
2865 } | |
2866 @O.print @H.p(msg('deletionwarn'))+"\n" | |
2867 @O.print @H.elementln("form", {'action'=>@myname+"?-delgroupsub+#{group}", 'method'=>'POST'}){ | |
2868 @H.hidden("group", group) + "\n" + \ | |
2869 @H.elementln("table"){ | |
2870 @H.elementln("tr"){ | |
2871 @H.elementln("td"){ | |
2872 sprintf msg('delgroup'), group | |
2873 } + \ | |
2874 @H.elementln("td"){ | |
2875 @H.radio("delete", "yes", msg('yes')) + ' ' + \ | |
2876 @H.radio("delete", "no", msg('no'), true) | |
2877 } | |
2878 } + \ | |
2879 @H.elementln("tr"){ | |
2880 @H.elementln("td"){ | |
2881 sprintf msg('really?'), group | |
2882 } + \ | |
2883 @H.elementln("td"){ | |
2884 @H.radio("delete2", "yes", msg('yes')) + ' ' + \ | |
2885 @H.radio("delete2", "no", msg('no'), true) | |
2886 } | |
2887 } | |
2888 } + \ | |
2889 "<br>\n" + @H.submit_reset("GO") | |
2890 } | |
2891 | |
2892 @O.print footer() | |
2893 end | |
2894 def newgroup() | |
2895 admgroup(nil) | |
2896 end | |
2897 | |
2898 def delgroupsub(group) | |
2899 if !checkauth | |
2900 return nil | |
2901 end | |
2902 user = @params['user'] | |
2903 if group != @params['group'] | |
2904 @O.print @H.p("Group mismatch") | |
2905 return nil | |
2906 end | |
2907 unless (gr=grepgroup(group)) | |
2908 @O.print @H.p("No such group #{group}") | |
2909 return nil | |
2910 end | |
2911 group = gr | |
2912 unless @sc.isadmin(user, group) | |
2913 @O.print @H.p("You are not administrator of #{group}.") | |
2914 return nil | |
2915 end | |
2916 unless @params['delete'] && /yes/i =~ @params['delete'] \ | |
2917 && @params['delete2'] && /yes/i =~ @params['delete2'] | |
2918 @O.print @H.p(msg('chicken')) | |
2919 return nil | |
2920 end | |
2921 @O.print @H.elementln("h1"){ | |
2922 msg('group')+" #{group} "+msg('deletion') | |
2923 } | |
2924 @O.print @H.p(@sc.destroygroup(group) ? msg("done") : msg("failure")) | |
2925 | |
2926 @O.print footer() | |
2927 end | |
2928 | |
2929 def deleteuser(user) | |
2930 @sc.deleteuser(user) && | |
2931 begin | |
2932 pm = open_pm | |
2933 pm.delete(user) | |
2934 pm.close() | |
2935 true | |
2936 rescue | |
2937 nil | |
2938 end | |
2939 end | |
2940 def delusersub(user) | |
2941 if !checkauth | |
2942 return nil | |
2943 end | |
2944 user = @params['user'] | |
2945 if user != @params['user'] | |
2946 @O.print @H.p("User mismatch") | |
2947 return nil | |
2948 end | |
2949 unless (us=users().grep(user)[0]) | |
2950 @O.print @H.p("No such user #{user}") | |
2951 return nil | |
2952 end | |
2953 user = us | |
2954 unless @params['delete'] && /yes/i =~ @params['delete'] \ | |
2955 && @params['delete2'] && /yes/i =~ @params['delete2'] | |
2956 @O.print @H.p(msg('chicken')) | |
2957 return nil | |
2958 end | |
2959 @O.print @H.elementln("h1"){ | |
2960 msg('user')+" #{user} "+msg('deletion') | |
2961 } | |
2962 @O.print @H.p(deleteuser(user) ? msg("done") : msg("failure")) | |
2963 | |
7 | 2964 @O.print @H.p(@H.a(@myname, msg('login'))) |
0 | 2965 end |
2966 | |
2967 def admgroupsub() | |
2968 if !checkauth | |
2969 return nil | |
2970 end | |
2971 user = @params['user'] | |
2972 group = @params['group'] | |
2973 unless (gr=grepgroup(group)) | |
2974 @O.print @H.element("pre"){"No such group #{group.inspect}"} | |
2975 return nil | |
2976 end | |
2977 unless @sc.isadmin(user, group) | |
2978 @O.print @H.p("You are not administrator of #{group}.") | |
2979 return nil | |
2980 end | |
2981 gorup = gr | |
2982 @O.print @H.elementln("h1"){ | |
2983 msg('group', 'management', 'done') | |
2984 } | |
2985 @O.print @H.elementln("h2"){ | |
2986 msg('group')+" #{group}" + | |
2987 if group != @sc.groupname(group) | |
2988 " (#{@sc.groupname(group)})" | |
2989 end.to_s | |
2990 } | |
2991 somethingdone = nil | |
2992 for u in users() | |
2 | 2993 u = @sc.isuser(u) # users() value is considered tainted. |
2994 next unless u # Use registered value in @sc. | |
0 | 2995 for var, kind in { |
2996 "mem"=>['members', 'member'], 'adm'=>['admin', 'administrator']} | |
2997 memv = "#{var}-#{u}" | |
2998 if @params[memv] | |
2999 joinp = ((/^yes/i =~ @params[memv]) && true) | |
3000 membp = if var=='mem' | |
3001 @sc.ismember(u, group) | |
3002 else # admin | |
3003 @sc.isadmin(u, group) | |
3004 end && true | |
3005 if var=='adm' && @sc.admins(group).length == 1 && membp && !joinp | |
3006 @O.print @H.p(sprintf(msg('soleadmin'), u, group)) | |
3007 elsif joinp ^ membp | |
3008 somethingdone = true | |
3009 @sc.addgroup(group, [u], !joinp, kind[0]) | |
3010 @O.print @H.elementln("p"){ | |
3011 sprintf "%s [%s](%s) %s %s", msg('user'), u, | |
3012 msg(kind[1]), | |
3013 joinp ? msg('addedtogroup'): msg('removedfromgp'), group | |
3014 } | |
3015 end | |
3016 end | |
3017 end | |
3018 end # users() | |
3019 | |
3020 # add or remove for group in groups | |
3021 for g in @sc.groups() | |
3022 next if g == group | |
3023 memv = "mem-#{g}" | |
3024 if @params[memv] | |
3025 joinp = ((/^yes/i =~ @params[memv]) && true) | |
3026 membp = (@sc.ismember(g, group) && true) | |
3027 if joinp ^ membp | |
3028 somethingdone = true | |
3029 @sc.addgroup(group, [g], !joinp) | |
3030 @O.print @H.elementln("p"){ | |
3031 sprintf "%s [%s] %s %s", msg('group'), g, | |
3032 joinp ? msg('addedtogroup'): msg('removedfromgp'), group | |
3033 } | |
3034 end | |
3035 end | |
3036 end # groups | |
3037 unless somethingdone | |
3038 # @O.print @H.p(msg('nothingtodo')) | |
3039 end | |
3040 @O.print footer() | |
3041 end | |
3042 def newgroupsub() | |
3043 if !checkauth | |
3044 nil | |
3045 end | |
3046 user = @params['user'] | |
3047 newgroup = @params['group'] | |
3048 newgname = @params['gname'] | |
3049 | |
3050 | |
3051 if @sc.groups.grep(newgroup)[0] | |
3052 @O.print @H.p(msg('existent')+newgroup) | |
3053 return nil | |
3054 end | |
2 | 3055 if dupl=@sc.name2group(newgname) |
3056 @O.print @H.p(sprintf(msg('dupname'), newgname)) | |
3057 @O.print groupnamesString() | |
3058 return nil | |
3059 end | |
0 | 3060 @sc.creategroup(newgroup, newgname, [user]) |
3061 admgroup(newgroup) | |
3062 end | |
3063 | |
14 | 3064 # |
3065 # Methods Related to viaMail functions | |
3066 def gen_sessionpswd() | |
3067 | |
3068 end | |
3069 def viamail_registform() | |
3070 c = "# " | |
3071 nl = "\n" | |
3072 user = @params['user'] | |
3073 msg('addsched') + "-" * 20 + nl*2 + \ | |
3074 c + msg('user') + nl + \ | |
3075 "user=" + user + nl*2 + \ | |
3076 c + msg('sessionpswd') + nl + \ | |
3077 "sp=hoge" + nl*2 + \ | |
3078 c + msg('date') + nl + \ | |
3079 "date="+Time.now.strftime("%Y/%m/%d") + nl*2 + \ | |
3080 c + msg('time') + sprintf(msg('24hourtxt'), @opt['alldaydir']) + nl + \ | |
3081 "time=3000"+nl*2 + \ | |
3082 c + msg('publicp') + nl + \ | |
3083 "public=yes" + nl*2 + \ | |
3084 c + msg('neednotify') + nl + \ | |
3085 "nt10m=yes (%s) | |
3086 nttoday=yes (%s) | |
3087 nt1d=yes (%s) | |
3088 nt7d=yes (%s)" % ["10"+msg('minutes')+msg('before'), | |
3089 msg('theday'), msg('precedingday'), | |
3090 "7"+msg('days')+msg('before')] + nl*2 + \ | |
3091 | |
3092 c + msg('schedulehere') | |
3093 end | |
3094 def viamail_footer() | |
3095 viamail_registform() | |
3096 end | |
3097 def show_by_text(date, days) | |
3098 user = @params['user'] | |
3099 personal = true | |
3100 sched = dayTextString(user, date, days, personal) | |
3101 # @O.print outstr | |
3102 | |
3103 sendMail(mailaddress(user), | |
3104 "After5 Schedule", | |
3105 @opt['url'] + "\n" + \ | |
3106 Time.now.strftime("%Y/%m/%d") + \ | |
3107 sprintf(msg('schedlist'), days) + "\n\n" + \ | |
3108 if sched > '' | |
3109 sched | |
3110 else | |
3111 msg('noplan')+"\n" | |
3112 end + \ | |
3113 viamail_footer | |
3114 ) | |
3115 | |
3116 end | |
3117 def parseHeader | |
3118 contline=nil | |
3119 header=Hash.new | |
3120 text=Array.new | |
3121 | |
3122 field=nil | |
3123 # header | |
3124 while line=STDIN.gets | |
3125 text << line | |
3126 break if /^$/ =~ line | |
3127 | |
3128 if /^\s+/ =~ line | |
3129 if field | |
3130 header[field][-1] << line | |
3131 end | |
3132 else | |
3133 if /^([^:]+):\s*(.*)/ =~ line | |
3134 field=$1.downcase | |
3135 header[field] or header[field] = [] | |
3136 header[field] << $2 | |
3137 end | |
3138 end | |
3139 end | |
3140 header | |
3141 end | |
3142 def mail_regsched() | |
3143 @params = Hash.new # Reset | |
3144 | |
3145 reqparams = %w[user sp date time public] | |
3146 otherparams = %w[nt10m nttoday nt1d nt7d] | |
3147 setall = lambda{ | |
3148 reqparams.each{|key| return false unless @params.has_key?(key)} | |
3149 return true | |
3150 } | |
3151 stack = "" | |
3152 while line=gets # !setall.call && line=gets | |
3153 if /^(\S+)=(.*)/ =~ line | |
3154 next unless reqparams.index($1) || otherparams.index($1) | |
3155 @params[$1] = $2 | |
3156 #if reqparams.index($1) | |
3157 STDERR.print "Set #{$1} to #{$2}\n" | |
3158 #end | |
3159 buf = "" | |
3160 elsif /^\s*\#|^$/ =~ line | |
3161 # skip comments | |
3162 else | |
3163 buf += line | |
3164 end | |
3165 end | |
3166 unless setall.call | |
3167 STDERR.print "Insufficient variables\n" | |
3168 exit 1 | |
3169 end | |
3170 p buf | |
3171 | |
3172 y, m, d = date2ymd(@params["date"]) | |
3173 @params["year"] = y | |
3174 @params["month"] = m | |
3175 @params["day"] = d | |
3176 @params["schedule"] = buf | |
3177 @params["editmode"] = "modify" | |
3178 @params["sessionpw"] = @params["sp"] | |
3179 p @params | |
3180 add_remove() | |
3181 end | |
3182 def mail_getsched() | |
3183 user = nil | |
3184 while bline=gets | |
3185 if /(\S+@\S+)/ =~ bline | |
3186 break if user=@sc.isuser($1) | |
3187 end | |
3188 end | |
3189 unless user | |
3190 sendMail(@opt['maintainer'], "viaMail Request Error", | |
3191 "This is `#{@mybase}' in #{@mydir}\n" + | |
3192 "Invalid schedule request from #{ENV['SENDER']}.\n\n") | |
3193 exit 1 | |
3194 end | |
3195 today = Time.now.strftime("%Y/%m/%d") | |
3196 days = 7 | |
3197 if bline=gets | |
3198 if /\d+/ =~ bline | |
3199 days = bline.to_i | |
3200 end | |
3201 end | |
3202 # Send user to schedules of today and near future | |
3203 @params['user'] = user | |
3204 show_by_text(today, days) | |
3205 end | |
3206 def doMail() | |
3207 days = 7 | |
3208 # Confirm `via Mail' | |
3209 prohibitviahttp() | |
3210 @H = TEXTout.new | |
3211 unless ENV['RECIPIENT'] && ENV['SENDER'] | |
3212 STDERR.print "Call me via qmail\n" | |
3213 exit 1 | |
3214 end | |
3215 @mailmode = true | |
3216 header = parseHeader # is this necessary? | |
3217 if /regist/ =~ ENV["EXT"] | |
3218 mail_regsched() | |
3219 else | |
3220 mail_getsched() | |
3221 end | |
3222 end | |
3223 | |
3224 # | |
3225 # Password related Methos | |
0 | 3226 def setpasswd(user) |
3227 prohibitviahttp() | |
3228 pm = open_pm() | |
3229 exit 1 unless pm | |
3230 if pm.userexist?(user) then | |
3231 begin | |
3232 system "stty -echo" | |
3233 STDERR.print "New passwd: " | |
3234 p1 = STDIN.gets | |
3235 STDERR.print "\nAgain: " | |
3236 p2 = STDIN.gets | |
3237 ensure | |
3238 system "stty echo" | |
3239 end | |
3240 if (p1 == p2) then | |
3241 pm.setpasswd(user, p1.chop!) | |
3242 end | |
3243 STDERR.print "New password for #{user} set successfully\n" | |
3244 else | |
3245 STDERR.print "User #{user} not found\n" | |
3246 end | |
3247 pm.close() | |
3248 exit 0 | |
3249 end | |
3250 def adduser(user) | |
3251 prohibitviahttp() | |
3252 pm = open_pm() | |
3253 exit 1 unless pm | |
3254 newpwd = pm.setnewpasswd(user, 4) | |
3255 print "#{user}'s password is #{newpwd}\n" | |
3256 pm.close() | |
3257 exit 0 | |
3258 end | |
3259 def deluser(user) | |
3260 prohibitviahttp() | |
3261 pm = open_pm() | |
3262 exit 1 unless pm | |
3263 pm.delete(user) | |
3264 pm.close() | |
3265 exit 0 | |
3266 end | |
3267 | |
3268 # read configuratoin file | |
3269 def readconf(conf) | |
3270 cf = "after5.cf" #conf # || @opt['conf'] | |
3271 cf = File.join(@mydir, cf) unless test(?s, cf) | |
3272 cf = File.join(ENV["HOME"], cf) unless test(?s, cf) | |
3273 return unless test(?s, cf) | |
3274 begin | |
3275 IO.foreach(cf){|line| | |
26 | 3276 line = line.toeuc |
0 | 3277 next if /^\s *#/ =~ line |
3278 line.chop! | |
3279 line.sub!(/^\s*#.*/, '') | |
3280 next if /^$/ =~ line | |
3281 case line | |
3282 # title, type = line.split(/\t+/) | |
3283 when /^([a-z]+)=(.*)/oi | |
3284 key, value = $1, $2 | |
3285 case value | |
6 | 3286 when /^(no|none|null|nil|false|0|off)$/io |
0 | 3287 @opt[key] = nil |
3288 else | |
3289 @opt[key] = value | |
3290 end | |
3291 print "#{key} set to #{value}\n" if $DEBUG | |
3292 end | |
3293 } | |
3294 rescue | |
26 | 3295 STDERR.printf("Configuration file %s not readable\n", cf) |
0 | 3296 end |
3297 end | |
3298 | |
3299 def parsedate(string) | |
3300 if %r,^(\d\d\d\d+)/(\d+)/(\d+)/(\d+)/([^/]+)$, =~ string | |
3301 sprintf "%04d/%02d/%02d/%04d/%s", $1.to_i, $2.to_i, $3.to_i, $4.to_i, | |
3302 grepgroup($5) | |
3303 elsif %r,^(\d\d\d\d+)/(\d+)/(\d+)/(\d+), =~ string | |
3304 sprintf "%04d/%02d/%02d/%04d", $1.to_i, $2.to_i, $3.to_i, $4.to_i | |
3305 elsif %r,^(\d\d\d\d+)/(\d+)/(\d+), =~ string | |
3306 sprintf "%04d/%02d/%02d", $1.to_i, $2.to_i, $3.to_i | |
3307 elsif %r,^(\d\d\d\d+)/(\d+), =~ string | |
3308 sprintf "%04d/%02d", $1.to_i, $2.to_i | |
3309 elsif %r,^(\d\d\d\d+)/(\d+), =~ string | |
3310 sprintf "%04d", $1.to_i | |
3311 end | |
3312 end | |
3313 | |
3314 def getarg() | |
3315 argument = {} | |
3316 | |
3317 while /^-/ =~ ARGV[0] | |
3318 case ARGV[0] | |
3319 when '-f' | |
3320 conf = ARGV[1] | |
3321 ARGV.shift | |
3322 when "-d" | |
3323 $DEBUG = true | |
3324 when "-install" | |
14 | 3325 when "-stream" |
3326 # ARGV.shift | |
3327 # @job = 'show_by_text "2005/1/18"' | |
3328 @job = 'doMail' | |
0 | 3329 when "-addsched" |
3330 @job = "addsched" | |
3331 when "-today" | |
3332 @job = "today" | |
2 | 3333 when "-today_p" |
3334 argument['displaymode'] = 'personal' | |
3335 @job = "today" | |
3336 when "-today_n" | |
3337 argument['displaymode'] = 'normal' | |
3338 @job = "today" | |
0 | 3339 when "-remove" |
3340 ARGV.shift | |
3341 @job = 'remove "'+parsedate(ARGV[0])+'"' | |
14 | 3342 when "-move" |
3343 ARGV.shift | |
3344 @job = 'move "'+parsedate(ARGV[0])+'"' | |
0 | 3345 when "-modify" |
3346 ARGV.shift | |
3347 @job = 'modify "'+parsedate(ARGV[0])+'"' | |
3348 when "-month" | |
3349 ARGV.shift | |
3350 @job = 'month "'+parsedate(ARGV[0])+'"' | |
3351 when "-show" | |
3352 ARGV.shift | |
3353 # @job = "show '"+ARGV[0]+"'" | |
3354 @job = "show '"+parsedate(ARGV[0])+"'" | |
3355 when "-login" | |
3356 @job = "login" | |
3357 when "-userman" | |
3358 @job = "userman" | |
3359 when "-usermod" | |
3360 @job = "usermod" | |
3361 when "-groupinout" | |
3362 @job = "groupinout" | |
3363 when "-groupsubmit" | |
3364 @job = "groupsubmit" | |
3365 when "-groupman" | |
3366 @job = "groupman" | |
3367 when "-groupmod" | |
3368 @job = "groupmod" | |
3369 when "-notify" | |
3370 @job = 'notify' # + exit | |
3371 when "-newgroup" | |
3372 @job = 'newgroup' | |
3373 when "-admgroup" | |
3374 ARGV.shift | |
3375 gr = safecopy(grepgroup(ARGV[0])) | |
3376 ##gr.untaint | |
3377 @job = 'admgroup "'+gr+'"' | |
3378 when "-admgroupsub" | |
3379 @job = 'admgroupsub' | |
3380 when "-newgroupsub" | |
3381 @job = 'newgroupsub' | |
3382 when "-delusersub" | |
3383 ARGV.shift | |
6 | 3384 usr = safecopy(users().grep(ARGV[0])[0]) |
0 | 3385 @job = 'delusersub "'+usr+'"' |
3386 when "-delgroupsub" | |
3387 ARGV.shift | |
3388 gr = grepgroup(ARGV[0]) | |
3389 @job = 'delgroupsub "'+gr+'"' | |
3390 when /-(setpasswd|deluser|adduser)$/ | |
3391 ARGV.shift | |
3392 @job = $1+ " '#{ARGV[0]}'" # + exit | |
3393 when "" | |
3394 end | |
3395 ARGV.shift | |
3396 end | |
3397 | |
3398 readconf(@conf) | |
3399 | |
3400 query = '' | |
3401 method = ENV["REQUEST_METHOD"] | |
3402 if /POST/i =~ method then | |
3403 length = ENV["CONTENT_LENGTH"].to_i | |
3404 query = STDIN.read(length) | |
3405 elsif /GET/i =~ method then | |
3406 query = ENV["QUERY_STRING"] | |
3407 else # executed from command line | |
3408 query = ARGV.join("&") | |
3409 end | |
3410 | |
3411 for unit in query.split(/\&/) | |
3412 if /^([a-z][-_0-9@%a-z.]*)=(.*)/i =~ unit | |
3413 key, value = $1, $2 | |
3414 #value.gsub!(/%(..)/){[$1.hex].pack("c")} # これでURLデコードが一発 | |
3415 decode!(value) | |
3416 decode!(key) | |
3417 value = Kconv::toeuc(value) # EUCに変換 | |
3418 printf "[%s] = %s\n", key, value if $DEBUG | |
3419 argument[key] = value | |
3420 end | |
3421 end | |
3422 argument | |
3423 end | |
3424 def getcookie() | |
3425 cookie = {} | |
7 | 3426 return cookie unless ENV['HTTP_COOKIE'] |
3427 #if /value=(.*)/ =~ ENV['HTTP_COOKIE'] | |
3428 for cv in ENV['HTTP_COOKIE'].split(/[\; ]+/).grep(/(value|prefs)=(.*)/) | |
0 | 3429 # value=$1.gsub!(/%(..)/){[$1.hex].pack("c")} |
7 | 3430 next unless /\w+=(.*)/ =~ cv |
0 | 3431 value=decode!($1) |
7 | 3432 next unless value |
0 | 3433 for line in value.split("&") |
3434 if /(\w+)=(.*)/ =~ line | |
3435 key, value = $1, $2 | |
3436 #value.gsub!(/%(..)/){[$1.hex].pack("c")} # これでURLデコードが一発 | |
3437 decode!(value) | |
3438 value = Kconv::toeuc(value) # EUCに変換 | |
3439 printf "cookie[%s] = %s\n", key, value if $DEBUG | |
3440 cookie[key] = value | |
3441 end | |
3442 end | |
3443 end | |
3444 cookie | |
3445 end | |
3446 end | |
3447 | |
17 | 3448 $KCODE='e' if RUBY_VERSION < "1.9" |
0 | 3449 After5.new.doit |
3450 | |
3451 if __FILE__ == $0 | |
3452 end | |
3453 | |
3454 | |
3455 # Local variables: | |
3456 # buffer-file-coding-system: euc-jp | |
3457 # End: |