dradis-projects 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ require_relative 'gem_version'
2
+
3
+ module Dradis
4
+ module Plugins
5
+ module Projects
6
+ # Returns the version of the currently loaded Projects as a
7
+ # <tt>Gem::Version</tt>.
8
+ def self.version
9
+ gem_version
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,139 @@
1
+ require 'logger'
2
+
3
+ class ExportTasks < Thor
4
+ include Dradis::Plugins::thor_helper_module.to_s.constantize
5
+
6
+ namespace "dradis:plugins:projects:export"
7
+
8
+ desc "template", "export the current repository structure as a dradis template"
9
+ method_option :file, type: :string, desc: "the template file to create, or directory to create it in"
10
+ def template
11
+ require 'config/environment'
12
+
13
+ logger = Logger.new(STDOUT)
14
+ logger.level = Logger::DEBUG
15
+ template_path = options.file || Rails.root.join('backup').to_s
16
+
17
+ unless template_path =~ /\.xml\z/
18
+ date = DateTime.now.strftime("%Y-%m-%d")
19
+ sequence = Dir.glob(File.join(template_path, "dradis-template_#{date}_*.xml")).collect do |a|
20
+ a.match(/_([0-9]+)\.xml\z/)[1].to_i
21
+ end.max || 0
22
+
23
+ template_path = File.join(template_path, "dradis-template_#{date}_#{sequence + 1}.xml")
24
+ end
25
+
26
+ detect_and_set_project_scope
27
+
28
+ exporter = Dradis::Plugins::Projects::Export::Template.new(
29
+ content_service: content_service_for(Dradis::Plugins::Projects::Export::Template),
30
+ logger: logger
31
+ )
32
+
33
+ File.open(template_path, 'w') { |f| f.write exporter.export() }
34
+
35
+ logger.info { "Template file created at:\n\t#{ File.expand_path( template_path ) }" }
36
+ logger.close
37
+ end
38
+
39
+
40
+ desc "package", "creates a copy of your current repository"
41
+ long_desc "Creates a copy of the current repository, including all nodes, notes and " +
42
+ "attachments as a zipped archive. The backup can be imported into another " +
43
+ "dradis instance using the 'Project Package Upload' option."
44
+ method_option :file, type: :string, desc: "the package file to create, or directory to create it in"
45
+ def package
46
+ require 'config/environment'
47
+
48
+ logger = Logger.new(STDOUT)
49
+ logger.level = Logger::DEBUG
50
+ package_path = options.file || Rails.root.join('backup')
51
+
52
+ unless package_path =~ /\.zip\z/
53
+ date = DateTime.now.strftime("%Y-%m-%d")
54
+ sequence = Dir.glob(File.join(package_path, "dradis-export_#{date}_*.zip")).collect { |a| a.match(/_([0-9]+)\.zip\z/)[1].to_i }.max || 0
55
+ package_path = File.join(package_path, "dradis-export_#{date}_#{sequence + 1}.zip")
56
+ end
57
+
58
+ detect_and_set_project_scope
59
+
60
+ Dradis::Plugins::Projects::Export::Package.new(
61
+ content_service: content_service_for(Dradis::Plugins::Projects::Export::Package),
62
+ logger: logger
63
+ ).export(filename: package_path)
64
+
65
+ logger.info{ "Project package created at:\n\t#{ File.expand_path( package_path ) }" }
66
+ logger.close
67
+ end
68
+
69
+ end
70
+
71
+ class UploadTasks < Thor
72
+ include Dradis::Plugins::thor_helper_module.to_s.constantize
73
+
74
+ namespace "dradis:plugins:projects:upload"
75
+
76
+ # This task will load into the current database the contents of the template
77
+ # file passed as the first argument
78
+ desc "template FILE", "create a new repository structure from an XML file"
79
+ def template(file_path)
80
+ require 'config/environment'
81
+
82
+ logger = Logger.new(STDOUT)
83
+ logger.level = Logger::DEBUG
84
+
85
+ unless File.exists?(file_path)
86
+ $stderr.puts "** the file [#{file_path}] does not exist"
87
+ exit -1
88
+ end
89
+
90
+ detect_and_set_project_scope
91
+
92
+ content_service = content_service_for(Dradis::Plugins::Projects::Upload::Template)
93
+ template_service = Dradis::Plugins::TemplateService.new(plugin: Dradis::Plugins::Projects::Upload::Template)
94
+
95
+ importer = Dradis::Plugins::Projects::Upload::Template::Importer.new(
96
+ logger: logger,
97
+ content_service: content_service,
98
+ template_service: template_service
99
+ )
100
+
101
+ importer.import(file: file_path)
102
+
103
+ logger.close
104
+ end
105
+
106
+
107
+ # The reverse operation to the dradis:export:project:package task. From a
108
+ # zipped project package extract the contents of the archive and populate
109
+ # the dradis DB and attachments with them.
110
+ desc "package FILE", "import an entire repository package"
111
+ def package(file_path)
112
+ require 'config/environment'
113
+
114
+ logger = Logger.new(STDOUT)
115
+ logger.level = Logger::DEBUG
116
+
117
+ unless File.exists?(file_path)
118
+ $stderr.puts "** the file [#{file_path}] does not exist"
119
+ exit -1
120
+ end
121
+
122
+
123
+ detect_and_set_project_scope
124
+
125
+ content_service = content_service_for(Dradis::Plugins::Projects::Upload::Package)
126
+ template_service = Dradis::Plugins::TemplateService.new(plugin: Dradis::Plugins::Projects::Upload::Package)
127
+
128
+ importer = Dradis::Plugins::Projects::Upload::Package::Importer.new(
129
+ logger: logger,
130
+ content_service: content_service,
131
+ template_service: template_service
132
+ )
133
+
134
+ importer.import(file: file_path)
135
+
136
+ logger.close
137
+ end
138
+
139
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dradis-projects
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Martin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: combustion
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dradis-plugins
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubyzip
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.1.0
97
+ description: This plugin allows you to dump the contents of the repo into a zip archive
98
+ and restore the state from one of them.
99
+ email:
100
+ - etd@nomejortu.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".ruby-version"
107
+ - CONTRIBUTING.md
108
+ - Gemfile
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - app/controllers/dradis/plugins/projects/packages_controller.rb
113
+ - app/controllers/dradis/plugins/projects/templates_controller.rb
114
+ - config/routes.rb
115
+ - dradis-projects.gemspec
116
+ - lib/dradis-projects.rb
117
+ - lib/dradis/plugins/projects.rb
118
+ - lib/dradis/plugins/projects/engine.rb
119
+ - lib/dradis/plugins/projects/export/package.rb
120
+ - lib/dradis/plugins/projects/export/template.rb
121
+ - lib/dradis/plugins/projects/gem_version.rb
122
+ - lib/dradis/plugins/projects/upload/package.rb
123
+ - lib/dradis/plugins/projects/upload/template.rb
124
+ - lib/dradis/plugins/projects/version.rb
125
+ - lib/tasks/thorfile.rb
126
+ homepage: http://dradisframework.org
127
+ licenses:
128
+ - GPL-2
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.4.5
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Project export/upload for the Dradis Framework.
150
+ test_files: []