webappsword_sdk 0.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.
Files changed (88) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +24 -0
  4. data/README.md +67 -0
  5. data/Rakefile +20 -0
  6. data/VERSION +1 -0
  7. data/bin/webappsword_sdk +85 -0
  8. data/easy_installer-0.0.1.gem +0 -0
  9. data/example/Rakefile +72 -0
  10. data/example/additional/after_install.rb +1 -0
  11. data/example/additional/return_callback.rb +2 -0
  12. data/example/arch.zip +0 -0
  13. data/example/config.yml +6 -0
  14. data/example/files/joomla/index.php +54 -0
  15. data/example/installers/global.rb +2 -0
  16. data/example/installers/local.rb +2 -0
  17. data/example/validators/ftp.rb +6 -0
  18. data/example/validators/local.rb +0 -0
  19. data/lib/easy_installer.rb +4 -0
  20. data/lib/easy_installer/autoload.rb +28 -0
  21. data/lib/easy_installer/coffeescript_sandbox.rb +95 -0
  22. data/lib/easy_installer/config.rb +138 -0
  23. data/lib/easy_installer/config_validator.rb +73 -0
  24. data/lib/easy_installer/fake/ftp/install_helper.rb +34 -0
  25. data/lib/easy_installer/fake/ftp/validate_helper.rb +12 -0
  26. data/lib/easy_installer/fake/local/install_helper.rb +30 -0
  27. data/lib/easy_installer/fake/local/standart_input.yml +2 -0
  28. data/lib/easy_installer/fake/local/validate_helper.rb +6 -0
  29. data/lib/easy_installer/fake/php/validate_helper.rb +12 -0
  30. data/lib/easy_installer/fake/validator.rb +0 -0
  31. data/lib/easy_installer/fake/zip.rb +9 -0
  32. data/lib/easy_installer/generators/base.rb +25 -0
  33. data/lib/easy_installer/generators/config.rb +58 -0
  34. data/lib/easy_installer/install.rb +56 -0
  35. data/lib/easy_installer/install_helpers/result.rb +14 -0
  36. data/lib/easy_installer/install_helpers/template.rb +19 -0
  37. data/lib/easy_installer/install_helpers/zip.rb +9 -0
  38. data/lib/easy_installer/methods/ftp/install_helper.rb +105 -0
  39. data/lib/easy_installer/methods/ftp/standart_input.yml +5 -0
  40. data/lib/easy_installer/methods/ftp/standart_input.yml~ +5 -0
  41. data/lib/easy_installer/methods/ftp/validate_helper.rb +24 -0
  42. data/lib/easy_installer/methods/local/install_helper.rb +37 -0
  43. data/lib/easy_installer/methods/local/standart_input.yml +2 -0
  44. data/lib/easy_installer/methods/local/validate_helper.rb +4 -0
  45. data/lib/easy_installer/methods/sample/install_helper.rb +67 -0
  46. data/lib/easy_installer/methods/sample/standart_input.yml +5 -0
  47. data/lib/easy_installer/methods/sample/standart_input.yml~ +5 -0
  48. data/lib/easy_installer/methods/sample/validate_helper.rb +17 -0
  49. data/lib/easy_installer/modules/php/standart_input.yml +6 -0
  50. data/lib/easy_installer/modules/php/validate_helper.rb +47 -0
  51. data/lib/easy_installer/sandbox.rb +100 -0
  52. data/lib/easy_installer/sandbox_modules/message.rb +62 -0
  53. data/lib/easy_installer/steps.rb +36 -0
  54. data/lib/easy_installer/temp.rb +23 -0
  55. data/lib/easy_installer/translate.rb +70 -0
  56. data/lib/easy_installer/validator.rb +99 -0
  57. data/lib/easy_installer/validator_support_methods.rb +37 -0
  58. data/tests/files/additional/after_install.rb +1 -0
  59. data/tests/files/config.yml +10 -0
  60. data/tests/files/installers/global.rb +1 -0
  61. data/tests/files/installers/local.rb +1 -0
  62. data/tests/files/sample.zip +0 -0
  63. data/tests/files/template.erb +1 -0
  64. data/tests/files/translations/pl.yml +11 -0
  65. data/tests/files/validators/ftp.rb +3 -0
  66. data/tests/files/validators/local.rb +0 -0
  67. data/tests/files/validators/sample.rb +2 -0
  68. data/tests/test_config.rb +30 -0
  69. data/tests/test_config_validator.rb +22 -0
  70. data/tests/test_ftp.rb +51 -0
  71. data/tests/test_install.rb +19 -0
  72. data/tests/test_sandbox.rb +48 -0
  73. data/tests/test_sandbox_messages.rb +18 -0
  74. data/tests/test_steps.rb +19 -0
  75. data/tests/test_temp.rb +14 -0
  76. data/tests/test_template.rb +17 -0
  77. data/tests/test_validator.rb +31 -0
  78. data/tests/test_zip.rb +26 -0
  79. data/tests/wrong_config/config.yml +6 -0
  80. data/tests/wrong_config/install/global.rb +2 -0
  81. data/tests/wrong_config/install/local.rb +1 -0
  82. data/tests/wrong_config/translations/pl.yml +11 -0
  83. data/tests/wrong_config/validators/ftp.rb +4 -0
  84. data/tests/wrong_config/validators/local.rb +0 -0
  85. data/tests/wrong_config/validators/sample.rb +3 -0
  86. data/tests/~test_translator.rb +17 -0
  87. data/webappsword_sdk.gemspec +24 -0
  88. metadata +149 -0
@@ -0,0 +1,62 @@
1
+ module EasyInstaller
2
+ class Sandbox
3
+ module Message
4
+ def self.beforecode
5
+ "add_message = (type, message) ->
6
+ result.push {type: 'message', class: type, message: message}
7
+
8
+ redirect_to = (site) ->
9
+ result.push {type: 'message', class: 'redirect_to', message: site}
10
+ "
11
+ end
12
+
13
+ def self.aftercode
14
+ ""
15
+ end
16
+
17
+ def self.result_analize(raw_result)
18
+ if raw_result["type"] == "message"
19
+ return Result::Message.new(raw_result)
20
+ elsif raw_result["type"] == "action"
21
+ return Result::Action.new(raw_result)
22
+ else
23
+ return false
24
+ end
25
+ end
26
+
27
+ def self.name
28
+ "messages"
29
+ end
30
+ module IncludedCode
31
+ end
32
+
33
+ module EvalInstanceMethods
34
+ def messages
35
+ @returned
36
+ end
37
+ end
38
+
39
+ module Result
40
+ class Message
41
+ def initialize(raw_message)
42
+ @message = raw_message
43
+ end
44
+ def to_s
45
+ @message[:message].to_s
46
+ end
47
+ def raw
48
+ @message[:message]
49
+ end
50
+ end
51
+ class Action
52
+ def initialize(raw_message)
53
+ @action = raw_message
54
+ end
55
+ def to_s
56
+ @action[:site].to_s
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,36 @@
1
+ module EasyInstaller
2
+ class Steps
3
+ def initialize(config, method)
4
+ @config = config
5
+ @method = method
6
+ @config.method = method
7
+ end
8
+ # First step which validates inputs data from user. In case of error it returns false and sets inputs_errors.
9
+ # inputs_errors is hash which looks like:
10
+ # {
11
+ # "input_name" => "error"
12
+ # }
13
+ def validate(inputs)
14
+ validator = EasyInstaller::Validator.new(@config)
15
+ validator.import_from_config_by_method(@method)
16
+ raise validator.inputs_errors unless validator.check(inputs)
17
+ end
18
+
19
+ # This is second step it evals install code with support of helper methods
20
+ def install(inputs)
21
+ install = EasyInstaller::Installer.new(@config)
22
+ install.install(@config.install_code(@method), inputs)
23
+ end
24
+ # Third step which evals code after successfull instalation
25
+ def after_install
26
+ install = EasyInstaller::Installer.new(@config)
27
+ install.install(@config.after_install_code)
28
+ end
29
+ # Last step which is evaled by redirecting user back to page for example to remove install directory on server
30
+ def return_callback(inputs)
31
+ install = EasyInstaller::Installer.new(@config)
32
+ install.install(@config.return_callback_code, inputs)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ require 'tempfile'
2
+ require 'fileutils'
3
+ module EasyInstaller
4
+ class Temp
5
+ def initialize
6
+ @tempdir = File.join(Dir.tmpdir, "easyinstaller#{rand(1..10000)}")
7
+ FileUtils.mkdir_p(tempdir)
8
+
9
+ end
10
+
11
+ def copy_to_tempdir(dir)
12
+ FileUtils.cp_r(dir, @tempdir)
13
+ end
14
+
15
+ def clear
16
+ FileUtils.rm_rf(@tempdir)
17
+ end
18
+
19
+ def tempdir
20
+ @tempdir
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,70 @@
1
+ require 'yaml'
2
+ # Class used to translate GUI
3
+ module EasyInstaller
4
+ class Translate
5
+ # Lets you specific path to language pack
6
+ class << self
7
+ attr_accessor :translation_file_path
8
+ end
9
+ # Sets location
10
+ # ==== Attributes
11
+ # * +location+ - String: 2 char representation of location
12
+ # ==== Example
13
+ # set_location("pl")
14
+ def self.set_location(location)
15
+ @@location = location.to_s
16
+ path = String.new
17
+ unless translation_file_path
18
+ path = File.join("translations", @@location+".yml")
19
+ else
20
+ path = File.join(translation_file_path, @@location+".yml")
21
+ end
22
+ @@translator = YAML::load(File::open(path))
23
+ end
24
+
25
+ # Returns translated input
26
+ # ==== Attributes
27
+ # * +name+ - String: name of input
28
+ # * +type+ - String or Symbol: Type of value
29
+ # ====Example
30
+ # input("path", :name)
31
+ # input("path", :description)
32
+ def self.input(name, type)
33
+ begin
34
+ @@translator["input"][name.to_s][type.to_s]
35
+ rescue
36
+ name
37
+ end
38
+ end
39
+
40
+ # Returns translated method
41
+ # ==== Attributes
42
+ # * +name+ - String: name of input
43
+ # * +type+ - String or Symbol: Type of value
44
+ # ====Example
45
+ # method("ftp", :title)
46
+ # method("local", :description)
47
+ def self.method(name, type)
48
+ begin
49
+ @@translator["method"][name.to_s][type.to_s]
50
+ rescue
51
+ name
52
+ end
53
+ end
54
+
55
+ # Returns translated info about application
56
+ # ==== Attributes
57
+ # * +type+ - String or Symbol: value
58
+ # ====Example
59
+ # app(:info1)
60
+ # app("info2")
61
+ def self.app(type)
62
+ begin
63
+ @@translator["app"][type.to_s]
64
+ rescue
65
+ type.to_S
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,99 @@
1
+ require 'singleton'
2
+ require 'rubygems'
3
+ require 'yaml'
4
+ # class which includes all necessary helpers for validator code
5
+ module EasyInstaller
6
+
7
+ module ValidatorHelper #:nodoc:
8
+ attr_accessor :validator
9
+ module IncludedCode
10
+ end
11
+ module EvalInstanceMethods
12
+
13
+ end
14
+ def self.beforecode
15
+ "check = (params, code) ->
16
+ @code = code
17
+ @input = params['for']
18
+ @input_ready = params['then'] || input
19
+ result.push {
20
+ code: @code
21
+ input: @input
22
+ input_ready: @input_ready
23
+ }
24
+ "
25
+ end
26
+ def self.aftercode
27
+ ""
28
+ end
29
+ end
30
+ # Singleton Class which handles input validation
31
+ class Validator
32
+ attr_accessor :inputs_errors
33
+ def initialize(config)
34
+ @config = config
35
+ end
36
+
37
+ # Automaticaly imports validation function from config by method
38
+ # ==== Attributes
39
+ # * +method+ - String : name of method
40
+ def import_from_config_by_method(method)
41
+ @method = method
42
+ sandbox = Sandbox.new @config.validating_code(method)
43
+ sandbox.modules << ValidatorHelper
44
+ sandbox.eval
45
+ @checking_functions = sandbox.returned_raw
46
+ end
47
+
48
+ # Manualy add validating function to class
49
+ # ==== Attributes
50
+ # * +input+ - Array of String : list of input names which will be validated by function
51
+ # * +input_ready+ - Array of String: list of input names which have to be ready to run function
52
+ # * +&block+ - Block of code : validating code
53
+ # ==== Example
54
+ # add_validating_function(['path'],['path','host']) do
55
+ # #some code
56
+ # true
57
+ # end
58
+ def add_validating_function(input, input_ready, code)
59
+ @checking_functions = Array.new unless @checking_functions
60
+ @checking_functions << {:input => input, :input_ready=>input_ready, :code => code }
61
+ end
62
+
63
+ # Eval each validating functions and returns validated user_input
64
+ def check(inputs)
65
+ lang = @config["lang"]
66
+ require "easy_installer/modules/#{lang}/validate_helper"
67
+ require "easy_installer/methods/#{@method}/install_helper" if @method
68
+ require "easy_installer/methods/#{@method}/validate_helper" if @method
69
+ # runner = ValidatorRunner.new
70
+ # runner.inputs = inputs
71
+ # runner.extend(ModuleValidateHelper)
72
+ # runner.extend(InstallHelper) if @method
73
+ # runner.extend(MethodValidateHelper) if @method
74
+
75
+ @inputs_errors = inputs.clone
76
+ @inputs_errors.each{|key,val| @inputs_errors[key]=nil}
77
+
78
+ @checking_functions.each do |element|
79
+ begin
80
+ return false unless (element['code'].call)
81
+ rescue Exception => e
82
+ element['input'].each do |key, val|
83
+ @inputs_errors[key] = e.message
84
+ end
85
+ return false
86
+ end
87
+ end
88
+ return true
89
+ end
90
+ #checks is inputs valid
91
+ # def valid?
92
+ # ifcheck_evaled
93
+ # end
94
+ # Removes all validating functions
95
+ def clear_checking_functions
96
+ @checking_functions = Array.new
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,37 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ class ValidatorSupportMethods
5
+
6
+ def self.assert_http_body(requested_url, expected_result, error_msg)
7
+ result = self.get_html_content(requested_url)
8
+ if expected_result == result
9
+ return true
10
+ else
11
+ raise error_msg
12
+ end
13
+ end
14
+
15
+ def self.assert_http_for_multi_error(requested_url)
16
+ result = self.get_html_content(requested_url)
17
+ if result == 'OK'
18
+ return true
19
+ else
20
+ return result.split("\n")
21
+ end
22
+ end
23
+
24
+ protected
25
+ def self.get_html_content(requested_url)
26
+ url = URI.parse(requested_url)
27
+ full_path = (!url.query) ? url.path : "#{url.path}?#{url.query}"
28
+ the_request = Net::HTTP::Get.new(full_path)
29
+
30
+ the_response = Net::HTTP.start(url.host, url.port) { |http|
31
+ http.request(the_request)
32
+ }
33
+
34
+ raise "Response was not 200, response was #{the_response.code}" if the_response.code != "200"
35
+ return the_response.body
36
+ end
37
+ end
@@ -0,0 +1 @@
1
+ redirect_to "http://google.pl/"
@@ -0,0 +1,10 @@
1
+ methods:
2
+ - ftp
3
+ - local
4
+ lang: "php"
5
+ submodules:
6
+ - mysql
7
+ additonal_inputs:
8
+ site:
9
+ - description
10
+ - title
@@ -0,0 +1 @@
1
+ false
@@ -0,0 +1 @@
1
+ true
Binary file
@@ -0,0 +1 @@
1
+ <%= @sample %>one
@@ -0,0 +1,11 @@
1
+ input:
2
+ path:
3
+ name: "sciezka"
4
+ description: "ścieżka do"
5
+ method:
6
+ ftp:
7
+ title: "FTP"
8
+ description: "Zainstaluj za pomocą FTP"
9
+ app:
10
+ info: "Info about jooma which is cool"
11
+ info2: "This could be info about what you need to install joomla on your machine"
@@ -0,0 +1,3 @@
1
+ check for:["http_address", "path"], ->
2
+ nielacze
3
+ false
File without changes
@@ -0,0 +1,2 @@
1
+ check for: ["http_address", "path"], ->
2
+ true
@@ -0,0 +1,30 @@
1
+ require 'test/unit'
2
+ require 'easy_installer/config.rb'
3
+ require 'yaml'
4
+
5
+ class EasyInstaller::Config
6
+ def path_to_gem
7
+ File.join Dir.pwd
8
+ end
9
+ end
10
+ class TestConfig< Test::Unit::TestCase
11
+
12
+ def test_praser_validation
13
+ @config = EasyInstaller::Config.new("tests/files/config.yml")
14
+ assert(@config.valid?, "Vaild config didn't passed: valid?")
15
+ end
16
+
17
+ def test_getting_install_code
18
+ @config = EasyInstaller::Config.new("tests/files/config.yml")
19
+ code = @config.install_code "ftp"
20
+ assert_equal("false", code)
21
+ code = @config.install_code "local"
22
+ assert_equal("true", code)
23
+ end
24
+
25
+ def test_required_items
26
+ @config = EasyInstaller::Config.new("tests/files/config.yml")
27
+ assert_kind_of(Array, @config.required_inputs_for_method_as_tree("ftp").flatern_to_array)
28
+ end
29
+
30
+ end
@@ -0,0 +1,22 @@
1
+ require 'test/unit'
2
+ require 'easy_installer/config_validator'
3
+
4
+ class TestConfigValidator < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def test_simple_validation
9
+ @config = EasyInstaller::Config.new("tests/files/config.yml")
10
+ should_be_true = EasyInstaller::Config::Validator.new(@config)
11
+ assert_equal(true, should_be_true.check)
12
+ end
13
+
14
+ def test_invalid_config
15
+ @invalid_config = EasyInstaller::Config.new("tests/wrong_config/config.yml")
16
+ should_be_false = EasyInstaller::Config::Validator.new(@invalid_config)
17
+ assert_equal(false, should_be_false.check)
18
+ puts "error"
19
+ assert_kind_of(String, should_be_false.error_message)
20
+ assert_kind_of(Array, should_be_false.error_backtrace)
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ $LOAD_PATH << '../lib/'
2
+ require 'test/unit'
3
+ require 'easy_installer'
4
+ require 'easy_installer/methods/ftp/validate_helper'
5
+ require 'easy_installer/methods/ftp/install_helper'
6
+
7
+ class ExampleClass
8
+
9
+ end
10
+
11
+ class TestFtpHelper < Test::Unit::TestCase
12
+ def setup
13
+ @class = ExampleClass.new
14
+ @class.extend(EasyInstaller::MethodValidateHelper)
15
+ end
16
+
17
+ def test_testing_connection
18
+ if ENV["ftp_host"] && ENV["ftp_username"] && ENV["ftp_password"]
19
+ res = @class.check_connection "ftp_host"=>ENV["ftp_host"], "ftp_username"=>ENV["ftp_username"], "ftp_password"=>ENV["ftp_password"]
20
+ assert_equal(true, res, "problem with connecting to given ftp")
21
+ else
22
+ puts ""
23
+ puts "WARNING:"
24
+ puts "Add sample ftp access data to ENV : ftp_host ftp_username ftp_password"
25
+ puts ""
26
+ end
27
+ res = @class.check_connection :ftp_host=>"smaple.qw", :ftp_username=>"ENV", :ftp_password=>"q"
28
+ assert_equal(false, res, "problem with wrong data to ftp")
29
+ end
30
+
31
+ def test_simple_install
32
+ if ENV["ftp_host"] && ENV["ftp_username"] && ENV["ftp_password"] && ENV["path"]
33
+ params = {
34
+ "path" => ENV['path'],
35
+ "ftp_host" => ENV['ftp_host'],
36
+ "ftp_username" => ENV['ftp_username'],
37
+ "ftp_password" => ENV['ftp_password']
38
+ }
39
+ code ="
40
+ setup @inputs
41
+ move_directory('tests/example/files/joomla', @inputs['path'])
42
+ "
43
+ evaluator = EasyInstaller::Sandbox.new(code)
44
+ evaluator.helpers << EasyInstaller::InstallHelper
45
+ evaluator.inputs = params
46
+
47
+ assert_equal(true, evaluator.eval)
48
+ puts evaluator.returned
49
+ end
50
+ end
51
+ end