runit-man 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/runit-man/app.rb +27 -20
  2. metadata +2 -2
@@ -82,27 +82,34 @@ class RunitMan < Sinatra::Base
82
82
  data[:text]
83
83
  end
84
84
 
85
- get '/view' do
85
+ def data_of_file_view(request)
86
86
  if !request.GET.has_key?('file')
87
+ return nil
88
+ end
89
+ file_path = request.GET['file']
90
+ return nil unless files_to_view.include?(file_path)
91
+ {
92
+ :name => file_path,
93
+ :text => IO.read(file_path)
94
+ }
95
+ end
96
+
97
+ get '/view' do
98
+ data = data_of_file_view(request)
99
+ if data.nil?
87
100
  return not_found
88
101
  end
89
- f = request.GET['file']
90
- return not_found unless all_files_to_view.include?(f)
91
102
  @scripts = []
92
- @title = t.runit.view_file.title(h(f), h(host_name))
93
- erb :view_file, :locals => {
94
- :name => f,
95
- :text => IO.read(f)
96
- }
103
+ @title = t.runit.view_file.title(h(data[:name]), h(host_name))
104
+ erb :view_file, :locals => data
97
105
  end
98
106
 
99
107
  get '/view.txt' do
100
- if !request.GET.has_key?('file')
108
+ data = data_of_file_view(request)
109
+ if data.nil?
101
110
  return not_found
102
111
  end
103
- f = request.GET['file']
104
- return not_found unless files_to_view.include?(f)
105
- IO.read(f)
112
+ data[:text]
106
113
  end
107
114
 
108
115
  def log_action(name, text)
@@ -112,18 +119,18 @@ class RunitMan < Sinatra::Base
112
119
  end
113
120
 
114
121
  post '/:name/signal/:signal' do |name, signal|
115
- srv = ServiceInfo[name]
116
- return not_found if srv.nil?
117
- srv.send_signal(signal)
122
+ service = ServiceInfo[name]
123
+ return not_found if service.nil?
124
+ service.send_signal(signal)
118
125
  log_action(name, "send signal \"#{signal}\"")
119
126
  ''
120
127
  end
121
128
 
122
129
  post '/:name/:action' do |name, action|
123
- srv = ServiceInfo[name]
130
+ service = ServiceInfo[name]
124
131
  action = "#{action}!".to_sym
125
- return not_found if srv.nil? || !srv.respond_to?(action)
126
- srv.send(action)
132
+ return not_found if service.nil? || !service.respond_to?(action)
133
+ service.send(action)
127
134
  log_action(name, action)
128
135
  ''
129
136
  end
@@ -159,8 +166,8 @@ class RunitMan < Sinatra::Base
159
166
  def create_run_script(dir)
160
167
  script_name = File.join(dir, 'run')
161
168
  template_name = File.join(GEM_FOLDER, 'sv', 'run.erb')
162
- File.open(script_name, 'w') do |handle|
163
- handle.print Erubis::Eruby.new(IO.read(template_name)).result(
169
+ File.open(script_name, 'w') do |script_source|
170
+ script_source.print Erubis::Eruby.new(IO.read(template_name)).result(
164
171
  :all_services_directory => RunitMan.all_services_directory,
165
172
  :active_services_directory => RunitMan.active_services_directory,
166
173
  :port => RunitMan.port,
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 6
8
- - 1
9
- version: 1.6.1
8
+ - 2
9
+ version: 1.6.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Akzhan Abdulin