Advertisement
Guest User

Untitled

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