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