This repository has been archived by the owner on Mar 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Rakefile
96 lines (87 loc) · 2.55 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- coding: utf-8 -*-
require 'rake/testtask'
require_relative 'lib/user'
require_relative 'lib/conf'
Rake::TestTask.new do |t|
t.pattern = 't/**/test*.rb'
end
class User
def self.add_with_passwd(name, ruby, login, email)
u = self.add(
'name' => name,
'ruby' => ruby,
'login' => login,
'email' => email
)
if u
puts "Add user #{login}."
self.set_passwd(login, login)
return true
end
false
end
end
task 'dummy' do
dummy_users = [
['松村 史郎', 'まつむら しろう', 'matsumura', '[email protected]'],
['柏原 高明', 'かしわら たかあき', 'takaaki', '[email protected]'],
['戸谷 鬼怒子', 'とたに きぬこ', 'kinuko', '[email protected]'],
['山口 雪絵', 'やまぐち ゆきえ', 'yukie', '[email protected]'],
['篠原 慎太郎', 'しのはら しんたろう', 'sin', '[email protected]'],
['佐久間 ひろよ', 'さくま ひろよ', '1029224532', '[email protected]'],
['伴 守', 'ばん まもる', '7427466391', '[email protected]'],
['Li Mei Kung', '', 'kung', '[email protected]'],
['William M. Mickle', '', 'fuleat', '[email protected]'],
['Kate J. Roberts', '', 'Somrat', '[email protected]']
]
cnt = 0
dummy_users.map do |u|
cnt += 1 if User.add_with_passwd(u[0], u[1], u[2], u[3])
end
puts "Added #{cnt} users."
end
task 'htaccess' do
conf = Conf.new
['api'].each do |dir|
path = "public/#{dir}/.htaccess"
if File.exist?(path)
print "#{path} already exists. Rewrite it (y or N)? "
next if STDIN.gets !~ /^y/i
end
puts "Create #{path}"
open(path, 'w').write <<EOF
AuthType Digest
AuthUserFile "#{conf[:master, :authn, :htdigest]}"
AuthName "#{conf[:master, :authn, :realm]}"
Require valid-user
EOF
end
if conf[:master, :authn_account]
htdigest = conf[:master, :authn_account, :htdigest]
puts "Create #{htdigest}"
htd = WEBrick::HTTPAuth::Htdigest.new(htdigest)
htd.set_passwd(
conf[:master, :authn_account, :realm],
conf[:master, :authn_account, :user],
conf[:master, :authn_account, :passwd]
)
htd.flush
htaccess =
Pathname.new(File.dirname(File.expand_path(__FILE__))) +
'public/account/.htaccess'
puts "Create #{htaccess}"
open(htaccess, 'w') do |io|
io.write <<-EOF
AuthType Digest
AuthUserFile "#{htdigest}"
AuthName "#{conf[:master, :authn_account, :realm]}"
Require valid-user
EOF
end
else
# remove auth files
end
end
task 'verify' do
Conf.new.verify_config
end