runit-man 2.2.4 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/i18n/en.yml CHANGED
@@ -4,6 +4,8 @@ en:
4
4
  title: "%{p1} - %{p2}"
5
5
  header: "%{p1}: %{p2}"
6
6
  error: Error encountered while accessing resource
7
+ errors:
8
+ invalid_encoding: "File contains octets that cannot be parsed as UTF-8 character sequences."
7
9
  loading: "Please wait while loading…"
8
10
  footer: "State of services updated automatically every %{sec} seconds."
9
11
  services:
data/i18n/ru.yml CHANGED
@@ -4,6 +4,8 @@ ru:
4
4
  title: "%{p1} - %{p2}"
5
5
  header: "%{p1}: %{p2}"
6
6
  error: Ошибка обращения к ресурсу
7
+ errors:
8
+ invalid_encoding: "Файл содержит октеты, которые не получается распознать как символьные последовательности UTF-8."
7
9
  loading: "Идёт загрузка…"
8
10
  footer: "Состояние сервисов обновляется автоматически каждые %{sec} секунд."
9
11
  services:
data/lib/runit-man/app.rb CHANGED
@@ -123,12 +123,20 @@ class RunitMan < Sinatra::Base
123
123
  srv = ServiceInfo[name]
124
124
  return nil if srv.nil? || !srv.logged?
125
125
  text = ''
126
- text.force_encoding('utf-8') if text.respond_to?(:force_encoding)
127
- File::Tail::Logfile.open(srv.log_file_location, :backward => count, :return_if_eof => true) do |log|
128
- log.tail do |line|
129
- line.force_encoding('utf-8') if line.respond_to?(:force_encoding)
130
- text += line
126
+ begin
127
+ text.force_encoding('utf-8') if text.respond_to?(:force_encoding)
128
+ File::Tail::Logfile.open(srv.log_file_location, :backward => count, :return_if_eof => true) do |log|
129
+ log.tail do |line|
130
+ if line.respond_to?(:force_encoding)
131
+ line.force_encoding('utf-8')
132
+ raise ArgumentError.new('wrong encoding') unless line.valid_encoding?
133
+ end
134
+ line.force_encoding('utf-8') if line.respond_to?(:force_encoding)
135
+ text += line
136
+ end
131
137
  end
138
+ rescue ArgumentError
139
+ text = I18n.t('runit.errors.invalid_encoding')
132
140
  end
133
141
 
134
142
  {
@@ -139,6 +147,25 @@ class RunitMan < Sinatra::Base
139
147
  }
140
148
  end
141
149
 
150
+ def data_of_file_view(request)
151
+ if !request.GET.has_key?('file')
152
+ return nil
153
+ end
154
+ file_path = request.GET['file']
155
+ return nil unless all_files_to_view.include?(file_path)
156
+ text = IO.read(file_path)
157
+ begin
158
+ text.force_encoding('utf-8') if text.respond_to?(:force_encoding)
159
+ raise ArgumentError.new('wrong encoding') unless text.valid_encoding?
160
+ rescue ArgumentError
161
+ text = I18n.t('runit.errors.invalid_encoding')
162
+ end
163
+ {
164
+ :name => file_path,
165
+ :text => text
166
+ }
167
+ end
168
+
142
169
  get %r[^/([^/]+)/log(?:/(\d+))?/?$] do |name, count|
143
170
  data = log_of_service(name, count)
144
171
  return not_found if data.nil?
@@ -169,20 +196,6 @@ class RunitMan < Sinatra::Base
169
196
  data[:text]
170
197
  end
171
198
 
172
- def data_of_file_view(request)
173
- if !request.GET.has_key?('file')
174
- return nil
175
- end
176
- file_path = request.GET['file']
177
- return nil unless all_files_to_view.include?(file_path)
178
- text = IO.read(file_path)
179
- text.force_encoding('utf-8') if text.respond_to?(:force_encoding)
180
- {
181
- :name => file_path,
182
- :text => text
183
- }
184
- end
185
-
186
199
  get '/view' do
187
200
  data = data_of_file_view(request)
188
201
  if data.nil?
@@ -1,4 +1,4 @@
1
1
  module RunitManVersion
2
- VERSION = '2.2.4'.freeze
2
+ VERSION = '2.2.5'.freeze
3
3
  end
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runit-man
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 4
10
- version: 2.2.4
9
+ - 5
10
+ version: 2.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Akzhan Abdulin