runit-man 1.4.9 → 1.5.0

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.
@@ -35,3 +35,10 @@ runit:
35
35
  updated: "Page updated at %1"
36
36
  reload: Reload
37
37
  raw: Raw
38
+ view_file:
39
+ raw: Raw
40
+ title: 'File %1 on %2'
41
+ header: 'View %1 file on %2'
42
+ updated: "Page updated at %1"
43
+ reload: Reload
44
+
@@ -37,3 +37,9 @@ runit:
37
37
  updated: "Страница обновлена %1"
38
38
  reload: Обновить страницу
39
39
  raw: Текст
40
+ view_file:
41
+ raw: Текст
42
+ title: 'Файл %1 на %2'
43
+ header: 'Просмотр файла %1 на %2'
44
+ updated: "Страница обновлена %1"
45
+ reload: Обновить страницу
@@ -81,6 +81,29 @@ class RunitMan < Sinatra::Base
81
81
  data[:text]
82
82
  end
83
83
 
84
+ get '/view' do
85
+ if !request.GET.has_key?('file')
86
+ return not_found
87
+ end
88
+ f = request.GET['file']
89
+ return not_found unless files_to_view.include?(f)
90
+ @scripts = []
91
+ @title = t.runit.view_file.title(h(f), h(host_name))
92
+ erb :view_file, :locals => {
93
+ :name => f,
94
+ :text => IO.read(f)
95
+ }
96
+ end
97
+
98
+ get '/view.txt' do
99
+ if !request.GET.has_key?('file')
100
+ return not_found
101
+ end
102
+ f = request.GET['file']
103
+ return not_found unless files_to_view.include?(f)
104
+ IO.read(f)
105
+ end
106
+
84
107
  def log_action(name, text)
85
108
  env = request.env
86
109
  addr = env.include?('X_REAL_IP') ? env['X_REAL_IP'] : env['REMOTE_ADDR']
@@ -112,6 +135,14 @@ class RunitMan < Sinatra::Base
112
135
  do_cmd("ln -sf #{File.join(RunitMan.all_services_directory, 'runit-man')} #{File.join(RunitMan.active_services_directory, 'runit-man')}")
113
136
  end
114
137
 
138
+ def enable_view_of(file_location)
139
+ files_to_view << File.expand_path(file_location, '/')
140
+ end
141
+
142
+ def files_to_view
143
+ @files_to_view ||= []
144
+ end
145
+
115
146
  private
116
147
  def do_cmd(command)
117
148
  system(command) or raise "Cannot execute #{command}"
@@ -26,6 +26,14 @@ module Helpers
26
26
  ServiceInfo.all
27
27
  end
28
28
 
29
+ def files_to_view
30
+ RunitMan.files_to_view.map do |f|
31
+ File.symlink?(f) ? File.expand_path(File.readlink(f), File.dirname(f)) : f
32
+ end.select do |f|
33
+ File.readable?(f)
34
+ end.uniq.sort
35
+ end
36
+
29
37
  def service_action(name, action, label)
30
38
  partial :service_action, :locals => {
31
39
  :name => name,
@@ -5,11 +5,16 @@ RunitMan.set :active_services_directory, '/etc/service'
5
5
  RunitMan.set :all_services_directory, '/etc/sv'
6
6
 
7
7
  OptionParser.new { |op|
8
+ op.separator 'Server options:'
8
9
  op.on('-s server') { |val| RunitMan.set :server, val }
9
10
  op.on('-p port') { |val| RunitMan.set :port, val.to_i }
10
11
  op.on('-b addr') { |val| RunitMan.set :bind, val } if RunitMan.respond_to?(:bind)
12
+ op.separator 'runit options:'
11
13
  op.on('-a active_services_directory (/etc/service by default)') { |val| RunitMan.set :active_services_directory, val }
12
14
  op.on('-f all_services_directory (/etc/sv by default)') { |val| RunitMan.set :all_services_directory, val }
15
+ op.separator 'View options:'
16
+ op.on('-v file_location', 'Enables view of specified file through runit-man') { |val| RunitMan.enable_view_of(val) }
17
+ op.separator 'Configuration options:'
13
18
  op.on_tail('-r', '--register', 'Register as runit service') do
14
19
  RunitMan.register_as_runit_service
15
20
  exit
@@ -18,3 +18,8 @@
18
18
  <%= partial(:service_info, :collection => service_infos) %>
19
19
  </tbody>
20
20
  </table>
21
+ <ul>
22
+ <% files_to_view.each do |f| %>
23
+ <li><a target="_blank" href="/view?file=<%= h(f) %>"><%= h(f) %></a></li>
24
+ <% end %>
25
+ </ul>
@@ -0,0 +1,10 @@
1
+ <% content_for :content do %>
2
+ <%= t.runit.view_file.header(h(name), h(host_name)) %> | <a href="/view.txt?file=<% h(name) %>"><%= t.runit.view_file.raw %></a>
3
+
4
+ <pre><%= h(text) %></pre>
5
+ <% end %>
6
+ <% content_for :footer do %>
7
+ <p>
8
+ <%= t.runit.view_file.updated(Time.now.utc) %> <a href="javascript:;" rel="nofollow" onclick="window.location.reload()"><%= t.view_file.reload %></a>
9
+ </p>
10
+ <% end %>
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 4
8
- - 9
9
- version: 1.4.9
7
+ - 5
8
+ - 0
9
+ version: 1.5.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-04-05 00:00:00 +04:00
17
+ date: 2010-04-09 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -147,6 +147,7 @@ files:
147
147
  - public/css/tripoli.type.css
148
148
  - views/log.erb
149
149
  - views/layout.erb
150
+ - views/view_file.erb
150
151
  - views/index.erb
151
152
  - views/_services.erb
152
153
  - views/_service_action.erb