cewebs-servicesbase 3.0.1
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.
- checksums.yaml +7 -0
- data/AUTHORS +1 -0
- data/LICENSE.GPL +674 -0
- data/README.md +18 -0
- data/Rakefile +25 -0
- data/cewebs-servicesbase.gemspec +28 -0
- data/contracts/administration.xml +55 -0
- data/contracts/delivery.xml +59 -0
- data/contracts/notification.xml +20 -0
- data/contracts/report.xml +42 -0
- data/contracts/repository.xml +64 -0
- data/lib/cewebs-servicesbase/configuration.rb +93 -0
- data/lib/cewebs-servicesbase/password.rb +39 -0
- data/lib/cewebs-servicesbase/scaffold.rb +27 -0
- data/lib/cewebs-servicesbase/service.rb +379 -0
- data/lib/cewebs-servicesbase/strings.rb +36 -0
- data/lib/cewebs-servicesbase/view.rb +73 -0
- data/server/data/Default/aman.xml +10 -0
- data/server/data/Default/custom.rng +11 -0
- data/server/data/Default/custom.xml +3 -0
- data/server/data/repositories.xml +3 -0
- data/server/service +54 -0
- data/server/service.riddl.xml +14 -0
- data/server/service.xml +10 -0
- data/test/tc_configuration.rb +29 -0
- data/tools/cewebs-servicesbase +26 -0
- metadata +138 -0
data/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# CEWebS Services Base
|
|
2
|
+
|
|
3
|
+
Contracts (riddl) and code that is used by all services of CEWebS. Start your own service with the sample:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
cewebs-servicesbase new hello # scaffold the sample
|
|
7
|
+
hello/service start # port 9030
|
|
8
|
+
cewebs-aman service aman hello # the AMan in the directory aman offers the service
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Change the port in `hello/service`, and the identifier, addresses and descriptions in `hello/service.xml`, before
|
|
12
|
+
the AMan is told about the service.
|
|
13
|
+
|
|
14
|
+
See the README of `cewebs-transformationengine` for how all parts of CEWebS work together.
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
GPL-3.0-or-later, see LICENSE.GPL.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rubygems/package_task'
|
|
3
|
+
require 'rake/testtask'
|
|
4
|
+
|
|
5
|
+
Rake::TestTask.new do |t|
|
|
6
|
+
t.test_files = FileList['./test/tc_*.rb']
|
|
7
|
+
t.warning = false
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
spec = eval(File.read('cewebs-servicesbase.gemspec'))
|
|
11
|
+
Gem::PackageTask.new(spec) do |pkg|
|
|
12
|
+
FileUtils.mkdir 'pkg' rescue nil
|
|
13
|
+
FileUtils.rm_rf Dir.glob('pkg/*')
|
|
14
|
+
FileUtils.ln_sf "#{pkg.name}.gem", "pkg/#{spec.name}.gem"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
task :default => :gem
|
|
18
|
+
|
|
19
|
+
task :push => :gem do |r|
|
|
20
|
+
sh "gem push pkg/#{spec.name}.gem"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
task :install => :gem do |r|
|
|
24
|
+
sh "gem install pkg/#{spec.name}.gem"
|
|
25
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "cewebs-servicesbase"
|
|
3
|
+
s.version = "3.0.1"
|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
|
5
|
+
s.license = "GPL-3.0-or-later"
|
|
6
|
+
s.summary = "Base for all services of CEWebS"
|
|
7
|
+
|
|
8
|
+
s.description = "Contracts (riddl) and code that is used by all services of CEWebS. Scaffolds new services."
|
|
9
|
+
|
|
10
|
+
s.files = Dir['{contracts/**/*,server/**/*,tools/**/*,lib/**/*}'] + %w(LICENSE.GPL Rakefile cewebs-servicesbase.gemspec README.md AUTHORS)
|
|
11
|
+
s.require_path = 'lib'
|
|
12
|
+
s.extra_rdoc_files = ['README.md']
|
|
13
|
+
s.bindir = 'tools'
|
|
14
|
+
s.executables = ['cewebs-servicesbase']
|
|
15
|
+
s.test_files = Dir['test/tc_*.rb']
|
|
16
|
+
|
|
17
|
+
s.required_ruby_version = '>=3.2'
|
|
18
|
+
|
|
19
|
+
s.authors = ['Juergen eTM Mangler']
|
|
20
|
+
s.email = 'juergen.mangler@gmail.com'
|
|
21
|
+
s.homepage = 'http://www.cewebs.org'
|
|
22
|
+
|
|
23
|
+
s.add_runtime_dependency 'riddl', '~> 1.0'
|
|
24
|
+
s.add_runtime_dependency 'thin', '~> 1.8'
|
|
25
|
+
s.add_runtime_dependency 'markus', '~> 4.0'
|
|
26
|
+
s.add_runtime_dependency 'xml-smart', '~> 0.5'
|
|
27
|
+
s.add_runtime_dependency 'redel', '~> 3.1'
|
|
28
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Administration: how the AMan manages instances and configuration of a service.
|
|
3
|
+
Replaces CEWebSAdministration.wsdl.
|
|
4
|
+
|
|
5
|
+
POST / createInstance
|
|
6
|
+
DELETE /{instance} deleteInstance
|
|
7
|
+
GET /{instance}/parts getConfigurationParts
|
|
8
|
+
PUT /{instance}/parts/{part} setConfiguration
|
|
9
|
+
GET /{instance}/entrypoints getEntryPoints
|
|
10
|
+
-->
|
|
11
|
+
<description xmlns="http://riddl.org/ns/description/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
|
12
|
+
<message name="create">
|
|
13
|
+
<parameter name="authentication" type="string"/>
|
|
14
|
+
<parameter name="key" type="string"/>
|
|
15
|
+
<parameter name="description" type="string"/>
|
|
16
|
+
</message>
|
|
17
|
+
<message name="key">
|
|
18
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
19
|
+
</message>
|
|
20
|
+
<message name="change">
|
|
21
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
22
|
+
<parameter name="operation" type="string">
|
|
23
|
+
<choice>
|
|
24
|
+
<value>valueDelete</value>
|
|
25
|
+
<value>valueAdd</value>
|
|
26
|
+
<value>valueReplace</value>
|
|
27
|
+
<value>treeDelete</value>
|
|
28
|
+
<value>treeAdd</value>
|
|
29
|
+
<value>treeAddDynamic</value>
|
|
30
|
+
<value>treeReplace</value>
|
|
31
|
+
</choice>
|
|
32
|
+
</parameter>
|
|
33
|
+
<parameter name="path" type="string"/>
|
|
34
|
+
<parameter name="xml" type="string"/>
|
|
35
|
+
</message>
|
|
36
|
+
<message name="xml">
|
|
37
|
+
<parameter name="result" mimetype="text/xml"/>
|
|
38
|
+
</message>
|
|
39
|
+
|
|
40
|
+
<resource>
|
|
41
|
+
<post in="create" out="xml"/>
|
|
42
|
+
<resource>
|
|
43
|
+
<delete in="key"/>
|
|
44
|
+
<resource relative="parts">
|
|
45
|
+
<get in="key" out="xml"/>
|
|
46
|
+
<resource>
|
|
47
|
+
<put in="change" out="xml"/>
|
|
48
|
+
</resource>
|
|
49
|
+
</resource>
|
|
50
|
+
<resource relative="entrypoints">
|
|
51
|
+
<get in="key" out="xml"/>
|
|
52
|
+
</resource>
|
|
53
|
+
</resource>
|
|
54
|
+
</resource>
|
|
55
|
+
</description>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Delivery: how the TransformationEngine gets content from a service.
|
|
3
|
+
Replaces CEWebSDelivery.wsdl (prepare, getDocument, getFile, getChunk).
|
|
4
|
+
|
|
5
|
+
/{instance}/{prepare|document|file|chunk}/{command}
|
|
6
|
+
|
|
7
|
+
Request headers: CEWEBS-KEY (mandatory), CEWEBS-USER, CEWEBS-LANGUAGE (comma
|
|
8
|
+
separated), CEWEBS-MODIFIED (iso8601, age of the copy in the engine cache).
|
|
9
|
+
All parameters belong to the command.
|
|
10
|
+
|
|
11
|
+
The engine calls prepare before document and file, in order to find out if a user is
|
|
12
|
+
necessary. It does not for chunk, so services have to check the user themselves.
|
|
13
|
+
-->
|
|
14
|
+
<description xmlns="http://riddl.org/ns/description/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
|
15
|
+
<message name="command">
|
|
16
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
17
|
+
<zeroOrMore>
|
|
18
|
+
<choice>
|
|
19
|
+
<parameter name="*" type="string"/>
|
|
20
|
+
<parameter name="*" mimetype="*"/>
|
|
21
|
+
</choice>
|
|
22
|
+
</zeroOrMore>
|
|
23
|
+
</message>
|
|
24
|
+
<message name="xml">
|
|
25
|
+
<parameter name="result" mimetype="text/xml"/>
|
|
26
|
+
</message>
|
|
27
|
+
<message name="content">
|
|
28
|
+
<parameter name="result" mimetype="*"/>
|
|
29
|
+
</message>
|
|
30
|
+
|
|
31
|
+
<resource>
|
|
32
|
+
<resource>
|
|
33
|
+
<resource relative="prepare">
|
|
34
|
+
<resource>
|
|
35
|
+
<get in="command" out="xml"/>
|
|
36
|
+
<post in="command" out="xml"/>
|
|
37
|
+
</resource>
|
|
38
|
+
</resource>
|
|
39
|
+
<resource relative="document">
|
|
40
|
+
<resource>
|
|
41
|
+
<get in="command" out="xml"/>
|
|
42
|
+
<post in="command" out="xml"/>
|
|
43
|
+
</resource>
|
|
44
|
+
</resource>
|
|
45
|
+
<resource relative="file">
|
|
46
|
+
<resource>
|
|
47
|
+
<get in="command" out="content"/>
|
|
48
|
+
<post in="command" out="content"/>
|
|
49
|
+
</resource>
|
|
50
|
+
</resource>
|
|
51
|
+
<resource relative="chunk">
|
|
52
|
+
<resource>
|
|
53
|
+
<get in="command" out="content"/>
|
|
54
|
+
<post in="command" out="content"/>
|
|
55
|
+
</resource>
|
|
56
|
+
</resource>
|
|
57
|
+
</resource>
|
|
58
|
+
</resource>
|
|
59
|
+
</description>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Notification: an engine or a service tells the AMan that it changed its own
|
|
3
|
+
configuration. Replaces CEWebSNotification.wsdl.
|
|
4
|
+
|
|
5
|
+
PUT /{part} changeConfiguration
|
|
6
|
+
-->
|
|
7
|
+
<description xmlns="http://riddl.org/ns/description/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
|
8
|
+
<message name="change">
|
|
9
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
10
|
+
<parameter name="operation" type="string"/>
|
|
11
|
+
<parameter name="path" type="string"/>
|
|
12
|
+
<parameter name="xml" type="string"/>
|
|
13
|
+
</message>
|
|
14
|
+
|
|
15
|
+
<resource>
|
|
16
|
+
<resource>
|
|
17
|
+
<put in="change"/>
|
|
18
|
+
</resource>
|
|
19
|
+
</resource>
|
|
20
|
+
</description>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Report: how the RMan gets reports from a service.
|
|
3
|
+
Replaces CEWebSReport.wsdl.
|
|
4
|
+
|
|
5
|
+
GET /{instance} getReportList
|
|
6
|
+
GET /{instance}/{report}/pages/{page} getReportParameters
|
|
7
|
+
POST /{instance}/{report} getReport
|
|
8
|
+
-->
|
|
9
|
+
<description xmlns="http://riddl.org/ns/description/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
|
10
|
+
<message name="key">
|
|
11
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
12
|
+
</message>
|
|
13
|
+
<message name="parameters">
|
|
14
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
15
|
+
<zeroOrMore>
|
|
16
|
+
<choice>
|
|
17
|
+
<parameter name="*" type="string"/>
|
|
18
|
+
<parameter name="*" mimetype="*"/>
|
|
19
|
+
</choice>
|
|
20
|
+
</zeroOrMore>
|
|
21
|
+
</message>
|
|
22
|
+
<message name="xml">
|
|
23
|
+
<parameter name="result" mimetype="text/xml"/>
|
|
24
|
+
</message>
|
|
25
|
+
<message name="report">
|
|
26
|
+
<parameter name="result" mimetype="*"/>
|
|
27
|
+
</message>
|
|
28
|
+
|
|
29
|
+
<resource>
|
|
30
|
+
<resource>
|
|
31
|
+
<get in="key" out="xml"/>
|
|
32
|
+
<resource>
|
|
33
|
+
<post in="parameters" out="report"/>
|
|
34
|
+
<resource relative="pages">
|
|
35
|
+
<resource>
|
|
36
|
+
<get in="parameters" out="xml"/>
|
|
37
|
+
</resource>
|
|
38
|
+
</resource>
|
|
39
|
+
</resource>
|
|
40
|
+
</resource>
|
|
41
|
+
</resource>
|
|
42
|
+
</description>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Repository: how a TransformationEngine registers itself and its services.
|
|
3
|
+
Replaces CEWebSRepository.wsdl. CEWEBS-KEY is the key of the engine, which is
|
|
4
|
+
returned by the initial POST.
|
|
5
|
+
|
|
6
|
+
POST / registerWithRepository
|
|
7
|
+
PUT / newEngineLocation
|
|
8
|
+
GET /available getServices
|
|
9
|
+
POST /services registerService
|
|
10
|
+
PUT /services/{service} rename
|
|
11
|
+
DELETE /services/{service} unregisterService
|
|
12
|
+
GET /services/{service}/entrypoints getEntryPoints
|
|
13
|
+
GET /services/{service}/reports hasServiceReports
|
|
14
|
+
GET /shared getSharedParts
|
|
15
|
+
-->
|
|
16
|
+
<description xmlns="http://riddl.org/ns/description/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
|
17
|
+
<message name="register">
|
|
18
|
+
<parameter name="key" type="string"/>
|
|
19
|
+
<parameter name="link" type="string"/>
|
|
20
|
+
</message>
|
|
21
|
+
<message name="location">
|
|
22
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
23
|
+
<parameter name="link" type="string"/>
|
|
24
|
+
</message>
|
|
25
|
+
<message name="service">
|
|
26
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
27
|
+
<parameter name="id" type="integer"/>
|
|
28
|
+
<parameter name="comment" type="string"/>
|
|
29
|
+
</message>
|
|
30
|
+
<message name="rename">
|
|
31
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
32
|
+
<parameter name="comment" type="string"/>
|
|
33
|
+
</message>
|
|
34
|
+
<message name="key">
|
|
35
|
+
<header name="CEWEBS-KEY" type="string"/>
|
|
36
|
+
</message>
|
|
37
|
+
<message name="xml">
|
|
38
|
+
<parameter name="result" mimetype="text/xml"/>
|
|
39
|
+
</message>
|
|
40
|
+
|
|
41
|
+
<resource>
|
|
42
|
+
<post in="register" out="xml"/>
|
|
43
|
+
<put in="location"/>
|
|
44
|
+
<resource relative="available">
|
|
45
|
+
<get in="key" out="xml"/>
|
|
46
|
+
</resource>
|
|
47
|
+
<resource relative="services">
|
|
48
|
+
<post in="service" out="xml"/>
|
|
49
|
+
<resource>
|
|
50
|
+
<put in="rename"/>
|
|
51
|
+
<delete in="key"/>
|
|
52
|
+
<resource relative="entrypoints">
|
|
53
|
+
<get in="key" out="xml"/>
|
|
54
|
+
</resource>
|
|
55
|
+
<resource relative="reports">
|
|
56
|
+
<get in="key" out="xml"/>
|
|
57
|
+
</resource>
|
|
58
|
+
</resource>
|
|
59
|
+
</resource>
|
|
60
|
+
<resource relative="shared">
|
|
61
|
+
<get in="key" out="xml"/>
|
|
62
|
+
</resource>
|
|
63
|
+
</resource>
|
|
64
|
+
</description>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
2
|
+
require 'xml/smart'
|
|
3
|
+
|
|
4
|
+
module CEWebS
|
|
5
|
+
# Changes in configuration files. The same operation is applied by the AMan (to
|
|
6
|
+
# its copy), by the services, and by the engine.
|
|
7
|
+
module Configuration
|
|
8
|
+
# condition in a path, the texts in it can contain everything
|
|
9
|
+
PREDICATE = /(?<predicate>\[(?:[^\[\]"']|"[^"]*"|'[^']*'|\g<predicate>)*\])/
|
|
10
|
+
|
|
11
|
+
# text in a condition
|
|
12
|
+
def self::literal(text) #{{{
|
|
13
|
+
return "\"#{text}\"" unless text.include?('"')
|
|
14
|
+
return "'#{text}'" unless text.include?("'")
|
|
15
|
+
'concat(' + text.split(/(")/).reject(&:empty?).map { |t| t == '"' ? %q{'"'} : "\"#{t}\"" }.join(',') + ')'
|
|
16
|
+
end #}}}
|
|
17
|
+
|
|
18
|
+
# path without conditions: a/b[@id="x"]/c => a/b/c
|
|
19
|
+
# If there are multiple paths (connected by |) the last one is the actual path.
|
|
20
|
+
def self::plain(path) #{{{
|
|
21
|
+
path.gsub(PREDICATE,'').split('|').last.to_s.sub(/\A\/+/,'')
|
|
22
|
+
end #}}}
|
|
23
|
+
|
|
24
|
+
def self::apply(file,operation,path,xml='') #{{{
|
|
25
|
+
node = nil
|
|
26
|
+
if %w{treeAdd treeAddDynamic treeReplace}.include?(operation)
|
|
27
|
+
raise 'The piece of xml you return is empty!' if xml.to_s.strip == ''
|
|
28
|
+
node = XML::Smart.string(xml).root
|
|
29
|
+
end
|
|
30
|
+
XML::Smart.modify(file) do |doc|
|
|
31
|
+
case operation
|
|
32
|
+
when 'treeDelete', 'valueDelete'
|
|
33
|
+
doc.find("(#{path})[1]").delete_all!
|
|
34
|
+
when 'treeAdd', 'treeAddDynamic'
|
|
35
|
+
# the path selects all elements the new one can be placed after
|
|
36
|
+
pos = doc.find(path).last
|
|
37
|
+
if pos
|
|
38
|
+
pos.add_after node
|
|
39
|
+
else
|
|
40
|
+
parent = parent(path)
|
|
41
|
+
first = doc.find(parent + '/*').first
|
|
42
|
+
first ? first.add_before(node) : doc.find(parent).first.add(node)
|
|
43
|
+
end
|
|
44
|
+
when 'treeReplace'
|
|
45
|
+
old = doc.find(path).first
|
|
46
|
+
if old
|
|
47
|
+
old.replace_by node
|
|
48
|
+
else
|
|
49
|
+
doc.find(parent(path)).first.add node
|
|
50
|
+
end
|
|
51
|
+
when 'valueAdd'
|
|
52
|
+
name = path[/[^\/]+\z/]
|
|
53
|
+
doc.find(parent(path)).each do |ele|
|
|
54
|
+
if name[0] == '@'
|
|
55
|
+
ele.attributes[name[1..-1]] = xml
|
|
56
|
+
else
|
|
57
|
+
ele.add(name,xml)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
when 'valueReplace'
|
|
61
|
+
doc.find(path).each do |ele|
|
|
62
|
+
ele.is_a?(XML::Smart::Dom::Attribute) ? ele.value = xml : ele.text = xml
|
|
63
|
+
end
|
|
64
|
+
else
|
|
65
|
+
raise "Operation #{operation} not known!"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end #}}}
|
|
69
|
+
|
|
70
|
+
# new order for the children of path, returns the resulting xml
|
|
71
|
+
def self::sort(file,path,order) #{{{
|
|
72
|
+
ret = nil
|
|
73
|
+
XML::Smart.modify(file) do |doc|
|
|
74
|
+
doc.find(path).each do |p|
|
|
75
|
+
order.each do |o|
|
|
76
|
+
p.find('.' + o).each do |ele|
|
|
77
|
+
ele.parent.add(ele)
|
|
78
|
+
ret = p
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
ret = ret.dump if ret
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
ret
|
|
85
|
+
end #}}}
|
|
86
|
+
|
|
87
|
+
# everything up to the last / outside of conditions
|
|
88
|
+
def self::parent(path) #{{{
|
|
89
|
+
i = path.gsub(PREDICATE) { |m| ' ' * m.length }.rindex('/') or return '.'
|
|
90
|
+
i == 0 ? '/' : path[0...i]
|
|
91
|
+
end #}}}
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
2
|
+
require 'digest/sha2'
|
|
3
|
+
require 'openssl'
|
|
4
|
+
require 'securerandom'
|
|
5
|
+
require 'xml/smart'
|
|
6
|
+
|
|
7
|
+
module CEWebS
|
|
8
|
+
# The attribute pass in the persons.xml: scrypt${salt}${hash}
|
|
9
|
+
module Password
|
|
10
|
+
HASHED = /\Ascrypt\$(\h{32})\$\h{64}\z/
|
|
11
|
+
|
|
12
|
+
def self::create(text,salt=SecureRandom.hex(16)) #{{{
|
|
13
|
+
hash = OpenSSL::KDF.scrypt(text.to_s,:salt => salt,:N => 2**14,:r => 8,:p => 5,:length => 32)
|
|
14
|
+
"scrypt$#{salt}$#{hash.unpack1('H*')}"
|
|
15
|
+
end #}}}
|
|
16
|
+
|
|
17
|
+
def self::hashed?(stored); stored.to_s.match?(HASHED); end
|
|
18
|
+
|
|
19
|
+
# passwords that have been written into the file by hand are not hashed
|
|
20
|
+
def self::valid?(stored,text) #{{{
|
|
21
|
+
given = create(text,*stored.to_s[HASHED,1])
|
|
22
|
+
return false if stored.to_s == ''
|
|
23
|
+
given = text.to_s unless hashed?(stored)
|
|
24
|
+
OpenSSL.fixed_length_secure_compare(Digest::SHA256.digest(stored),Digest::SHA256.digest(given))
|
|
25
|
+
end #}}}
|
|
26
|
+
|
|
27
|
+
# xml of a change (see Configuration) without readable passwords
|
|
28
|
+
def self::protect(operation,path,xml) #{{{
|
|
29
|
+
return xml if xml.to_s.strip == ''
|
|
30
|
+
if operation.start_with?('value')
|
|
31
|
+
path.end_with?('@pass') && !hashed?(xml) ? create(xml) : xml
|
|
32
|
+
else
|
|
33
|
+
doc = XML::Smart.string(xml)
|
|
34
|
+
doc.find('//@pass').each { |a| a.value = create(a.value) unless a.value == '' || hashed?(a.value) }
|
|
35
|
+
doc.root.dump
|
|
36
|
+
end
|
|
37
|
+
end #}}}
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Please see the LICENSE.GPL file for copyright and distribution information
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
|
|
4
|
+
module CEWebS
|
|
5
|
+
# Used by the tools of all gems
|
|
6
|
+
module Scaffold
|
|
7
|
+
# Copies everything in template, and further files, to dir. If dir already exists
|
|
8
|
+
# its data and configuration is kept, everything else is updated.
|
|
9
|
+
def self::create(template,dir,*files) #{{{
|
|
10
|
+
update = File.exist?(dir)
|
|
11
|
+
FileUtils.mkdir_p(dir)
|
|
12
|
+
sources = Dir.glob(File.join(template,'*')) + files
|
|
13
|
+
sources.reject! { |f| File.basename(f) == 'data' || f.end_with?('.conf') } if update
|
|
14
|
+
FileUtils.cp_r(sources,dir,:remove_destination => true)
|
|
15
|
+
# contains keys and users
|
|
16
|
+
File.chmod(0700,File.join(dir,'data')) if File.directory?(File.join(dir,'data'))
|
|
17
|
+
puts 'Directory already exists, updating ...' if update
|
|
18
|
+
!update
|
|
19
|
+
end #}}}
|
|
20
|
+
|
|
21
|
+
# data of a scaffolded service
|
|
22
|
+
def self::data(dir,*path) #{{{
|
|
23
|
+
file = File.join(File.expand_path(dir),'data',*path)
|
|
24
|
+
File.exist?(file) ? file : abort("#{file} not found")
|
|
25
|
+
end #}}}
|
|
26
|
+
end
|
|
27
|
+
end
|