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