Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $proxmox = new Proxmox($credentials);
- $firewall = $proxmox->get('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules');
- if (isset($_REQUEST['position'])) {
- for ($i = 0; !empty($firewall['data']); $i++, $firewall = $proxmox->get('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules')) {
- $proxmox->delete('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules/' . $firewall['data'][$i]['pos']);
- }
- print_r($_REQUEST);
- for ($i = 0; isset($_REQUEST['type'][$i]); $i++) {
- if (!isset($_REQUEST['check'][$i])) $_REQUEST['check'][$i] = 0;
- if ((is_numeric($_REQUEST['position'][$i]) && $_REQUEST['position'][$i] >= 0 && $_REQUEST['position'][$i] < 100) && ($_REQUEST['check'][$i] == 1 || $_REQUEST['check'][$i] == 0) &&
- ($_REQUEST['type'][$i] == 'in' || $_REQUEST['type'][$i] == 'out') && ($_REQUEST['proto'][$i] == 'tcp' || $_REQUEST['proto'][$i] == 'udp' || $_REQUEST['proto'][$i] == 'icmp') &&
- ($_REQUEST['action'][$i] == 'ACCEPT' || $_REQUEST['action'][$i] == 'DROP' || $_REQUEST['action'][$i] == 'REJECT') && (is_numeric($_REQUEST['port'][$i]) && $_REQUEST['port'][$i] >= 0 && $_REQUEST['port'][$i] < 65536)) {
- $variables = array('pos' => $_REQUEST['position'][$i], 'enable' => $_REQUEST['check'][$i], 'type' => $_REQUEST['type'][$i], 'proto' => $_REQUEST['proto'][$i], 'action' => $_REQUEST['action'][$i], 'dport' => $_REQUEST['port'][$i]);
- $proxmox->create('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules', $variables);
- }
- }
- }
- $firewall = $proxmox->get('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules');
- ?>
- <html><head>
- <link rel="stylesheet" href="css/panel.css" type="text/css" />
- <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
- <script>
- function clonar(num) {
- html = '<td style="width: 150px;"><button class="boton" type="button" onclick="javascript: deleteRule(' + num + ');">Eliminar Regla</button></td>';
- html = html + '<td><label for="position" style="color: white;">Posición: </label><input style="width: 60px; height: 45px;" type="num" min="0" max="100" value="' + num + '" name="position[]"></td>';
- html = html + '<td><input type="checkbox" class="css-checkbox" name="check[]" value="1" id="check[]" /><label for="check[]" class="css-label cb0" style="color: white; font-size: medium;">Activo</label></td>';
- html = html + '<td><select name="type[]" style="height: 45px;"><option value="in">Entrada</option><option value="out">Salida</option></select></td>';
- html = html + '<td><select name="proto[]" style="height: 45px;"><option value="tcp">TCP</option><option value="udp" >UDP</option><option value="icmp" >ICMP</option></select></td>';
- html = html + '<td><select name="action[]" style="height: 45px;"><option value="ACCEPT">ACCEPT</option><option value="DROP">DROP</option><option value="REJECT">REJECT</option></select></td>';
- html = html + '<td><label for="port" style="color: white;">Puerto: </label><input style="width: 60px; height: 45px;" type="num" min="1" max="65535" value="1" name="port[]"></td></tr>';
- $("#newrule").html(html);
- }
- </script>
- </head><body>
- <form action="firewall.php?id=<?php echo $id; ?>" method="POST">
- <table>
- <?php for ($i = 0; isset($firewall['data'][$i]['pos']); $i++) { ?>
- <tr class="terre">
- <td style="width: 150px;"><button class="boton" type="button" onclick="javascript: deleteRule(<?php echo $i; ?>);">Eliminar Regla</button></td>
- <td><label for="position" style="color: white;">Posición: </label><input style="width: 60px; height: 45px;" type="num" min="0" max="100" value="<?php echo $firewall['data'][$i]['pos']; ?>" name="position[]"></td>
- <td><input type="checkbox" class="css-checkbox" <?php if ($firewall['data'][$i]['enable'] == 1) echo 'checked="checked" '; ?> name="check[]" value="1" id="check<?php echo $i; ?>" /><label for="check[]" class="css-label cb0" style="color: white; font-size: medium;">Activo</label></td>
- <td><select name="type[]" style="height: 45px;"><option value="in" <?php if ($firewall['data'][$i]['type'] == 'in') echo 'selected="selected" '; ?>>Entrada</option><option value="out" <?php if ($firewall['data'][$i]['type'] == 'out') echo 'selected="selected" '; ?>>Salida</option></select></td>
- <td><select name="proto[]" style="height: 45px;"><option value="tcp" <?php if ($firewall['data'][$i]['proto'] == 'tcp') echo 'selected="selected" '; ?>>TCP</option><option value="udp" <?php if ($firewall['data'][$i]['proto'] == 'udp') echo 'selected="selected" '; ?>>UDP</option><option value="icmp" <?php if ($firewall['data'][$i]['proto'] == 'icmp') echo 'selected="selected" '; ?>>ICMP</option></select></td>
- <td><select name="action[]" style="height: 45px;"><option value="ACCEPT" <?php if ($firewall['data'][$i]['action'] == 'ACCEPT') echo 'selected="selected" '; ?>>ACCEPT</option><option value="DROP" <?php if ($firewall['data'][$i]['action'] == 'DROP') echo 'selected="selected" '; ?>>DROP</option><option value="REJECT" <?php if ($firewall['data'][$i]['action'] == 'REJECT') echo 'selected="selected" '; ?>>REJECT</option></select></td>
- <td><label for="port" style="color: white;">Puerto: </label><input style="width: 60px; height: 45px;" type="num" min="1" max="65535" value="1" name="port[]"></td></tr>
- <?php } ?>
- <tr id="newrule" class="terre">
- </table>
- <button type="button" class="boton" onClick="javascript: clonar(<?php echo $i; ?>);">Añadir Regla</button>
- <button type="submit" class="boton">Actualizar Reglas</button>
- </form>
- </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement