<!--
OpenVAS Manager
$Id$
Description: OpenVAS Manager Protocol (OMP) quick first scan wizard.

Authors:
Matthew Mundell <matthew.mundell@greenbone.net>
Timo Pollmeier <timo.pollmeier@greenbone.net>

Copyright:
Copyright (C) 2012-2014 Greenbone Networks GmbH

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-->

<!--
  This wizard sets up a new task and target to run an unauthenticated scan on a
  host (or range of hosts) specified by the parameter "hosts" using the
  "Full and Fast" scan config and default port range.

  Required parameters:
  hosts : The hosts to scan. Syntax is the same as for the hosts parameter of
          the OMP command CREATE_TARGET.

  To run this wizard, use the OMP command RUN_WIZARD.
  Please see the OMP documentation for details.
 -->

<wizard>
  <params>
    <!-- ID of the config to use (optional) -->
    <param>
      <optional>1</optional>
      <name>config_id</name>
      <regex>^[a-z0-9\\-]+$</regex>
    </param>

    <!-- ID of the alert to use (optional) -->
    <param>
      <optional>1</optional>
      <name>alert_id</name>
      <regex>^[a-z0-9\\-]+$</regex>
    </param>

    <!-- ID of the Scanner for the task (optional) -->
    <param>
      <optional>1</optional>
      <name>scanner_id</name>
      <regex>^[a-z0-9\\-]+$</regex>
    </param>

    <!-- ID of the slave to use (optional) -->
    <param>
      <optional>1</optional>
      <name>slave_id</name>
      <regex>^[a-z0-9\\-]+$</regex>
    </param>

    <!-- Optional credentials -->
    <param>
      <optional>1</optional>
      <name>smb_credential</name>
      <regex>^[a-z0-9\\-]+$</regex>
    </param>
    <param>
      <optional>1</optional>
      <name>ssh_credential</name>
      <regex>^[a-z0-9\\-]+$</regex>
    </param>
    <param>
      <optional>1</optional>
      <name>ssh_port</name>
      <regex>^0*(6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d\d\d|[1-5]\d\d\d\d|\d{1,4})$</regex>
    </param>
    <param>
      <optional>1</optional>
      <name>esxi_credential</name>
      <regex>^[a-z0-9\\-]+$</regex>
    </param>

    <!-- The target hosts to scan -->
    <param>
      <optional>0</optional>
      <name>hosts</name>
      <regex>^[-[:alnum:],: \\./]{1,2000}$</regex>
    </param>

    <!-- ID of the Port List for the Target (optional) -->
    <param>
      <optional>1</optional>
      <name>port_list_id</name>
      <regex>^[a-z0-9\\-]+$</regex>
    </param>
  </params>

  <step>
    <command>
      <xsl:stylesheet
          version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output
          method="xml"
          encoding="UTF-8"/>
        <xsl:template match="/">
          <create_target>
            <name><make_unique>1</make_unique>Target for immediate scan of IP <xsl:value-of select="/wizard/params/param[name='hosts']/value"/></name>
            <hosts><xsl:value-of select="/wizard/params/param[name='hosts']/value"/></hosts>

            <xsl:if test="/wizard/params/param[name='port_list_id']/value != ''">
              <port_list id="{/wizard/params/param[name='port_list_id']/value}"/>
            </xsl:if>
            <xsl:if test="/wizard/params/param[name='ssh_credential']/value != ''">
              <ssh_lsc_credential id="{/wizard/params/param[name='ssh_credential']/value}">
                <port>
                  <xsl:choose>
                    <xsl:when test="/wizard/params/param[name='ssh_port']/value != ''">
                      <xsl:value-of select="/wizard/params/param[name='ssh_port']/value"/>
                    </xsl:when>
                    <xsl:otherwise>22</xsl:otherwise>
                  </xsl:choose>
                </port>
              </ssh_lsc_credential>
            </xsl:if>
            <xsl:if test="/wizard/params/param[name='smb_credential']/value != ''">
              <smb_lsc_credential id="{/wizard/params/param[name='smb_credential']/value}"/>
            </xsl:if>
            <xsl:if test="/wizard/params/param[name='esxi_credential']/value != ''">
              <esxi_lsc_credential id="{/wizard/params/param[name='esxi_credential']/value}"/>
            </xsl:if>
          </create_target>
        </xsl:template>
      </xsl:stylesheet>
    </command>
  </step>
  <step>
    <command>
      <xsl:stylesheet
          version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output
          method="xml"
          encoding="UTF-8"/>
        <xsl:template match="/">
          <create_task>
            <name>Immediate scan of IP <xsl:value-of select="/wizard/params/param[name='hosts']/value"/></name>
            <target id="{/wizard/previous/response/create_target_response/@id}"/>
            <xsl:choose>
              <xsl:when test="/wizard/params/param[name='config_id']/value != ''">
                <config id="{/wizard/params/param[name='config_id']/value}"/>
              </xsl:when>
              <xsl:otherwise>
                <config id="daba56c8-73ec-11df-a475-002264764cea"/>
              </xsl:otherwise>
            </xsl:choose>

            <xsl:if test="/wizard/params/param[name='alert_id']/value != ''">
              <alert id="{/wizard/params/param[name='alert_id']/value}"/>
            </xsl:if>

            <xsl:if test="/wizard/params/param[name='scanner_id']/value != ''">
              <scanner id="{/wizard/params/param[name='scanner_id']/value}"/>
            </xsl:if>

            <xsl:if test="/wizard/params/param[name='slave_id']/value != ''">
              <slave id="{/wizard/params/param[name='slave_id']/value}"/>
            </xsl:if>
          </create_task>
        </xsl:template>
      </xsl:stylesheet>
    </command>
  </step>
  <step>
    <command>
      <xsl:stylesheet
          version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output
          method="xml"
          encoding="UTF-8"/>
        <xsl:template match="/">
          <start_task task_id="{/wizard/previous/response/create_task_response/@id}"/>
        </xsl:template>
      </xsl:stylesheet>
    </command>
  </step>

  <mode>
    <name>init</name>
    <read_only>1</read_only>
    <step>
      <command>
        <xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:output
            method="xml"
            encoding="UTF-8"/>
          <xsl:template match="/">
            <get_settings />
          </xsl:template>
        </xsl:stylesheet>
      </command>
    </step>
  </mode>
</wizard>
