Untitled

                Never    
HTML
       
<?php
require_once './models/UserDTO.php';
require_once './models/UserDAO.php';
session_start();

if (isset($_SESSION['user'])) {
    $user = $_SESSION['user'];
    ?>
    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Manage</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
              integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
              crossorigin="anonymous">

        <script type="text/javascript">
            function check() {
                var checkboxes = document.getElementsByName('ips[]');
                var button = document.getElementById('check_all');

                if (button.value == 'Select all') {
                    for (var i in checkboxes) {
                        checkboxes[i].checked = 'false';
                    }
                    button.value = 'Deselect all';
                } else {
                    for (var i in checkboxes) {
                        checkboxes[i].checked = '';
                    }
                    button.value = 'Select all';
                }
            }
        </script>
    </head>
    <body>

    <nav class="navbar navbar-default navbar-expand-lg navbar-dark bg-dark fixed-top">
        <div class="container-fluid">
            <a class="navbar-brand" href="index">Dashboard</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
                    aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item active">
                        <a class="nav-link" href="manage">Manage servers <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="import">Add servers</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="scan">Scanning results</a>
                    </li>
                    <?php
                    if ($user->getUsername() === 'admin') {
                        ?>
                        <li class="nav-item">
                            <a class="nav-link" href="users">Manage users</a>
                        </li>
                        <?php
                    }
                    ?>
                </ul>
                <div class="text-light mr-4">Hello <?php
                    echo $user->getUsername();
                    ?></div>
                <form class="form-inline my-2 my-lg-0" action="index" method="post">
                    <input type="submit" class="btn btn-danger" value="Logout" name="action">
                </form>
            </div>
        </div>
    </nav>

    <div class="container">
        <div class="row justify-content-center" style="margin-top: 15%">
            <table class="table table-striped text-center">
                <thead>
                <tr>
                    <th>
                        <div class="input-group">
                            <input type="button" value="Select all" id="check_all" onclick="check()">
                        </div>
                    </th>
                    <th>User</th>
                    <th>Server (IP)</th>
                    <th>Action</th>
                </tr>
                </thead>
                <tbody>
                <?php
                $dao = new UserDAO();
                foreach ($dao::serverListing($user->getUsername()) as $item) {
                    ?>
                    <tr>
                        <td>
                            <div class=" input-group input-group-prepend">
                                <div class="input-group-text">
                                    <input type="checkbox" name="ips" value="<?= $item['ip'] ?>">
                                    <input type="checkbox" name="user" value="<?= $item['username'] ?>"
                                           >
                                </div>
                            </div>
                        </td>
                        <td><?php echo $item['username'] ?></td>
                        <td><?php echo $item['ip'] ?></td>
                        <td>
                            <form action="scan" method="get">
                                <input type="hidden" name="ip" value="<?= $item['ip'] ?>">
                                <input type="hidden" name="username" value="<?= $item['username'] ?>">
                                <input type="submit" value="Show result" name="action" class="btn btn-info mr-3">
                                <input type="submit" value="Scan port" name="action" class="btn btn-info">
                            </form>
                        </td>
                    </tr>
                    <?php
                }
                ?>

                </tbody>
            </table>
        </div>

        <div class="row justify-content-center mt-5 mb-3">
            <input type="submit" id="scan_selected_ports" value="Scan selected ports" class="btn btn-info mr-5"
                   name="action">
            <input type="button" value="Add new server" class="btn btn-dark" onclick="window.location.href='import'">
        </div>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script>
            $(document).ready(function () {
                $("#scan_selected_ports").click(function () {
                    var ips_list = [];
                    var users = [];

                    $.each($("input[name='ips']:checked"), function () {
                        ips_list.push($(this).val());
                        if(this.checked) {
                            $.each($("input[name='user']"), function () {
                                // this.checked = true;
                                users.push($(this).val());
                            });
                        }
                    });

                    console.log(ips_list, users);
                    $.ajax({
                        type: 'GET',
                        url: 'http://lvh.me/nmap/scan',
                        data: {
                            'ips_list': ips_list,
                            'username': users,
                            'action': 'Scan selected ports'
                        },
                        success: function (msg) {
                            alert("Success");
                            //console.log(msg);
                        }
                    });
                });
            });

        </script>
    </body>
    </html>
    <?php

} else {
    header('Location: login');
}