Class: Arachni::UI::Web::Addons::AutoDeploy

Inherits:
Base
  • Object
show all
Defined in:
lib/arachni/ui/web/addons/autodeploy.rb,
lib/arachni/ui/web/addons/autodeploy/lib/manager.rb

Overview

Auto-deploy add-on.

Allows users to automatically convert any SSH enabled Linux box into an Arachni Dispatcher.

@author: Tasos “Zapotek” Laskos

<[email protected]>
<[email protected]>

@version: 0.1.1

Defined Under Namespace

Classes: Manager

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#adelete, #aget, #apost, #aput, #delete, #get, #initialize, #path_addon, #path_root, #path_views, #post, #put, #settings

Constructor Details

This class inherits a constructor from Arachni::UI::Web::Addons::Base

Class Method Details

.infoObject



192
193
194
195
196
197
198
199
# File 'lib/arachni/ui/web/addons/autodeploy.rb', line 192

def self.info
    {
        :name           => 'Auto-deploy',
        :description    => %q{Enables you to automatically convert any SSH enabled Linux box into an Arachni Dispatcher.},
        :author         => 'Tasos "Zapotek" Laskos <[email protected]> ',
        :version        => '0.2'
    }
end

Instance Method Details

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/arachni/ui/web/addons/autodeploy.rb', line 30

def run

    settings.helpers do
        require File.dirname( __FILE__ ) + '/autodeploy/lib/manager'

        def autodeploy
            @@autodeploy ||= Manager.new( Options.instance, settings )
        end

    end

    aget "/" do
        autodeploy.list_with_liveness {
            |deployments|
            async_present :index, :deployments => deployments,
                :root => current_addon.path_root, :show_output => false,
                :ret => {}
        }
    end

    post "/" do

        opts = {}
        if !params[:pool_size].empty?
            opts[:pool_size] = params[:pool_size].to_i
        end

        if !params[:nickname].empty?
            opts[:nickname]  = params[:nickname]
        end

        if !params[:weight].empty?
            opts[:weight]    = params[:weight]
        end

        if params[:pipe_id].empty?
            opts[:pipe_id]   = params[:pipe_id]
        end

        params.each { |k, v| opts[k.to_sym] = v }
        opts.delete( :password )
        opts.delete( :_csrf )

        deployment = Manager::Deployment.new( opts )

        if !params[:host] || params[:host].empty? || !params[:user] ||
            params[:user].empty? || !params[:password] || params[:password].empty? ||
            !params[:port] || params[:port].empty? ||
            !params[:dispatcher_port] || params[:dispatcher_port].empty?

            flash[:err] = "Please fill in all mandatory fields."

            present :index, :deployments => autodeploy.list,
                :root => current_addon.path_root, :show_output => false,
                :ret => {}, :errors => deployment.errors
        else

            settings.log.autodeploy_setup_started( env, autodeploy.get_url( deployment ) )
            channel = autodeploy.setup( deployment, params[:password] )

            present :index, :deployments => autodeploy.list,
                :root => current_addon.path_root, :channel => channel,
                :show_output => true,  :ret => {}
        end
    end

    get '/channel/:channel' do
        content_type :json
        autodeploy.output( params[:channel] ).to_json
    end

    get '/channel/:channel/finalize' do |channel|
        deployment = autodeploy.finalize_setup( params[:channel] )
        log.autodeploy_deployment_saved( env,
            "ID: #{deployment.id} [#{autodeploy.get_url( deployment )}]" )

        redirect '/', :flash => { :ok => "Deployment was successful." }
    end

    apost '/:ids' do |ids|

        ret = {}
        if !params[:password] || params[:password].empty?
            msg = "The password field is required."
            async_redirect '/', :flash => { :err => msg }
        else
            if params[:action] == 'delete'

                ret = autodeploy.delete( params[:id], params[:password] )

                if ret[:code]
                    msg = "Uninstall process aborted because the last command failed." +
                        " Please ensure that the password is correct and the network is up."
                    async_redirect '/', :flash => { :err => msg }
                else
                    log.autodeploy_deployment_deleted( env, params[:id] )
                    msg = "Uninstall process was successful."
                    async_redirect '/', :flash => { :ok => msg }
                end

            elsif params[:action] == 'run'
                deployment = autodeploy.get( params[:id] )
                ret = autodeploy.run( deployment, params[:password] )

                sleep 5
                autodeploy.alive?( deployment ){
                    |alive|

                    if alive
                        msg = "Dispatcher is up and running."

                        url = deployment.host + ':' + deployment.dispatcher_port.to_s
                        DispatcherManager::Dispatcher.first_or_create( :url => url )

                        settings.log.autodeploy_dispatcher_enabled( env,
                            "ID: #{deployment.id} [#{autodeploy.get_url( deployment )}]" )

                        async_redirect '/', :flash => { :ok => msg }
                    else
                        msg = "Could not run the Dispatcher." +
                            " Please ensure that the password is correct and the network is up."

                        async_redirect '/', :flash => { :err => msg }
                    end
                }
            elsif params[:action] == 'shutdown'
                deployment = autodeploy.get( params[:id] )
                autodeploy.shutdown( deployment, params[:password] ) {
                    |ret|
                    err = "Could not shutdown the Dispatcher." +
                        " Please ensure that the password is correct and the network is up."

                    if ret[:code] == 0
                       autodeploy.alive?( deployment ){
                           |liveness|
                           if !liveness
                               msg = "Dispatcher has been shutdown."

                               settings.log.autodeploy_dispatcher_shutdown( env,
                                    "ID: #{deployment.id} [#{autodeploy.get_url( deployment )}]" )

                               async_redirect '/', :flash => { :ok => msg }
                           else
                               async_redirect '/', :flash => { :err => err }
                           end
                       }
                    else
                        async_redirect '/', :flash => { :err => err }
                end
                }
            end
        end

    end


end

#titleObject



188
189
190
# File 'lib/arachni/ui/web/addons/autodeploy.rb', line 188

def title
    "Auto-deploy [#{Manager.new( Options.instance, settings ).list.size}]"
end