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