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