<div class="middle">
  <div class="left">
    <div class="choose_mode">
      <input type="radio" name="mode" value="mongbat" id="mode_mongbat" checked="checked" />
      <label for="mode_mongbat"><span></span> Automatic evasions</label>    
      <input type="radio" name="mode" value="evasions" id="mode_evasions" />
      <label for="mode_evasions"><span></span> Manual evasions</label>
    </div>
    
    <div class="evasions_tree">
      <div id="evasions_evtree" class="evasions_evtree">
        <ul>
          <%
            @protocols = {
              :eth => 'Ethernet',
              :ipv4 => 'IPv4',
              :ipv6 => 'IPv6',
              :tcp => 'TCP',
              :udp => 'UDP',
              :netbios => 'NetBIOS',
              :smb => 'SMB',
              :msrpc => 'MSRPC',
              :http => 'HTTP'
            }

            evasions = {}
            evasion_names = []
            evasion_to_attack_mapping = {}
            protocol_to_attack_mapping = {}

            @p4.attacks.each do |attack|
              attack.evasions.each do |ev|
                protocol, ev_name = ev.name.split("_", 2)
                unless evasion_names.include?(ev.name)
                  evasion_names.push(ev.name)
                  evasions[protocol] ||= []
                  evasions[protocol].push ev
                end
                evasion_to_attack_mapping[ev.name] ||= []
                evasion_to_attack_mapping[ev.name].push attack.short_name
                evasion_to_attack_mapping[ev.name].uniq!
                protocol_to_attack_mapping[protocol] ||= []
                protocol_to_attack_mapping[protocol].push attack.short_name
                protocol_to_attack_mapping[protocol].uniq!
              end
            end

            option_names = {}
          %>

          <% @protocols.each do |protocol, readable_name| %>
            <% next if evasions[protocol.to_s].nil? %>

            <li id="<%= protocol %>_li" class="evtree-closed protocol" data-attack="<%= protocol_to_attack_mapping[protocol.to_s].join(',') %>">
              <input type="checkbox" id="<%= protocol %>_checkbox" disabled="disabled" />
              <a href="#" data-value="<%= protocol %>" class="evtree_li_a plus">+</a>
              <a href="#" data-value="<%= protocol %>" class="evtree_li_a"><%= readable_name %></a>

              <ul>
                <% evasions[protocol.to_s].each do |evasion| %>              
                  <li id="<%= evasion.name %>_li" class="evtree-closed evasion" data-attack="<%= evasion_to_attack_mapping[evasion.name].join(',') %>">
                    <input type="checkbox" id="<%= evasion.name %>_checkbox" class="check_path" name="evasions[<%= evasion.name %>][enabled]" value="1" />

                    <% if evasion.options.empty? %>
                      &nbsp;&nbsp;&nbsp;<%= evasion.comment %>                
                    <% else %>
                      <a href="#" data-value="<%= evasion.name %>" class="evtree_li_a plus">+</a>
                      <a href="#" data-value="<%= evasion.name %>" class="evtree_li_a"><%= evasion.comment %></a>

                      <ul>
                        <% evasion.options.each_with_index do |opt, idx| %>
                          <%
                            li_id = "#{opt.name}_li"

                            if option_names[li_id].nil?
                              option_names[li_id] = 1
                            else
                              option_names[li_id] += 1
                              li_id << "__#{option_names[li_id].to_s}"
                            end                      
                          %>

                          <li id="<%= li_id %>" class="evtree-leaf-closed">                        
                            <%= opt.name %><br />

                            <% if opt.instance_of? Predator4Module::IntegerOption %>
                              <% field_width = [opt.min.to_s.size, opt.max.to_s.size].max + 1 %>
                              <input id="evasions_<%= evasion.name %>_options_<%= idx %>" name="evasions[<%= evasion.name %>][options][<%= idx %>]" class="evtree-select check_path" value="<%= opt.max %>" size="<%= field_width %>" />
                              <label for="evasions_<%= evasion.name %>_options_<%= idx %>">Int, [<%= opt.min %>-<%= opt.max %>,<%= opt.step %>]</label>
                              <br />
                            <% elsif opt.instance_of? Predator4Module::PropabilityOption %>
                              <input id="evasions_<%= evasion.name %>_options_<%= idx %>" name="evasions[<%= evasion.name %>][options][<%= idx %>]" class="evtree-select check_path" value="100%" size="4" />
                              <br />                        
                            <% elsif opt.instance_of? Predator4Module::ChoiceOption %>
                              <ul>
                                <% first_option = true %>
                                <% opt.choices.each_key do |choice_name| %>                              
                                  <li id="evasions_<%= evasion.name %>_options_<%= idx %>_<%= choice_name %>_li" class="evtree-leaf-closed">
                                    <input type="<%= opt.single_valid ? "radio" : "checkbox" %>" name="evasions[<%= evasion.name %>][options][<%= idx %>][]" id="evasions_<%= evasion.name %>_options_<%= idx %>_<%= choice_name %>" value="<%= choice_name %>" class="check_path" <% if first_option %>checked="checked"<% end %> />
                                    <label for="evasions_<%= evasion.name %>_options_<%= idx %>_<%= choice_name %>"><%= opt.choices[choice_name] %></label>
                                  </li>
                                  <% first_option = false %>
                                <% end %>
                              </ul>
                            <% end %>
                          </li>
                        <% end %>
                      </ul>
                    <% end %>
                  </li>
                <% end %>
              </ul>
            </li>
          <% end %>
        </ul>
      </div>
    </div>

    <!-- <div class="actions">
      <input type="submit" value="CLEAR EVASIONS" />
    </div> -->
  </div>

  <div class="breaches">
    <div class="header">
      SECURITY BREACHES:
      <span class="breach_count">0</span>
      <span class="separator">|</span>
      DURATION:
      <span class="duration">0 SEC</span>
    </div>
    <ul class="breaches_list">
    </ul>
    <div class="actions">
      <input type="submit" value="DOWNLOAD REPORT" />
      <input type="submit" value="LOG" />
    </div>
  </div>
</div>

<div class="line"></div>

<div class="bottom">
  <!-- DEFAULT VALUES FOR RUNNING IN MONGBAT MODE (DEFAULT AND AUTOMATIC) -->
  <input type="hidden" id="mongbat_mode" name="mongbat_mode" value="random"/>
  <input type="hidden" id="mongbat_time" name="mongbat_time" value="43200"/>
  <input type="hidden" id="mongbat_workers" name="mongbat_workers" value="16"/>
  <input type="hidden" id="mongbat_minev" name="mongbat_minev" value="2"/>
  <input type="hidden" id="net_cfg_type" name="net_cfg_type" value="writable"/>

  <input type="submit" value="EXECUTE" class="wide_button execute" />
</div>

<div class="hidden">
  <div class="log" id="log"></div>
</div>