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