runit-man 1.8.4 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ require 'base64'
1
2
  require 'ftools'
2
3
  require 'json'
3
4
  require 'erubis'
@@ -160,10 +161,26 @@ class RunitMan < Sinatra::Base
160
161
  files_to_view << File.expand_path(file_location, '/')
161
162
  end
162
163
 
164
+ def add_user(name, password)
165
+ allowed_users[name] = password
166
+ end
167
+
163
168
  def files_to_view
164
169
  @files_to_view ||= []
165
170
  end
166
171
 
172
+ def allowed_users
173
+ @allowed_users ||= {}
174
+ end
175
+
176
+ def prepare_to_run
177
+ unless allowed_users.empty?
178
+ use Rack::Auth::Basic do |username, password|
179
+ allowed_users.include?(username) && allowed_users[username] == password
180
+ end
181
+ end
182
+ end
183
+
167
184
  private
168
185
  def create_run_script(dir)
169
186
  script_name = File.join(dir, 'run')
@@ -14,6 +14,7 @@ OptionParser.new { |op|
14
14
  op.on('-f all_services_directory (/etc/sv by default)') { |val| RunitMan.set :all_services_directory, val }
15
15
  op.separator 'View options:'
16
16
  op.on('-v file_location', 'Enables view of specified file through runit-man') { |val| RunitMan.enable_view_of(val) }
17
+ op.on('-u user:password', 'Requires user name with given password to auth') { |val| RunitMan.add_user(*(val.split(':', 2))) }
17
18
  op.separator 'Configuration options:'
18
19
  op.on_tail('-r', '--register', 'Register as runit service') do
19
20
  RunitMan.register_as_runit_service
@@ -21,5 +22,7 @@ OptionParser.new { |op|
21
22
  end
22
23
  }.parse!(ARGV.dup)
23
24
 
25
+ RunitMan.prepare_to_run
26
+
24
27
  RunitMan.run!
25
28
 
@@ -36,7 +36,7 @@ class ServiceInfo
36
36
  end
37
37
 
38
38
  def stat
39
- @status.inactive? ? 'inactive' : @status.to_s
39
+ @status.to_s
40
40
  end
41
41
 
42
42
  def active?
@@ -54,6 +54,7 @@ class ServiceStatus
54
54
  end
55
55
 
56
56
  def to_s
57
+ return 'inactive' if inactive?
57
58
  # try to mimics stat behaviour to minimize readings
58
59
  result = status_string
59
60
  result += ', got TERM' if got_term?
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 8
8
- - 4
9
- version: 1.8.4
7
+ - 9
8
+ - 0
9
+ version: 1.9.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Akzhan Abdulin
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-11 00:00:00 +04:00
17
+ date: 2010-07-19 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency