Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. $proxmox = new Proxmox($credentials);
  2. $firewall = $proxmox->get('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules');
  3. if (isset($_REQUEST['position'])) {
  4. for ($i = 0; !empty($firewall['data']); $i++, $firewall = $proxmox->get('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules')) {
  5. $proxmox->delete('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules/' . $firewall['data'][$i]['pos']);
  6. }
  7. print_r($_REQUEST);
  8. for ($i = 0; isset($_REQUEST['type'][$i]); $i++) {
  9. if (!isset($_REQUEST['check'][$i])) $_REQUEST['check'][$i] = 0;
  10. if ((is_numeric($_REQUEST['position'][$i]) && $_REQUEST['position'][$i] >= 0 && $_REQUEST['position'][$i] < 100) && ($_REQUEST['check'][$i] == 1 || $_REQUEST['check'][$i] == 0) &&
  11. ($_REQUEST['type'][$i] == 'in' || $_REQUEST['type'][$i] == 'out') && ($_REQUEST['proto'][$i] == 'tcp' || $_REQUEST['proto'][$i] == 'udp' || $_REQUEST['proto'][$i] == 'icmp') &&
  12. ($_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)) {
  13. $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]);
  14. $proxmox->create('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules', $variables);
  15. }
  16. }
  17. }
  18. $firewall = $proxmox->get('/nodes/' . $node . '/qemu/' . $vmid . '/firewall/rules');
  19. ?>
  20. <html><head>
  21. <link rel="stylesheet" href="css/panel.css" type="text/css" />
  22. <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
  23. <script>
  24. function clonar(num) {
  25. html = '<td style="width: 150px;"><button class="boton" type="button" onclick="javascript: deleteRule(' + num + ');">Eliminar Regla</button></td>';
  26. html = html + '<td><label for="position" style="color: white;">Posici&oacute;n: </label><input style="width: 60px; height: 45px;" type="num" min="0" max="100" value="' + num + '" name="position[]"></td>';
  27. 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>';
  28. html = html + '<td><select name="type[]" style="height: 45px;"><option value="in">Entrada</option><option value="out">Salida</option></select></td>';
  29. 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>';
  30. 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>';
  31. 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>';
  32. $("#newrule").html(html);
  33. }
  34. </script>
  35. </head><body>
  36. <form action="firewall.php?id=<?php echo $id; ?>" method="POST">
  37. <table>
  38. <?php for ($i = 0; isset($firewall['data'][$i]['pos']); $i++) { ?>
  39. <tr class="terre">
  40. <td style="width: 150px;"><button class="boton" type="button" onclick="javascript: deleteRule(<?php echo $i; ?>);">Eliminar Regla</button></td>
  41. <td><label for="position" style="color: white;">Posici&oacute;n: </label><input style="width: 60px; height: 45px;" type="num" min="0" max="100" value="<?php echo $firewall['data'][$i]['pos']; ?>" name="position[]"></td>
  42. <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>
  43. <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>
  44. <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>
  45. <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>
  46. <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>
  47. <?php } ?>
  48. <tr id="newrule" class="terre">
  49. </table>
  50. <button type="button" class="boton" onClick="javascript: clonar(<?php echo $i; ?>);">A&ntilde;adir Regla</button>
  51. <button type="submit" class="boton">Actualizar Reglas</button>
  52. </form>
  53. </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement