webappsword_sdk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,14 @@
1
+ module EasyInstaller
2
+ module ResultHelper
3
+ class Result
4
+ include Singleton
5
+ attr_accessor :display
6
+ end
7
+
8
+ def message(type, message)
9
+ if type == :display
10
+ Result.instance.display = message
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ require 'erb'
2
+ module EasyInstaller
3
+ module InstallHelper
4
+ module Template
5
+ def define_template( filename )
6
+ @_templates = [] unless @_templates
7
+ @_templates << {
8
+ :filename => filename,
9
+ :erb => ERB.new(File.read(filename))}
10
+ end
11
+
12
+ def save_templates
13
+ @_templates.each{|template|
14
+ File.open(template[:filename],"w"){|f|
15
+ f.write(template[:erb].result(binding))}}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module EasyInstaller
2
+ module InstallHelper
3
+ module ZipFile
4
+ def unzip(filename, destination)
5
+ system("unzip #{filename} -d #{destination}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,105 @@
1
+ require 'net/ftp'
2
+ module EasyInstaller
3
+ module InstallHelper
4
+ def setup params = {}
5
+ host = params["ftp_host"]
6
+ username = params["ftp_username"]
7
+ password = params["ftp_password"]
8
+
9
+ @ftp = Net::FTP.new(host)
10
+ @ftp.login(username, password)
11
+ end
12
+ # copy local directory to remote can be used to push data to server
13
+ # e.g. move_directory("joomla_installer", @inputs["path"])
14
+ # * *Args* :
15
+ # - +local_directory+ -> path to local directory
16
+ # - +remote_directory+ -> path where put directory
17
+ # * *Returns* :
18
+ # - true
19
+ def move_directory(local_directory,remote_directory)
20
+ begin
21
+ puts remote_directory
22
+ @ftp.mkdir(remote_directory)
23
+ rescue
24
+ puts "can't create directory"
25
+ end
26
+ Dir.entries(local_directory).each do |element|
27
+ if element == "." || element == ".."
28
+ next
29
+ end
30
+ if File.directory?(local_directory+"/"+element)
31
+ move_directory(local_directory+"/"+element, remote_directory+"/"+element)
32
+ else
33
+ puts "binary put "
34
+ puts local_directory+"/"+element
35
+ @ftp.putbinaryfile(local_directory+"/"+element, remote_directory+"/"+element)
36
+ puts "send"
37
+ end
38
+
39
+ end
40
+ end
41
+ # create directory on remote server and sets permissions
42
+ # e.g. create_directory("tmp", 664)
43
+ # * *Args* :
44
+ # - +dirpath+ -> path to dir
45
+ # - +chmod+ -> 3 digits of chmod
46
+ # * *Returns* :
47
+ # - true
48
+ def create_directory(dirpath, chmod=664)
49
+ dir = dirpath.split '/'
50
+ dir.each_index do |index|
51
+ begin
52
+ @ftp.mkdir(dir[0..index].join '/')
53
+ # @ftp.sendcmd("SITE CHMOD 0#{chmod} #{dir[0..index].join '/'}")
54
+ puts "SITE CHMOD 0#{chmod} #{dir[0..index].join '/'}"
55
+ rescue
56
+ # @ftp.sendcmd("SITE CHMOD 0#{chmod} #{dir[0..index].join '/'}")
57
+ puts "Can't create #{dir[0..index].join '/'}"
58
+ end
59
+ end
60
+ end
61
+
62
+ # delete directory from remote server
63
+ # * *Args* :
64
+ # - +dirpath+ -> path to dir
65
+ # * *Returns* :
66
+ # - true
67
+ def remove_directory(dirpath)
68
+ @ftp.rmdir(dirpath)
69
+ end
70
+ # copy from local to remote and set premissions
71
+ # * *Args* :
72
+ # - +local_file+ -> path to local file
73
+ # - +remote_file+ -> path where put file
74
+ # - +chmod+ -> 3 digits of chmod
75
+ # * *Returns* :
76
+ # - true
77
+ def move_file(local_file,remote_file, chmod=664)
78
+ create_directory(File.dirname(remote_file), chmod)
79
+ @ftp.putbinaryfile(local_file, remote_file)
80
+ @ftp.sendcmd("SITE CHMOD 0#{chmod} #{remote_file}")
81
+ end
82
+ # sets premissions on remote folder
83
+ # * *Args* :
84
+ # - +remote_file+ -> path to file
85
+ # - +chmod+ -> 3 digits of chmod
86
+ # * *Returns* :
87
+ # - true
88
+ def chmod(remote_file, chmod)
89
+ @ftp.sendcmd("SITE CHMOD 0#{chmod} #{remote_file}")
90
+ end
91
+ #sets premissions to folder and sub-folders
92
+ # * *Args* :
93
+ # - +remote_file+ -> path to file
94
+ # - +chmod+ -> 3 digits of chmod
95
+ # * *Returns* :
96
+ # - true
97
+ def chmod_r(remote_dir, chmod)
98
+ @ftp.sendcmd("SITE CHMOD 0#{chmod} #{remote_dir}")
99
+ @ftp.list(remote_dir).each do |element|
100
+ chmod_r(File.joint(remote_dir, element))
101
+ end
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,5 @@
1
+ - path
2
+ - http_address
3
+ - ftp_host
4
+ - ftp_username
5
+ - ftp_password
@@ -0,0 +1,5 @@
1
+ ftp:
2
+ - path
3
+ - ftp_host
4
+ - ftp_username
5
+ - ftp_password
@@ -0,0 +1,24 @@
1
+ require 'easy_installer/methods/ftp/install_helper'
2
+ module EasyInstaller
3
+ module MethodValidateHelper
4
+ include InstallHelper
5
+ # copy local directory to remote can be used to push data to server
6
+ # e.g. move_directory("joomla_installer", @inputs["path"])
7
+ # * *Args* :
8
+ # - +params+ -> hash with data to connect {"ftp_host"=>"", "ftp_username"=> "", "ftp_password"=>""} @inputs
9
+ # * *Returns* :
10
+ # - true -> if connecting
11
+ # - false -> if fails
12
+ def check_connection params = {}
13
+ host = params["ftp_host"]
14
+ username = params["ftp_username"]
15
+ password = params["ftp_password"]
16
+ begin
17
+ setup "ftp_host"=>host, "ftp_username"=>username, "ftp_password"=>password
18
+ true
19
+ rescue
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ require 'fileutils'
2
+ module EasyInstaller
3
+ module InstallHelper
4
+ def setup(params)
5
+ end
6
+
7
+ def move_directory(from_directory, to_directory)
8
+ FileUtils::mkdir_p(to_directory)
9
+ FileUtils::rm_rf(to_directory)
10
+ FileUtils::mv(from_directory, to_directory)
11
+ end
12
+
13
+ def create_directory(dirpath,chmod=664)
14
+ FileUtils::mkdir_p(to_directory)
15
+ FileUtils::chmod(chmod, dirpath)
16
+ end
17
+
18
+ def move_file(local_file,remote_file, chmod=664)
19
+ FileUtils::mv(local_file, remote_file)
20
+ FileUtils::chmod(chmod, remote_file)
21
+ end
22
+
23
+ def delete_directory(dirpath)
24
+ FileUtils::rm_rf(dirpath)
25
+ end
26
+
27
+ def chmod(remote_file, chmod)
28
+ FileUtils::chmod(chmod, remote_file)
29
+ end
30
+
31
+ def chmod_r(remote_dir, chmod)
32
+ FileUtils::chmod_R(chmod, remote_dir)
33
+ end
34
+
35
+
36
+ end
37
+ end
@@ -0,0 +1,2 @@
1
+ - path
2
+ - http_address
@@ -0,0 +1,4 @@
1
+ module EasyInstaller
2
+ module MethodValidateHelper
3
+ end
4
+ end
@@ -0,0 +1,67 @@
1
+ require 'net/ftp'
2
+ module EasyInstaller
3
+ module InstallHelper
4
+ def setup params = {}
5
+ host = params[:host] || $user_input["ftp_host"].value
6
+ username = params[:username] || $user_input["ftp_username"].value
7
+ password = params[:password] || $user_input["ftp_password"].value
8
+ @ftp = Net::FTP.new(host)
9
+ @ftp.login(username, password)
10
+ end
11
+
12
+ def move_directory(local_directory,remote_directory)
13
+ begin
14
+ puts remote_directory
15
+ @ftp.mkdir(remote_directory)
16
+ rescue
17
+ puts "can't create directory"
18
+ end
19
+ Dir.entries(local_directory).each do |element|
20
+ if element == "." || element == ".."
21
+ next
22
+ end
23
+ if File.directory?(local_directory+"/"+element)
24
+ move_directory(local_directory+"/"+element, remote_directory+"/"+element)
25
+ else
26
+ puts "binary put "
27
+ puts local_directory+"/"+element
28
+ @ftp.putbinaryfile(local_directory+"/"+element, remote_directory+"/"+element)
29
+ puts "send"
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ def create_directory(dirpath, chmod=664)
36
+ dir = dirpath.split '/'
37
+ dir.each_index do |index|
38
+ begin
39
+ @ftp.mkdir(dir[0..index].join '/')
40
+ # @ftp.sendcmd("SITE CHMOD 0#{chmod} #{dir[0..index].join '/'}")
41
+ puts "SITE CHMOD 0#{chmod} #{dir[0..index].join '/'}"
42
+ rescue
43
+ # @ftp.sendcmd("SITE CHMOD 0#{chmod} #{dir[0..index].join '/'}")
44
+ puts "Can't create #{dir[0..index].join '/'}"
45
+ end
46
+ end
47
+ end
48
+
49
+ def move_file(local_file,remote_file, chmod=664)
50
+ create_directory(File.dirname(remote_file), chmod)
51
+ @ftp.putbinaryfile(local_file, remote_file)
52
+ @ftp.sendcmd("SITE CHMOD 0#{chmod} #{remote_file}")
53
+ end
54
+
55
+ def chmod(remote_file, chmod)
56
+ @ftp.sendcmd("SITE CHMOD 0#{chmod} #{remote_file}")
57
+ end
58
+ #need to test
59
+ def chmod_r(remote_dir, chmod)
60
+ @ftp.sendcmd("SITE CHMOD 0#{chmod} #{remote_dir}")
61
+ @ftp.list(remote_dir).each do |element|
62
+ chmod_r(File.joint(remote_dir, element))
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ - path
2
+ - http_address
3
+ - ftp_host
4
+ - ftp_username
5
+ - ftp_password
@@ -0,0 +1,5 @@
1
+ ftp:
2
+ - path
3
+ - ftp_host
4
+ - ftp_username
5
+ - ftp_password
@@ -0,0 +1,17 @@
1
+ require 'easy_installer/methods/ftp/install_helper'
2
+ module EasyInstaller
3
+ module MethodValidateHelper
4
+ include InstallHelper
5
+ def check_connection params = {}
6
+ host = params[:host] || $user_input["ftp_host"].value
7
+ username = params[:username] || $user_input["ftp_username"].value
8
+ password = params[:password] || $user_input["ftp_password"].value
9
+ begin
10
+ setup :ftp_host=>host, :ftp_username=>username, :ftp_password=>password
11
+ true
12
+ rescue
13
+ false
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ php:
2
+ mysql:
3
+ - mysql_host
4
+ - mysql_username
5
+ - mysql_password
6
+ - mysql_database
@@ -0,0 +1,47 @@
1
+ require 'erb'
2
+ module EasyInstaller
3
+ module ModuleValidateHelper
4
+ def php?
5
+ file = File.new("phptest.php", "w")
6
+ file.write("<? echo 'OK' ?>")
7
+ file.close
8
+ begin
9
+ move_file(file.path, $user_input['path'].value+'/'+"phptest.php",777)
10
+ ValidatorSupportMethods.assert_http_body($user_input['http_address'].value+"/phptest.php","OK","no_php")
11
+ File.delete(file.path)
12
+ true
13
+ rescue
14
+ File.delete(file.path)
15
+ false
16
+ end
17
+ end
18
+
19
+ def mysql?
20
+ mysql_host = $user_input['mysql_host'].value
21
+ mysql_username = $user_input['mysql_username'].value
22
+ mysql_password = $user_input['mysql_password'].value
23
+ mysql_database = $user_input['mysql_database'].value
24
+ template = ERB.new <<-EOF
25
+ <?
26
+ $link = mysql_connect('<%= mysql_host %>', '<%= mysql_username %>', '<%= mysql_password %>')
27
+ or die('Could not connect: ' . mysql_error());
28
+ echo 'Connected successfully';
29
+ mysql_select_db('<%= mysql_database %>') or die('Could not select database');
30
+ print("OK");
31
+ ?>
32
+ EOF
33
+ file = File.new("mysql.php", "w")
34
+ file.write(template.result binding)
35
+ file.close
36
+ begin
37
+ move_file(file.path, $user_input['path'].value+'/'+"mysql.php",777)
38
+ ValidatorSupportMethods.assert_http_body($user_input['http_address'].value+"/mysql.php","OK","no_mysql")
39
+ File.delete(file.path)
40
+ true
41
+ rescue
42
+ File.delete(file.path)
43
+ true
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,100 @@
1
+ require 'coffee-script'
2
+ require 'v8'
3
+ module EasyInstaller
4
+ class Sandbox
5
+ class Runner
6
+ attr_accessor :inputs
7
+ end
8
+ attr_accessor :modules
9
+ attr_accessor :helpers
10
+ attr_accessor :inputs
11
+ attr_accessor :errors
12
+
13
+ def initialize(code, params = {})
14
+ @code = code
15
+ @helpers = []
16
+ @inputs = {}
17
+ @modules = []
18
+ @params = {
19
+ :coffee_script => true
20
+ }
21
+ @params.merge!(params)
22
+ end
23
+
24
+ def add_module(mod)
25
+ @modules << mod
26
+ end
27
+
28
+ def add_helper(helper)
29
+ @helpers << helper
30
+ end
31
+
32
+ def eval
33
+ run = Runner.new
34
+ run.inputs = @inputs
35
+ #include modules
36
+ @modules.each do |mod|
37
+ extend mod::EvalInstanceMethods
38
+ @code = "#{mod.beforecode}
39
+ #{@code}
40
+ #{mod.aftercode}"
41
+ run.extend(mod::IncludedCode)
42
+ end
43
+ #include return code
44
+ @code = "result = []
45
+ #{@code}
46
+ return result"
47
+ #include helpers
48
+ @helpers.each do |single_module|
49
+ run.extend single_module
50
+ end
51
+ #compile to coffeescript
52
+ @code = CoffeeScript.compile @code if @params[:coffee_script] == true
53
+ #eval code
54
+ V8::Context.new(:with => run) do |cxt|
55
+ @returned = cxt.eval(@code)
56
+ end
57
+ return true
58
+ end
59
+
60
+ def returned
61
+ unless @returned
62
+ raise "First eval Code"
63
+ end
64
+ @returned_packed = Result.new(@returned, @modules)
65
+ @returned_packed
66
+ end
67
+
68
+ def success?
69
+ @success
70
+ end
71
+ def returned_raw
72
+ unless @returned
73
+ raise "First eval Code"
74
+ end
75
+ @returned
76
+ end
77
+
78
+ class Result
79
+ def initialize(raw_result, modules)
80
+ @data = {}
81
+ @raw_result = raw_result
82
+ modules.each do |single_module|
83
+ @raw_result.each do |result|
84
+ data = single_module.result_analize(result)
85
+ unless data == false
86
+ @data[single_module.name] = [] unless @data[single_module.name]
87
+ @data[single_module.name] << data
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ def method_missing(method_name, *args)
94
+ @data[method_name.to_s] ||= []
95
+ @data[method_name.to_s]
96
+ end
97
+
98
+ end
99
+ end
100
+ end