Skip to content

Commit

Permalink
Updated elasticsearch.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Chan9390 committed Aug 30, 2017
1 parent f9ce6cc commit e9e4e9b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions chef/cookbooks/metasploitable/recipes/elasticsearch.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#
# Copyright:: 2017, The Authors, All Rights Reserved.

include_recipe 'metasploitable::7zip'
include_recipe 'metasploitable::jdk8'

This comment has been minimized.

Copy link
@jbarnett-r7

jbarnett-r7 Aug 30, 2017

Contributor

JDK8 is still a requirement, we should leave the include_recipe here.

This comment has been minimized.

Copy link
@Chan9390

Chan9390 Aug 30, 2017

Author Contributor

Okay


powershell_script 'Download ElasticSearch' do
code '(New-Object System.Net.WebClient).DownloadFile(\'http://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/1.1.1/elasticsearch-1.1.1.zip\', \'C:\Windows\Temp\elasticsearch-1.1.1.zip\')'
end
Expand All @@ -18,6 +15,7 @@

execute 'Install ElasticSearch' do
command '"C:\Program Files\elasticsearch-1.1.1\bin\service.bat" install'
environment ({"JAVA_HOME" => "C:\\Program Files\\Java\\jdk1.8.0_144"})

This comment has been minimized.

Copy link
@jbarnett-r7

jbarnett-r7 Aug 30, 2017

Contributor

You should use an "if" statement here to make sure that the JDK is actually installed. The recipe should fail if it is not installed, with a good error message letting the user know.

action :run
end

Expand All @@ -39,11 +37,18 @@
action :start
end

powershell_script 'Sleep 5 secs' do
code 'Start-Sleep -s 5'
end

powershell_script 'Test response' do
code '$req = [System.Net.HttpWebRequest]::Create(\'http://localhost:9200/metasploitable3/\'); $req.method = \'PUT\'; $req.GetResponse()'
code "$req = [System.Net.HttpWebRequest]::Create('http://localhost:9200/metasploitable3/'); $req.method = 'PUT'; $req.GetResponse()"
end

powershell_script 'Test' do
code 'powershell -Command "$body = [System.Text.Encoding]::ASCII.GetBytes(\'{\"user\":\"kimchy\", \"post_date\": \"2009-11-15T14:12:12\", \"message\": \"Elasticsearch\" }\'); $req = [System.Net.HttpWebRequest]::Create(\'http://localhost:9200/metasploitable3/message/1\'); $req.method = \'PUT\'; $req.ContentType = \'application/x-www-form-urlencoded\'; $stream = $req.GetRequestStream(); $stream.Write($body, 0, $body.Length); $stream.close(); $req.GetResponse()"'
powershell_script 'Sleep 5 secs' do
code 'Start-Sleep -s 5'

This comment has been minimized.

Copy link
@jbarnett-r7

jbarnett-r7 Aug 30, 2017

Contributor

I'm not sure if this is possible, but we should look into moving the sleep to the ruby side instead of running it on the client.

end

powershell_script 'Test' do
code "$body = [System.Text.Encoding]::ASCII.GetBytes('{\"user\":\"kimchy\", \"post_date\": \"2009-11-15T14:12:12\", \"message\": \"Elasticsearch\" }'); $req = [System.Net.HttpWebRequest]::Create('http://localhost:9200/metasploitable3/message/1'); $req.method = 'PUT'; $req.ContentType = 'application/x-www-form-urlencoded'; $stream = $req.GetRequestStream(); $stream.Write($body, 0, $body.Length); $stream.close(); $req.GetResponse()"
end

0 comments on commit e9e4e9b

Please sign in to comment.