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