<%
	def draw_option(name, opt)

		defval =  h(opt.default || '') 
		
		if (params[name.to_sym])
			defval = params[name.to_sym].to_s
		end
		
		case opt.class.to_s
		when 'Msf::OptEnum'
			ret = '<select name="' + h(name) + '">' + "\n"

			opt.enums.sort.each do |val|
				sel = (val == defval) ? 'SELECTED' : ''
				ret << '<option value="' + h(val) + '"' + " #{sel}>" + h(val) + "</option>\n"
			end
			
			ret << "</select>\n"
			
			ret
		else
			'<input type="text" name="' + h(name) + '" value="' + defval + '" />'
		end
	end


%>

<table align="center" cellspacing="0" cellpadding="3" width="100%" class="EAconf_moduleFull">
    <tr>
        <td width="100%" class="EAconf_moduleName" colspan="2">
            <%= h(@tmod.name) %> <br />
	</td>
    </tr>
    <tr>
        <td height="10" colspan="2">
        </td>
    </tr>
    <tr>
        <td width="100%" colspan="2">
            <p>Select payload for target <strong><%= h(@target.name) %></strong>:</p>
        </td>
    </tr>
    <tr>
        <td height="10" colspan="2">
        </td>
    </tr>

<% if @exploit_error %>

    <tr>
        <td width="100%" class="moduleError" colspan="2">
            Validation Error: <%= h(@exploit_error) %><br />
        </td>
    </tr>


<% end %>


<% if @exploit_console %>

    <tr>
        <td width="100%" class="moduleError" colspan="2">
            Exploit launched. If the exploit console window does not appear, please click
			<a href="#" onclick="javascript:window.parent.openConsoleWindowExploit(<%= @exploit_console %>);">here</a>.
        </td>
    </tr>

<% end %>

<% if @cur_step == nil %>

    <tr>
        <th colspan="2" class="moduleOptionsHeader">
            CURRENT CONFIGURATION - <%= link_to "change target", :action => "view", :refname => h(params[:refname]) %>
        </th>
    </tr>

    <tr>
        <td class="opt_name">EXPLOIT</td>
        <td><%= @tmod.refname %></td>
    </tr>

    <tr>
        <td class="opt_name">TARGET</td>
        <td><%= @target.name %></td>
    </tr>

    <tr>
        <th class="moduleOptionsHeader">Name</th>
        <th class="moduleOptionsHeader">Description</th>
    </tr>

	<% 
		rcol_a = 'item_row_col_a' 
		rcol_b = 'item_row_col_b'
		rcol   = rcol_b
	%>
	
    <% @payloads.each_with_index do |p, idx| %>
    <tr class='<%=h rcol = (rcol == rcol_a) ? rcol_b : rcol_a %>'>
        <% o = p[1].new %>
        <td><%= link_to h(p[0]), :refname => @tmod.refname.gsub('/', ':'), :step => "config",
        :target => h(params[:target].to_i), :payload => idx %></td>
        <td><%= h(o.description) %></td>
    </tr>
    <% end %>
    
<% elsif @cur_step == "config" %>

    <p>Please enter all of the required options and press 'Launch Exploit' to continue.</p>
    
    <tr>
        <th colspan="2" class="moduleOptionsHeader">
            CURRENT CONFIGURATION -
            <%= link_to "change payload", :action => "config", :refname => h(params[:refname]) %>
        </th>
    </tr>
    <tr>
        <td class="opt_name">EXPLOIT</td>
        <td><%= h @tmod.refname %></td>
    </tr>

    <tr>
        <td class="opt_name">TARGET</td>
        <td><%= h @target.name %></td>
    </tr>
	    
	<tr>
        <td class="opt_name">PAYLOAD</td>
        <td><%= h @payload_name %></td>
    </tr>
	
    <tr>
        <th colspan="2" class="moduleOptionsHeader">STANDARD OPTIONS</th>
    </tr>
    
    <form action="/exploits/config" method="post">
        <%= hidden_field_tag "refname", h(params[:refname]) %>
        <%= hidden_field_tag "step", "exploit" %>
        <%= hidden_field_tag "target", h(params[:target]) %>
        <%= hidden_field_tag "payload", h(params[:payload]) %>
    
    <% @tmod.options.sort.each { |name, option|
        next if (option.advanced?)
        next if (option.evasion?) %>
        <tr>
            <td class="opt_name"><%= h name %></td>
            <td class="opt_required"><%= (option.required?) ? "Required" : "" %></td>
        </tr>
        <tr>
            <td><%= h option.desc %> (type: <%= h option.type %>)</td>
            <td>
				<%= draw_option('eopt_'+h(name), option) %>
            </td>
        </tr>
    <% } %>
    <% @payload_inst.options.sort.each { |name, option|
        next if (option.advanced?)
        next if (option.evasion?) %>
        <tr>
            <td class="opt_name"><%= h name %></td>
            <td class="opt_required"><%= (option.required?) ? "Required" : "" %></td>
        </tr>
        <tr>
            <td><%= h option.desc %> (type: <%= h option.type %>)</td>
            <td>
                <%= draw_option('popt_'+h(name), option) %>
            </td>
        </tr>
    <% } %>
 
    <tr>
        <th colspan="2"><br/><%= submit_tag "Launch Exploit" %><br/></th>
    </tr>

    <tr>
        <th colspan="2" class="moduleOptionsHeader">ADVANCED OPTIONS</th>
    </tr> 
	
    <% @tmod.options.sort.each { |name, option|
        next if not option.advanced? %>
        <tr>
            <td class="opt_name"><%= h name %></td>
            <td class="opt_required"><%= (option.required?) ? "Required" : "" %></td>
        </tr>
        <tr>
            <td><%= h option.desc %> (type: <%= h option.type %>)</td>
            <td>
                <%= draw_option('eopt_'+h(name), option) %>
            </td>
        </tr>
    <% } %>
    <% @payload_inst.options.sort.each { |name, option|
        next if not option.advanced? %>
        <tr>
            <td class="opt_name"><%= h name %></td>
            <td class="opt_required"><%= (option.required?) ? "Required" : "" %></td>
        </tr>
        <tr>
            <td><%= h option.desc %> (type: <%= h option.type %>)</td>
            <td>
                <%= draw_option('popt_'+h(name), option) %>
            </td>
        </tr>
    <% } %> 

    <tr>
        <th colspan="2"><br/><%= submit_tag "Launch Exploit" %><br/></th>
    </tr>

    <tr>
        <th colspan="2" class="moduleOptionsHeader">EVASION OPTIONS</th>
    </tr>
	
    <% @tmod.options.sort.each { |name, option|
        next if not option.evasion? %>
        <tr>
            <td class="opt_name"><%= name %></td>
            <td class="opt_required"><%= (option.required?) ? "Required" : "" %></td>
        </tr>
        <tr>
            <td><%= h option.desc %> (type: <%= h option.type %>)</td>
            <td>
                <%= draw_option('eopt_'+h(name), option) %>
            </td>
        </tr>
    <% } %>
    <% @payload_inst.options.sort.each { |name, option|
        next if not option.evasion? %>
        <tr>
            <td class="opt_name"><%= h name %></td>
            <td class="opt_required"><%= (option.required?) ? "Required" : "" %></td>
        </tr>
        <tr>
            <td><%= html_escape(option.desc) %> (type: <%= option.type %>)</td>
            <td>
                <%= draw_option('popt_'+h(name), option) %>
            </td>
        </tr>
    <% } %> 
    
	<tr>
        <th colspan="2"><br/><%= submit_tag "Launch Exploit" %><br/></th>
    </tr>
				  
    </form>

	<% if @exploit_console %>
	<script>
 		<% if params[:consoleOpen] and params[:consoleOpen] == "direct" %>
 			window.location="/console/index/<%= @exploit_console %>"
 		<% else %>
 			window.parent.openConsoleWindowExploit(<%= @exploit_console %>);
 		<% end %>
	</script>
	<% end %>

<% end %>

</table>

