<!-- Faraday Penetration Test IDE -->
<!-- Copyright (C) 2013  Infobyte LLC (http://www.infobytesec.com/) -->
<!-- See the file 'doc/LICENSE' for the license information -->

<form name="form" novalidate>
    <div class="modal-header">
        <div class="modal-button">
            <button class="btn btn-success" ng-click="modal.ok()" ng-disabled="form.$invalid || modal.data.severity === undefined || (modal.data.type === 'VulnerabilityWeb' && modal.host_parents) || modal.data.parents.length == 0">OK</button>
            <button class="btn btn-danger" ng-click="modal.cancel()">Cancel</button>
        </div>
        <h3 class="modal-title">Vulnerability creation</h3>
    </div>
    <div class="modal-body">
        <div class="form-horizontal">
            <h5>Target</h5>
            <div class="form-group">
                <div class="col-md-10">
                    <div class="form-group input-accordion">
                        <input type="text" ng-model="modal.target_filter" class="form-control input-sm" placeholder="Search targets" ng-change="modal.currentPage = 0">
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="btn-group btn-small-margin">
                        <button type="button" class="btn btn-default btn-sm" title="Select page" ng-click="modal.setTargets(true, modal.currentPage*modal.pageSize, modal.pageSize)">
                            Select page
                        </button>
                        <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" title="Select options">
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            <li ng-show="modal.target_filter && modal.targets_filtered.length > 0">
                                <a class="ws" ng-click="modal.setTargets(true, 0, modal.targets_filtered.length)">Select all hosts in search</a>
                            </li>
                            <li>
                                <a class="ws" ng-click="modal.setTargets(false, 0, modal.targets.length)">Select all hosts</a>
                            </li>
                            <li>
                                <a class="ws" ng-click="modal.setTargets(false, 0, 0)">Clear selection</a>
                            </li>
                        </ul>
                    </div><!-- .btn-group -->
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <uib-accordion close-others="true">
                        <uib-accordion-group is-open="isopen" ng-repeat="host in modal.targets_filtered = (modal.targets | filter:modal.target_filter) | startFrom:modal.currentPage*modal.pageSize | limitTo:modal.pageSize" template-url="scripts/statusReport/partials/accordion-group.html" is-disabled="host.services.length < 1">
                            <uib-accordion-heading>
                                <a ng-click="modal.setTarget(host)" ng-class="{'multi-selected': modal.data.parents.indexOf(host) >= 0}">{{host.name}} ({{host.hostnames[0]}})</a>
                            </uib-accordion-heading>
                            <div class="panel-body" ng-repeat="service in host.services">
                                <a ng-model="service" ng-click="modal.setTarget(service)" ng-class="{'multi-selected': modal.data.parents.indexOf(service) >= 0}">{{service.name}}  {{service.ports}}</a>
                            </div>
                        </uib-accordion-group>
                    </uib-accordion>
                    <div class="showPagination" ng-show="modal.targets_filtered.length > modal.pageSize">
                        <div class="form-group">
                            <ul class="pagination">
                                <li><a ng-hide="modal.currentPage <= 0" ng-click="modal.currentPage = modal.currentPage - 1"><span aria-hidden="true">&laquo;</span><span class="sr-only">Previous</span></a></li>
                                <li><a>{{modal.currentPage+1}}/{{ ((modal.targets_filtered.length / modal.pageSize) | integer) + 1}}</a></li>
                                <li><a ng-hide="modal.currentPage >= ((modal.targets_filtered.length / modal.pageSize) | integer)" ng-click="modal.currentPage = modal.currentPage + 1"><span aria-hidden="true">&raquo;</span><span class="sr-only">Next</span></a></li>
                            </ul>
                            <ng-form name="goToPage">
                                <div class="col-md-2">
                                    <input type="number" class="form-control" ng-model="modal.newCurrentPage" placeholder="Go to page"/>
                                </div>
                                <button class="btn btn-danger" ng-click="modal.go()">GO</button>
                            </ng-form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="alert alert-danger target_not_selected" role="alert" ng-hide="modal.data.parents.length > 0">
                <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
                <span class="sr-only">Error:</span>
                There is no target selected
                </div>
            <div class="alert alert-danger target_not_selected" role="alert" ng-show="modal.data.type === 'VulnerabilityWeb' && modal.host_parents">
                <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
                <span class="sr-only">Error:</span>
                Trying to create a Web Vulnerability with one or more Host parents. Please deselect the Host targets or <a href="" ng-click="modal.resetTarget()">click here to deselect all targets</a>
            </div>
        </div>

        <div class="form-horizontal">
            <div class="form-group">
                <div class="col-md-12">
                    <h5>Search vulnerability database templates <a href="https://github.com/infobyte/faraday/wiki/vulnerabilities-database" target="_blank"><span class="glyphicon glyphicon-question-sign" title="Read more about vulnerability templates in the official Faraday Documentation"></span></a></h5>
                    <input type="text" ng-model="modal.cwe_selected" class="form-control input-sm" placeholder="Search for vulnerability templates" uib-typeahead="cwe as cwe.name for cwe in modal.cweList | filter:{name: $viewValue} | limitTo:10" typeahead-on-select="modal.populate($item, $model, $label)">
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4">
                    <h5>Type</h5>
                    <select class="form-control" ng-model="modal.data.type" ng-options="option.value as option.name for option in modal.vuln_types">
                    </select>
                </div>
                <div class="col-md-4 severities">
                    <h5>Severity</h5>
                    <button type="button" class="btn btn-default dropdown-toggle color-{{modal.data.severity}}" name="severity" data-toggle="dropdown" title="Change severity" ng-class="{'button-error': modal.data.severity === undefined}">
                    {{modal.data.severity || 'Add severity'}} <span class="caret"></span>
                    </button>
                    <ul id="nav" class="dropdown-menu dropdown-menu-left" role="menu">
                        <li ng-repeat="s in modal.severities"><a href="" class="ws color-{{s}}" ng-click="modal.data.severity=s">{{s}}</a></li>
                    </ul><!-- WS navigation -->
                </div>
                <div class="col-md-4">
                    <h5>Ease of Resolution</h5>
                    <select class="form-control" ng-model="modal.data.easeofresolution" ng-options="e for e in modal.easeofresolution">
                        <option value=""></option>
                    </select>
                </div>
            </div><!-- .form-group -->
            <div class="form-group" ng-class="{'has-error': form.name.$invalid }">
                <div class="col-md-12">
                    <label class="sr-only" for="vuln-name">Vuln name</label>
                    <input type="text" class="form-control" id="vuln-name" name="name" placeholder="Name" ng-model="modal.data.name" required/>
                </div>
            </div><!-- .form-group -->
            <div class="form-group" ng-class="{'has-error': form.desc.$invalid }">
                <div class="col-md-12">
                    <label class="sr-only" for="vuln-desc">Vuln description</label>
                    <textarea class="form-control" id="vuln-desc" name="desc" placeholder="Description" ng-model="modal.data.desc" required></textarea>
                </div>
            </div><!-- .form-group -->
            <div class="form-group">
                <div class="col-md-12">
                    <label class="sr-only" for="vuln-data">Vuln data</label>
                    <textarea class="form-control" id="vuln-data" placeholder="Data" ng-model="modal.data.data"></textarea>
                </div>
            </div><!-- .form-group -->
            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group margin-bottom-sm">
                        <label class="sr-only" for="vuln-refs">References</label>
                        <input type="text" class="form-control" id="vuln-refs" placeholder="Reference" ng-model="modal.new_ref"/>
                        <span class="input-group-addon cursor" ng-click="modal.newReference()"><i class="fa fa-plus-circle"></i></span>
                    </div>
                </div>
                <div class="col-md-12 reference" ng-repeat="reference in modal.data.refs">
                    <div class="input-group margin-bottom-sm">
                        <label class="sr-only" for="vuln-refs">References</label>
                        <input type="text" class="form-control" id="vuln-refs" placeholder="Reference" ng-model="reference.value" disabled/>
                        <span class="input-group-addon cursor" ng-click="modal.data.refs.splice($index, 1)"><i class="fa fa-minus-circle"></i></span>
                    </div>
                </div>
            </div><!-- .form-group -->
            <div class="form-group">
                <div class="col-md-12">
                    <label class="sr-only" for="vuln-resolution">Vuln Resolution</label>
                    <textarea class="form-control" id="vuln-resolution" placeholder="Resolution" ng-model="modal.data.resolution"></textarea>
                </div>
            </div><!-- .form-group -->
            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group margin-bottom-sm">
                        <label class="sr-only" for="vuln-policyviolations">Policy Violations</label>
                        <input type="text" class="form-control" id="vuln-policyviolations" placeholder="Policy Violations" ng-model="modal.new_policyviolation"/>
                        <span class="input-group-addon cursor" ng-click="modal.newPolicyViolation()"><i class="fa fa-plus-circle"></i></span>
                    </div>
                </div>
                <div class="col-md-12 reference" ng-repeat="policyviolation in modal.data.policyviolations">
                    <div class="input-group margin-bottom-sm">
                        <label class="sr-only" for="vuln-policyviolations">Policy Violation</label>
                        <input type="text" class="form-control" id="vuln-policyviolations" placeholder="Policy Violation" ng-model="policyviolation.value" disabled/>
                        <span class="input-group-addon cursor" ng-click="modal.data.policyviolations.splice($index, 1)"><i class="fa fa-minus-circle"></i></span>
                    </div>
                </div>
            </div><!-- .form-group -->
        </div>

        <div class="animate-switch-container" ng-switch on="modal.data.type">
            <div class="animate-switch" ng-switch-when="VulnerabilityWeb">
                <div class="form-horizontal">
                    <div class="form-group">
                        <div class="col-md-4">
                            <label class="sr-only control-label" for="vuln-method">Method</label>
                            <input type="text" class="form-control" id="vuln-method" placeholder="Method" ng-model="modal.data.method"/>
                        </div>
                        <div class="col-md-3">
                            <label class="sr-only control-label" for="vuln-pname">Param Name</label>
                            <input type="text" class="form-control" id="vuln-pname" placeholder="Param name" ng-model="modal.data.pname"/>
                        </div>
                        <div class="col-md-5">
                            <label class="sr-only control-label" for="vuln-params">Params</label>
                            <input type="text" class="form-control" id="vuln-params" placeholder="Params" ng-model="modal.data.params"/>
                        </div>
                    </div><!-- .form-group -->
                    <div class="form-group">
                        <div class="col-md-4">
                            <label class="sr-only control-label" for="vuln-path">Path</label>
                            <input type="text" class="form-control" id="vuln-path" placeholder="Path" ng-model="modal.data.path"/>
                        </div>
                        <div class="col-md-4">
                            <label class="sr-only control-label" for="vuln-query">Query</label>
                            <input type="text" class="form-control" id="vuln-query" placeholder="Query" ng-model="modal.data.query"/>
                        </div>
                        <div class="col-md-4">
                            <label class="sr-only control-label" for="vuln-website">Website</label>
                            <input type="text" class="form-control" id="vuln-website" placeholder="Website" ng-model="modal.data.website"/>
                        </div>
                    </div><!-- .form-group -->
                    <div class="form-group">
                        <div class="col-md-12">
                            <label class="sr-only control-label" for="vuln-request">Request</label>
                            <textarea class="form-control" id="vuln-request" placeholder="Request" ng-model="modal.data.request"></textarea>
                        </div>
                    </div><!-- .form-group -->
                    <div class="form-group">
                        <div class="col-md-12">
                            <label class="sr-only control-label" for="vuln-response">Response</label>
                            <textarea class="form-control" id="vuln-response" placeholder="Response" ng-model="modal.data.response"></textarea>
                        </div>
                    </div><!-- .form-group -->
                </div><!-- .form-horizontal -->
            </div><!-- .animate-switch -->
            <div class="animate-switch" ng-switch-when="Vulnerability"></div>
        </div><!-- .animate-switch-container -->

        <h4>Impact</h4>
        <div ng-repeat="(key, value) in modal.data.impact" class="normal-size" style="cursor: pointer;">
            <h4><span ng-class="{'label label-default': !value, 'label label-success': value}" ng-click="modal.toggleImpact(key)">{{key}}</span></h4>
        </div><!-- .normal-size -->

        <h4>Evidence</h4>
        <div class="alert alert-danger normal-size" role="alert" ng-if="modal.file_name_error">
          <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
          <span class="sr-only">Error:</span>
          Cannot upload evidence starting with underscore, please choose a different name for the file.
        </div>
        <div class="form-group normal-size">
            <input type="file" id="evidence" ng-file-select ng-multiple="true" resetOnClick="false" ng-file-change="modal.selectedFiles($files, $event)"/>
            <p class="help-block">Multiple files are allowed.</p>
        </div><!-- .form-group -->
        <div id="evidenceFiles" class="normal-size" ng-if="modal.data._attachments">
            <ul>
                <li ng-repeat="e in modal.data._attachments | orderObjectBy:'name':true | orderBy:'name'">
                    <div class="btn-group">
                        <button type="button" class="btn btn-default">
                            <span class="fa {{icons[e.name]}}" title="Evidence {{e.name}}"></span> {{e.name}}
                        </button><!-- ng-repeat -->
                        <button type="button" class="btn btn-danger" ng-click="modal.removeEvidence(e.name)">
                            <span class="glyphicon glyphicon-trash"></span>
                        </button>
                    </div>
                </li>
            </ul>
        </div><!-- #evidenceFiles -->
    </div><!-- .modal-body -->
    <div class="modal-footer">
        <div class="modal-button">
            <button class="btn btn-success" ng-click="modal.ok()" ng-disabled="form.$invalid || modal.data.severity === undefined || (modal.data.type === 'VulnerabilityWeb' && modal.host_parents) || modal.data.parents.length == 0">OK</button>
            <button class="btn btn-danger" ng-click="modal.cancel()">Cancel</button>
        </div>
    </div>
</form>
