ts-admin 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app.rb +2 -1
- data/controller/remap.rb +45 -18
- data/layout/default.xhtml +1 -1
- data/lib/ts-admin/traffic_server.rb +66 -79
- data/lib/ts-admin/version.rb +1 -1
- data/view/remap/form.xhtml +1 -1
- data/view/remap/list.xhtml +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cfd3ae8690d1a8d7947db457375f7ef7b1cb93b
|
4
|
+
data.tar.gz: d873461743c02ff698fd70dccf7c595399ec7977
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25cc66b1569c8319b3e5a2340db91438c5aea729050216124cc5ddaf84ecd4000fa0c83d946725a7c192740b8cc557507f71842af139b4defae30ee1754f62db
|
7
|
+
data.tar.gz: e2b9b88282ee405f46ca8137ab511511661cf11f89b993ffdb2b75204c7cc656993820171dbac30f9259c3f10e451220e1a626fcc92392e4a215cd05082e3350
|
data/app.rb
CHANGED
data/controller/remap.rb
CHANGED
@@ -14,13 +14,14 @@ class RemapController < Controller
|
|
14
14
|
if request.post?
|
15
15
|
@from = request[:from]
|
16
16
|
@to = request[:to]
|
17
|
-
if traffic_server.
|
17
|
+
if (entry = traffic_server.new_remap_entry(@type, @from, @to)).valid?
|
18
|
+
traffic_server.remap_entries << entry
|
18
19
|
traffic_server.save
|
19
20
|
restart_traffic_server
|
20
|
-
flash[:info] = "
|
21
|
+
flash[:info] = "#{entry.type.to_s.capitalize} definition added"
|
21
22
|
call(r('/'))
|
22
23
|
else
|
23
|
-
|
24
|
+
set_errors(entry)
|
24
25
|
render_view :form
|
25
26
|
end
|
26
27
|
else
|
@@ -37,21 +38,31 @@ class RemapController < Controller
|
|
37
38
|
if request.post?
|
38
39
|
@from = request[:from]
|
39
40
|
@to = request[:to]
|
40
|
-
if traffic_server.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
if entry = traffic_server.remap_entries.get_id(@id).first
|
42
|
+
entry.from = @from
|
43
|
+
entry.to = @to
|
44
|
+
if entry.valid?
|
45
|
+
traffic_server.save
|
46
|
+
restart_traffic_server
|
47
|
+
flash[:info] = "#{entry.type.to_s.capitalize} definition updated"
|
48
|
+
call(r('/'))
|
49
|
+
else
|
50
|
+
set_errors(entry)
|
51
|
+
render_view :form
|
52
|
+
end
|
45
53
|
else
|
46
|
-
flash[:error] = "
|
54
|
+
flash[:error] = "Remap definition not found"
|
47
55
|
render_view :form
|
48
56
|
end
|
49
57
|
else
|
50
|
-
@entry = traffic_server.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
58
|
+
if @entry = traffic_server.remap_entries.get_id(@id).first
|
59
|
+
@type = @entry.type
|
60
|
+
@from = @entry.from
|
61
|
+
@to = @entry.to
|
62
|
+
render_view :form
|
63
|
+
else
|
64
|
+
call(r('/'))
|
65
|
+
end
|
55
66
|
end
|
56
67
|
end
|
57
68
|
|
@@ -59,11 +70,14 @@ class RemapController < Controller
|
|
59
70
|
return unless login_required
|
60
71
|
set_env
|
61
72
|
|
62
|
-
|
63
|
-
traffic_server.save
|
64
|
-
restart_traffic_server
|
73
|
+
@id = request[:id]
|
65
74
|
|
66
|
-
|
75
|
+
if entry = traffic_server.remap_entries.get_id(@id).first
|
76
|
+
traffic_server.remap_entries.delete(entry)
|
77
|
+
traffic_server.save
|
78
|
+
restart_traffic_server
|
79
|
+
flash[:info] = "#{entry.type.to_s.capitalize} definition removed"
|
80
|
+
end
|
67
81
|
|
68
82
|
call(r('/'))
|
69
83
|
end
|
@@ -83,4 +97,17 @@ class RemapController < Controller
|
|
83
97
|
@type = request[:type]
|
84
98
|
end
|
85
99
|
|
100
|
+
def set_errors(entry)
|
101
|
+
case entry.errors.first
|
102
|
+
when :type_invalid
|
103
|
+
flash[:error] = "Invalid remap type: #{entry.type.to_s}"
|
104
|
+
when :from_invalid
|
105
|
+
flash[:error] = "Invalid from: #{entry.from.to_s}"
|
106
|
+
when :to_invalid
|
107
|
+
flash[:error] = "Invalid to: #{entry.to.to_s}"
|
108
|
+
when :duplicate_entry
|
109
|
+
flash[:error] = "Duplicate remap definition"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
86
113
|
end
|
data/layout/default.xhtml
CHANGED
@@ -39,7 +39,7 @@
|
|
39
39
|
<footer id="footer">
|
40
40
|
<p>
|
41
41
|
© 2012-2013 <a href="http://www.sic-software.com/">SIC! Software GmbH</a><br />
|
42
|
-
<a href="https://github.com/SICSoftwareGmbH/TSAdmin">TSAdmin</a> is free software and is licensed under the MIT license.
|
42
|
+
<a href="https://github.com/SICSoftwareGmbH/TSAdmin">TSAdmin</a> (v#{TSAdmin::VERSION}) is free software and is licensed under the MIT license.
|
43
43
|
</p>
|
44
44
|
</footer>
|
45
45
|
</div>
|
@@ -5,89 +5,87 @@ module TSAdmin
|
|
5
5
|
class TrafficServer
|
6
6
|
MARKER_TEXT = "CONFIGURATION FROM TSADMIN"
|
7
7
|
|
8
|
-
|
9
|
-
@options = {
|
10
|
-
'config_path' => '/etc/trafficserver',
|
11
|
-
'restart_cmd' => '/etc/init.d/trafficserver restart'
|
12
|
-
}.merge(options)
|
13
|
-
@config_path = @options['config_path']
|
14
|
-
end
|
15
|
-
|
16
|
-
def redirects
|
17
|
-
load unless defined?(@redirects)
|
18
|
-
@redirects.dup.freeze
|
19
|
-
end
|
20
|
-
|
21
|
-
def maps
|
22
|
-
load unless defined?(@maps)
|
23
|
-
@maps.dup.freeze
|
24
|
-
end
|
8
|
+
class RemapError < StandardError; end
|
25
9
|
|
26
|
-
|
27
|
-
|
10
|
+
class ValidatingArray < Array
|
11
|
+
class InvalidObject < StandardError; end
|
12
|
+
def add(o)
|
13
|
+
raise InvalidObject unless o.respond_to?(:valid?) && o.valid?
|
14
|
+
super
|
15
|
+
end
|
16
|
+
def method_missing(m, *args, &block)
|
17
|
+
if m.to_s =~ /^get_(\w+)$/ && args.count == 1
|
18
|
+
select{|i| i.respond_to?($1) && i.send($1) == args[0]}
|
19
|
+
else
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
28
23
|
end
|
29
24
|
|
30
|
-
|
31
|
-
|
25
|
+
class RemapEntry
|
26
|
+
attr_accessor :type, :id, :from, :to
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
28
|
+
def initialize(ts, type, from, to)
|
29
|
+
@ts = ts
|
30
|
+
@type = type.to_sym
|
31
|
+
@from = from.downcase
|
32
|
+
@to = to.downcase
|
33
|
+
@id = Digest::SHA1.hexdigest(@from)
|
34
|
+
end
|
41
35
|
|
42
|
-
|
36
|
+
def valid?
|
37
|
+
errors.count == 0
|
38
|
+
end
|
43
39
|
|
44
|
-
|
45
|
-
|
40
|
+
def errors
|
41
|
+
e = []
|
42
|
+
e << :type_invalid unless [:map, :redirect].include?(@type)
|
43
|
+
e << :from_invalid unless valid_url?(@from)
|
44
|
+
e << :to_invalid unless valid_url?(@to)
|
45
|
+
e << :duplicate_entry unless @ts.remap_entries.get_from(@from).select{|e| e != self}.count == 0
|
46
|
+
e.compact.uniq
|
47
|
+
end
|
46
48
|
|
47
|
-
|
49
|
+
private
|
48
50
|
|
49
|
-
|
51
|
+
def valid_url?(url)
|
52
|
+
!!(url =~ URI::regexp) rescue false
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
entry[:id] = Digest::SHA1.hexdigest("#{from}_#{to}")
|
56
|
+
def initialize(options={})
|
57
|
+
@options = {
|
58
|
+
'config_path' => '/etc/trafficserver',
|
59
|
+
'restart_cmd' => '/etc/init.d/trafficserver restart'
|
60
|
+
}.merge(options)
|
61
|
+
@config_path = @options['config_path']
|
59
62
|
end
|
60
63
|
|
61
|
-
def
|
62
|
-
load
|
63
|
-
|
64
|
-
|
65
|
-
@redirects.delete_if{|m| m[:id] == id}
|
64
|
+
def remap_entries
|
65
|
+
load unless defined?(@remap_entries)
|
66
|
+
@remap_entries
|
67
|
+
end
|
66
68
|
|
67
|
-
|
69
|
+
def new_remap_entry(type, from, to)
|
70
|
+
RemapEntry.new(self, type, from, to)
|
68
71
|
end
|
69
72
|
|
70
73
|
def save
|
71
74
|
own_config = ''
|
72
|
-
own_config << "#{marker_begin}\n"
|
73
|
-
|
74
|
-
|
75
|
-
own_config << "redirect #{redirect[:from]} #{redirect[:to]} #{options}\n"
|
76
|
-
end
|
77
|
-
maps.each do |map|
|
78
|
-
options = map[:options] ? '' : ''
|
79
|
-
own_config << "map #{map[:from]} #{map[:to]} #{options}\n"
|
75
|
+
own_config << "#{self.class.marker_begin}\n"
|
76
|
+
remap_entries.each do |remap_entry|
|
77
|
+
own_config << "#{remap_entry.type.to_s} #{remap_entry.from} #{remap_entry.to}\n"
|
80
78
|
end
|
81
|
-
own_config << "#{marker_end}\n"
|
79
|
+
own_config << "#{self.class.marker_end}\n"
|
82
80
|
|
83
81
|
file_content = ''
|
84
82
|
in_config_block = false
|
85
83
|
own_config_written = false
|
86
84
|
File.read(remap_path).each_line do |line|
|
87
|
-
if line.strip == marker_begin
|
85
|
+
if line.strip == self.class.marker_begin
|
88
86
|
in_config_block = true
|
89
87
|
next
|
90
|
-
elsif line.strip == marker_end
|
88
|
+
elsif line.strip == self.class.marker_end
|
91
89
|
in_config_block = false
|
92
90
|
next
|
93
91
|
end
|
@@ -112,28 +110,19 @@ module TSAdmin
|
|
112
110
|
|
113
111
|
private
|
114
112
|
|
115
|
-
def marker_begin
|
116
|
-
"# BEGIN #{MARKER_TEXT}"
|
117
|
-
end
|
118
|
-
|
119
|
-
def marker_end
|
120
|
-
"# END #{MARKER_TEXT}"
|
121
|
-
end
|
122
|
-
|
123
113
|
def remap_path
|
124
114
|
File.join(@config_path, 'remap.config')
|
125
115
|
end
|
126
116
|
|
127
117
|
def load
|
128
|
-
@
|
129
|
-
@maps = []
|
118
|
+
@remap_entries = ValidatingArray.new
|
130
119
|
|
131
120
|
in_config_block = false
|
132
121
|
File.read(remap_path).each_line do |line|
|
133
|
-
if line.strip == marker_begin
|
122
|
+
if line.strip == self.class.marker_begin
|
134
123
|
in_config_block = true
|
135
124
|
next
|
136
|
-
elsif line.strip == marker_end
|
125
|
+
elsif line.strip == self.class.marker_end
|
137
126
|
in_config_block = false
|
138
127
|
next
|
139
128
|
end
|
@@ -141,19 +130,17 @@ module TSAdmin
|
|
141
130
|
next unless in_config_block
|
142
131
|
|
143
132
|
type, from, to, *options = line.split(/\s+/)
|
144
|
-
|
145
|
-
|
146
|
-
when :redirect
|
147
|
-
@redirects << {:id => id, :type => type.to_sym, :from => from, :to => to, :options => {}}
|
148
|
-
when :map
|
149
|
-
@maps << {:id => id, :type => type.to_sym, :from => from, :to => to, :options => {}}
|
150
|
-
end
|
133
|
+
@remap_entries << RemapEntry.new(self, type, from, to)
|
134
|
+
@remap_entries.delete_if{|e| !e.valid?}
|
151
135
|
end
|
152
136
|
end
|
153
137
|
|
154
|
-
def
|
155
|
-
|
138
|
+
def self.marker_begin
|
139
|
+
"# BEGIN #{MARKER_TEXT}"
|
156
140
|
end
|
157
141
|
|
142
|
+
def self.marker_end
|
143
|
+
"# END #{MARKER_TEXT}"
|
144
|
+
end
|
158
145
|
end
|
159
146
|
end
|
data/lib/ts-admin/version.rb
CHANGED
data/view/remap/form.xhtml
CHANGED
data/view/remap/list.xhtml
CHANGED
@@ -7,14 +7,14 @@
|
|
7
7
|
</header>
|
8
8
|
<p>
|
9
9
|
<ul class="remap">
|
10
|
-
<?r @traffic_server.
|
10
|
+
<?r @traffic_server.remap_entries.get_type(@type.to_sym).each do |entry| ?>
|
11
11
|
<li>
|
12
|
-
<span class="url from"><a href="#{
|
12
|
+
<span class="url from"><a href="#{entry.from}">#{remap_url_highlight_scheme(entry.from)}</a></span>
|
13
13
|
<span class="arrow icon-chevron-right"></span>
|
14
|
-
<span class="url to"><a href="#{
|
14
|
+
<span class="url to"><a href="#{entry.to}">#{remap_url_highlight_scheme(entry.to)}</a></span>
|
15
15
|
<span class="buttons">
|
16
|
-
<a class="icon-pencil" href="/remap/edit?id=#{
|
17
|
-
<a class="icon-trash" href="/remap/delete?id=#{
|
16
|
+
<a class="icon-pencil" href="/remap/edit?id=#{entry.id}" title="Edit"></a>
|
17
|
+
<a class="icon-trash" href="/remap/delete?id=#{entry.id}" title="Delete"></a>
|
18
18
|
</span>
|
19
19
|
</li>
|
20
20
|
<?r end ?>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ts-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Schwab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|